|
Page 1 of 1
|
[ 9 posts ] |
|
NQC to C-source convert problem + help
Author |
Message |
Wonderland2001
Rookie
Joined: Tue Feb 21, 2012 5:22 pm Posts: 5
|
 NQC to C-source convert problem + help
Hi, Got a problem to convert NQC to C-source. I use RobotC (RCX) My program is called Wall Follower that i found on this site http://www.philohome.com/wallfollower/wallfollower.htm |  |  |  | Code: #pragma config(Sensor, S1, , sensorTouch) #pragma config(Sensor, S2, SENSOR_1, sensorLightActive) #pragma config(Sensor, S4, , sensorTouch) #pragma config(Motor, motorA, right, tmotorNormal, openLoop, ) #pragma config(Motor, motorC, left, tmotorNormal, openLoop, ) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// Motor speed and direction
#define MFWD 3 #define MFLT 2 #define MOFF 1 #define MREV 0
// Distance thresholds #define XL3 527 #define XL2 480 #define XL1 444
#define XR1 430 #define XR2 420 #define XR3 410
int value, x, dx; int motl, motr;
task main() { SetSensor(SENSOR_1,SENSOR_LIGHT); Wait(100); // Charge GP2D12 sensor SetUserDisplay(value,0); // Display distance (remove for RCX firmware 1.5)
SetSensor(SENSOR_1,SENSOR_TOUCH); // Activate sensor Wait(5); SetSensorMode(SENSOR_1,SENSOR_MODE_RAW); value=SENSOR_1; // Get distance SetSensor(SENSOR_1,SENSOR_LIGHT); // Re-cahrge sensor for next time Wait(25); x=value; dx=0;
until (false) {
SetSensor(SENSOR_1,SENSOR_TOUCH); Wait(5); SetSensorMode(SENSOR_1,SENSOR_MODE_RAW); value=SENSOR_1; // Get distance SetSensor(SENSOR_1,SENSOR_LIGHT); // and recharge Wait(15); // shorter delay because calculations take time!
dx=x-value; //Distance variarion x=value;
motl=MFWD; motr=MFWD; if (x>=XL1) // Close to the wall { if (x>=XL3) { motr=MREV; // Very close, turn in place } else if (x>=XL2) { motr=MOFF; // close enough, turn } else if (x>=XL1) { motr=MFLT; // a bit too close, shallow turn }
} else // far from the wall { if (x<=XR2) // far from wall, { if (dx<2) // if small variation turn (avoids turning too short on salient angles) motl=MOFF; } else if (x<=XR1) { motl=MFLT; // a bit too far, shallow turn
}
}
switch(motr) { case MFWD: OnFwd(OUT_C); break; case MFLT: Float(OUT_C); break; case MOFF: Off(OUT_C); break; case MREV: OnRev(OUT_C); break; } switch(motl) { case MFWD: OnFwd(OUT_A); break; case MFLT: Float(OUT_A); break; case MOFF: Off(OUT_A); break; case MREV: OnRev(OUT_A); break; }
} }
|  |  |  |  |
Errors: Can someone help my find the sollutions for my C-source code (RobotC)? Thanks! Jack
|
Tue Feb 21, 2012 5:37 pm |
|
 |
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 630 Location: If I told you, I'd have to kill you.
|
 Re: NQC to C-source convert problem + help
Which version of RobotC are you using? Anything higher than 2.03 loses RCX support. Regarding the commands, they are completely different in NQC. You would really have to rewrite the whole program. I would suggest looking at some of the RCX curriculum available here. There is also a list of frequently used RCX commands at this site.Does this help?
_________________A.K.A. inxt-generation Self-proclaimed genius, and future world dominator. My Brickshelf Folder"Don't they teach recreational mathematics anymore?" - The Tenth Doctor Bow down to Nikola Tesla, King of the Geek Gods.
|
Wed Feb 22, 2012 12:25 am |
|
 |
Wonderland2001
Rookie
Joined: Tue Feb 21, 2012 5:22 pm Posts: 5
|
 Re: NQC to C-source convert problem + help
Hi, thanks for your respons! It works a little bit, can you help me? The piece (code) gives some errors. Here the new version:  |  |  |  | Code: #pragma config(Sensor, S2, sonarSensor, sensorLightActive) #pragma config(Motor, motorA, right, tmotorNormal, openLoop) #pragma config(Motor, motorC, left, tmotorNormal, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// Motor speed and direction
#define MFWD 3 #define MFLT 2 #define MOFF 1 #define MREV 0
// Distance thresholds #define XL3 527 #define XL2 480 #define XL1 444
#define XR1 430 #define XR2 420 #define XR3 410
int value, x, dx; int motleft, motright;
task main() { SetSensor(sonarSensor,SENSOR_LIGHT); wait10Msec(100); // Charge GP2D12 sensor SetUserDisplay(value); // Display distance SetSensor(sonarSensor,SENSOR_TOUCH); // Activate sensor wait10Msec(5); SetSensorMode(sonarSensor,SENSOR_MODE_RAW); value=SensorValue(sonarSensor); // Get distance SetSensor(sonarSensor,SENSOR_LIGHT); // Re-cahrge sensor for next time wait10Msec(25); x=value; dx=0;
until (false) {
SetSensor(Sensorlight,SENSOR_TOUCH); wait10Msec(5); SetSensorMode(Sensorlight,SENSOR_MODE_RAW); value=Sensorlight; // Get distance SetSensor(Sensorlight,SENSOR_LIGHT); // and recharge wait10Msec(15); // shorter delay because calculations take time!
dx=x-value; //Distance variarion x=value;
motleft=MFWD; motright=MFWD; if (x>=XL1) // Close to the wall { if (x>=XL3) { motright=MREV; // Very close, turn in place } else if (x>=XL2) { motright=MOFF; // close enough, turn } else if (x>=XL1) { motright=MFLT; // a bit too close, shallow turn }
} else // far from the wall { if (x<=XR2) // far from wall, { if (dx<2) // if small variation turn (avoids turning too short on salient angles) motleft=MOFF; } else if (x<=XR1) { motleft=MFLT; // a bit too far, shallow turn
}
}
switch(motright) { case MFWD: motor[motorA] = 100; motor[motorC] = 0; break; case MFLT: Float(OUT_C); break; case MOFF: motor[motorA] = 100; motor[motorC] = 0; break; case MREV: motor[motorA] = 100; motor[motorC] = -100; break; } switch(motleft) { case MFWD: motor[motorA] = 100; motor[motorC] = 100; break; case MFLT: Float(OUT_A); break; case MOFF: motor[motorA] = 0; motor[motorC] = 100; break; case MREV: motor[motorA] = -100; motor[motorC] = 100; break; }
} } |  |  |  |  |
|
Wed Feb 22, 2012 5:57 pm |
|
 |
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 630 Location: If I told you, I'd have to kill you.
|
 Re: NQC to C-source convert problem + help
Unfortunetly, I can't look through your code right now. I'm working on a big project that has to be finished by friday. I'll get back to you as soon as I can. In the meantime, I would suggest looking through the RobotC help files for more on setting the sensors, motor commands, etc.
_________________A.K.A. inxt-generation Self-proclaimed genius, and future world dominator. My Brickshelf Folder"Don't they teach recreational mathematics anymore?" - The Tenth Doctor Bow down to Nikola Tesla, King of the Geek Gods.
|
Wed Feb 22, 2012 6:48 pm |
|
 |
Wonderland2001
Rookie
Joined: Tue Feb 21, 2012 5:22 pm Posts: 5
|
 Re: NQC to C-source convert problem + help
Hi, i have solve 3 the little problems (about motor float,..) Now i got 4 errors, can you check my problems, thanks!  |  |  |  | Code: #pragma config(Sensor, S2, sonarSensor, sensorSONAR) #pragma config(Motor, motorA, right, tmotorNormal, openLoop) #pragma config(Motor, motorC, left, tmotorNormal, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// Motor speed and direction
#define MFWD 3 #define MFLT 2 #define MOFF 1 #define MREV 0
// Distance thresholds #define XL3 527 #define XL2 480 #define XL1 444
#define XR1 430 #define XR2 420 #define XR3 410
int value, x, dx; int motleft, motright;
task main() { SetSensor(S2,SENSOR_LIGHT); wait10Msec(100); // Charge GP2D12 sensor nxtDisplayCenteredTextLine(0, "Sonar Reading"); // Display distance SetSensor(S2,SENSOR_TOUCH); // Activate sensor wait10Msec(5); SetSensorMode(S2,SENSOR_MODE_RAW); value=SensorValue(S2); // Get distance SetSensor(S2,SENSOR_LIGHT); // Re-cahrge sensor for next time wait10Msec(25); x=value; dx=0;
while (true) {
SetSensor(S2,SENSOR_TOUCH); wait10Msec(5); SetSensorMode(S2,SENSOR_MODE_RAW); value=S2; // Get distance SetSensor(S2,SENSOR_LIGHT); // and recharge wait10Msec(15); // shorter delay because calculations take time!
dx=x-value; //Distance variarion x=value;
motleft=MFWD; motright=MFWD; if (x>=XL1) // Close to the wall { if (x>=XL3) { motright=MREV; // Very close, turn in place } else if (x>=XL2) { motright=MOFF; // close enough, turn } else if (x>=XL1) { motright=MFLT; // a bit too close, shallow turn }
} else // far from the wall { if (x<=XR2) // far from wall, { if (dx<2) // if small variation turn (avoids turning too short on salient angles) motleft=MOFF; } else if (x<=XR1) { motleft=MFLT; // a bit too far, shallow turn
}
}
switch(motright) { case MFWD: motor[motorA] = 100; motor[motorC] = 0; break; case MFLT: motor[motorA] = 50; motor[motorC] = 0; break; case MOFF: motor[motorA] = 100; motor[motorC] = 0; break; case MREV: motor[motorA] = 100; motor[motorC] = -100; break; } switch(motleft) { case MFWD: motor[motorA] = 100; motor[motorC] = 100; break; case MFLT: motor[motorA] = 0; motor[motorC] = 50; break; case MOFF: motor[motorA] = 0; motor[motorC] = 100; break; case MREV: motor[motorA] = -100; motor[motorC] = 100; break; }
} } |  |  |  |  |
|
Sun Feb 26, 2012 6:42 am |
|
 |
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 630 Location: If I told you, I'd have to kill you.
|
 Re: NQC to C-source convert problem + help
This last code of yours uses commands for the NXT. You said your using it the the RCX, didn't you? Which is it?
_________________A.K.A. inxt-generation Self-proclaimed genius, and future world dominator. My Brickshelf Folder"Don't they teach recreational mathematics anymore?" - The Tenth Doctor Bow down to Nikola Tesla, King of the Geek Gods.
|
Sun Feb 26, 2012 2:55 pm |
|
 |
Wonderland2001
Rookie
Joined: Tue Feb 21, 2012 5:22 pm Posts: 5
|
 Re: NQC to C-source convert problem + help
oeps, well i have change from robot type, because i got only a sonarsensor for the nxt robot.
|
Sun Feb 26, 2012 5:48 pm |
|
 |
Wonderland2001
Rookie
Joined: Tue Feb 21, 2012 5:22 pm Posts: 5
|
 Re: NQC to C-source convert problem + help
Nobody can help? 
|
Thu Mar 01, 2012 8:02 am |
|
 |
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 630 Location: If I told you, I'd have to kill you.
|
 Re: NQC to C-source convert problem + help
Okay, I am REALLY, sincerely sorry that it's been so long. I was sick for about 2.5 weeks, and couldn't think very well. After that, I kinda forgot about this until I saw it when I scrolled down the forums. I know how to fix the code, but before I do that, have you figured it out yourself?
_________________A.K.A. inxt-generation Self-proclaimed genius, and future world dominator. My Brickshelf Folder"Don't they teach recreational mathematics anymore?" - The Tenth Doctor Bow down to Nikola Tesla, King of the Geek Gods.
|
Sun Mar 25, 2012 4:20 pm |
|
|
|
Page 1 of 1
|
[ 9 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|