Absolute position reglation in firmware

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Absolute position reglation in firmware

Post by schodet »

Hello,

I finally made progress to my new regulation method for the LEGO firmware.

This new algorithm controls one motor so that its position matches the position set by the user. At any time, even when the motor is moving, the set position can be changed, and the control algorithm will move the motor towards the new position.

Compared to original speed regulation, absolute position regulation offers the following advantages:

* position consign can be changed at any time,
* target position is held automatically,
* motor can slow down before the target position is reached,
* can be used remotely with precise movements,
* smooth transition between acceleration, full speed and deceleration,
* regulated synchronized mode.

I made a page documenting the change here, with a short tutorial, examples and the NXC API.

I made a binary (version 1.29i-813df11) so that you can test it. If you want to see what changed in firmware code, you can see change logs on gitweb or clone the git repository. The change is on a wip branch in my repository, but I will push it to the master branch in the following days if no grave regression or API problem is found.

Nicolas.
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Absolute position reglation in firmware

Post by mattallen37 »

Cool, sounds like EXACTLY what I have been wanting. I really hope this gets implemented into NXC.

Edit: I just flashed one of my NXT's with the FW, and used the "posreg.h" file, and it works SUPER well. Thanks SO much. John, please add this to the official NXC stuff.
BTW, is the FW based off of the original FW? or is it based off of a FW enhanced by John? Never-mind, the answer is no.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Absolute position reglation in firmware

Post by mattallen37 »

You posted the following:

"TODO: document how to wait for a movement to be finished."

How about a function that returns how far from the target the motor is? If it returns a zero, then it is at its target. I think it would be the same as comparing the "MotorTachoCount" to the last requested position.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Absolute position reglation in firmware

Post by h-g-t »

Looks interesting but does it follow the same controlled pattern when slowing down? I mean a movement analogous to the NXT-G ramp up-ramp down sequence?

Forgive my lack of comprehension but I am confused by your graph, since all examples seem to end up at the same speed, even when the speed is being limited.
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.
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: Absolute position reglation in firmware

Post by spillerrec »

The vertical axis the the current position of the motor and the horizontal axis is the time in seconds. So you will need to guess the speed by looking at how far it has moved in relation to the time.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Absolute position reglation in firmware

Post by h-g-t »

I see, thanks.
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.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Absolute position reglation in firmware

Post by HaWe »

schodet wrote:Hello,
I finally made progress to my new regulation method for the LEGO firmware.
This new algorithm controls one motor so that its position matches the position set by the user. At any time, even when the motor is moving, the set position can be changed, and the control algorithm will move the motor towards the new position.
Great idea! I appreciate this very much! (I actually posted this to the wishlist to NXC already more than 1 year ago!)
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: Absolute position reglation in firmware

Post by schodet »

mattallen37 wrote:Cool, sounds like EXACTLY what I have been wanting. I really hope this gets implemented into NXC.
Edit: I just flashed one of my NXT's with the FW, and used the "posreg.h" file, and it works SUPER well. Thanks SO much. John, please add this to the official NXC stuff.
BTW, is the FW based off of the original FW? or is it based off of a FW enhanced by John? Never-mind, the answer is no.
Nice you liked it :)

This is based on the original FW, but I am slowly merging enhanced FW feature as needed.
mattallen37 wrote:"TODO: document how to wait for a movement to be finished."
How about a function that returns how far from the target the motor is? If it returns a zero, then it is at its target. I think it would be the same as comparing the "MotorTachoCount" to the last requested position.
This can be done, but it is not always sufficient. The motor can be off by one or two degree depending on how well your PID coefficients are tuned.
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: Absolute position reglation in firmware

Post by schodet »

h-g-t wrote:Looks interesting but does it follow the same controlled pattern when slowing down? I mean a movement analogous to the NXT-G ramp up-ramp down sequence?
Forgive my lack of comprehension but I am confused by your graph, since all examples seem to end up at the same speed, even when the speed is being limited.
spillerrec wrote:The vertical axis the the current position of the motor and the horizontal axis is the time in seconds. So you will need to guess the speed by looking at how far it has moved in relation to the time.
Exactly, on the graph you can see the slowing down when the position approaches the target 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
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Absolute position reglation in firmware

Post by mattallen37 »

schodet wrote:Nice you liked it :)

This is based on the original FW, but I am slowly merging enhanced FW feature as needed.
That is good, but wouldn't it be better for John to add your single function to his tried and proven FW, than for you to add his countless modifications to your single one? I need RS-485 support, as well as the math (bitwise operators, sin, and cosin), among other things.
schodet wrote:This can be done, but it is not always sufficient. The motor can be off by one or two degree depending on how well your PID coefficients are tuned.
Well, I understand, but if it must be EXACTLY on the position, what difference will there be in making another function? I would just use a range to find out if it is at the right place. Something like the following:

Code: Select all

if(  MotorTachoCount (OUT_A)>=(TargetPosition-Threshold)  &&  MotorTachoCount (OUT_A)<=(TargetPosition+Threshold)  )
It will check the position compared to the target position, + or - the threshold. Basically, if the target was 180, and the threshold was 5, the "if" statement would be true if the MotorTachoCount was in the range of 175-185.
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 2 guests