Romi: Improve TurnSensor calibration

I’m using the Pololu TurnSensor library for my Romi, linked here:

I’m wondering how do I improve the calibration of my Romi’s gyroscope during the calibration period, to result in more accurate turns. Are there any ways to improve the calibration of my Romi’s gyroscope? I usually leave the Romi on a flat surface when it’s calibrating.

Hello.

It sounds like you are already doing the basics: making sure the Romi is flat and still during the calibration process.

You mentioned wanting to make more accurate turns, but the example program you linked to is actually for resisting turns. If you are using that example, can you tell me more about how your Romi behaves when you run the program? Or, if you are just using the “TurnSensor” library for another program that actually is making turns, can you post that program and let me know what sort of accuracy you are seeing versus what you are aiming for?

- Patrick

void Driving::turnLeft(int degrees=90) {
  delay(250);
  int degreesCheck;
  if(degrees==90||degrees==270)
    degreesCheck = 90;
  else
    degreesCheck=degrees;
  double turnSpeedCurr;
  turnSensorReset();

  do{    
  turnSensorUpdate();

  int32_t turnSpeed = ((int32_t)degrees*turnAngle1-(int32_t)turnAngle) / (turnAngle1 / kP) - turnRate / kD;
  
  turnSpeed = constrain(turnSpeed, -150, 150);

  turnSpeedCurr = (double)turnSpeed;


  motors.setSpeeds(-turnSpeedCurr*GDPMultiplier, turnSpeedCurr*GDPMultiplier);

  } while(abs(((int32_t)turnAngle >> 16) * 360 >> 16)<degreesCheck);

  motors.setSpeeds(0,0);
  turnSensorReset();
  stop();
}

I’ve modified the RotationResist example code in order to make the robot turn 90 degrees using the same PID and logic. I’ve attached my modified code above.

I’ve set kP to 25 and kD to 35. Anything in the code I can improve to make the turns better? My turns right now are less than 90 degrees. Do you think the fact that I’m constraining the turn speed to between -150 and 150 is having a negative effect on the turns?

It seems like you have identified a few possible sources for why your system is not turning a full 90° (error from the gyro sensor, unoptimized algorithm, etc.). The next step is to try and figure out which of those possible sources are the main contributors so you can focus your attention on the areas where you have the most room for improvement. That requires characterizing the problem better.

You said that the turns are currently less than 90°, can you try to measure/quantify how much less? Can you print how much the robot thinks it has turned based on the gyro sensor data and compare that to how much it is actually turning? If you look at the results of several turns, are the differences between your target angle, the actual angle, and the measured angle systematic or random?

- Patrick