Hello all,
We are attempting to make MotionMagicVoltage work with the two motors in unison. Our current code is attached.
What we want to happen:
The mechanism (powered by the two motors) to continuously move from its current location to the desired location.
What happens:
The mechanism moves toward the desired location for about half a second and then stops. Pressing and holding the button again results in the same motion. Movement stops when the mechanism reaches the desired location.
The button is a .whileHeld() and the command is still running after movement stops
What we’ve tried:
using followerPivotMotor.setControl(new Follower(leaderPivotMotor.getDeviceID(), true)); in the constructor (leader moves, follower doesnt)
using followerPivotMotor.setControl(new Follower(leaderPivotMotor.getDeviceID(), true)); every time setPivot is called (leader moves, follower doesnt)
doing both things at the same time (leader moves, follower doesnt)
not using the Follower class, inverting the leader motor, and using .setControl on both motors (brief movement, then nothing)
and in that repo check line 27. they make the MotionMagicVoltage object for the whole subsystem, not each time the function is run.
in your code on line 133, you are just running .setControl, and not using your MotionMagicVoltage at all. if you check line 105 in the example, the way they do it is m_fx.setControl(m_mmReq.withPosition(10).withSlot(0));
also in your code on line 134, youre setting the follower motor, and you should only have to ever set the leader motor if configured properly
my team just uses PositionClosedLoop which works well for our use case, and is a lot simpler.
You didn’t share quite enough code to find the issue. Did you try using PositionVoltage? I usually start with position control, and then layer in Motion Magic once I get that working.
Make sure your CANCoder and the motor are “in phase”, meaning positive motor output makes the encoder value get larger (and vice versa. Check the CANCoder and motor for faults in Tuner X, they might help point you at the problem.
I agree with @58sConeSnatcher , you should create the MotionMagicVoltage object once and reuse it. However, I think it should work the way you have it.
For the half a second of movement: do you have a default command running? If the button is an instant command, it may be getting overridden by the default. For the command still running after movement stops, is the subsystem required in the command? Is there a default command for it to go back to after the movement is done? Could also put a .onFalse in there.
For the two motors: I’m not sure setting control for the follower motor is needed; it might be worth trying just making it as a new Follower without the .setControl part.