Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/DCMotor
- Timestamp:
- Oct 31, 2019, 6:25:49 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/DCMotor
v1 v2 1 1 == DC Motor Control 2 For stronger and faster movement, FRC robots use all sorts of motors. There are large motors that propel the robot, small motors that drive flywheel or manipulators, etc. Most DC motors use more power than can be supplied directly from the !RoboRIO so instead the roboRIO communicates with a dedicated high-power motor controller and tells it how fast and in which direction to move the motor. FRC robots support several types of motor controllers; a common and powerful controller is the [https://www.andymark.com/products/talon-srx-speed-controller Talon SRX] often called a CAN Talon.2 For stronger and faster movement, FRC robots use all sorts of motors. There are large motors that propel the robot, small motors that drive flywheels or manipulators, etc. Most DC motors use more power than can be supplied directly from the !RoboRIO so instead the roboRIO communicates with a dedicated high-power motor controller and tells it how fast and in which direction to move the motor. FRC robots support several types of motor controllers, but there are two main types: simple PWM motor controllers like the Talon SR and intelligent motor controllers such as the [https://www.andymark.com/products/talon-srx-speed-controller Talon SRX] (aka CAN Talon). 3 3 4 Create another program using the !TimedRobot java template and name it !MotorTest. 4 PWM motor controllers are connected to one of the PWM output ports on the roboRIO. PWM stands for pulse-width modulation and communicates how much battery power to deliver to the motor ranging from -100% (full reverse) to +100% (full forward) or anything in-between. Intelligent motor controllers contain their own microprocessor that can perform sophisticated management of the motor such as keeping it at a particular speed or following a motion profile or keeping a motor in a particular position (e.g. rotated to 30-degrees); we'll talk more about their capabilities later and you can read about them [https://buildmedia.readthedocs.org/media/pdf/phoenix-documentation/latest/phoenix-documentation.pdf here]. 5 6 Create another program using the !TimedRobot java template and name it !MotorTest: 5 7 6 The motor controller Class 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]. To use the library, you need to add it to the project: 8 === Smart Motor Controller Example (Macadamia) 9 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]. 11 12 To use this class, you need to add it to the !MotorTest project: 7 13 * WPILib->Manage Vendor Libraries 8 14 * -> Install new library (offline) 9 15 * -> Select ctre phoneix library (or similar) 10 16 11 Modify the generatedcode as follows:17 Modify the auto-generated template code as follows: 12 18 13 19 * Add the following imports: 14 20 {{{ 15 import edu.wpi.first.wpilibj.XboxController;16 import edu.wpi.first.wpilibj.GenericHID.Hand;17 import com.ctre.phoenix.motorcontrol.can.*;21 import edu.wpi.first.wpilibj.XboxController; 22 import edu.wpi.first.wpilibj.GenericHID.Hand; 23 import com.ctre.phoenix.motorcontrol.can.*; 18 24 }}} 19 25 * 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 … … 23 29 }}} 24 30 * in robotInit() instantiate the controller and motor controller objects 25 26 27 28 31 {{{ 32 xbox = new XboxController(0); // Xbox controller on port 0 33 m_rearLeft = new WPI_TalonSRX(4); // CAN Talon ID 4 34 }}} 29 35 * in teleopPeriodic() read the xbox controller and adjust the DC motor accordingly 30 31 32 33 34 35 36 37 38 36 {{{ 37 // Read xbox controller left joystick x axis 38 // value returned is between -1.0 and 1.0 39 double x = xbox.getX(Hand.kLeft); 40 // DC Motor controllers apply between -1.0 (full reverse) 41 // 0=stop and +1.0 (full forward) power 42 // Set motor speed based on joystick 43 m_rearLeft.set(x); 44 }}} 39 45 40 Note: you'll need to press the Enable button on the driver station to put the robot in Teleop mode so that teleopPeriodic() is called repeatedly. 46 === PWM Motor Controller Example (Hazelnut) 47 ...Coming Soon... 48 49 === Running the Program 50 51 After you launch the driver station, you'll need to select Teleop mode and then press the Enable button. When you enable teleop mode, teleopInit() is called once and then teleopPeriodic() is called repeatedly until you disable the robot. 41 52 42 53 * Extra Credit: use the left joystick Y axis to control the left motor power and the right joystick Y axis to control the right motor power...now you have a driveable robot!