Help Programming Autonomous

Hello all,

So first off I am using the command based robot template from WPI, and I need to create a command group that will be run during our autonomous period. We are just going to shoot the balls that are in our robot and that’s it for autonomous, nothing complicated.

Basically what I need the robot to do is:

  1. Begin running shooter motor (this will be running throughout autonomous)
  2. Wait 3 seconds or so (for motor to spin up)
  3. run our ball delivery motor for ~1.5 sec
  4. stop ball delivery motor
  5. Run conveyor motor to put 2nd ball in place
  6. run ball delivery motor again
  7. stop motors

I have commands written to do all of these functions, I just need a way to put them together into a command group with a delay in-between. Can anyone offer any guidance that has worked with the command based template?

This was for a slightly different issue, but it explains the ideas required and provides CommandSequence, which you might find useful yourself!

There is WaitCommand() for the delay part. And you already have the other commands written as you note above. The next step is to create a new class that extends CommandGroup and add all the commands to it.

Ok so this is what I have set up, will the Timer.delay(3) delay the next command from running for three seconds, or do I have to use something else?

public class AutonomousCommand extends CommandGroup {

public AutonomousCommand() {
    addParallel(new AutonomousShoot());
    Timer.delay(3);
    addSequential(new AutonomousDeliver());
    addSequential(new AutonomousConveyor());
    addSequential(new AutonomousDeliver());
    addSequential(new AllStop());

100% don’t do that! You’ll end up pausing all commands for 3 seconds…

Instead of Timer.delay(3), you want addSequential(new WaitCommand(3));

haha alright thanks, new programmer here so I don’t exactly know what everything does. Didn’t know there was such a thing as WaitCommand() but thanks!

Alright so I got a chance to test the autonomous today and it doesn’t work. What happens is that when I run the shooter motor runs but then the delivery wheel runs right away as well. The wait command doesn’t seem to be doing anything and the other commands don’t timeout when they are supposed to. (I have the others using setTimeout()).

Can anyone offer any insight into what might be going wrong?

As far as timeOuts for commands, although you are setting the timeout, did you change the isFinished() method to read “return isTimedOut();” I had an issue with this before i buckled down and decided to actually read the documentation more thoroughly.

if you want to know what our code looks like, it’s a simple three line command sequence.

addParallel(new TmAutonPrepareShooter(1.0));
addSequential(new WaitCommand(3.0));
addSequential(new TmAutonShootBall(5));

The first command simply sets the shooter to a speed to 1.0 and then returns. The second command is a 3 second delay while the shooter actually gets up to speed (notice that the first command says Parallel, while the second says Sequential). And the last command turns on the motors that feed into the shooter at a slow enough speed to allow time for the shooter to regain it’s momentum. (The parameter is 5 seconds, speed is set within the class). In your case, you are breaking up the two motors that I’m controlling in one command. It seems like you are doing most of this, another thing to check is to make sure the in the end() and interrupted() methods of each command that you are stopping the motors. Not sure if this will solve you problem but I hope it helps.

Thanks! I’ll try to make the changes tonight and see if that fixes the issue tomorrow morning.

I hope you read this before competition, but it’s also good to have initialization code that simply turns everything off when you start each state (teleop, auto and disabled). In each of our subsystems we have an init() method that simply turns off the motors associated with the subsystems and is called in each of the main init methods (teleopInit, autonomousInit and disabledInit). That could explain why your motors are starting up right away, they could be reading leftovers from the last time you were in teleop. But on second thought, this is unlikely after a power cycle, so I’m not sure. Regardless it’s a good practice.

Thanks so much! It worked perfectly. After we got the speed right on the shooter motor we were able to score during autonomous!

No problem! I’m happy I could help! And CONGRATULATIONS on your win!!! That’s AWESOME! Hope to see you guys in St. Louis!

Thanks!! We had an awesome alliance and were able to get 2 triples in the elimination matches. We are so pumped for nationals!

Here’s a pic of our triple.





That’s interesting, I didn’t expect to see many ramp bots this year, but I guess that’s what 1501 did? Also, if you ever have any other questions, feel free to PM me and I’ll try to help as best I can. And if you’re having trouble at nationals stop by our pit and we’ll see if we can help. Best of luck!!