- Controlling a motor with joystick input
- Reading encoder values
- Converting encoder ticks to distance
- Sending data to SmartDashboard
Complete Example
- Java
- C++
What This Example Demonstrates
Motor Control
The motor controller accepts values from -1.0 to 1.0:1.0= full speed forward0.0= stopped-1.0= full speed reverse
Encoder Setup
Encoders measure rotation with “counts per revolution” (CPR). To convert to distance:- 6-inch diameter wheel
- 360 CPR encoder
- Distance in inches
(π × diameter) / counts_per_revolution
SmartDashboard
robotPeriodic() runs in all modes (disabled, autonomous, teleop, test). This makes it perfect for updating dashboard values continuously.
Running in Simulation
- Open SmartDashboard or Shuffleboard
- Enable the robot in teleoperated mode
- Move the joystick to control the motor
- Watch the encoder distance value update on the dashboard
Source Location
- Java:
wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Robot.java - C++:
wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp