Changes between Initial Version and Version 1 of ControlSystems/SoftwareTeam/Training/GettingStarted/DCMotor


Ignore:
Timestamp:
Oct 30, 2019, 10:37:09 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

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

    v1 v1  
     1== DC Motor Control
     2For 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.
     3
     4Create another program using the !TimedRobot java template and name it !MotorTest.
     5 
     6The 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:
     7* WPILib->Manage Vendor Libraries
     8* -> Install new library (offline)
     9* -> Select ctre phoneix library  (or similar)
     10
     11Modify the generated code as follows:
     12
     13* Add the following imports:
     14{{{
     15import edu.wpi.first.wpilibj.XboxController;
     16import edu.wpi.first.wpilibj.GenericHID.Hand;
     17import com.ctre.phoenix.motorcontrol.can.*;
     18}}}
     19* 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
     20{{{
     21   private XboxController xbox;
     22   private WPI_TalonSRX m_rearLeft;
     23}}}
     24* in robotInit() instantiate the controller and motor controller objects
     25  {{{
     26    xbox = new XboxController(0);     // Xbox controller on port 0
     27    m_rearLeft = new WPI_TalonSRX(4); // CAN Talon ID 4
     28  }}}
     29* in teleopPeriodic() read the xbox controller and adjust the DC motor accordingly
     30  {{{
     31     // Read xbox controller left joystick x axis
     32     // value returned is between -1.0 and 1.0
     33     double x = xbox.getX(Hand.kLeft);
     34     // DC Motor controllers apply between -1.0 (full reverse)
     35     // 0=stop and +1.0 (full forward) power
     36     // Set motor speed based on joystick
     37     m_rearLeft.set(x);
     38  }}}
     39
     40Note: 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.
     41
     42* 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!