Changes between Version 24 and Version 25 of ControlSystems/SoftwareTeam/Training/GettingStarted/IntroRobotJava
- Timestamp:
- Oct 28, 2019, 11:53:15 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/IntroRobotJava
v24 v25 205 205 {{{ 206 206 private Encoder leftEncoder, rightEncoder; 207 207 208 // Uncomment next line for Macademia 208 209 // private Talon leftMotor, rightMotor; … … 227 228 // leftMotor = new WPI_TalonSRX(3); 228 229 // rightMotor = new WPI_TalonSRX(4); 229 }}} 230 * In robotPeriodic() read and display the encoder values 231 {{{ 232 double l_distance = leftEncoder.getDistance(); 233 double r_distance = rightEncoder.getDistance(); 234 SmartDashboard.putNumber("Left", l_distance); 235 SmartDashboard.putNumber("Right", r_distance); 230 231 // to go forward, left motor turns clockwise, right motor counter-clockwise 232 rightMotor.setInverted(true); 233 }}} 234 235 * In robotPeriodic() display the encoder values 236 {{{ 237 SmartDashboard.putNumber("Left", leftEncoder.getDistance()); 238 SmartDashboard.putNumber("Right", rightEncoder.getDistance()); 236 239 }}} 237 240 … … 241 244 leftEncoder.reset(); 242 245 rightEncoder.reset(); 243 // start motors turning at 20% power246 // start motors turning forward at 20% power 244 247 leftMotor.set(0.20); 245 248 rightMotor.set(0.20); 246 249 }}} 247 250 248 * In autonomousPeriodic() check to see if we've gone the desired distance 249 then stop the motors. 250 {{{ 251 if ((leftEncoder.getDistance() > 36.0) || 252 (rightEncoder.getDistance() > 36.0)) { 253 leftMotor.stopMotor(); 254 rightMotor.stopMotor(); 255 } 251 * In the default section of autonomousPeriodic() stop if we've gone the desired distance. 252 Notice our first use of the logical OR operator: '||' 253 {{{ 254 default: 255 if ((leftEncoder.getDistance() > 36.0) || 256 (rightEncoder.getDistance() > 36.0)) { 257 leftMotor.stopMotor(); 258 rightMotor.stopMotor(); 259 } 256 260 }}} 261 262 When you launch the driver station, you'll need to select "Autonomous" mode (look above the Enable button) and then press the Enable button. The autonomousInit() method will run first and then the autonomousPeriodic() method will be called repeatedly until the robot is disabled. If your robot isn't doing what it should be, press the Disable button immediately to stop the robot. 263 264 Why didn't the robot go straight? 265 266 Extra credit: See if you can make it go straight. 267 257 268 258 269 == Study some examples