2-axis Stabalising Platform Control of DC Motor using Arduino and 9-DOF RazorIMU

Hi all,

I am currently doing a project on 2-axis (roll and pitch) stabalising platform. The image of the final product can be seen below.

Final Product

However, I have trouble programming arduino to control the 2 DC motors. I am using the following components:

1 x Arduino UNO
1 x 9-DOF Razor IMU
2 x Faulhaber 2657W024CR DC Motor
1 x Motor Driver 1A Dual TB6612FNG

I have managed to use the Arduino UNO to read the values from the Razor IMU and store into 3 different variables using the following code:

//Assign variables for 9-dof sensor;
String input = "";
int i = 0;
int ey; //error yaw
int ep; //error pitch
int er; //error roll

void loop()
{ 
while (Serial.available() > 0)
  {
    //Error detection
    char c = Serial.read();
    input += c;
    if (c == '\n')
    {
      if (i == 0) {
        ey = input.toInt();
        Serial.print("yaw"); Serial.print('\t'); Serial.println(ey);
        input = "";
        i++;
      }
      else if (i == 1) {
        ep = input.toInt();
        Serial.print("pitch"); Serial.print('\t'); Serial.println(ep);
        input = "";
        i++;
      }
      else if (i == 2) {
        er = input.toInt();
        Serial.print("roll"); Serial.print('\t'); Serial.println(er);
        input = "";
        i = 0;
      }
    }
  }
}

The following is the reading I obtain from the arduino:

values obtained by Arduino using Razor IMU

However, I cannot seem to find a way to use these values to control my 2 DC motors. I would really appreciate if someone could help me with the Arduino coding to use the IMU readings to control the motor to stabalise the platform. Thank you so much in advance.

I cannot seem to find a way to use these values to control my 2 DC motors.

The normal way to do this is to compare the current angle of the device with the target angle of the platform and to output power to the motor to move the platform towards the required angle.

Doing this can be a little brutal as the platform is likely to overshoot the required angle and need to reverse its direction of travel to compensate, only to overshoot in the opposite direction. Not surprisingly there is a solution to this by applying the correction in proportion to the difference between the current angle and the required angle, aka the error.

Do a search on PID control for more information.