View Single Post
  #10   Spotlight this post!  
Unread 12-02-2015, 12:21
cstelter cstelter is offline
Programming Mentor
AKA: Craig Stelter
FRC #3018 (Nordic Storm)
Team Role: Mentor
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Mankato, MN
Posts: 77
cstelter will become famous soon enough
Re: Pd loop autonomous

Just to be clear-- I've posted a lot of code about an idea about how to manage a state machine in Autonomous, but I don't advocate that. I don't discourage anyone from inventing their own state machine in any way, it can be fun and useful learning experience. But if your goal is to get up and running as quickly as possible with a robust way to manage autonomous, my vote is with RobotBuilder -> Java/C++ using Commands and subsystems.

Someone can correct me if I am wrong-- I don't *think* you even need to organize your motors into subsystems if you don't want to-- you can probably use commands without any calls to requires(mySubsytem). Of course it is then up to you to insure you don't schedule two commands using the same motors or unpredictable results may occur. But there is great benefit in being able to schedule a new command when an event happens only to interrupt a previously scheduled command that needs the same subsystem. Still, I'm pretty sure you can get the benefit of command sequencing without absolutely having to use subsystems. You just may shoot yourself in the foot more easily than with them.

Benefits of Commands:
  • You can sequence as many commands together as you like
  • You can schedule two commands to run in parallel (provided they require separate subsystems).
  • You can group commands together and schedule the full group in sequence by another group.
  • It is a far more robust way to create a sequence of events than any state machine, is well tested by many teams each year, and once you wrap your head around the paradigm, imo is the fastest way to build up extremely complex sequences of autonomous code.
  • prexisting commands like WaitCommand(time) exist that you don't even have to write.
  • Specialied commands like PIDCommand or setpoint command will instantiate nearly fully written from RobotBuilder.
  • The same commands can be easily tied to any joystick button whileHeld, whenPressed, whenRelease, etc. So the same command you write for autonomous (placeTote, liftTote, etc.) can be tied to a button for teleop.

To get up and running using Commands:
  1. You must run call Scheduler.getInstance().run() in your autonomousPeriodic and teleopPeriodic methods.
  2. You must build up your autonomous sequence as a Command group with as many commands sequenced within it as you like, and schedule it to start during AutonomousInit.
  3. Each command needs code for construction, initialization, execution, and how it determines when it is done running. If required, you can also provide code for each time your command ends and each time your command is interrupted by another command.
  4. For Teleop, if you use subsystems, you can assign a default command to the subsystem and the system will automatically schedule those commands to run. If you don't use subsystems (assuming that can actually work as I'm guessing), then it is up to you to schedule all commands you want to run during teleopInit().
Reply With Quote