ROBOTC.net forumshttp://robotc.net/forums/ Problem holding motor in fixed position for jointed armhttp://robotc.net/forums/viewtopic.php?f=52&t=5088 Page 1 of 1

 Author: bongju328 [ Wed Nov 07, 2012 10:22 pm ] Post subject: Problem holding motor in fixed position for jointed arm We have a jointed arm connected to a Tetrix DC motor on our chassis. We are having difficulty holding the arm in position. Once the arm gets to the desired position and the motor power is reduced to zero, the weight of the arm causes it to fall. We tried using an encoder with the nMotorEncoderTarget command, but the motor stalls out before it gets to the desired position. We tried using servos, but they are not strong enough to lift our arm.Can anyone offer a programming and/or hardware solution to hold a motor in a fixed position?

Author:  MHTS [ Thu Nov 08, 2012 12:40 am ]
Post subject:  Re: Problem holding motor in fixed position for jointed arm

If you need to hold the arm stationary, you need PID control. Not just simple position PID control because like you said, as soon as it reaches target height, power gets cut off and the arm drops. Then PID kicks in again and lift the arm again and the cycle repeats. In other words, the RobotC built-in PID control doesn't work in that situation. You need to write your own PID control which integrates the output power. It's almost similar to speed PID control instead of position PID control where PID will cumulate the output power according to the error. When error goes to zero, the integrated power level is maintained. A simplified version will look something like this:
 Code:int error = targetHeight - nMotorEncoder[armMotor];int armPower += (int)(Kp*error);//// Limit the arm power range to -100 to 100.//if (armPower > 100){    armPower = 100;}else if (armPower < -100){    armPower = -100;}motor[armMotor] = armPower;

In theory, as long as you tune Kp correctly, it should work. However, you may still have issues in reality. Note that you have gravity that will help the arm to come down but fights you on the way up. So ideally, you need to do speed control as well. But that makes the algorithm really complicated. Also, this simple algorithm suffers a downside because it will keep integrating the power till it hits the max. The power will not come down unless error is negative which means it will overshoot back and forth before it will hold the position. In theory, you really need full PID control where the D (differential term) will allow the output power to come down when it approaches to target. You may want to try the above and see how well you can make it before thinking of improving it.

Author:  MHTS [ Thu Nov 08, 2012 1:09 am ]
Post subject:  Re: Problem holding motor in fixed position for jointed arm

Wait, there may be a much simpler solution. Try this and see if that works.
 Code:bFloatDuringInactiveMotorPWM = false;

I never use this before, so I don't know if it has the desired effect. In theory, this will put the motors in "brake" mode (i.e. when power is cut, it will apply brake).

 Author: bongju328 [ Thu Nov 08, 2012 9:57 am ] Post subject: Re: Problem holding motor in fixed position for jointed arm That command only seems to work for NXT motors. Has anybody gotten it work for Tetrix DC motors?

Author:  MHTS [ Thu Nov 08, 2012 8:03 pm ]
Post subject:  Re: Problem holding motor in fixed position for jointed arm

 bongju328 wrote:That command only seems to work for NXT motors. Has anybody gotten it work for Tetrix DC motors?

bFloatDuringInactiveMotorPWM indeed does not work for Textrix motor controllers. Just for the kick of it, we have an arm design prototype (we have since abandoned that design because it was fragile and hard to control), so I wrote a simple PID control on the arm. Surprisingly, it does work to hold the arm in mid-air even at the most stressed position (horizontal). It looks like even a simple P-only controller works. The trick was that if I set the arm to go to a certain height, PID control will try to get there but it will never reach the target height I specified because as it approaches the target, the power is reduced. So there is an equilibrium point that the power will be reduced to a level such that it is enough to hold the arm stationary but not enough to raise it to the target. So it is holding the position even though it may not be the target position. So for example, if I want to have the arm raised to 30 inches, I would specify 40 inches instead and it will stop and hold at 30.
So the simple P-only PID controller looks something like this:
 Code:int error = targetHeight - nMotorEncoder[armMotor];int armPower = (int)(Kp*error);//// Limit the arm power range to -100 to 100.//if (armPower > 100){    armPower = 100;}else if (armPower < -100){    armPower = -100;}motor[armMotor] = armPower;

 Author: amcerbu [ Sun Nov 11, 2012 1:07 pm ] Post subject: Re: Problem holding motor in fixed position for jointed arm A similar question was raised on the FTC Forums. Here's the link; hopefully this helps:http://ftcforum.usfirst.org/showthread.php?1359-Problem-holding-motor-in-fixed-position-for-jointed-armFTC Forums user Skinkworks had some interesting advice to give near the end. I'd encourage you read the entire thread anyway.EDIT: Whoops, I didn't realize this was exactly the same post.

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/