Changes between Version 13 and Version 14 of ControlSystems/SoftwareTeam/Training/GettingStarted/DCMotor
- Timestamp:
- Nov 8, 2019, 11:06:33 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/DCMotor
v13 v14 6 6 Create another program using the !TimedRobot java template and name it !MotorTest: 7 7 8 === Smart (CAN) Motor Controller Example (Hazelnut )8 === Smart (CAN) Motor Controller Example (Hazelnut, Almond) 9 9 10 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]. … … 26 26 {{{ 27 27 private XboxController xbox; 28 private WPI_TalonSRX m_ rearLeft;28 private WPI_TalonSRX m_Left; 29 29 }}} 30 30 * in robotInit() instantiate the controller and motor controller objects 31 31 {{{ 32 xbox = new XboxController(0); 33 m_ rearLeft = new WPI_TalonSRX(4); // CAN Talon ID 432 xbox = new XboxController(0); // Xbox controller on port 0 33 m_Left = new WPI_TalonSRX(4); // CAN Talon ID 4 34 34 }}} 35 35 * in teleopPeriodic() read the xbox controller and adjust the DC motor accordingly 36 36 {{{ 37 // Read xbox controller left joystick xaxis37 // Read game controller left joystick Y axis 38 38 // value returned is between -1.0 and 1.0 39 double x = xbox.getX(Hand.kLeft); 39 40 // For xbox controller uncomment next line 41 double x = xbox.getY(Hand.kLeft); 42 // For F310 controller uncomment next line 43 // double x = -xbox.getRawAxis(1); 44 40 45 // DC Motor controllers apply between -1.0 (full reverse) 41 46 // 0=stop and +1.0 (full forward) power 42 47 // Set motor speed based on joystick 43 m_ rearLeft.set(x);48 m_Left.set(x); 44 49 }}} 45 50 … … 60 65 {{{ 61 66 private XboxController xbox; 62 private Talon m_ rearLeft;67 private Talon m_Left; 63 68 }}} 64 69 * in robotInit() instantiate the controller and motor controller objects 65 70 {{{ 66 71 xbox = new XboxController(0); // Xbox controller on USB port 0 67 m_ rearLeft = new Talon(1);// TalonSR connected to roboRIO PWM 172 m_Left = new Talon(1); // TalonSR connected to roboRIO PWM 1 68 73 }}} 69 74 * in teleopPeriodic() read the xbox controller and adjust the DC motor accordingly 70 75 {{{ 71 // Read xbox controller left joystick xaxis76 // Read game controller left joystick Y axis 72 77 // value returned is between -1.0 and 1.0 73 double x = xbox.getX(Hand.kLeft); 78 79 // For xbox controller uncomment next line 80 double x = xbox.getY(Hand.kLeft); 81 // For F310 controller uncomment next line 82 // double x = -xbox.getRawAxis(1); 83 74 84 // DC Motor controllers apply between -1.0 (full reverse) 75 85 // 0=stop and +1.0 (full forward) power 76 86 // Set motor speed based on joystick 77 m_ rearLeft.set(x);87 m_Left.set(x); 78 88 }}} 79 89