Page 1 of 2

transcoding RobotC -> NXC

Posted: 25 May 2013, 14:49
by HaWe
hey,
what would you suggest to be the best way to mimic (transcode) the following RobotC code snippet to the best matching NXC code?

// no equivalents to functionalities of nMotorEncoderTarget[] and nMotorRunState[] and nSyncedMotors =... and nSyncedTurnRatio = ...;
//
// no idea what tmotorNxtEncoderClosedLoop actually means

// simple:
// tMotor ~ char
// #define right_m OUT_A;
// #define left_m OUT_C;
// wait1Msec(1) ~ Wait(1)
// ecplicite type casting (int) may be dropped.

Code: Select all

const tMotor   right_m              = (tMotor) motorA; //tmotorNxtEncoderClosedLoop //*!!!!*//
const tMotor   left_m               = (tMotor) motorC; //tmotorNxtEncoderClosedLoop //*!!!!*//


#define MOTOR_POWER 60


/************************* Motion planning functions *****************************/

// void do_move(tMotor m, int d) - Command the motor m to move through the
// prescribed encoder counts d and block until the movement is complete.
void do_move(tMotor m, int d)
{
	nMotorEncoderTarget[m] = d;
	motor[m] = MOTOR_POWER;
	while (nMotorRunState[m] != 0) {
		wait1Msec(1);
	}
	motor[m] = 0;
}

// void go_fwd (float dist_mm) - Move robot forward the given distance in mm. Blocks
// til movement done.
void go_fwd (float dist_mm)
{
	int dist;

	dist = (int)(dist_mm * MM_TO_ENC);
	nSyncedMotors = synchAC;
	nSyncedTurnRatio = +100;
	do_move (right_m, dist);
}

// void turn_left (float ang_deg) - Turns robot left given angle in degrees. Blocks
// til movement done.
void turn_left (float ang_deg)
{
	int dist;

	dist = (int)(ang_deg * DEG_TO_ENC);
	if (dist > 0) {
		nSyncedMotors = synchAC;
		nSyncedTurnRatio = -100;
		do_move (right_m, dist);
	}
}

// void turn_right (float ang_deg) - Turns robot right given angle in degrees. Blocks
// til movement done.
void turn_right (float ang_deg)
{
	int dist;

	dist = (int)(ang_deg * DEG_TO_ENC);
	if (dist > 0) {
		nSyncedMotors = synchCA;
		nSyncedTurnRatio = -100;
		do_move (left_m, dist);
	}
}

Re: transcoding RobotC -> NXC

Posted: 25 May 2013, 18:26
by mattallen37
Once you know exactly what everything is (how the code works), read it as pseudo code, and convert that into NXC.

Re: transcoding RobotC -> NXC

Posted: 25 May 2013, 18:46
by HaWe
that exactly is the question!
I don't know what exactly the code is doing - otherwise I would be already long finished :roll:

e.g.,
are the motor targets absolute or relative?
is sth like synch ratio (AC or CA) also in NXC?
what about run state in NXC?

Re: transcoding RobotC -> NXC

Posted: 25 May 2013, 18:49
by mattallen37
Maybe you should look it up in the ROBOTC manual, and/or ask on the ROBOTC forums.

Re: transcoding RobotC -> NXC

Posted: 25 May 2013, 18:51
by HaWe
If you don't know the answer please keep off of this thread instead of giving me silly replies.

Re: transcoding RobotC -> NXC

Posted: 25 May 2013, 19:12
by mattallen37
You asked how to convert ROBOTC into NXC, so I told you how I do it. You asked what some ROBOTC specific things do, so I suggested two places that you could probably get the answers.

When people ask a question on a forum, they are usually seeking an answer to a question. Those who reply usually either tell them the answer, or point them towards the answer. Is it silly of me to try to help you find the information you are looking for?

Re: transcoding RobotC -> NXC

Posted: 25 May 2013, 19:28
by HaWe
did you just once again had a bad breakfast? :lol:
I asked my question just here in this place to get an answer here in this place.
Don't hezitate to read it again! :mrgreen:
doc-helmut wrote:hey,
what would you suggest to be the best way to mimic (transcode) the following RobotC code snippet to the best matching NXC code?

// no equivalents to functionalities of nMotorEncoderTarget[] and nMotorRunState[] and nSyncedMotors =... and nSyncedTurnRatio = ...;
//
// no idea what tmotorNxtEncoderClosedLoop actually means

// simple:
// tMotor ~ char
// #define right_m OUT_A;
// #define left_m OUT_C;
// wait1Msec(1) ~ Wait(1)
// ecplicite type casting (int) may be dropped.

Code: Select all

const tMotor   right_m              = (tMotor) motorA; //tmotorNxtEncoderClosedLoop //*!!!!*//
const tMotor   left_m               = (tMotor) motorC; //tmotorNxtEncoderClosedLoop //*!!!!*//


#define MOTOR_POWER 60


/************************* Motion planning functions *****************************/

// void do_move(tMotor m, int d) - Command the motor m to move through the
// prescribed encoder counts d and block until the movement is complete.
void do_move(tMotor m, int d)
{
	nMotorEncoderTarget[m] = d;
	motor[m] = MOTOR_POWER;
	while (nMotorRunState[m] != 0) {
		wait1Msec(1);
	}
	motor[m] = 0;
}

// void go_fwd (float dist_mm) - Move robot forward the given distance in mm. Blocks
// til movement done.
void go_fwd (float dist_mm)
{
	int dist;

	dist = (int)(dist_mm * MM_TO_ENC);
	nSyncedMotors = synchAC;
	nSyncedTurnRatio = +100;
	do_move (right_m, dist);
}

// void turn_left (float ang_deg) - Turns robot left given angle in degrees. Blocks
// til movement done.
void turn_left (float ang_deg)
{
	int dist;

	dist = (int)(ang_deg * DEG_TO_ENC);
	if (dist > 0) {
		nSyncedMotors = synchAC;
		nSyncedTurnRatio = -100;
		do_move (right_m, dist);
	}
}

// void turn_right (float ang_deg) - Turns robot right given angle in degrees. Blocks
// til movement done.
void turn_right (float ang_deg)
{
	int dist;

	dist = (int)(ang_deg * DEG_TO_ENC);
	if (dist > 0) {
		nSyncedMotors = synchCA;
		nSyncedTurnRatio = -100;
		do_move (left_m, dist);
	}
}

Re: transcoding RobotC -> NXC

Posted: 25 May 2013, 19:34
by mattallen37
Well, you're welcome to wait until someone comes along and does all the work for you, that's your choice. If you'd like it sooner rather than later (or possibly never), I suggest that you invest your own time into figuring it out, and then converting it. As I said earlier, the ROBOTC manual and the ROBOTC forums are probably the best places to gather information specific to ROBOTC.

Re: transcoding RobotC -> NXC

Posted: 25 May 2013, 19:42
by HaWe
well, surprisingly you really seem to be convinced that this is an adequate piece of advice. :shock:
Ok then, I'll let you in the belief and I hope you finally keep quiet. :?
Maybe other people here have more sense of what is helpful -and more willingness too. :D

In any case I for one am otherwise always ready and willing and anxious to help others in a friendly way.

Re: transcoding RobotC -> NXC

Posted: 26 May 2013, 06:51
by mightor
Matt, Doc is banned from the ROBOTC forums, that's why the question was posted here. There's not a whole lot of code there, I'm sure you'll figure it out, Doc.

As for Matt's answer, I don't think there's anything wrong with it, it's concise and to the point. The ROBOTC curriculum is a good place to start. You can also download a 30 day trial of ROBOTC, so you can see the code working. Hopefully that's enough time for you to convert this to NXC.

= Xander