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


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

--

Legend:

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

    v1 v2  
    11== 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.
     2For 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).
    33
    4 Create another program using the !TimedRobot java template and name it !MotorTest.
     4PWM 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
     6Create another program using the !TimedRobot java template and name it !MotorTest:
    57 
    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
     10The 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
     12To use this class, you need to add it to the !MotorTest project:
    713* WPILib->Manage Vendor Libraries
    814* -> Install new library (offline)
    915* -> Select ctre phoneix library  (or similar)
    1016
    11 Modify the generated code as follows:
     17Modify the auto-generated template code as follows:
    1218
    1319* Add the following imports:
    1420{{{
    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.*;
    1824}}}
    1925* 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
     
    2329}}}
    2430* 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   }}}
     31{{{
     32   xbox = new XboxController(0);     // Xbox controller on port 0
     33   m_rearLeft = new WPI_TalonSRX(4); // CAN Talon ID 4
     34}}}
    2935* 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   }}}
     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}}}
    3945
    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
     51After 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.
    4152
    4253* 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!