Resetting motors with encoders attached

I’m competing this summer at the robocup worlds competition and I have a little problem with bringing a motor back to it’s original spot.

The motor spins a metal piece in circles. Before I move onto the 2nd part of the program, I would like to be able to reset the piece so that it goes back to the encoder place zero and upright.

How would I be able to do that?
Originally the program worked when we competed in the Pre-lims however it doesn’t work anymore

Uh, you looking for a programming solution? Or are you looking for a mechanical solution?

What exactly is happening? Is your arm failing to stop at the right place (as-in, it spins past that point)? Or is it not going far enough?

If it’s the first problem, toss a simple SetMotor(1,-127) command into your program. Or, whatever would run the spinning bit in reverse. It’ll jar the thing to a dead stop. 100-250 ms should do it.

If it’s the second? My suggestion (if you’re the programmer) is to add a limit switch that’s triggered when the spinning… whatever you built is in the position you want it. Encoders are likely to drift, but a digital switch is immune to it.

Stuck in a hotel room with only a few parts, and looking for alternative methods to fix this? You can use the light sensor to check for something being in a specific orientation if you set them up right. Ultrasonics do the same thing. Neither will be perfect, but they should work. Multiple encoders tend to stop the drifting issue. IMEs are worse than Quad Encoders, if you can change them over.

If you post a few photos of the robot and describe what the mechanism is, I can get a better idea of what you’re talking about and make some better suggestions. A metal piece spinning in circles could make 150 revolutions in a match, or one. Encoder drift is really bad if it’s the former, but totally manageable with the latter.

if you are looking for a programatical solution using only a shaft encoder, here is what I would recommend, use proportional control.

something like
while Abs(EncoderValue) >1
motor = encoderValue * P
where p is the proportional factor, depending on what the exact requirements, are it could be more or less than one. P would be experimentally determined.

This code will run your motor so that the closer you get to 0 the slower it goes, and even if you overshoot and the value goes negative, then the motor will reverse to come back to center. this will make it self adjust, increasing P will make you come to center faster, but you may risk overshooting, a lower P value will cause it to adjust slower but will be more accurate, conversely you could actually have different P values, say, set it to 2 when you are far from cente, but 1/2 when you get close. Another risk you may run is that if "encoderValue * P) is too low, the motor just wont mover. to fix this you may want to make your code something like this

While Abs(EncoderValue) > 50
P = 2
power = EncoderValue * P
Motor = power

While Abs(EncoderValue) < 50 && Abs(EncoderValue) > 1
P = .5
power = EncoderValue * P
If (Power < 30) Power = 30
Motor = power