NXC: motor rotate to a specific ("absolute") encoder target

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: motor rotating to a encoder target

Post by mattallen37 »

I think you want APR (Absolute Position Regulation). It is a feature that was developed (released) last fall, and implemented officially by John in March 2011.

Here is an example using the (now) native NXC API(s).

Code: Select all

task main(){
  PosRegEnable (OUT_A);                  //Start the APR control
  PosRegSetMax (OUT_A, 0, 0);            //Set the max parameters (0 is unlimited)
  while(true){
    PosRegSetAngle (OUT_A, (Random(1000)-500));      //Set the position you want, as often as you want.
    Wait(2500);
  }
}
Note, that before you start the APR (using PosRegEnable), the motor can be used normally (with things like OnFwd, Off...). This is nice to have to center the motor (home the encoder).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: motor rotating to a encoder target

Post by HaWe »

yes, correct, thanks, matt! :)
Unfortunately these keywords and their nomenclature are quite odd (they should start by "RotatXXXX..." or "SetRotatXXX...") and they are hard and complicated to handle -
but am I right that we my write a much more simple function for those above like
RotateToEncoderTarget(char port, char pwr, int accel, long target)
or even
RotateMotorToTarget(char port, char pwr, int accel, long target)

Code: Select all

safecall void RotateToEncoderTarget(char port, char pwr, int accel, long target) {
  PosRegEnable (port);                  
  PosRegSetMax (port, pwr, accel);           
  PosRegSetAngle (port, target);  
}
now
1) how is "acceleration" to be used and
2) how can we reset/disable this to normal use by OnFwd or Float ?
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: NXC: motor rotating to a encoder target

Post by schodet »

doc-helmut wrote:yes, correct, thanks, matt! :)
Unfortunately these keywords and their nomenclature are quite odd (they should start by "RotatXXXX..." or "SetRotatXXX...") and they are hard and complicated to handle -
but am I right that we my write a much more simple function for those above like
RotateToEncoderTarget(char port, char pwr, int accel, long target)
or even
RotateMotorToTarget(char port, char pwr, int accel, long target)

Code: Select all

safecall void RotateToEncoderTarget(char port, char pwr, int accel, long target) {
  PosRegEnable (port);                  
  PosRegSetMax (port, pwr, accel);           
  PosRegSetAngle (port, target);  
}
Absolute position regulation is a separated mode of control, so it has to be enabled to be used, then it keep the motor controlled to the desired position.
1) how is "acceleration" to be used
See http://nxt-firmware.ni.fr.eu.org/change ... egulation/ for a presentation.
2) how can we reset/disable this to normal use by OnFwd or Float ?
Call OnFwd or Float, or any other classic motor function to disable absolute regulation.
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: motor rotating to a encoder target

Post by HaWe »

schodet wrote:
doc-helmut wrote:yes, correct, thanks, matt! :)
Unfortunately these keywords and their nomenclature are quite odd (they should start by "RotatXXXX..." or "SetRotatXXX...") and they are hard and complicated to handle -
but am I right that we my write a much more simple function for those above like
RotateToEncoderTarget(char port, char pwr, int accel, long target)
or even
RotateMotorToTarget(char port, char pwr, int accel, long target)

Code: Select all

safecall void RotateToEncoderTarget(char port, char pwr, int accel, long target) {
  SetMotorRegulationTime (10);
  PosRegEnable (port);                  
  PosRegSetMax (port, pwr, accel);           
  PosRegSetAngle (port, target);  
}
Absolute position regulation is a separated mode of control, so it has to be enabled to be used, then it keep the motor controlled to the desired position.
1) how is "acceleration" to be used
See http://nxt-firmware.ni.fr.eu.org/change ... egulation/ for a presentation.
2) how can we reset/disable this to normal use by OnFwd or Float ?
Call OnFwd or Float, or any other classic motor function to disable absolute regulation.
thx, but what's written in the link is too hard to understand for me (my English is not good enough to understand all the words and the meanings even using Google translate).
Is something wrong with my suggestion about RotateToEncoderTarget?
What exactly are the unit values of acceleration?
Last edited by HaWe on 20 Aug 2011, 08:35, edited 1 time in total.
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: NXC: motor rotating to a encoder target

Post by linusa »

doc-helmut wrote: thx, but what's written in the link is too hard to understand for me (my English is not good enough to understand all the words and the meanings even using Google translate).
Naaaa, give it a try. I can understand it, and your English is better -- you know "target" better than I do, for example ;)
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
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: motor rotating to a encoder target

Post by HaWe »

linusa wrote:
doc-helmut wrote: thx, but what's written in the link is too hard to understand for me (my English is not good enough to understand all the words and the meanings even using Google translate).
Naaaa, give it a try. I can understand it, and your English is better -- you know "target" better than I do, for example ;)
Linusa, YOU even negated that any function about this even existed, and all you can do is post polemics and platitutes.
My question was.
Is something wrong with my suggestion about RotateToEncoderTarget?
What exactly are the unit values of acceleration?
Last edited by HaWe on 20 Aug 2011, 08:36, edited 1 time in total.
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: NXC: motor rotating to a encoder target

Post by schodet »

doc-helmut wrote:thx, but what's written in the link is too hard to understand for me (my English is not good enough to understand all the words and the meanings even using Google translate).
Well, would you prefer in french?
doc-helmut wrote:Is something wrong with my suggestion about RotateToEncoderTarget?
This would suggest that this use the same system as RotateMotor family. This is not the case.
doc-helmut wrote:What exactly are the unit values of acceleration?
Good point, I just updated the presentation page.

By the way, absolute position regulation works better when regulation time is set to 10 ms :

Code: Select all

SetMotorRegulationTime(MS_10);
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: motor rotating to a encoder target

Post by HaWe »

This would suggest that this use the same system as RotateMotor family. This is not the case.
1) I don't understand yet what you mean.
What is wrong?
Won't the motor go correctly to the target if I'm always using

Code: Select all

safecall void RotateToEncoderTarget(char port, char pwr, int accel, long target) {
  SetMotorRegulationTime (10);
  PosRegEnable (port);                 
  PosRegSetMax (port, pwr, accel);           
  PosRegSetAngle (port, target); 
}
?
Sometimes I'll have to move my robot arms directly to the upper or lower limit or a certain postion in between (e.g., start position).
Sometimes I have to move it relative legs until a sensor event happens (e.g., positioning the claw to grab an object).
So I have to decide what function to use depending on the circumstances requested behaviour, but all function actually rotate a certain motor.

A syntax which can be adjusted and applied to relative and absolute targetting would be intuitively the best:
RotateMotor(port,"RelativeAngle") vs. RotateToTarget(port, "AbsoluteTarget")

So again, what's wrong, what am I missing?
(simple sentences in simple words by a simple grammar I probably understand (in English, no way in French). Too many words exceeding 5 or 6 lines cause a stack overflow in my head: it's 40 years ago I had English lessons, I never talked to English People in reality, and I actually never had French at all - but what about you talking German?)

2)
Speed unit is degree per 100 ms
is this the same speed unit used by OnFwd or RotateMotor (in absolute values 0...100) ?
schodet
Posts: 139
Joined: 29 Sep 2010, 11:21
Contact:

Re: NXC: motor rotating to a encoder target

Post by schodet »

doc-helmut wrote:
This would suggest that this use the same system as RotateMotor family. This is not the case.
1) I don't understand yet what you mean.
Well, in this case, could you please find someone to translate my message to german?
doc-helmut wrote:2)
Speed unit is degree per 100 ms
is this the same speed unit used by OnFwd or RotateMotor (in absolute values 0...100) ?
Yes.
LEGO things http://ni.fr.eu.org/lego/ - NXT Improved Firmware (GCC) http://nxt-firmware.ni.fr.eu.org/ - Other robots http://apbteam.org
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: motor rotating to a encoder target

Post by HaWe »

-@schodet:
i guess you mean it's no good that the name RotateToEncoderTarget reminds of the other Rotate cmds.
But all rotate motor cmds rotate the motors, so it's good that all those functions start with "Rotate...".

acc to this function /wrap:

Code: Select all

safecall void RotateToEncoderTarget(char port, char pwr, int accel, long target) {
  SetMotorRegulationTime (10);
  PosRegEnable (port);                 
  PosRegSetMax (port, pwr, accel);           
  PosRegSetAngle (port, target);
}
to my observation it does not work with motors working "the other way round" (because mounted other way round or because of an intermediate gear).
e.g. having reached the encoder value -6000 e.g. by OnFwd(port, +pwr) there is no way to let the motor target -4000 (neither by using
PosRegSetMax (port, -80, 0);
PosRegSetAngle (port, -4000);
nor by
PosRegSetMax (port, +80, 0);
PosRegSetAngle (port, -4000);

in both cases the motors were turning "fwd" to more negative values, no way to get them targetting values closer to zero.
This seems to be a bug or a missing functionality.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest