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).