robot - Turning Motor on Lego NXT returns error 0002EA Type 2 -


i writing program using robotc lego nxt imitate behaviour of puppy. section of code supposed rotate head connected motor port 3 , read value on ultra sonic sensor. if while head turned, dog called, turn in direction facing. following function called when ultrasonic sensor reads value (meaning robot has come close wall):

visible

void sonarsensor() {  int sensorvalleft;  int sensorvalright; bool alreadyturned = false;  int i,j; = 0; j = 0;  motor[1] = 0; motor[2] = 0;  motor[3] = -speed/2; wait10msec(15); motor[3] = 0; sensorvalleft = sensorvalue[3];  while(i<100) {     if(sensorvalue[4] > 40)//calibrate sound sensor     {         //turn left         motor[1]=speed;         motor[2] = -speed;         wait10msec(25);         = 1000;         j = 1000;         alreadyturned = true;     }     else     {         i++;         wait1msec(5);      } } motor[3] = speed/2; wait10msec(30); motor[3] = 0; sensorvalright = sensorvalue[3];  while(j<100) {     if(sensorvalue[3] > 1)//calibrate sound sensor     {         //turn right         motor[1]-=speed;         motor[2] = speed;         wait10msec(25);         j = 1000;         alreadyturned = true;     }     else     {         j++;         wait1msec(5);      } } if(alreadyturned == false) {     if(sensorvalleft > sensorvalright)     {         //turn left         motor[1]=speed;         motor[2] = -speed;         wait10msec(25);     }     else     {         //turn right         motor[1]=-speed;         motor[2] = speed;         wait10msec(25);     } } 

}visible

when head (motor[3]) rotates first time error 0002ea type2 appears on nxt screen. @ first thought because over-rotating motor causing obstructed tried play around wait times made no difference.

any ideas on causes error or how fix appreciated.

thanks, dominique

the answer why motor[3] causes error quite simple. motora, motorb, , motorc values defined in enum, motora=0, motorb=1, , motorc=2. so, motor[1] , motor[2] equivalent calling motor[motorb] , motor[motorc]. however, motor[3] isn't equivalent anything. it's trying set power of motor doesn't exist. motor[0] ok, however, , correspond motor[motora].


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -