Changes between Version 2 and Version 3 of ControlSystems/SoftwareTeam/Training/GettingStarted/DCMotor


Ignore:
Timestamp:
Oct 31, 2019, 6:40:44 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

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

    v2 v3  
    66Create another program using the !TimedRobot java template and name it !MotorTest:
    77 
    8 === Smart Motor Controller Example (Macadamia)
     8=== Smart Motor Controller Example (Hazelnut)
    99
    10 The smart motor controller class for the TalonSRX is provided by a third party (Cross The Road Electronics aka CTRE); the team laptops already have the CTRE framework installed; if your laptop does not, you can download and install it [http://www.ctr-electronics.com/control-system/hro.html#product_tabs_technical_resources here]. 
     10This example is for a robot that has a TalonSRX motor controller with its CAN bus address set to 3.  A Java Class is available that makes it easy to access the extensive capabilities of the TalonSRX; the class is provided by the manufacturer (Cross The Road Electronics aka CTRE) and must be installed on the laptop and added to the project.  Team laptops already have the CTRE framework installed; if your laptop does not, you can download and install it [http://www.ctr-electronics.com/control-system/hro.html#product_tabs_technical_resources here]. 
    1111
    12 To use this class, you need to add it to the !MotorTest project:
     12To use this class, you must add it to the !MotorTest project:
    1313* WPILib->Manage Vendor Libraries
    1414* -> Install new library (offline)
     
    4444}}}
    4545
    46 === PWM Motor Controller Example (Hazelnut)
    47 ...Coming Soon...
     46=== PWM Motor Controller Example (Macadamia)
     47This example is for a robot with a PWM motor controller such as a TalonSR or Spark connected to the !RoboRIO PWM port 1.
     48
     49Modify the auto-generated template code as follows:
     50
     51* Add the following imports:
     52{{{
     53   import edu.wpi.first.wpilibj.XboxController;
     54   import edu.wpi.first.wpilibj.Talon;
     55}}}
     56* declare variable for the Xbox controller and [https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599703-repeatable-low-power-movement-controlling-servos-with-wpilib servo motor] in the Robot class
     57{{{
     58   private XboxController xbox;
     59   private Talon m_rearLeft;
     60}}}
     61* in robotInit() instantiate the controller and motor controller objects
     62{{{
     63   xbox = new XboxController(0); // Xbox controller on USB port 0
     64   m_rearLeft = new Talon(1);    // TalonSR connected to roboRIO PWM 1
     65}}}
     66* in teleopPeriodic() read the xbox controller and adjust the DC motor accordingly
     67{{{
     68   // Read xbox controller left joystick x axis
     69   // value returned is between -1.0 and 1.0
     70   double x = xbox.getX(Hand.kLeft);
     71   // DC Motor controllers apply between -1.0 (full reverse)
     72   // 0=stop and +1.0 (full forward) power
     73   // Set motor speed based on joystick
     74   m_rearLeft.set(x);
     75}}}
     76
    4877
    4978=== Running the Program