Absolute Position Regulation Tips [NXC]

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: Absolute Position Regulation Tips [NXC]

Post by linusa »

mattallen37 wrote:I don't think you understand the APR. It never says "Ok, I'm done regulating, motor is free again."; never. It is always actively trying to go to the position (that's what's so incredibly awesome about it).
Ah ok, that makes sense and justifies the question of the whole thread, of course :-). I didn't have the chance to play around with APR before, and it's sime while ago that I read the article about it. Thanks for clearing that up!
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: Absolute Position Regulation Tips [NXC]

Post by mattallen37 »

Indeed, it has come a long way since the old control commands :D

IMO APR is the best single addition to NXC (Edit: that is, since I started using it in '09).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Re: Absolute Position Regulation Tips [NXC]

Post by ricardocrl »

Ahmahm, good discussion. :D

But then, what is the criteria of the FW to change the runstate?? The graph you showed (http://www.mindstorms.rwth-aachen.de/tr ... tateEx.png) makes me believe that judging by the runstate is a better option, if I really need accuracy in the end position.
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: Absolute Position Regulation Tips [NXC]

Post by schodet »

Hello,
ricardocrl wrote:But then, what is the criteria of the FW to change the runstate?
As said Matt, the absolute position regulation will never change the runstate, the motor is always controlled.

There is two regulation modes. When you did not set any speed limitation, the best is to monitor the actual position (or speed) to know whether the movement is finished.

When you use speed limitation, what I usually do is to consider that the movement is finished once the consign (which is speed limited and is the current controlled position) reaches the final position.
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Absolute Position Regulation Tips [NXC]

Post by h-g-t »

Been trying to follow this but it is all a bit too complex, even after reading the tutorial (several times).

Can this be used with standard firmware by just including the posreg.hfile?

If I use posreg.h, do I still have to set the rate from 100ms to 10ms or is this handled by the firmware?

What are the upper and lower limits of the 3 PID parameters?

What are the default values of the PID parameters?

If I set regulation parameters for ports A and B at the start of a program, do I only have to use the standard motor commands thereafter and regulation is applied automatically?

I use worm drives in my project so there is no movement unless the motors are turning. The motors are therefore set to float to avoid using battery power when idle.

Can I set regulation before using a motor then cancel it when movement is complete, then re-engage regulation before the next movement and so on?

Or can I set them to float when regulation is complete for a specific movement?

Or does the system not use any power when friction (rather than regulation) is preventing movement?

Are there any examples of programs using regulation written in NXC that I can look at?

Sorry to ask so many questions but I think the smoother movement under regulation would minimise vibration, if only I could understand it.
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.
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: Absolute Position Regulation Tips [NXC]

Post by schodet »

h-g-t wrote:Been trying to follow this but it is all a bit too complex, even after reading the tutorial (several times).

Can this be used with standard firmware by just including the posreg.h file?
No, you need John Hansen Enhanced firmware, or NXT Improved Firmware if you feel like hacking on the firmware.
If I use posreg.h, do I still have to set the rate from 100ms to 10ms or is this handled by the firmware?
Yes, however this is not mandatory but you will get better result if you reduce the regulation interval. Use SetMotorRegulationTime.
What are the upper and lower limits of the 3 PID parameters?
They are the same as the default control, you can use PID constants.
What are the default values of the PID parameters?
See PosRegEnable documentation.
If I set regulation parameters for ports A and B at the start of a program, do I only have to use the standard motor commands thereafter and regulation is applied automatically?
If you leave the absolute position regulation mode, you will have to enable it again.
I use worm drives in my project so there is no movement unless the motors are turning. The motors are therefore set to float to avoid using battery power when idle.

Can I set regulation before using a motor then cancel it when movement is complete, then re-engage regulation before the next movement and so on?

Or can I set them to float when regulation is complete for a specific movement?
If I understand the questions right, yes and yes.
Or does the system not use any power when friction (rather than regulation) is preventing movement?
I am used to never disable regulation, you could use a multimeter to measure current if you like.
Are there any examples of programs using regulation written in NXC that I can look at?
Here is one: http://ni.fr.eu.org/blog/position_control_test/
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Absolute Position Regulation Tips [NXC]

Post by h-g-t »

Thank you very much for taking the time to assist me.
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.
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Absolute Position Regulation Tips [NXC]

Post by h-g-t »

Just wanted to say that I finally bit the bullet and used the new motor regulation.

Much simpler than I expected, only needed the following commands -

PosRegEnable (OUT_A); // Enable positive regulation for panning motor- Port A
PosRegSetMax (OUT_A, 75, 75); // Speed and acceleration limit
SetMotorRegulationTime (10); // Speed up the regulation process

PosRegAddAngle (OUT_A, h_move); // Pan to next column

I thought it might be too slow but it is just as fast, although noticeably smoother.

Thank you very much Mr Schodet! :D :D :D
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.
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Absolute Position Regulation Tips [NXC]

Post by h-g-t »

I want to add a facility to go back a fixed number of steps by continually storing the motor positions n steps back so that I can regress to that point.

The problem is that my program is proceeding in increments using the 'add' method and not storing the total values.

Can I read one of the rotation counters to get the absolute values without cancelling the positive regulation mode?

Is so, which one would be best?

As an alternative, I could calculate absolute values for all points for both motors and store these in a 2-dimensional matrix before moving.

Problem is that under some circumstances the matrix would need about 180 elements (360 'cells') with values ranging from 0 to 40,000 in one column and 0 to 5,000 in the other.

Would the NXT be capable of holding arrays of that length and with such large contents?

I am trying to determine what my options are before re-writing the program so any comments would be appreciated.
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.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Absolute Position Regulation Tips [NXC]

Post by mattallen37 »

Instead of always adding a value using something like PosRegAddAngle, why not keep a running total in the program? I use PosRegSetAngle instead of PosRegAddAngle.

As far as the NXT being able to hold that many values, that isn't anywhere near the RAM limit. Assuming you used arrays of long (even though 40,000 would fit in an unsigned int), 360 elements would only use 1,440 bytes of RAM, out of the 32k available.
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: No registered users and 23 guests