transcoding RobotC -> NXC

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

transcoding RobotC -> NXC

Post 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);
	}
}
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: transcoding RobotC -> NXC

Post by mattallen37 »

Once you know exactly what everything is (how the code works), read it as pseudo code, and convert that into NXC.
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: transcoding RobotC -> NXC

Post 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?
Last edited by HaWe on 25 May 2013, 18:50, edited 1 time in total.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: transcoding RobotC -> NXC

Post by mattallen37 »

Maybe you should look it up in the ROBOTC manual, and/or ask on the ROBOTC forums.
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: transcoding RobotC -> NXC

Post by HaWe »

If you don't know the answer please keep off of this thread instead of giving me silly replies.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: transcoding RobotC -> NXC

Post 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?
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: transcoding RobotC -> NXC

Post 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);
	}
}
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: transcoding RobotC -> NXC

Post 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.
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: transcoding RobotC -> NXC

Post 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.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: transcoding RobotC -> NXC

Post 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
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 2 guests