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

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post by HaWe »

hi,
I just also tried to find Motor commands for motor rotating to a encoder target but can't find the proper cmd:
I expected sth like

Code: Select all

RotateToEncoderTarget(char port, char PwrPerc, long Target)
RotateToEncoderTarget(OUT_A, 80, 7890)
but I can't find anything like that
Last edited by HaWe on 21 Jan 2012, 13:12, 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 »

The RotateMotor*() command family does that.
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 »

which family member (son, daughter, grandma, nephew) and how specifically?
e.g.
RotateToEncoderTarget(OUT_A, 80, 7890)
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: NXC: motor rotating to a encoder target

Post by linusa »

Lets copy the NXC help

void RotateMotor ( byte outputs,
char pwr,
long angle
) [inline]

Rotate motor.

Run the specified outputs forward for the specified number of degrees.
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
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:which family member (son, daughter, grandma, nephew) and how specifically?
e.g.
RotateToEncoderTarget(OUT_A, 80, 7890)
RotateMotor is the big daddy

son is RotateMotorEx NXCDefs.h with nephew RotateMotorExPID NXCDefs.h and cousin RotateMotorPID NXCDefs.h
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 »

Just get specific an detailed, how is the code to be written for RotateToEncoderTarget(OUT_A, 80, 7890)?
Why don't you want to write t explicitely?
Or is it too complicated to write?
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:Just get specific an detailed, how is the code to be written for RotateToEncoderTarget(OUT_A, 80, 7890)?
Why don't you want to write t explicitely?
Or is it too complicated to write?
RotateToEncoderTarget RotateMotor(OUT_A, 80, 7890) ? Are you serious???
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 »

I guess you miss understand:
I don't want it to ratate 7890 relatively but to an absolute target regardless of the current counter value!
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:I guess you miss understand:
I don't want it to ratate 7890 relatively but to an absolute target regardless of the current counter value!
Question wasn't clear (since it didn't say relative or absolute). The word target can be used in any case. I shouldn't even answer, but I think we had this before: Keep one of the three counters (probably best to use MotorRotationCount, also an NXC function) running and don't reset it (that's perfectly possible, you still got TachoCount to reset, BlockTachoCount is reserved for sync driving).

Then, each call looks like this:

Code: Select all

absoluteTarget = 7890;
power = 80;
relativeTarget = absoluteTarget  - MotorRotationCount(OUT_A);
if (relativeTarget < 0) {
   power = -power;
   relativeTarget = - relativeTarget;
}//end if
RotateMotor(OUT_A, power, relativeTarget);
But I can guess your answer might be: "I explicitely asked for an NXC function, I can do that code myself, I don't want to use this function / this counter, I just wanted to know if there is a function like RotateToEncoderTarget in NXC". Well, no, there isn't.
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 »

a target is a target and not a count of rotations to be done, but anyway, I thought it was clear.
In RobotC it's
SetRotationTarget (more or less)
for absolute targets.

And yes, there must be a built-in function meanwhile (IIRC) for approximating absolute encoder targets (even to hold the target if manipulated by external forces after reaching the target)
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests