So my project is a tad complex as previously mentioned on other posts, but i’m having a bit of an issue with the motor.
basically my program loops and depending on the value received from an arduino over serial, the 3pi will turn either left then straight, or right then straight.
The first time it loops through the call, it works perfectly fine, but the second time when the same command is sent, only motor 1 rotates and 2 does not move at all.
Looking at my code it all seems fine and there is no way it could be calling another function as there is nothing that would cause only one motor to move.
So I was wondering if you guys knew if it could possibly be that the pin motor 2 is connected to is busy with another process and therefore not responsive? kind of just baffles me.
below is just the code used in the switch case to determine orientation
if (mySerial.available()) {
someChar = mySerial.read();
switch (someChar) {
case 1:
motors.setSpeeds(60, -60); // turn left
break;
case 2:
motors.setSpeeds(-60, 60); //turn right
break;
case 3:
motors.setSpeeds(0, 0);
Serial.print(char(2)); //send 2 val to tell arduino that robot has stopped moving.
move = 0;
break;
case 4:
for (int x = 0; x<100; x++){
unsigned int position = robot.readLine(sensors, IR_EMITTERS_ON, 1);
if (position < 1000)
{
motors.setSpeeds(-200, 220); // We are far to the right of the line: turn left.
delay(100);
}
else if (position < 3000)
{
motors.setSpeeds(40, 40); // We are somewhat close to being centered on the line: drive left.
}
else
{
motors.setSpeeds(200, -220); // We are far to the left of the line: turn right.
delay(100);
}
}
break;
}
}