Hello everyone,
I want to gather values from a MPU6050 gyroscope and send them to my arduino mega2560 , from where if they pass the values defined in the code, send signal to the drone after passing through a low pass filter. For example when i tilt the giroscope forward, the drone moves forward without problem. The issue comes in with other movements.
Here is the code section where i think i should make the changes
loop{
gatherValuesMPU();
analogWrite( pitchPin, pitch );//send the values to the low pass filter>drone joystick
analogWrite( rollPin, roll );//send the values to the low pass filter>drone joystick
}
gatherValuesMPU(){
//left movement
if ((ypr[2] * 180 / M_PI) < -20)
{
digitalWrite(rightLed, LOW);//Light a led to signal which way should the drone move
digitalWrite(leftLed, HIGH);//Light a led to signal which way should the drone move
roll = 254; // joystick to the left?
}
//right movement
if ((ypr[2] * 180 / M_PI) > 20)
{
digitalWrite(rightLed, HIGH);//Light a led to signal which way should the drone move
digitalWrite(leftLed, LOW);//Light a led to signal which way should the drone move
roll = 0; //Joystick to the right
}
//no movement left-right (turn off the leds) -
if (ypr[2] * 180 / M_PI >= -20 && ypr[2] * 180 / M_PI <= 20)
{
digitalWrite(rightLed, LOW);//Light a led to signal which way should the drone move
digitalWrite(leftLed, LOW);//Light a led to signal which way should the drone move
roll = 255/2; //middle
}
//forward movement
if ((ypr[1] * 180 / M_PI) < -15)
{
digitalWrite(backwardsLed, LOW);//Light a led to signal which way should the drone move
digitalWrite(forwardLed, HIGH);//Light a led to signal which way should the drone move
pitch = 0; //joystick forward
}
//backward movement
if ( (ypr[1] * 180 / M_PI) > 10)
{
digitalWrite(backwardsLed, HIGH);//Light a led to signal which way should the drone move
digitalWrite(forwardLed, LOW);//Light a led to signal which way should the drone move
pitch = 254; //backwards movement
}
//no movement forward , nor backwards
if (ypr[1] * 180 / M_PI >= -15 && ypr[1] * 180 / M_PI <= 10)
{
digitalWrite(forwardLed, LOW);//Light a led to signal which way should the drone move
digitalWrite(backwardsLed, LOW);//Light a led to signal which way should the drone move
pitch = 255/2;//middle
}
}
Here is the flowchart:
Here is the where the roll/pitch wires connect on the drone board after passing through the low pass filter

The joystick is still connected because i tried to de-solder it and place resistors in it's place, but unfortunately the whole thing then stopped working. So, the final question would be how to pass those movements of the gyro to the drone board joystick ?I am a begginer in this field and any help would be greatly apreciated.





