Autonomous help


#1

We are still developing code and have a question about this year’s autonomous. We are planning to teleop during autonomous, but aren’t sure how to do that. Do we need to copy our teleop code into the autonomous section, or will it simply skip autonomous if nothing is there.


#2

You need to put your teleop code into autonomous


#3

Thanks. That’s what I figured, but wasn’t sure.


#4

You do not need to copy the code. Just put it in a common method that both call or call the teleop methods (init and periodic) from the autonomous methods.

I hope this helps,
Steve


#5

If you are using Command-based robots, the scheduler can be run from autonomous, and that will include scheduling of your default commands.

If you are relying on the periodic methods to execute your code, I would expand what @Waz said and create a matchPeriodic() method that is directly called by both teleopPeriodic() as well as autonomousPeriodic(). That way all of your code will be equally run from both sides.


#6

We are still learning Java. How would we do that? We are not using command based.


#7

In your autonomousInit call teleopInit();

As

  @Override
  public void autonomousInit() {
    teleopInit();
  }

and in autonomousPeriodic call teleopPeriodic();

  @Override
  public void autonomousPeriodic() {
    teleopPeriodic();
    }

#8

Thanks! So that will make everything in teleop init and periodic run during autonomous?


#9

Yep, every time autonInit() is called (once) it will call teleopInit()
and every time autonPeriodic() is called (many many times) it will call teleopPeriodic()


#10

Hopefully this does not confuse you more, but there is a method you can call that will run your code in autonomous and teleop. It’s called robotPeriodic() and it’s part of the Iterative Robot Base class(and inherited into the timedRobot class if you wanted to know). Here is the link to the API doc with it(shows you all the methods in ItertiveRobotBase). Pasting your code into this loop should run the same stuff in both teleop and autonomous. Hope this helps!!