View Single Post
  #17   Spotlight this post!  
Unread 05-02-2015, 12:24
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: How to Program Mecanum

Building on last post--

When you push teleop mode on Drive station, IterativeRobot will call teleopInit() and then call teleopPeriodic() every 20ms.

Similarly when you press Autonomous from drive station, it calls autonomousInit() and then autonomousPeriodic() every 20ms after that.

Your autonomousPeriodic() directly calls your drivetrain so you are making that call every 20ms in autonomous. This is why this mode works for you.

Note, you should *never* call any subsytem functionality from anything but a command. You are only asking for trouble.

Your autonomousPeriodic() *should* be:

Code:
    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }
You should create a command field in your Robot class
Code:
public class Robot extends IterativeRobot {
    Command autonomousCommand;
    ...
and then you can do something like this in autonomousInit:
Code:
    public void autonomousInit() {
        // schedule the autonomous command (example)
        if (autonomousCommand == null) {
            autonomousCommand=new leftStraffe();
        } 
        autonomousCommand.start();
    }
Now, when you run autonomous, we simply run the scheduler. The autonomous starts your leftStraffe command (note, java convention is to name classes with a captial so LeftStraffe may be a better name because you will have to look back less to see how you spelled it if you are consistent with your naming conventions), so that command is now being controlled by the scheduler. It will call execute() which in turn will be the appropriate way call your mecanum drive function.
Reply With Quote