Page 1 of 5

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

Posted: 17 Aug 2011, 08:37
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

Re: NXC: motor rotating to a encoder target

Posted: 17 Aug 2011, 11:18
by linusa
The RotateMotor*() command family does that.

Re: NXC: motor rotating to a encoder target

Posted: 17 Aug 2011, 15:23
by HaWe
which family member (son, daughter, grandma, nephew) and how specifically?
e.g.
RotateToEncoderTarget(OUT_A, 80, 7890)

Re: NXC: motor rotating to a encoder target

Posted: 17 Aug 2011, 15:38
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.

Re: NXC: motor rotating to a encoder target

Posted: 17 Aug 2011, 15:38
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

Re: NXC: motor rotating to a encoder target

Posted: 17 Aug 2011, 19:39
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?

Re: NXC: motor rotating to a encoder target

Posted: 17 Aug 2011, 19:42
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???

Re: NXC: motor rotating to a encoder target

Posted: 17 Aug 2011, 19:45
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!

Re: NXC: motor rotating to a encoder target

Posted: 17 Aug 2011, 19:55
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.

Re: NXC: motor rotating to a encoder target

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