Skip to content

Simulate tank drive motor position and velocity - #51

Merged
aschokking merged 2 commits into
mainfrom
simulate-drive-motors
Nov 14, 2026
Merged

aschokking merged 2 commits into
mainfrom
simulate-drive-motors

Conversation

@aschokking

@aschokking aschokking commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Makes the tank drive motors in the simulator report position and velocity, so you can graph them in AdvantageScope like on a real robot. This also would let us do things like changing the drive to position test to read from the motor encoders instead of using our weird fake distance sensor.

Before

  • AngularVelocity was never set, so it always read 0.
  • Position was off by a factor of 2. The sim wrote meters straight into the encoder as rotations, but PoseSubsystem (and the tests' setPosition) treat 1 rotation as 0.5 m. Odometry and the pose were consistent with each other, so it didn't show on the field, but the motor readings and pose.getPosition() were wrong.
  • A disabled robot kept driving. Commands stop on disable, but the last motor power stayed applied and the sim kept moving the robot. The swerve sim already handled this.

Changes (EduSimulator)

  • Each side's position and velocity are written back into the mock motors every loop, using pose.scalingFactorFromRotationsToMeters.
  • Turning is split across the sides with a 0.6 m track width, so the left and right motors spin opposite ways when turning in place. The average of the two sides still equals the LinearEngine distance, so pose.getPosition() and odometry match the engine.
  • Motor power is treated as 0 while disabled. Unit tests use the existing forceDriverStationEnabledForUnitTests flag.

LinearEngine and RotationEngine still decide how the robot moves. The challenge tests drive those engines directly, so keeping them means a PID tuned against the tests behaves the same in the sim.

Voltage was already logged (the SCL mock reports power × 12), at AdvantageKit/FrontLeft/CANMotorController/Voltage.

Not included

  • Current: SCL's MockCANMotorController has no way to set it and reports the power value as its current. That needs an SCL change first.

Verification

  • New EduSimulatorTest: forward driving (voltage, matching left/right velocity, encoder position equals the engine distance), turning in place (opposite velocities, no forward travel) and the disabled lockout. All pass.
  • Full suite matches main test for test: the same 4 pass and the same 16 student-exercise tests fail as designed. DriveToPositionCommandTest still ends at 5.002332505667951.
  • gradlew checkstyle passes.
  • Tested in the interactive sim: voltage, angle and velocity all came through over NetworkTables.

🤖 Generated with Claude Code

The sim only moved the robot's pose; the drive motors never reported a
velocity, and their position was off by a factor of 2 because the
rotations-to-meters scaling (0.5 m per rotation) wasn't applied.

EduSimulator now writes each side's position and velocity back into the
mock motors, so they show up in AdvantageScope like on a real robot:
- Turning is split across the sides using a 0.6 m track width, so the
  left and right motors spin opposite ways when turning in place.
- The robot stops when disabled, matching the swerve sim. Before, the
  last motor power kept it driving.

LinearEngine and RotationEngine still decide how the robot moves, so the
challenge tests (which drive those engines directly) are unaffected.
DriveToPositionCommandTest still ends at 5.002332505667951.

Adds EduSimulatorTest covering forward driving, turning in place and the
disabled lockout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aschokking
aschokking merged commit 6abe63a into main Nov 14, 2026
3 checks passed
@aschokking
aschokking deleted the simulate-drive-motors branch November 14, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant