transcoding RobotC -> NXC

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

Re: transcoding RobotC -> NXC

Post by HaWe »

It's not the question why or if some ßutth@t (named mightor) banned me from the RobotC forum - RobotC at that time (6 years ago?) was bugged like hell, the support for this commercial product was under any review, reported bugs have been left undocumented, unfinished, unfixed, and forgotten, updates have been promised to come "next monday" (repeated several times over weeks and weeks and weeks...but monday never came) and they left efforts to establish a network connection for more than 1+1 NXT running into space finally resuming after more than 1/2 or even 1 year that this won't be possible ever because of firmware design. But not even the simple 1+1 version was documented in any way somewhere and at least did not work as expected.
What a crap.
Do you wonder that one gets mad because of this ?

Beyond that I highly doubt that any sole RobotC user is able to give advice to NXC motor commands as a substitute.

But anyway, my question is adressed to programmers who know both APIs for motor commands. I'm not very experienced in the extended NXC motor commands either. I wonder why this forum shouldn't be the right place to post a question like this.

And I'm really curious why it is not possible to ask a simple question in this forum without being offended in a snooty and arrogant manner and has to hear stupid sayings like "post this question elsewhere, do it by yourself, don't expect other people to do your work, I hope 30 days until extinction of the trial version will be enough time for transcoding".
A somewhat more constructive dialogue atmosphere would be very welcome and very much appreciated - for everyone's benefit. Sadly enough, that not even a site admin knows this simple wisdom - and keeps himself in it.

I'm just about to try transcoding Gordon Wyeth's particle filter to NXC (the code snippet above is part of that), I intended to publish the code when it will be finished (as I always do), and I guess many members of the NXC community will have a huge benefit from reading and experimenting and learning about how an embedded particle filter works and even how it might be improved a/o adjusted to own robot program designs for navigation and localization and sensor fusion.
afanofosc_99
Posts: 15
Joined: 26 Sep 2010, 18:18

Re: transcoding RobotC -> NXC

Post by afanofosc_99 »

Please, Doc, no need to argue with anyone. Everything you show can be done with RotateMotorEx in NXC.

Code: Select all


#define MOTOR_POWER 60

int nSyncedTurnRatio;

/************************* 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(byte outputs int d)
{
   RotateMotorEx(outputs, MOTOR_POWER, d, nSyncedTurnRatio, true, true);
}

// 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_mm * MM_TO_ENC);
   nSyncedTurnRatio = 0;
   do_move(OUT_AC, 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 = (ang_deg * DEG_TO_ENC);
   if (dist > 0) {
      nSyncedTurnRatio = -100;
      do_move (OUT_AC, 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 = (ang_deg * DEG_TO_ENC);
   if (dist > 0) {
      nSyncedTurnRatio = 100;
      do_move(OUT_AC, dist);
   }
}
You will need to define DEG_TO_ENC and MM_TO_ENC. And you may need to tweak the 100 and -100 turn ratios to get the left turn and the right turn to work correctly. Maybe set the last flag in RotateMotorEx from true to false - depending on whether setting motor power to 0 does a hard brake or a coast.

John Hansen
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: transcoding RobotC -> NXC

Post by h-g-t »

If you search for NXT particle filter there are quite a few hits, including at least one program.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: transcoding RobotC -> NXC

Post by HaWe »

thank you!
Mainly I was in doubt if the RobotC nMotorEncoderTarget was originally defined as a relative target - or as an absolute target which is possibly resetted (hidden?) from time to time to zero somewhere in Gordon's original source) . But as it appears it's supposed to be a relative target, so RotateMotorEx surely will work fine as you suggested.
The constants of course are already defined in the original source, and about the sync and the brake vs. coast thing I must see what happens.

If I once have managed to set up Gordon's model I surely will look for different SMC implementations (and will still have much to read about this topic).
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: transcoding RobotC -> NXC

Post by HaWe »

now there are some more obscured RobotC motor parameters to be unscrambled:

Code: Select all

	bFloatDuringInactiveMotorPWM = false;
	nMotorPIDSpeedCtrl[left_m]  = mtrSpeedReg;
	nMotorPIDSpeedCtrl[right_m] = mtrSpeedReg;
	nPidUpdateInterval = 5;
certainly bFloatDuringInactiveMotorPWM = false means: Motor-Off-mode == brake.
does the rest need to be noticed and adjusted for NXC's RotateMotorEx or can it simply be erased?

Code: Select all

task drive()
{
	float dx, dy, dq_degrees;
	int i, j;

	bFloatDuringInactiveMotorPWM = false;
	nMotorPIDSpeedCtrl[left_m]  = mtrSpeedReg;
	nMotorPIDSpeedCtrl[right_m] = mtrSpeedReg;
	nPidUpdateInterval = 5;
	nMaxRegulatedSpeed = MAX_SPEED;

	do {
		for (i = 0; i < num_waypts; i++) {
			for (j = 0; j < num_segments; j++) {

				// Wait for most up to date values
				wait_for_filter = 1;
				while (wait_for_filter > 0) {
					wait1Msec(1);
				}

				dx = waypt_x[i] - avg_x;
				dy = waypt_y[i] - avg_y;
				dist = sqrt(dx * dx + dy * dy) / (float)(num_segments - j);
				ATAN2(dy, dx, dq);
				dq -= avg_q;
				limit_ang(dq);
				dq_degrees = dq / PI * 180.0;
				StringFormat(cmd, "Q:%3.0f D:%3.0f", dq_degrees, dist);
				if (dq > 0.0) {
					turn_left (dq_degrees);
				} else if (dq < 0.0) {
					turn_right (-dq_degrees);
				}
				go_fwd (dist);

				// Finished moving so OK to run filter again
				if (wait_for_drive > 0) {
					wait_for_drive--;
				}
			}
		}
	} while (cycle_waypoints);
}
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests