We planned to set up joystick buttons to make the kicker move to a set position using potentiometers, but it keeps overshooting and getting stuck. Here’s what we have:
We tried using if instead of while because of watchdog problems, but that would only work by holding the button down. Now, the kicker pulls back too far and gets stuck. Does anyone know if it’s a problem in the code or in the numbers we used for the pots?
be careful with your comparison of kickerValue to HIGH_POT. because the programs happens in loops, kickerValue is a snapshot of it’s current position, a frame if you will. The moment that kickerValue is equal to High_POT may occur between frames. Use a >= or <=, to check if kickerValue is at or past the HIGH_POT value.
The idea is that with a single button press, the kicker will move to a position determined by a pot right?
if (button pressed)
//set a bool to true to indicate that the kicker is in forward "mode"
if (in forward mode)
{
if(kickerValue < HIGH_POT)
//move kicker forward
else
{
//stop kicker
//set bool to false to indicate the kicker is done
}
}
good idea to use a variable stopping point for the kicker.
Am I correct in assuming that the motor turns full on when the pot value is less then the joystick and doesn’t turn off until after it goes past?
You can set up a PID Loop to control the overshoot even if you are only bringing it to one position. A quick search of CD will give you a lot of information. Basically you are going to take the difference between the value of the joystick and the potentiometer to set the speed of the motor (needs to be on a speed controller of course).
PID is the best way to approach a set point. But in this case, it may be over engineering. The problem is that “not equal” in your while loop. In pure math equal or not equal is well defined. In real world engineering there are always tolerances. The A/D will have a noise floor for every signal so when you look to find a specific voltage you may never actually see. Change the while loop to less than High_Pot and then it will stop once it reaches the value or just a tad beyond - unless you are running so fast that the CPU does not see the change (not very likely with the cRIO). Good rule of thumb is to never use = or != when dealing with sensors.
The way I always do this sort of thing is the following:
...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).