Turrets/Wrists
Turrets and wrists are both a Pivot in YAMS: a mechanism that turns to an angle. A Pivot is different from an Arm because it does not account for gravity.
How a pivot works

A pivot is controlled exactly like an arm, with one difference: a Pivot does not account for gravity. It has no kG, its simulation applies no gravity, and it uses SimpleMotorFeedforward where an arm uses ArmFeedforward.
That is the right model for a turret, which turns about a vertical axis, and for a wrist that is balanced about its shaft: neither needs voltage just to stay where it is. It also makes a pivot simpler to tune.
If your mechanism needs voltage to hold itself up, it needs gravity accounted for: use an Arm.
Creating a pivot
This is the shape of a turret class, not a complete file: the imports and the motor controller object (spark, a SparkMax) are left out. The Arm tutorial builds a complete mechanism file the same way. The code is the same for Commands v2 and Commands v3 except for the package you import from and the class that owns the mechanism.
this is the Subsystem. The scheduler calls periodic() and simulationPeriodic() for you.
this is the Commands v3 Mechanism. A Mechanism has no periodic hook, so call periodic() yourself from Robot.robotPeriodic(), and run simulationPeriodic() in its own Notifier, started from Robot.simulationInit(). Where the tutorials put things shows both.
The options in motorConfig are explained in SmartMotorControllerConfig, and the options in config in PivotConfig.
In the rest of your code, turret is the TurretSubsystem (or TurretMechanism), and pivot is the YAMS Pivot inside it.
Controlling a pivot
A pivot takes Angle targets: pivot.setAngle(Degrees.of(90)) goes to 90° and holds it, pivot.runTo(Degrees.of(90), Degrees.of(1)) ends when it gets there, and pivot.getAngle() reads where it is. Controlling a mechanism lists every command, setpoint function and check, and When mechanism commands end explains how they work with a default command.
To track a moving target, give setAngle (or run) a Supplier<Angle>: it follows the supplier every loop and never ends. runTo with a supplier also follows it, but ends as soon as the turret catches up, so it is not for tracking.
Turret or wrist?

A turret turns on top of the robot. Its angle is measured from the robot's front, so 0° usually means pointing forward.
Configure it for how far it can turn:
Can spin forever (a slip ring, or nothing to wind up)
withContinuousWrapping and no soft limits, so it takes the short way round.
Is limited by its wiring
withSoftLimits, with hard limits a little wider. It may have to unwind the long way.
Use it to track something by giving setAngle a supplier, which it reads every loop. To aim at a point on the field, the turret's angle is the direction to the target minus the robot's heading:
A turret geared so its encoders turn more than once over its travel cannot tell where it is from one encoder. EasyCRT works out its true angle from two.
A wrist turns on the end of another mechanism, usually an arm. Its angle is measured from the arm it is mounted on, not from the ground.
Configure it with soft limits always, because a wrist has parts to hit at both ends of its travel, and a small moment of inertia.
Use it together with the arm it rides on. Keep the wrist in its own subsystem, and move the two from a command that owns neither, so each keeps its own default command.
A Pivot does not account for gravity, so it suits a wrist that is balanced about its shaft. A heavy, unbalanced wrist is pulled on by gravity by an amount that depends on the arm's angle as well as its own, which neither Pivot nor Arm models. Balance the wrist if you can. If you cannot, expect to need more kP, and check it holds at every arm angle.
Moment of inertia
How heavy the pivot is to turn is set on the motor config with withMomentOfInertia. It only matters in simulation, where it also decides the current the pivot draws from the battery simulation.
Configuring and tuning a pivot, step by step
Do the configuration steps first, in simulation, then tune the real pivot with live tuning. Tuning something that is configured wrong wastes the time.
Configure it
Set the gearing
Give the reduction from the motor to the pivot with withGearing.
Choose the positive direction
For a turret, counter-clockwise seen from above is positive, to match the robot's heading. Apply a small positive voltage and flip withMotorInverted if it turns the other way.
Choose where zero is
A turret's zero is usually pointing at the robot's front. A wrist's zero is usually in line with its arm. Set an absolute encoder's zero offset, or a starting position.
Wrap it or limit it
A turret that can spin forever gets withContinuousWrapping and no soft limits. Everything else gets withSoftLimits, inside withHardLimits. If its absolute encoder must read across zero, add withWrapping: it sets the encoder's range without the closed loop wrapping, so it works with soft limits.
Describe it to the simulator
Set withMomentOfInertia on the motor config.
What is different when tuning a pivot
A pivot is tuned like an arm without the kG step: follow Step 5 of the Arm tutorial, and see Tuning order for the keys to watch. What sets a pivot apart:
There is no kG. Start with kS: raise it until the pivot is just about to move, in each direction, and use the smaller value.
Friction varies with direction and position. Cables and hoses drag more one way, and more near the ends of the travel. Tune where the drag is worst.
kV matters more than on an arm for a turret that tracks, because its setpoint never stops moving.
What changes for each kind
Check both directions. Cables and hoses drag more one way than the other, and more near the end of the travel. Tune kS and kP where the drag is worst.
Tune it while tracking. A turret that aims at a target has a setpoint that never stops moving. Drive and spin the robot while it tracks, and raise kV and kP until it stays on target.
Check the seam. With continuous wrapping, command a move across the wrapping point and check it takes the short way.
Check the unwind. With soft limits, command an angle just past a limit and check the turret goes the long way round to reach it, or stops at the limit.
Tune it at several arm angles. Because a
Pivotdoes not account for gravity, an unbalanced wrist is pushed around by it as the arm moves. Tune with the arm level, where that is worst, then check with the arm up and down.Raise kP to hold against gravity if you cannot balance the wrist. Expect a small steady error that changes with the arm's angle.
Tune it holding a game piece, which changes both its weight and its balance.
Check the limits with the arm in every position. A wrist that clears the robot with the arm up may hit it with the arm down.
PivotConfig options
Every PivotConfig option is on the PivotConfig page under this one, with a graphic and an example for each. Options shared by every mechanism are in Shared options.
A Pivot needs its hard limits and a starting position before it can be created in simulation: see what simulation needs.
Code reference
Last updated
Was this helpful?
