I encounter a strange problem with an NXT 1's US sensor. The program consists of several tasks which are considered as states. The main task is used to initialize the input ports as low speed ones, then passes the control to the first state. At the beginning the program works perfectly well, the transitions between tasks happen as expected. But after some time, typically a couple of minutes, the robot seems locked in one state. It's always the same state, and normally there should be a state transition when the US sensor detects an object near. I've tried to put my hand in front of it, it doesn't seem to detect anything anymore, as if it was switched off.
Here are the parts of the code where I use the US sensor :
Code: Select all
task main() {
SetSensorLowspeed(IN_1); //Compass Sensor
SetSensorLowspeed(IN_2); //Ultra Sonic Sensor
SetSensorLowspeed(IN_3); //Colors Sensor
//...
}
task randomApproach() {
StartTask(randomCourse);
SetSensorLowspeed(IN_2); //Ultra Sonic Sensor
Wait(1000);
int mesure = 300;
while(SensorUS(IN_2) > 50) {
Wait(50);
}
mesure = SensorUS(IN_2);
//Musical identifier
PlayTone(131,32*__NOTETIME);
Wait(16*__WAITTIME);
StopTask(randomCourse);
Off(OUT_AC); //Use the brakes to stop the robot
Wait(500);
//...
}
//Called by randomApproach() to move the robot around like it's drunk
task randomCourse() {
int power;
while(true) {
power = Random(100);
OnFwd(OUT_C, power);
OnFwd(OUT_A, 100 - power);
//controle de l'ouverture de la griffe
if (MotorRotationCount(OUT_B) >= 90) {
OnRev(OUT_B, 50);
}
Wait(600);
}
}
//Called by scan()
task mesure() {
//Initialization : guarantees at least one measure will be done
distance = 300;
while(true){
if(distance>SensorUS(IN_2)) {
distance = SensorUS(IN_2);
ResetRotationCount(OUT_AC);
}
Wait(40);
}
}
So, do you seen anything that looks like awfully wrong practice to you in the code ? I confess I'm a bit confused about Low Speed sensors and their API functions : is there a need for a waiting time or is it included already in functions such as SensorUS(port) ?
Another thing : there was some other strange behaviour from the robot since I've changed the firmware to enable multitasking. (For instance, the ResetRotationCount function was not working properly anymore.) I'm using BricxCC, was there anything to change in its configuration after installing the enhanced firmware on the brick ? Now that I think of it, it could explain my problems... :s
Thanks in advance for your help !