transcoding RobotC -> NXC
Posted: 25 May 2013, 14:49
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.
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);
}
}