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.
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.