Changes between Version 6 and Version 7 of ControlSystems/SoftwareTeam/Training/GettingStarted/RobotFSM1


Ignore:
Timestamp:
Nov 6, 2019, 2:34:22 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/RobotFSM1

    v6 v7  
    3131 */
    3232public class Robot extends TimedRobot {
    33   private static final String kDefaultAuto = "Default";
    34   private static final String kCustomAuto = "My Auto";
    35   private String m_autoSelected;
    36   private final SendableChooser<String> m_chooser = new SendableChooser<>();
    3733  private Talon l_motor, r_motor;
    3834  private Encoder l_encoder, r_encoder;
    3935
     36  // The possible states for our autonomous behavior
    4037  private enum AutoState { STARTING, DRIVING, TURNING, STOPPED };
     38  // The current state
    4139  private AutoState state;
    4240 
    4341  private void driveForward() {
    44     // to go forward, left and right motors turn in opposite directions
    45     // so wheels turn in same direction
     42    // left and right motors face opposite directions so spin them in
     43    // opposite directions to turn the wheels in the same direction.
    4644    l_motor.set(0.20);
    4745    r_motor.set(-0.20);
    48     // reset encoders so we can tell how far we've driven
     46    // reset wheel encoders so we can tell how far we've driven
    4947    l_encoder.reset();
    5048    r_encoder.reset();
     
    5250
    5351  private void turnRight() {
    54     // to turn, both motors turn in the same direction
    55     // so wheels turn in opposite directions
     52    // left and right motors face opposite directions so spin them in
     53    // the same direction to turn wheels in opposite directions (rotate robot)
    5654    l_motor.set(0.20);
    5755    r_motor.set(0.20);
    58     // reset encoders so we can tell how far we've driven
     56    // reset wheel encoders so we can tell how far we've turned
    5957    l_encoder.reset();
    6058    r_encoder.reset();
     
    7270  @Override
    7371  public void robotInit() {
    74     m_chooser.setDefaultOption("Default Auto", kDefaultAuto);
    75     m_chooser.addOption("My Auto", kCustomAuto);
    76     SmartDashboard.putData("Auto choices", m_chooser);
    7772    // Talon motor controllers connected to PWM ports 0,1
    7873    l_motor = new Talon(0);
     
    9994
    10095  /**
    101    * This autonomous (along with the chooser code above) shows how to select
    102    * between different autonomous modes using the dashboard. The sendable
    103    * chooser code works with the Java SmartDashboard. If you prefer the
    104    * LabVIEW Dashboard, remove all of the chooser code and uncomment the
    105    * getString line to get the auto name from the text box below the Gyro
    106    *
    107    * <p>You can add additional auto modes by adding additional comparisons to
    108    * the switch structure below with additional strings. If using the
    109    * SendableChooser make sure to add them to the chooser code above as well.
    11096   */
    11197  @Override
    11298  public void autonomousInit() {
    113     m_autoSelected = m_chooser.getSelected();
    114     // m_autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto);
    115     System.out.println("Auto selected: " + m_autoSelected);
    11699    state = AutoState.STARTING;
    117100  }