Page 2 of 5

Re: NXC: motor rotating to a encoder target

Posted: 17 Aug 2011, 21:57
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).

Re: NXC: motor rotating to a encoder target

Posted: 18 Aug 2011, 06:29
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 ?

Re: NXC: motor rotating to a encoder target

Posted: 18 Aug 2011, 18:48
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.

Re: NXC: motor rotating to a encoder target

Posted: 18 Aug 2011, 20:15
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?

Re: NXC: motor rotating to a encoder target

Posted: 18 Aug 2011, 22:23
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 ;)

Re: NXC: motor rotating to a encoder target

Posted: 19 Aug 2011, 06:34
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?

Re: NXC: motor rotating to a encoder target

Posted: 19 Aug 2011, 19:20
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);

Re: NXC: motor rotating to a encoder target

Posted: 19 Aug 2011, 20:35
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) ?

Re: NXC: motor rotating to a encoder target

Posted: 21 Aug 2011, 19:45
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.

Re: NXC: motor rotating to a encoder target

Posted: 26 Oct 2011, 16:54
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.