90 Degree turn using sensor

Hi team
Following code snap for rotate the robot at Left Right and Around
In this case delay is used to decide the value of angle robot to be rotated
Once we set the delay value for example 90 degree it is working fine
But due to decay of battery voltage the motor speed can be reduced So previously set angle can be changed

as a solution we can use
for example turn Left
we can rotate robot until sensor one reached the black line and then stop the rotation
Hope above solution is worked

But I don’t understand how it write properly using coding
Hi expert…Can you please help me to write it

Thanks in advanced

void turn(unsigned char dir)
  case 'L':
    // Turn left.
    OrangutanMotors::setSpeeds(-80, 80);
  case 'R':
    // Turn right.
    OrangutanMotors::setSpeeds(80, -80);
  case 'B':
    // Turn around.
    OrangutanMotors::setSpeeds(80, -80);
  case 'S':
    // Don't do anything!


It is generally beyond the scope of our direct technical support to write custom user code like that, but what you’re describing sounds similar to how our maze solving example for the Zumo shield robot handles turns. So, you might be able to use the turn() function that starts on line 173 as an example.

The Zumo shield line sensor array consists of 6 sensors, so the turn() function continues to turn until one of the sensors (the second sensor in toward the turning direction) passes over the line.


Hi BrandonM

Sorry for late reply
I checked the above link and solved the my issue. So I decided to change the code accordant to the above link for Zume robot.

I observed the above link and found out that it does not have PID controller

Please advice

The followSegment() function that on line 258 uses simple proportional control (which is basically a PID controller with the I and D coefficients set to 0). The offset_from_center variable is the error, which then gets multiplied by P (1/3 in this case) to calculate a power difference that’s proportional to the error.


1 Like

Yes Thanks
What could you think if we replace following code that uses 3pi king :grinning: code

unsigned int position = robot.readLine(sensors, IR_EMITTERS_ON);
int proportional = (int)position - 2000;
int derivative = proportional - last_proportional;
integral += proportional;

last_proportional = proportional;

int power_difference = proportional / 20 + integral / 10000 + derivative * 3 / 2;

I think we have more rooms to adjust the robot more accurately isn’t it

Please advice

Most maze courses I’ve seen only have straight line segments to follow between turns, so typically a full PID algorithm isn’t necessary, but it should generally be fine to use one like you’re suggesting.


1 Like

Grate thanks for your valuable input

Thanks once again