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


Ignore:
Timestamp:
Nov 8, 2019, 10:49:31 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

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

    v1 v1  
     1{{{
     2package frc.robot;
     3
     4import edu.wpi.first.wpilibj.TimedRobot;
     5import edu.wpi.first.wpilibj.XboxController;
     6import edu.wpi.first.wpilibj.GenericHID.Hand;
     7import com.ctre.phoenix.motorcontrol.can.*;
     8
     9/**
     10 * The VM is configured to automatically run this class, and to call the
     11 * functions corresponding to each mode, as described in the TimedRobot
     12 * documentation. If you change the name of this class or the package after
     13 * creating this project, you must also update the build.gradle file in the
     14 * project.
     15 */
     16public class Robot extends TimedRobot {
     17  private XboxController xbox;
     18  private WPI_TalonSRX m_rearLeft;
     19
     20  /**
     21   * This function is run when the robot is first started up and should be
     22   * used for any initialization code.
     23   */
     24  @Override
     25  public void robotInit() {
     26    xbox = new XboxController(0);     // Xbox controller on port 0
     27    m_rearLeft = new WPI_TalonSRX(4); // CAN Talon ID 4
     28  }
     29
     30  /**
     31   * This function is called every robot packet, no matter the mode. Use
     32   * this for items like diagnostics that you want ran during disabled,
     33   * autonomous, teleoperated and test.
     34   *
     35   * <p>This runs after the mode specific periodic functions, but before
     36   * LiveWindow and SmartDashboard integrated updating.
     37   */
     38  @Override
     39  public void robotPeriodic() {
     40  }
     41
     42  @Override
     43  public void autonomousInit() {
     44  }
     45
     46  /**
     47   * This function is called periodically during autonomous.
     48   */
     49  @Override
     50  public void autonomousPeriodic() {
     51  }
     52
     53  /**
     54   * This function is called periodically during operator control.
     55   */
     56  @Override
     57  public void teleopPeriodic() {
     58    // Read xbox controller left joystick x axis
     59    // value returned is between -1.0 and 1.0
     60
     61    // For xbox controller, uncomment the following line
     62    // double x = xbox.getX(Hand.kLeft);
     63    // For Logitech F310 controller, uncomment the following line
     64    // double x = xbox.getRawAxis(1);
     65   
     66    // DC Motor controllers apply between -1.0 (full reverse)
     67    // 0=stop and +1.0 (full forward) power
     68    // Set motor speed based on joystick
     69    m_rearLeft.set(x);
     70  }
     71
     72  /**
     73   * This function is called periodically during test mode.
     74   */
     75  @Override
     76  public void testPeriodic() {
     77  }
     78}
     79}}}