Changes between Version 13 and Version 14 of ControlSystems/SoftwareTeam/Training/GettingStarted/DCMotor


Ignore:
Timestamp:
Nov 8, 2019, 11:06:33 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

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

    v13 v14  
    66Create another program using the !TimedRobot java template and name it !MotorTest:
    77 
    8 === Smart (CAN) Motor Controller Example (Hazelnut)
     8=== Smart (CAN) Motor Controller Example (Hazelnut, Almond)
    99
    1010This 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]. 
     
    2626{{{
    2727   private XboxController xbox;
    28    private WPI_TalonSRX m_rearLeft;
     28   private WPI_TalonSRX m_Left;
    2929}}}
    3030* in robotInit() instantiate the controller and motor controller objects
    3131{{{
    32    xbox = new XboxController(0);     // Xbox controller on port 0
    33    m_rearLeft = new WPI_TalonSRX(4); // CAN Talon ID 4
     32   xbox = new XboxController(0); // Xbox controller on port 0
     33   m_Left = new WPI_TalonSRX(4); // CAN Talon ID 4
    3434}}}
    3535* in teleopPeriodic() read the xbox controller and adjust the DC motor accordingly
    3636{{{
    37    // Read xbox controller left joystick x axis
     37   // Read game controller left joystick Y axis
    3838   // 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 
    4045   // DC Motor controllers apply between -1.0 (full reverse)
    4146   // 0=stop and +1.0 (full forward) power
    4247   // Set motor speed based on joystick
    43    m_rearLeft.set(x);
     48   m_Left.set(x);
    4449}}}
    4550
     
    6065{{{
    6166   private XboxController xbox;
    62    private Talon m_rearLeft;
     67   private Talon m_Left;
    6368}}}
    6469* in robotInit() instantiate the controller and motor controller objects
    6570{{{
    6671   xbox = new XboxController(0); // Xbox controller on USB port 0
    67    m_rearLeft = new Talon(1);    // TalonSR connected to roboRIO PWM 1
     72   m_Left = new Talon(1);        // TalonSR connected to roboRIO PWM 1
    6873}}}
    6974* in teleopPeriodic() read the xbox controller and adjust the DC motor accordingly
    7075{{{
    71    // Read xbox controller left joystick x axis
     76   // Read game controller left joystick Y axis
    7277   // 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 
    7484   // DC Motor controllers apply between -1.0 (full reverse)
    7585   // 0=stop and +1.0 (full forward) power
    7686   // Set motor speed based on joystick
    77    m_rearLeft.set(x);
     87   m_Left.set(x);
    7888}}}
    7989