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.

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
Start the simulation and open NetworkTables > Mechanisms in your dashboard. There is one entry per motor:
TopWheelandBottomWheel.Hold the right trigger.
TopWheel'smechanism/velocityshould rise to about 41.7 rotations per second (2500 RPM), andBottomWheel's to about 58.3 (3500 RPM), at the same time.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
spindoes.The wheels do not start again after
stop.stopturned the closed loop off. CallstartClosedLoopController()when a velocity command starts, asspindoes.The wheels settle well below their speeds.
kVis 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?
