View Single Post
  #3   Spotlight this post!  
Unread 08-02-2007, 16:56
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: OI potentiometer for controlling turret

Quote:
Originally Posted by team 888 View Post
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;