NXC and Braking
NXC and Braking
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
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
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC and Braking
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
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC and Braking
Thanks, I am a total newb. How does one set the PID value(s)?
Re: NXC and Braking
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]
http://www.youtube.com/watch?v=-5sBj8hg ... e=youtu.be
[youtube]http://www.youtube.com/watch?v=-5sBj8hg ... e=youtu.be[/youtube]
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC and Braking
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:For a result of this:
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]
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC and Braking
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
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/
http://bricxcc.sourceforge.net/
Re: NXC and Braking
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
John, I did a search for your posts, but did not find one with the ramping code.
Thanks,
Leor
Thanks,
Leor
Re: NXC and Braking
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.
#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.
Re: NXC and Braking
Well, I got better results now by trying this:
Still a little jitter at high power, but much better.
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 );
Who is online
Users browsing this forum: Semrush [Bot] and 4 guests