Dominique
Dominique

Reputation: 167

Turning Motor on Lego NXT returns error 0002EA Type 2

I a writing a program using RobotC for the Lego NXT to imitate the behaviour of a puppy. This section of code is supposed to rotate the head which is connected to motor port 3 and read the value on the ultra sonic sensor. If while the head is turned, the dog is called, it will turn in the direction it was already facing. The following function is called when the ultrasonic sensor reads a value (meaning the robot has come close to a wall):

void SonarSensor()
{

int sensorValleft;

int sensorValright;
bool alreadyTurned = false;

int i,j;
i = 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);
        i = 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);
    }
}

}

When the head (motor[3]) rotates the first time the error 0002EA Type2 appears on the NXT screen. At first we thought it was because we were over-rotating the motor causing it to be obstructed so we tried to play around with the wait times but it made no difference.

Any ideas on what causes this error or how to fix it would be appreciated.

Upvotes: 0

Views: 174

Answers (2)

BurningLights
BurningLights

Reputation: 2397

The answer as to why only motor[3] causes an error is actually quite simple. The motorA, motorB, and motorC values are defined in an enum, where motorA=0, motorB=1, and motorC=2. So, motor[1] and motor[2] are equivalent to calling motor[motorB] and motor[motorC]. However, motor[3] isn't equivalent to anything. It's trying to set the power of a motor that doesn't exist. motor[0] would be ok, however, and would correspond to motor[motorA].

Upvotes: 1

Dominique
Dominique

Reputation: 167

While debugging, I started putting break points in to see where the error was and it alwas occurred on the line motor[3] = -SPEED/2; it turns out that with the third motor the proper syntax is to use motor[motorA]=-SPEED/2;. I am not sure why only this motor returns this error as I am using two other motors which I set new speeds using

motor[1]=SPEED;
motor[2]=SPEED;

However, this was the way to abolish the error.

Upvotes: 0

Related Questions