Potentiometer RD4B Stabilization Program

Hello, I am posting this on behalf of my teams programmer. We have a reverse double 4 bar with a 1:7 ratio with four motors. We plan to put a potentiometer on the 84t gears to count shaft position with stabilization in mind.

How would we go about this program? We want it to keep the lift level while still allowing us to control the lift freely.

Please lead us in the right direction. Example code is especially helpful so we can see how its done. Also, would PID serve this function? (She does not currently know PID, I am just wondering)

Thank You! Feel free to P.M. me. And let me know if I’ve left something important out!

PID (or at least P) would indeed be helpful in this situation. In the past, I’ve experimented with an interface that would “freeze” the arm in whatever place we leave it if the arm joystick is left stationary. The pseudo-code would look something like:


int setpoint = SensorValue[armPot] //Get starting position of lift so it doesn't jump at start of driver op
while(true) { //Either user control loop, or possibly in a separate task
  if (abs(vexRT[armJoystick]) > THRESHOLD) { //Driver is trying to move arm
    setArmPower(vexRT[armJoystick]);
    setpoint = SensorValue[armPot];
  }
  else { //The joystick is approximately centered
    //Use a PID or P control loop to keep arm at setpoint
  }

  wait1Msec(10); //Tweak for physical response time 
                        //(jpearman knows how long motors take to respond) :)
}

Something I plan to do for my new bot. Balance+freeze lift is very sweet. But you do need KI for this… which adds a bit more pressure to the motors.

That code is nice…

You bet! Physical helpers like rubber bands reduces the dependency on the integral part of PID to keep your lift afloat as well. Otherwise you can send a good bit of current to the motors.

^^ This is very important.

When adding elastic, you’re aiming for “neutral buoyancy” on the arm. That is, you should be able to move the arm to any position and have it stay there without sagging. The goal is that the motors only are powered to move the arm, not to keep it still. Then, the code for freezing the arm is almost unnecessary.

However, because the load on the arm varies (i.e. with game objects or without) and the torque exerted by the rubber bands isn’t constant (angle of force and stretch of bands change), you can’t get the forces perfectly balanced for all situations. That’s why you have to write a P/PI/PID loop. If the arm is very close to “balanced” before PID, then the I term nearly drops out.

Ultimately you will want to balance the lift with its own weight and around half the weight of scoring objects you will lift. This way you need to apply similar power to move up as to move down.

With the elastic set up properly, you shouldn’t need to apply a holding power through trim or PID greater than 10-20, which should pose no risk to overheating motors.

Statically, yes. You want to balance. But the dynamics come into play making the control loops tougher to tune.

A reduced arm mass helps you overall because those rubber bands add a force that means you’re “coming in hot” to your target point which the D will have to compensate against in the PID loop. That momentum you carry from the rubber band force needs to be compensated as you approach your target arm value.

Reducing mass in the first place to not have such a heavy arm makes it much easier to tune an arm PID. Reduce the need for the rubber band forces so the motors are more easily in control.

OK, the need to get to 48" posts makes more mass required this year due to structure to get that high. Double reverse 4 or 6 bar linkages make for lots of weight and fun centers of mass too to take into account on the lift dynamics. Just another practical reason for lighter, minimal designs.

Thanks forth help so far, however, how May this be done without PID?

I will simply the PID down for you. Instead of PID I will explain just a P loop in terms of lift stabilization. Remember PID is actually 3 separate things.

P stands for proportional which just means more power the farther you are from where you want to be. To run P you multipy a constant by the distant your sensor is from where it wants to be and that gets you the value to send to the motor.
So to have it drivable by joystick and keep stable you would just need this

motor[leftside]=vexRT[CH1]+.25(SensorValue(rightSensor)-SensorValue(leftSensor);

motor[rightside]=vexRT[CH1]-.25(SensorValue(rightSensor)-SensorValue(leftSensor);

Which just says if the right side is way higher than the left said raise it more and lower the left side.

Here’s a link to a code sample you can use to solve your problem. It will show you how to control a motor using a potentiometer as input…

http://cybertotem.com/Blog/a-complete-motion-control-api-for-easyc