NXC and Braking

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
lamikam
Posts: 7
Joined: 18 Feb 2012, 19:58

NXC and Braking

Post by lamikam »

My Son is building a robotic arm for a science competition. We need to get a hard brake on the motor. I found the example below to brake and hold the motor arm in place.
However, when I execute the code, the motor does not stop completely. It actually does a small back-and-forth rotation and then stops. We need it basically to stop immediately, and
not rotate at all, with a load on it. Any suggestions, please?

Active braking

This will actively hold the motor at its current position (and act against forces which try to move it). This consumes a lot of power. The NXC-code to do this is:

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);

http://www.mindstorms.rwth-aachen.de/tr ... ivebraking
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC and Braking

Post by mattallen37 »

If it's overshooting, then try tuning the PID parameters. Sound like the D needs to be turned up a bit.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
lamikam
Posts: 7
Joined: 18 Feb 2012, 19:58

Re: NXC and Braking

Post by lamikam »

Thanks, I am a total newb. How does one set the PID value(s)?
lamikam
Posts: 7
Joined: 18 Feb 2012, 19:58

Re: NXC and Braking

Post by lamikam »

OK, I think I added the PID values, and used various combinations of PID_0 to PID_7 values, but do not see any difference. See this youtube video of the problem

http://www.youtube.com/watch?v=-5sBj8hg ... e=youtu.be
[youtube]http://www.youtube.com/watch?v=-5sBj8hg ... e=youtu.be[/youtube]
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC and Braking

Post by mattallen37 »

I actually don't know how to use the SetOutput API. I always use the APR implemented in the FW, or my own control loop.

What your video demonstrated was overshooting the target (commonly caused by an un-optimized D parameter).

Edit, you can embed YT videos like this:

Code: Select all

[youtube]-5sBj8hgPq0[/youtube]
For a result of this:

Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC and Braking

Post by afanofosc »

It would be helpful to see what you are doing before you apply the brakes. Have you looked at the routine I posted in a thread here that implements ramp up and ramp down before braking?

The bottom line is that if you are running the motor at full power or 75% power and it is still running at a high power level when it arrives at the desired stopping point then braking at that tachometer position will result in the sort of oscillation you are seeing. That's because the brake is applied at a position and the regulation is trying to maintain the speed at that position. It will initially overshoot the position and the PID control routine built into the firmware will power the motors to restore the position at the 0 speed/power specified.

If you are creating a robotic arm you could try to design your mechanism to work with lower power levels, which will help, or you can write your motor control routines to ramp down as it approaches the desired tachometer position before you finally apply the brakes at the position.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
lamikam
Posts: 7
Joined: 18 Feb 2012, 19:58

Re: NXC and Braking

Post by lamikam »

Thanks, do you have a link to that thread? Unfortunatly, the way my son built the arm, this motor needs > 75% power.
lamikam
Posts: 7
Joined: 18 Feb 2012, 19:58

Re: NXC and Braking

Post by lamikam »

John, I did a search for your posts, but did not find one with the ramping code.

Thanks,
Leor
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: NXC and Braking

Post by h-g-t »

I have been searching for a while and all I can find is a reference under 'Output Port Constants'

#define OUT_OPTION_RAMPDOWNTOLIMIT 0x20

but have no idea how to set that up for a particular motor.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
lamikam
Posts: 7
Joined: 18 Feb 2012, 19:58

Re: NXC and Braking

Post by lamikam »

Well, I got better results now by trying this:

Code: Select all

Coast(Port);
     Wait(50);
     Off( Port );
     Wait(300);

     SetOutput( Port, 0, 0,
          OutputMode,  OUT_MODE_BRAKE + OUT_MODE_MOTORON + OUT_MODE_REGULATED ,
          UpdateFlags, UF_UPDATE_MODE + UF_UPDATE_SPEED,
          RegMode,     OUT_REGMODE_SPEED );

Still a little jitter at high power, but much better.
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests