2

I'm building a quad-copter using an accelerometer and gyro. The form looks like this one:

img

My pitch is controlled by the front and back motors. My roll is controlled by the left and right motors.

I used PID and servo libraries.

Here's my pitch stability code:

double Kp=3.15, Ki=4.3, Kd=0.6;
int throttle = 1000;

PID PitchPID(&PitchInput, &PitchOutput, &PitchSetpoint, Kp, Ki, Kd, DIRECT);

 PitchPID.SetMode(AUTOMATIC);

  backESC.attach(3);
  frontESC.attach(5);

 // arme the motors
  backESC.writeMicroseconds(2000);
  frontESC.writeMicroseconds(2000);
  delay(5000);

  backESC.writeMicroseconds(700);
  frontESC.writeMicroseconds(700);
  delay(2000);

void loop{
 // i have the angle and pitch
  int xAngle = GetX();
  int Pitch = GetPitch();



PitchInput = (Pitch) ;
PitchSetpoint = 0;
PitchPID.SetOutputLimits(-150,150);
PitchPID.Compute();


backPower =  PitchOutput;

frontPower = (PitchOutput*-1);


frontESC.writeMicroseconds(backPower + throttle);
  backESC.writeMicroseconds(frontPower + throttle);
}

As you can see, I don't yet have a real algorithm to stabilize the quad. I would be grateful for some help. I have already tried some samples. It didn't go well. Even help without using my PID library would be appreciated.

BMitch
  • 231,797
  • 42
  • 475
  • 450
Goor Lavi
  • 412
  • 3
  • 16
  • can you (inside the code) identify which motors lie along the pitch and which along the roll? Afterwards we should be able to write a function to `incrementPitch()`, `decrementPitch()`, and the same for roll. –  May 03 '16 at 20:44
  • As u can see i declared only 2 motors front and back both lie along the pitch i was thinking if i will be able to stable only one axis the secound will be at the same way – Goor Lavi May 03 '16 at 20:51
  • Okay, so you just want to solve the yaw problem first. First find the magical numbers that keep the quad copter hanging in air ( as if when a stick was running through it top to bottom to make sure it had level yaw and pitch values) Then write an incrementYaw function. It should simply turn the two front motors faster while turning the 2 back motors slower. write a decrementYaw function. Now in a while loop, simply incrementYaw if yaw < 0, and decrementYaw if yaw > 0 –  May 03 '16 at 21:12
  • Im sorry i dont see for what i need the yaw can you explain? – Goor Lavi May 04 '16 at 15:15
  • by yaw I meant pitch :) –  May 04 '16 at 15:20
  • I'd write the code to balance it along both pitch and roll at first. But since you want to do it one by one, I suggest another method –  May 04 '16 at 15:27
  • find the necessary force for the motors to keep the vehicle steady in the air. Then increase the front lift while decreasing the back. That should result in an increase in pitch. –  May 04 '16 at 15:28
  • Why not learn from ardupilot? – n. m. could be an AI Sep 18 '17 at 14:08

0 Answers0