View Single Post
  #5   Spotlight this post!  
Unread 18-02-2010, 13:50
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
Re: Programming Pots

The way I always do this sort of thing is the following:

Code:
...encoder stuff to set up theEncoder (or potentiometer) and shove its value into iEncVal...

int setPoint;

if(iButton1){
setPoint = 100;
}
if(iButton2){
setPoint = 1000;
}

if(abs(iEncVal - setPoint) > DEADBAND){
if(iEncVal < (setPoint - approachDistance)){
motor->Set(1);
}else{
motor->Set(formula to figure out an scaled value based on approachDistance);
}
if(iEncVal > (setpoint + approachDistance)){
//stuff goes here
}
}else{
motor->Set(0);
}
Basically, make the buttons change the setPoint, and the motor ALWAYS drives to the current set point, and scales its speed down on approach (I find 10 encoder ticks generally works).