Changes between Version 24 and Version 25 of ControlSystems/SoftwareTeam/Training/GettingStarted/IntroRobotJava


Ignore:
Timestamp:
Oct 28, 2019, 11:53:15 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

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

    v24 v25  
    205205{{{
    206206  private Encoder leftEncoder, rightEncoder;
     207
    207208  // Uncomment next line for Macademia
    208209  // private Talon leftMotor, rightMotor;
     
    227228    // leftMotor = new WPI_TalonSRX(3);
    228229    // 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());
    236239  }}}
    237240
     
    241244    leftEncoder.reset();
    242245    rightEncoder.reset();
    243     // start motors turning at 20% power
     246    // start motors turning forward at 20% power
    244247    leftMotor.set(0.20);
    245248    rightMotor.set(0.20);
    246249  }}}
    247250
    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        }
    256260   }}}
     261
     262When 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
     264Why didn't the robot go straight? 
     265
     266Extra credit: See if you can make it go straight.
     267
    257268
    258269== Study some examples