Changes between Version 6 and Version 7 of ControlSystems/SoftwareTeam/Training/GettingStarted/RobotFSM1
- Timestamp:
- Nov 6, 2019, 2:34:22 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/RobotFSM1
v6 v7 31 31 */ 32 32 public 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<>();37 33 private Talon l_motor, r_motor; 38 34 private Encoder l_encoder, r_encoder; 39 35 36 // The possible states for our autonomous behavior 40 37 private enum AutoState { STARTING, DRIVING, TURNING, STOPPED }; 38 // The current state 41 39 private AutoState state; 42 40 43 41 private void driveForward() { 44 // to go forward, left and right motors turn in opposite directions45 // so wheels turn in same direction42 // left and right motors face opposite directions so spin them in 43 // opposite directions to turn the wheels in the same direction. 46 44 l_motor.set(0.20); 47 45 r_motor.set(-0.20); 48 // reset encoders so we can tell how far we've driven46 // reset wheel encoders so we can tell how far we've driven 49 47 l_encoder.reset(); 50 48 r_encoder.reset(); … … 52 50 53 51 private void turnRight() { 54 // to turn, both motors turn in the same direction55 // so wheels turn in opposite directions52 // left and right motors face opposite directions so spin them in 53 // the same direction to turn wheels in opposite directions (rotate robot) 56 54 l_motor.set(0.20); 57 55 r_motor.set(0.20); 58 // reset encoders so we can tell how far we've driven56 // reset wheel encoders so we can tell how far we've turned 59 57 l_encoder.reset(); 60 58 r_encoder.reset(); … … 72 70 @Override 73 71 public void robotInit() { 74 m_chooser.setDefaultOption("Default Auto", kDefaultAuto);75 m_chooser.addOption("My Auto", kCustomAuto);76 SmartDashboard.putData("Auto choices", m_chooser);77 72 // Talon motor controllers connected to PWM ports 0,1 78 73 l_motor = new Talon(0); … … 99 94 100 95 /** 101 * This autonomous (along with the chooser code above) shows how to select102 * between different autonomous modes using the dashboard. The sendable103 * chooser code works with the Java SmartDashboard. If you prefer the104 * LabVIEW Dashboard, remove all of the chooser code and uncomment the105 * getString line to get the auto name from the text box below the Gyro106 *107 * <p>You can add additional auto modes by adding additional comparisons to108 * the switch structure below with additional strings. If using the109 * SendableChooser make sure to add them to the chooser code above as well.110 96 */ 111 97 @Override 112 98 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);116 99 state = AutoState.STARTING; 117 100 }