Quote:
Originally Posted by team 888
We want to put a potentiometer on our control board for controlling our turret. I think i know how to program it if we were to put another potentiometer on the actual robot but there's no room and i don't want to mess around with the gear tooth sensor. Is there anyway to rotate the potentiometer and based on how many degrees it rotated turn the motor for the turret on for a certain amount of time???
|
The best way to do this is a PID control loop, with two inputs:
1. The potentiometer hooked up to one port of your OI telling it the desired angle of your robot
2. A potentiometer on the bot telling the current angle of the turret.
For the PID loop itself, it will look something like
Code:
error=phi-theta; // phi is current turrent angle, theta is desired angle
// make sure that the units match on both
Kp=20;
omega=(long)Kp*(long)error/2000L;
// Set limit bands
if(omega>64){omega=64;}
if(omega<-64){omega=-64;}
motor_pwm+=omega;