# How to make motor lock in position?

We have an arm on our robot that we want to stay in place once the driver stops using the joystick. Right now when the driver stops using the joystick, gravity takes over and drops the red/blue block back to the floor. In order to hold it in place, the driver has to keep pressing the button over and over again. Any help would be appreciated.

First of all, I would suggest adding rubber bands to your lift. The rubber bands often can add enough tension which will allow your lift to remain up even when no motor power is being applied.

The other thing that can be done is instead of shutting off motors when a button (or joystick) is not being pressed, set them to a low value such 10. This will give them just enough power to â€ślockâ€ť into place, but not actually continue to move the lift. We use this on our robots quite often.

Here is an example of what we doâ€¦

``````
if (vexRT[Ch2] < -10)
{
motor[leftbottomlift] = vexRT[Ch2];
motor[leftmiddlelift] = vexRT[Ch2];
motor[lefttoplift] = vexRT[Ch2];
motor[rightbottomlift] = vexRT[Ch2];
motor[rightmiddlelift] = vexRT[Ch2];
motor[righttoplift] = vexRT[Ch2];
}
else if (vexRT[Ch2] > 10)
{
motor[leftbottomlift] = vexRT[Ch2];
motor[leftmiddlelift] = vexRT[Ch2];
motor[lefttoplift] = vexRT[Ch2];
motor[rightbottomlift] = vexRT[Ch2];
motor[rightmiddlelift] = vexRT[Ch2];
motor[righttoplift] = vexRT[Ch2];
}
else
{
motor[leftbottomlift] = 8;   //this is what you want to do...
motor[leftmiddlelift] = 8;   //set motors to a small value
motor[lefttoplift] = 8;        //instead of zero.
motor[rightbottomlift] = 8;
motor[rightmiddlelift] = 8;
motor[righttoplift] = 8;
}

``````
1 Like

The professional way of doing it would be using potentiometers or encoders to keep it in place. You can look for PID Controller examples which provides exactly what you need.

Theoretically, PID may not be the best solution for this problem since when â€śerror=0â€ť the result of the PID equation also falls to zero. Then, as gravity kicks in, the motor position starts to slip, error values increase and PID kicks in again. Unfortunately, this can cause unwanted oscillations.

You might try this: Program a button to store the joystick value that caused the cube to be locked at the desired position, then constantly send that value to the lift motor once the joystick has been released. Think of it as your new default motor value. Then, when you move the joystick it uses (overrides) the other value. Press it again and it resets to zero.

Hope that helpsâ€¦

Steve Wilson
Coach & Mentor â€“ 400X

1 Like

I would recommend doing this:

``````motor[leftArm] = (vexRT[Ch3])+15;
motor[rightArm] = (vexRT[Ch3])+15;``````

You may want to raise/lower 15 to a different value, however, anything much higher will cause the motors to overheat.

https://vexforum.com/t/one-quick-393-motor-question/28386/1
Newest answer from Jpearmanâ€¦ the max is about 33, theoretical. I had no trouble with 20 with no other major stress (keeping the claw close)

The error would go to 0 when its at the target position, but I think thatâ€™s where the Integral and Derivative parts of the PID loop come into play, keeping the position at the target position even though thereâ€™s a force being applied. Iâ€™ve seen some really precise uses of PID like balancing a ball on a plane or rod (affected by gravity) so I think it would still help if itâ€™s tuned properly.

Setting your motors to a constant value seems like a pretty good way to trip the PTCs in your motors, effectively removing any chance of keeping your lift up. Adding rubber bands or increasing your gear ratio would avoid that problem. Running the math on what ratio you need isnâ€™t very hard, either.

No, as many others have said all over the forums, setting the motors at a low value is safe (even over longer time periods) and will not trip the PTCs.

Indeed, I set my motors to 10. What you can do is have the motors set themselves to 10 if the absolute value of the joystick is less than 15. Soâ€¦

if(abs(joystick value) < 15)
{
(armmotors) = 10;
}
else
{
(armmotors) = joystick value;
}