I’ve been trying to find out how to use motor encoders to turn a gear to a specific angle. we need it to rotate about 3/4 of a full revolution but can’t use milliseconds because of the battery power (in comp we often use overcharged and fully charged batteries so the power fluctuates). Is there any way for me to code it so I can tell the motor to turn a specific degree? I am using the latest version of robotC but I have no idea of how to use PIDs.
PID is not the place to go for rotation angles, PID is for speed control.
If you’re looking to position an arm or lever precisely, you may want to consider using the potentiometer for position sensing, or even limit switches, rather than encoders, as an option.
PID is still a perfectly good controller for position/ angle. And if the arm already starts in the same position then encoders can be fine. Here is an old quote of mine about PID
If you would not like to delve into pids, which I highly recommend if you have the knowledge as they are generally faster and more accurate but you could have the motor increase its power while the gear is not rotated enough and decrease the power of the motor when the gear is rotated past the fixed angle. The code would look like:
While(true){
If (Sensorvalue[gear] < targetangle)
Motor[gear]++;
Else if(sensorValue[gear] > targetangle )
Motor[gear]–;
Wait1Msec(100);
}
This code will always be correcting itself, overshooting and undershooting the target…
All that is is an I only loop. Compared to what I suggested which was a P only loop.
motor[arm] = .3*(goal - sensorValue[enc]);
That way you slow down as you approach to control yourself better.
The big red encoders can occasionally need a reset so managing a delta to where you want to go helps. Not sure about the IME’s as only seen those in conjunction with pots on an arm.
The error can be additive for the IME/quad. Putting a limit switch at the up or down position to reset yourself may be your trigger point or detecting velocity is 0 when power is high.