View unanswered posts | View active topics It is currently Sun Jul 21, 2019 6:41 am

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Problem holding motor in fixed position for jointed arm
Author Message
Rookie

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

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Rookie

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

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Novice

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

EDIT: Whoops, I didn't realize this was exactly the same post.

Sun Nov 11, 2012 1:07 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 6 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning