Welcome to the Titan Robotics programming subteam.
- Checkout Training2022/git-lesson
- Create a branch off of that branch called
<yourname>-git-lesson
- Push a commit that adds a file named <yourname>.txt to your new branch
- Merge your branch into Training2022/git-lesson and make sure this change is pushed
In a branch called yourname-motors
off of the motors
branch, write a program that uses some sort of input from an XboxController
to control a WPI_TalonFX
motor. Explicitly set the neutral mode of the motor. Don't forget to push your code (you don't need to merge the branch). For an extra (optional) challenge, create multiple motors and control them using a joystick, a button, and a trigger.
Here are some useful links that will be useful during training. You aren't expected to go check them out right now, but they're here for anyone who wants a preview of the kinds of things we'll go over.
Create a branch: git checkout -b your-branch-name
Stage changes: git add .
Commit staged changes: git commit -m "a short description of your changes"
Publish a new branch: git push -u origin your-branch-name
Switch to another existing branch: git checkout other-branch-name
Check for updates: git pull
Merge a branch into the branch you are on: git merge your-branch-name
WPI_TalonFX
constructor: WPI_TalonFX(int id)
(id
is the CAN id of the motor controller)
Control Modes:
motor.set(ControlMode.PercentOutput, pct)
- -1.0 <pct
< 1.0motor.set(ControlMode.Velocity, vel)
-vel
is in ticks per 100ms (requires an encoder and a PID index to be selected)motor.set(ControlMode.Position, pos)
-pos
is in ticks (requires an encoder and a PID index to be selected)
Neutral Modes:
motor.setNeutralMode(NeutralMode.Brake)
motor provides resistance to turningmotor.setNeutralMode(NeutralMode.Coast)
motor coasts to a stop without providing resistance
Inverting Directions:
motor.setInverted(true/false)
motor.setSensorPhase(true/false)
Encoder Initialization:
motor.configSensorInitializationStrategy(SensorInitializationStrategy.BootToZero, 0)
zeros the integrated encoder on startupmotor.configSensorInitializationStrategy(SensorInitializationStrategy.BootToAbsolutePosition, 0)
uses absolute orientation for the integrated encoder
Selecting an Encoder and PID index:
motor.configSelectedFeedbackSensor(TalonFXFeedbackDevice.IntegratedSensor, idx, 0)
selects the integrated encoder for PID indexidx
(usually 0)motor.selectProfileSlot(idx, 0)
tells the motor to use PID indexidx
(usually 0)
XboxController
constructor: XboxController(int port)
(port
is the USB port the controller is plugged into)
Joysticks: xbox.getLeftX()
, xbox.getLeftY()
, xbox.getRightX()
, and xbox.getRightY()
return values from -1.0 to +1.0. The left Y stick is reversed.
Buttons:
xbox.getXButton()
returnstrue
if the X button is currently pressedxbox.getXButtonPressed()
returnstrue
if the X button was pressed since the last time it was checkedxbox.getXButtonReleased()
returnstrue
if the X button was released since the last time it was checkedxbox.getLeftTrigger()
,xbox.getRightTrigger()
,xbox.getLeftStickButton()
, andxbox.getRightStickButton()
work the same way, with the same three variants.
Triggers: xbox.getLeftTriggerAxis()
and xbox.getRightTriggerAxis()
return values from 0.0 to 1.0.