Page 1 of 2

NXC and Braking

Posted: 18 Feb 2012, 20:01
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

Re: NXC and Braking

Posted: 18 Feb 2012, 20:56
by mattallen37
If it's overshooting, then try tuning the PID parameters. Sound like the D needs to be turned up a bit.

Re: NXC and Braking

Posted: 18 Feb 2012, 21:34
by lamikam
Thanks, I am a total newb. How does one set the PID value(s)?

Re: NXC and Braking

Posted: 18 Feb 2012, 21:48
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]

Re: NXC and Braking

Posted: 18 Feb 2012, 23:20
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:


Re: NXC and Braking

Posted: 19 Feb 2012, 02:11
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

Re: NXC and Braking

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

Re: NXC and Braking

Posted: 19 Feb 2012, 02:22
by lamikam
John, I did a search for your posts, but did not find one with the ramping code.

Thanks,
Leor

Re: NXC and Braking

Posted: 19 Feb 2012, 05:15
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.

Re: NXC and Braking

Posted: 19 Feb 2012, 16:35
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.