Changes between Version 2 and Version 3 of ControlSystems/SoftwareTeam/Training/GettingStarted/DCMotor
- Timestamp:
- Oct 31, 2019, 6:40:44 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/DCMotor
v2 v3 6 6 Create another program using the !TimedRobot java template and name it !MotorTest: 7 7 8 === Smart Motor Controller Example ( Macadamia)8 === Smart Motor Controller Example (Hazelnut) 9 9 10 Th e 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].10 This 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]. 11 11 12 To use this class, you need toadd it to the !MotorTest project:12 To use this class, you must add it to the !MotorTest project: 13 13 * WPILib->Manage Vendor Libraries 14 14 * -> Install new library (offline) … … 44 44 }}} 45 45 46 === PWM Motor Controller Example (Hazelnut) 47 ...Coming Soon... 46 === PWM Motor Controller Example (Macadamia) 47 This example is for a robot with a PWM motor controller such as a TalonSR or Spark connected to the !RoboRIO PWM port 1. 48 49 Modify 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 48 77 49 78 === Running the Program