Changes between Version 8 and Version 9 of ControlSystems/SoftwareTeam/Training/GettingStarted/ServoMotor


Ignore:
Timestamp:
Jan 28, 2020, 10:56:52 PM (5 years ago)
Author:
David Albert
Comment:

--

Legend:

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

    v8 v9  
    1010import edu.wpi.first.wpilibj.Servo;
    1111}}}
    12 * 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
     12* declare variables to hold the Xbox controller and [https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599703-repeatable-low-power-movement-controlling-servos-with-wpilib servo motor] objects.  The variables should be inside in the Robot class since the robot contains those objects ("hasa" relationship: the robot "has a" Servo motor):
    1313{{{
    1414   private XboxController xbox;
    1515   private Servo servo;
    1616}}}
    17 * in robotInit() instantiate the controller and motor objects
     17* in robotInit() instantiate (create) the controller and servo motor objects and store them in the variables you created above.
    1818  {{{
    1919    xbox = new XboxController(0); // Xbox controller on USB port 0
    2020    servo = new Servo(2);         // Servo connected to roboRIO PWM 2
    2121  }}}
    22 * in teleopPeriodic() read the xbox controller and adjust the servo motor accordingly
     22* in teleopPeriodic() read the xbox controller and adjust the servo motor position according to the joystick position.
    2323  {{{
    2424    // Read xbox controller left joystick x axis
     
    3333
    3434Connect a Servo motor to PWM port 2 on the roboRIO and run your program. 
    35 Launch the driver station on your laptop and select Teleop mode (bottom left side of the window).  You'll need to press the Enable button on the driver station to put the robot in Teleop mode.  When teleop is enabled, teleopInit() will be called once and then teleopPeriodic() is called repeatedly until the robot is disabled.
     35Launch the driver station on your laptop and select Teleop mode (bottom left side of the window).  You'll need to press the Enable button on the driver station to put the robot in Teleop mode.  When teleop is enabled, teleopInit() will be called once and then teleopPeriodic() is called repeatedly until the robot is disabled.  Move the left joystick along the X-axis and observe the servo motor.
    3636
    3737To see a complete Robot.java that demonstrates controlling the servo motor from an xbox controller using buttons and joystick, click [wiki:ControlSystems/SoftwareTeam/Training/GettingStarted/ServoMotor/Example1 here].