How to hold the position of a motor (NXC)?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
mindcharlie1
Posts: 4
Joined: 17 Mar 2011, 08:12

How to hold the position of a motor (NXC)?

Post by mindcharlie1 »

how to hold the position of a motor by using NXC? like, if i want to make a robot arm, and use it to hold an object. if i use the command "Off(OUT_A)", the position of the motor can be held, but the force is not strong enough. if I use the command "OnFwd(OUT_A, 100)", the motor will give an force on the object, but it might break the object. furthermore, will the motor itself be broken if it is stuck for a long time by the object? So what's the correct way to make the motor to hold the certain position with certain force?
timpattinson
Posts: 224
Joined: 30 Oct 2010, 04:10
Location: 127.0.0.1
Contact:

Re: How to hold the position of a motor (NXC)?

Post by timpattinson »

Edit: use linusa's info instead
Off() is the correct way to brake the motor.
mindcharlie1 wrote: furthermore, will the motor itself be broken if it is stuck for a long time by the object?
Well the motor has some kind of over-current protection designed for exactly that, but I'm not sure how effective it is.
Maybe using gears would help?
Last edited by timpattinson on 09 Aug 2011, 10:36, edited 1 time in total.
Commit to Lego Mindstorms StackExchange Q&A http://area51.stackexchange.com/proposals/4105
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: How to hold the position of a motor (NXC)?

Post by linusa »

Try this:

Code: Select all

safecall void MotorBrake(const byte &port)   {
//Enables active braking for a motor...
  
    SetOutput(port, Power, 0,
                    OutputMode,  OUT_MODE_BRAKE + OUT_MODE_MOTORON + OUT_MODE_REGULATED,
                    RegMode,     OUT_REGMODE_SPEED,
                    RunState,    OUT_RUNSTATE_RUNNING,
                    UpdateFlags, UF_UPDATE_MODE + UF_UPDATE_SPEED); // + UF_UPDATE_TACHO_LIMIT);

}//end MotorBrake
This is really strong, and consumes quite a lot of power, but it's "not a hack" and safe for the motors (even if they get a bit warmer). The motors have thermal over-heat-protection by the way. You can release this brake again using Coast().

Edit: P.S.: The MotorBrake() function might be the same as Off(), but there's a good chance it's stronger. Can't try it at the moment, please do try it for yourself.
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: How to hold the position of a motor (NXC)?

Post by mattallen37 »

Try looking into APR, which is a fairly new feature. It is now completely implemented into NXC and John's EFW. I haven't used all the features of it, but it seems to work great for everything I have needed it for so far (with NXT motors). For non-NXT motors (with the built in encoders), I made my own PID motor control loops so that I could input the position with a different sensor (like the RCX rotation sensor).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest