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


Ignore:
Timestamp:
Nov 3, 2019, 8:49:18 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

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

    v6 v7  
    5555    SmartDashboard.putNumber("Right", rightEncoder.getDistance());
    5656  }}}
    57   * For CAN motor controllers (Hazelnut) note the use of the [https://www.ctr-electronics.com/downloads/api/java/html/classcom_1_1ctre_1_1phoenix_1_1motorcontrol_1_1can_1_1_base_motor_controller.html#afb934a11682e710df123eec35aba1ba9 getSelectedFeedbackSensor()] method of the motor controller object which returns raw encoder counts. 
     57  * For CAN motor controllers (Hazelnut): 
    5858     * Add the following function to the Robot class:
    5959     {{{
     
    6262        }
    6363     }}}
    64      * Add the following to the robotPeriodic() method:
     64     * Add the following to the robotPeriodic() method;  note the use of the [https://www.ctr-electronics.com/downloads/api/java/html/classcom_1_1ctre_1_1phoenix_1_1motorcontrol_1_1can_1_1_base_motor_controller.html#afb934a11682e710df123eec35aba1ba9 getSelectedFeedbackSensor()] method of the motor controller object which returns raw encoder counts:
    6565     {{{
    6666        // Encoders connected to CAN controller return raw counts
    67         double l_raw = leftMotor.getSelectedSensorPosition();
    68         double r_raw = rightMotor.getSelectedSensorPosition();
     67        int l_raw = leftMotor.getSelectedSensorPosition();
     68        int r_raw = rightMotor.getSelectedSensorPosition();
    6969        // display distances on smart dashboard
    7070        SmartDashboard.putNumber("Left", raw2inches(l_raw, 360*2, 7.5));
     
    9292           rightMotor.stopMotor();
    9393        }
    94    }}}
    95    * For CAN motor controllers:
    96    {{{
    97         double l_raw = leftMotor.getSelectedSensorPosition();
    98         double r_raw = rightMotor.getSelectedSensorPosition();
     94  }}}
     95  * For CAN motor controllers:
     96  {{{
     97        int l_raw = leftMotor.getSelectedSensorPosition();
     98        int r_raw = rightMotor.getSelectedSensorPosition();
    9999        if ((raw2inches(l_raw, 360*2, 7.5) > 36.0) ||
    100100            (raw2inches(r_raw, 360*2, 7.5) > 36.0)) {
     
    102102           rightMotor.stopMotor();
    103103        }
    104    }}}
     104  }}}
    105105
    106106When 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.  It's usually a good idea to test your code with the robot up on a stool or blocks (wheels not touching the ground) in case your code doesn't work properly.