Welcome to DroneRacingPilots!
Join our free drone racing community today!
Sign up

Designing my Own controller and QuadCopter Code. Hit a RoadBlock, help needed!

Varon

New Member
Joined
Sep 14, 2019
Messages
3
Reaction score
1
Age
20
Hello everyone. I have been trying to create my own controller and quad copter and i hit a roadblock. The problem is that when i try to fly the quadcopter, it feels like its going to take off as your increase the throttle but once it gets to a point where its actually going to start taking off, it just goes berserk. it never takes off and it just starts going haywire. If i hold it with my hand from the buttom and try to do some basic tests, it seems to work. if you tilt towards a motor, that motor increases power and if you tilt quickly, the motor reacts with faster speed.

Im not sure if im missing a step or something. i looked into a million equations and tried quite a lot of them, its not working.

here is what i have right now, the Code takes input from the controller and changes throttle speed. The Angles comes from the chip MPU 6050 using Jeff's library. as far is i know, the Library filters the Acc and Gyro and uses both to give you the Angles but im not sure.

No code for movement yet since it cant even take off vertically. Im Using arduino nano for the quad and uno for the controller. Right now, the leveling code is inside the Quad itself.


Frame:Amazon.com: 90mm 3K Carbon Fiber Quadcopter Frame for Racing Quadcopter Micro FPV Drone: Toys & Games

the MPU chip:Amazon.com: MPU-6050 Accelerometer Gyro Sensor 6DOF Six-Axis IMU for Arduino Quadcopter Drone RC, 3-5V I2C Compass 40P Female to Male Dupont Cable, 40P Male Pin Header: Home Audio & Theater

The ESC :Amazon.com: Spedix IS35 4-in-1 35A 5S ESC (20x20mm): Toys & Games

Motors:

Code: [Select]
Code:

//
float Porpotional_gain=3;
float Integral_gain=1.3;
float Derivative_gain=0.2;

PidTime=millis(); // we Read the Current time.
TimeError=(PidTime-LastPidTime)/1000;
CurrentReading_Yaw=ypr[0] * 180/M_PI;; // we read current Angles.
CurrentReading_Roll=ypr[2] * 180/M_PI;
CurrentReading_Pitch=ypr[1]* 180/M_PI ;

Desired_Roll=Initial_Roll; //the initial Angle of the MPU when its flat on the ground
Desired_Pitch=Initial_Pitch;

Error_Pitch=Desired_Pitch-CurrentReading_Pitch;
Error_Roll=Desired_Roll-CurrentReading_Roll;

int_errorGain_Pitch+=(Error_Pitch*TimeError);
int_errorGain_Roll+=Error_Pitch*TimeError;

Integral_Pitch=Integral_gain*int_errorGain_Pitch;
Integral_Roll=Integral_gain*int_errorGain_Roll;

Derivative_Roll=Derivative_gain*(( Error_Roll - Prev_Error_Roll)/TimeError);
Derivative_Pitch=Derivative_gain*(( Error_Pitch - Prev_Error_Pitch)/TimeError);

Input_Pitch=(Porpotional_gain*Error_Pitch)+Integral_Pitch;
Input_Roll=(Porpotional_gain*Error_Roll)+Integral_Roll;


Motor_1_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)-Input_Pitch;
Motor_3_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)+Input_Pitch;
Motor_2_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)-Input_Roll;
Motor_4_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor) +Input_Roll;

Prev_Error_Pitch=Error_Pitch; // update values that we need to carry for the next loop call.
Prev_Error_Roll=Error_Roll;
LastPidTime=PidTime;
//The MinMicroSeconds is that smallest value the motor can take which is 1000 milis.
//MotorPower is Potentiometer reading from the controller and its scaled by 3.


Please, i just want to know if im missing something or is this just a "keep adjusting PID " type of problem. i tried tuning the PID multiple times and there is noticeable difference in the attempts to fly but never succeeded.


there is very little that happens outside of this loop in terms of balancing the Quad. What else does this need to get stable flight?
 

rtkDarling

Well-Known Member
Joined
Nov 1, 2018
Messages
457
Reaction score
539
Age
37
I have to ask: Why the heck would you do this? Betaflight, Raceflight, EMUflight, and KISS are all great options, and it's taken these devs YEARS to get the results we have now. Getting it to "hover" is just the beginning, are you writing your own algorithms to handle the filtering?

Hey, we all need a hobby, if it makes you happy enjoy! Personally, I think you're crazy, but you should wear that judgement with pride :)
 

Varon

New Member
Joined
Sep 14, 2019
Messages
3
Reaction score
1
Age
20
I have to ask: Why the heck would you do this? Betaflight, Raceflight, EMUflight, and KISS are all great options, and it's taken these devs YEARS to get the results we have now. Getting it to "hover" is just the beginning, are you writing your own algorithms to handle the filtering?

Hey, we all need a hobby, if it makes you happy enjoy! Personally, I think you're crazy, but you should wear that judgement with pride :)

right now i dont filter it cus im using a library called "i2cdev "to access the MPU 6050 and from my understanding, the library returns filtered AC and gyro based on an offset and uses both to return a Pitch, yaw and roll angles. And yes, im a little insane. actually alot But still! i want this to work so badly! i have been trying to get it to work for two months now ☹
 
  • Like
Reactions: rtkDarling

HighTechPauper

Well-Known Member
Joined
Feb 5, 2017
Messages
1,599
Reaction score
1,650
Location
The Chesapeake Bay
Some things must be accounted for... or berserk mode (aka Tasmanian Devil mode, aka BF Taz Mode) will occur...

Motor rotation/direction, and compensations for Inward or Outward prop rotation
Logical motor location on the quad
FC orientation and offset.

Are you sure it couldn't be one of these you are not accounting for?
If not then I would think it is PID and vibration related.
 

NeoCloneOne

Well-Known Member
Joined
Oct 6, 2017
Messages
187
Reaction score
136
Age
53
Location
Honolulu, Hawaii
If you're holding it in your hand while you are arming the quad, the gyro and accelerometers in the flight controller automatically are trying to compensate the output to the motors when you tilt it at angles, to try and level the quad. It is a dangerous situation if you ask me, because holding it in your hand while having it armed is a bad accident waiting to happen, especially not being able to predict what the quad is gonna do. The props can do some serious bodily harm and I'd hate to hear about it. Why us trying to write your own code so important? Betaflight, Butterflight, iFlight, etc. does fine and have been refined by developers over many years and work well.
 

Varon

New Member
Joined
Sep 14, 2019
Messages
3
Reaction score
1
Age
20
If you're holding it in your hand while you are arming the quad, the gyro and accelerometers in the flight controller automatically are trying to compensate the output to the motors when you tilt it at angles, to try and level the quad. It is a dangerous situation if you ask me, because holding it in your hand while having it armed is a bad accident waiting to happen, especially not being able to predict what the quad is gonna do. The props can do some serious bodily harm and I'd hate to hear about it. Why us trying to write your own code so important? Betaflight, Butterflight, iFlight, etc. does fine and have been refined by developers over many years and work well.
the quad is tiny so its not that dangerous. its a school project im doing.
 

Latest threads

Members online

No members online now.

Forum statistics

Threads
2,757
Messages
24,236
Members
2,339
Latest member
9TFoX