For the complete documentation index, see llms.txt. This page is also available as Markdown.

How do I control a mechanism without a mechanism class?

Control each SmartMotorController yourself, such as when the motors of one mechanism need different setpoints.

Goal: drive two motors that belong to one mechanism, but need different setpoints, from one subsystem with your own commands.

The example is a shooter with a top wheel and a bottom wheel. Spinning the bottom wheel faster than the top one puts backspin on the game piece, so the two wheels need different speeds at the same time.

Do you need this page?

YAMS mechanism classes (Arm, Elevator, FlyWheel and so on) drive one motor and its followers with one setpoint. Use them when you can:

  • Motors on one shaft or gearbox that always do the same thing: make the others followers.

  • Separate motors that must move together, such as one on each side of an intake arm: make the others loosely coupled followers.

  • Two different mechanisms, such as a shooter and a feeder: give each its own subsystem and mechanism class. One YAMS mechanism per subsystem.

Two panels. Tightly coupled, withFollowers: a leader and a follower are on one shaft or gearbox and the follower copies the leader's output. The motors are mechanically locked, there is one closed loop and one config, the followers are the same vendor as the leader, and voltage and duty cycle reach every motor. Loosely coupled, withLooselyCoupledFollowers: two separate motors joined only by the mechanism get the same setpoint and each runs its own PID. They are not mechanically locked, each has its own closed loop and config, vendors can be mixed, and voltage and duty cycle are not forwarded, so the leader moves alone.
Tightly coupled followers share a shaft. Loosely coupled followers are separate motors.

If none of those fit, control each SmartMotorController yourself, as below. The Double FlyWheel tutorial builds this same shooter step by step, with C++ as well; this page is the short version. You still get YAMS's telemetry, live tuning, current limiting, closed loop control and simulation for each motor. Without a mechanism class, your subsystem does three of its jobs: call setupTelemetry() on each motor once, updateTelemetry() every loop, and simIterate() every loop in simulation. You do not get the mechanism's drawing in the dashboard, or its ready-made commands and triggers.

Why not two FlyWheels in one subsystem?

Every YAMS-generated command (such as FlyWheel.run or Arm.setVoltage) requires the subsystem you passed to new SmartMotorControllerConfig(this). A subsystem runs one command at a time. So if topWheel.run(...) and bottomWheel.run(...) both require the same subsystem, scheduling the second cancels the first, and only one wheel spins.

The fix is one command that sets both motors, which is what this page writes.

The subsystem

The code uses two SPARK MAXes (CAN IDs 4 and 5), each driving a NEO 1:1 to a 4 inch wheel. The gains are placeholders: with them the wheels reach roughly the right speed in simulation, but tune them for your robot with Step 5: Tune it (for a flywheel, find kV first, then kP).

Bind it in RobotContainer:

In Robot, set shooter.setDefaultCommand(shooter.idle()), call periodic() from robotPeriodic() and start the simulation Notifier in simulationInit(), as in the Shooter/FlyWheels tutorial. Then in your opmode:

Each motor's simulation runs on its own, from the moment of inertia in its config, so simIterate() works without a mechanism class.

Check it

  1. Start the simulation and open NetworkTables > Mechanisms in your dashboard. There is one entry per motor: TopWheel and BottomWheel.

  2. Hold the right trigger. TopWheel's mechanism/velocity should rise to about 41.7 rotations per second (2500 RPM), and BottomWheel's to about 58.3 (3500 RPM), at the same time.

  3. Release it. Both coast down.

If it did not work

  • Only one wheel spins. Two commands that require this subsystem are fighting, so the second cancels the first. Set both motors from one command, as spin does.

  • The wheels do not start again after stop. stop turned the closed loop off. Call startClosedLoopController() when a velocity command starts, as spin does.

  • The wheels settle well below their speeds. kV is too low; see How do I shoot with a shooter?

Next

Feed the game piece only once both wheels are at speed, with atSpeed(...) and a feeder: How do I shoot with a shooter?

Last updated

Was this helpful?