View unanswered posts | View active topics It is currently Fri Sep 19, 2014 10:29 pm






Reply to topic  [ 6 posts ] 
Problem holding motor in fixed position for jointed arm 
Author Message
Rookie

Joined: Mon Sep 19, 2011 10:19 pm
Posts: 8
Post 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?


Wed Nov 07, 2012 10:22 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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.


Thu Nov 08, 2012 12:40 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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).


Thu Nov 08, 2012 1:09 am
Profile
Rookie

Joined: Mon Sep 19, 2011 10:19 pm
Posts: 8
Post 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?


Thu Nov 08, 2012 9:57 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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;


Thu Nov 08, 2012 8:03 pm
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post 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-arm

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


Sun Nov 11, 2012 1:07 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.