Arduino Forum

Community => Exhibition / Gallery => Topic started by: baselsw on Aug 25, 2013, 11:01 pm

Title: BlueCopter - Arduino Quadcopter
Post by: baselsw on Aug 25, 2013, 11:01 pm
Hey,

I spent the summer working with a new hobby of mine, Quadcopters =D! The quadcopter board is homemade (atmega32u4). Because my board has the same pinout as a leonardo, I decided to go with the multiwii firmware. So I etched a shield for my board containing headers for the receiver, motors and the IMU (cheap chinese found on ebay, ADXL345, L3G4200D, HMC5883 and BMP085).

I was happy with the quadcopter, it flew very nicely (after some PID changes of course).. But in the end I'm the type that likes to write my own code.. Trying to look at multiwii's code to see how they made it work (just to get a hunch), I directly noticed that the code isn't very, hmm how do I put it, reader friendly... So I trashed Multiwii, and there my summer began learning the dynamics and physics of quadcopters.

Three days later, I got a working code.. Three weeks after that I finally managed to find the optimal PID values for my quadcopter =P (yes it took three weeks of tweaking)..

Anyhow I'm not going to bore you out with my story. Instead I'm going to share my code with the arduino community and a video of the quadcopters first flight with my code..

If there is a big demand for a code explanation/theory about quadcopters and how everything works, shout out here, and I'll come up with something for you...

Here is the code: https://github.com/baselsw/BlueCopter

See attachment for pinout..

And here is the video:
http://www.youtube.com/watch?v=J7V1K-8xw6c

Edit: I've updated the code.. Made the sketch run more efficiently and reduced code size.. With this change I managed to find better PID values and thus get better/faster stabilization.. For those interested I've added pictures of the main board and hardware setup..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: nickgammon on Aug 25, 2013, 11:12 pm
Very nice, but I think I'll move it to Exhibition / Gallery.

Thanks for sharing the video and the code.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Aug 25, 2013, 11:20 pm

Very nice, but I think I'll move it to Exhibition / Gallery.

Thanks for sharing the video and the code.

Hey, thanks Nick =)..  Couldn't figure out where to start the topic..  Good thing you moved it..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Jantje on Aug 26, 2013, 12:47 am
Tweeking takes time. Very good job I would say. Though the drawings are not clear to me at all.
Thats probably cause by my lack of knowledge
Jantje
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Aug 26, 2013, 01:22 am

Tweeking takes time. Very good job I would say. Though the drawings are not clear to me at all.
Thats probably cause by my lack of knowledge
Jantje


Thx =).. By drawing I assume you mean the pinout? Well, it's simple.. I used the X-configuration (meaning the quad is flying in a X shape).. If you look at the pinout the motor pins should be,

Left upper motor: Pin 6
Left bottom motor: Pin 5
Right upper motor: Pin 10
Right bottom motor: Pin 9

For RX (receiver), PPM signal (Pulse-position modulation), The pins are as follows:
Roll: Pin 16
Pitch: Pin 14
Yaw: Pin 15
Throttle: Pin 7
AUX1: Pin 8
AUX2: Pin 0

I've also got a LED on pin 13, that indicates if the quad is in rate or level/angle mode..

And of course SDA/SCL for the sensors...

Currently the code only uses the accelerometer and gyrometer to make the quad stable during rate- and angle mode..

In the future I may implement heading hold (magnetometer) and altitude hold (barometer).. Not sure yet, cause I didn't have any need for them...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Arvis on Aug 29, 2013, 05:13 pm
Awesome project! How much did it cost to build it?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Aug 29, 2013, 05:23 pm

Awesome project! How much did it cost to build it?


Thanks bro =)..! Well, for the quadcopter parts without the main board (home made btw), around 150 USD. I bought all the parts (frame, ESC, motors, propellers...etc) from hobbyking.

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: robtillaart on Aug 29, 2013, 06:06 pm
Well done,

many questions pop up
- how high can it fly?
- how long can it stay in the air?
- what does it do when it looses contact with remote?
- ...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Aug 29, 2013, 07:03 pm

Well done,

many questions pop up
- how high can it fly?
- how long can it stay in the air?
- what does it do when it looses contact with remote?
- ...


-- Pretty high.. I didn't measure the distance yet.. But it's so high that it starts to look like a small fly in the sky (cant see the orientation of the quad, nothing)..
-- I'm using a double 2200mAh (3 cells, LiPo, coupled in parallell).. It gave me approx. 15min of flight..
-- Well I lost contact with it when I pushed the throttle to the max! (meaning it flew very high).. Nothing special happens.. It will stay leveled in the air until battery begins to run out, and it will descend (depending on the ESC ur using, it can descend slowly(ESC cutting power slowly) or it will suddenly stop (ESC cuts the power alltogether)).

And here's my parts list (all from hobbyking.com):












Item/PartPcs
20CM Male to Male Servo Lead (JR) 26AWG (10pcs/set)
1
Hobby King 2.4Ghz 6Ch Tx & Rx V2 (Mode 2)
1
Turnigy 2200mAh 3S 25C Lipo Pack
2
NTM Prop Drive 28 Series Accessory Pack
4
Hobby King Quadcopter Power Distribution Board
1
NTM Prop Drive 28-26 1350KV / 310W
4
HobbyKing 30A BlueSeries Brushless Speed Controller
4
Hobbyking X666 Glass Fiber Quadcopter Frame 666mm
1
8045 SF Props 2pc Standard Rotation/2 pc RH Rotation (Blue)
1


And consider buying spares of ex. propellers and such (if you're a beginner you'll need it)..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: nickgammon on Aug 29, 2013, 11:03 pm
Do you need an additional device to "bind" or "register" the receiver to the transmitter, or does the one you listed do that?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Aug 29, 2013, 11:14 pm

Do you need an additional device to "bind" or "register" the receiver to the transmitter, or does the one you listed do that?


The packages comes with a transmitter and receiver..

No, you get a 'special' wire that shorts the signal line on the PWR-input to ground (on the receiver).. This will put it in binding mode (Led will start to blink once per second)... In the transmitter all you have to do is hold the bind button and turn it on.. One second later the connection is accomplished, and the led on the receiver will stop blinking =D!

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 05, 2013, 03:18 pm
i have made quadcopter with arduino uno and gy_80 sensor i have ppm 4channel radio controller and it is not sum every single channel is ppm . i tried to use your program for this but receiver dont work when i want it to fly .....
" when i connect my ppm receiver to single motor with esc radio control work perfectly but when i use it as quadcopter with code does not work
.........
help me plz . help :(
faramarz.zareian@gmail.com
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Sep 05, 2013, 06:40 pm

i have made quadcopter with arduino uno and gy_80 sensor i have ppm 4channel radio controller and it is not sum every single channel is ppm . i tried to use your program for this but receiver dont work when i want it to fly .....
" when i connect my ppm receiver to single motor with esc radio control work perfectly but when i use it as quadcopter with code does not work
.........
help me plz . help :(
faramarz.zareian@gmail.com


Well, it won't work, I'd be surprised if it did.. This sketch is written for the arduino leonardo (atmega32u4), meaning it won't work on the UNO directly, specially the receiver part. The receiver is using the PCINT (pin change interrupts), and because there is no built-in library for arduino I had to address the registers directly, the atmega32u4 registers (which is not the same for the UNO atmega328p)..

For a beginner I recommend the use of MultiWii's code (http://www.multiwii.com/software), my code is "kind of" for people that wants to write their own code and needs some starting ground..

Edit: Another thing I would like to add.. If you decide to modify my code to work with your quadcopter, you'd have to make sure that your ESC supports PWM at a frequency of ~480-500Hz... Most ESC are made to only support PPM.. PPM isn't the same as PWM, the signal looks different and in most ESC is made to run on a frequency of 50Hz...

Here is a whole discussion about the difference: http://forum.arduino.cc/index.php/topic,14146.0.html

And if you decide to replace the 480Hz PWM with 50Hz PPM, you'll have a lot of trouble getting the quadcopter to be stable... With a little luck, you'll maybe be able to fly it in rate mode.. Angle/Level mode needs a faster update rate...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 07, 2013, 11:52 pm


Tweeking takes time. Very good job I would say. Though the drawings are not clear to me at all.
Thats probably cause by my lack of knowledge
Jantje


Thx =).. By drawing I assume you mean the pinout? Well, it's simple.. I used the X-configuration (meaning the quad is flying in a X shape).. If you look at the pinout the motor pins should be,

Left upper motor: Pin 6
Left bottom motor: Pin 5
Right upper motor: Pin 10
Right bottom motor: Pin 9

For RX (receiver), PPM signal (Pulse-position modulation), The pins are as follows:
Roll: Pin 16
Pitch: Pin 14
Yaw: Pin 15
Throttle: Pin 7
AUX1: Pin 8
AUX2: Pin 0

I've also got a LED on pin 13, that indicates if the quad is in rate or level/angle mode..

And of course SDA/SCL for the sensors...

Currently the code only uses the accelerometer and gyrometer to make the quad stable during rate- and angle mode..

In the future I may implement heading hold (magnetometer) and altitude hold (barometer).. Not sure yet, cause I didn't have any need for them...


For RX (receiver), PPM signal (Pulse-position modulation), The pins are as follows:
you mean ppm receiver work with your code ?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Sep 08, 2013, 12:13 am

For RX (receiver), PPM signal (Pulse-position modulation), The pins are as follows:
you mean ppm receiver work with your code ?


Yes, the receiver sends ordinary servo pulses/PPM to the arduino (one signal per axis/control-rod, a total of 6 pins/signals). And because the signals are ordinary servo signals (50Hz update rate), I used interrupts in order to read these when they change and thus avoid getting my loop rate (~800Hz) draged down by these signals..

Here is a example of how these signals looks like:

(http://www.hooked-on-rc-airplanes.com/images/servo-pulse.jpg)

Edit: I just read your other post about needing a code that reads PPM. I'll try to explain how I did it code-wise:

Let me begin by stating the problem ahead.. If we take the throttle-rod as an example, when the throttle-rod is in the (0% position) the receiver will send a signal that's ~21ms long (a high pulse for 1ms and a low pulse for 20ms).. And when its in the (100% position) the receiver will send a signal that's ~22ms long (a high pulse for 2ms and a low pulse for 20ms).. As you noticed the 20ms part is just a "synchronization part" and doesn't provide anything useful in our case..

What we need is to measure how long the "high pulses" are. And to do that we need to know when a pulse starts and when it ends. The simplest way of doing this is using External interrupts (very few pins on arduino!!)..

Here is a example code:

Code: [Select]

#define RX_INT_PIN_THROTTLE 0
volatile int rxPrev = 0; //variable that will contain the previous time
volatile int rxVal = 0; //variable that will contain the current throttle pulse length

void rxGoesHigh(){
/* As soon as we get into this function we measure the current time (with micros)
and put that value in our variable rxPrev. After that we re-attach the same interrupt
but this time we want it to fire when the pin goes low "FALLING". When that happens it
will call the function rxGoesLow */
  rxPrev=micros();
  attachInterrupt(RX_INT_PIN_THROTTLE,rxGoesLow,FALLING);
}
void rxGoesLow(){
/* As soon as we get into this function we measure the current time (with micros) and
subtract the previous time (rxPrev). By doing that we will get the length of the pulse,
from start to the end. We end this process by re-attaching the throttle pin to a RISING
interrupt, which will repeat the process again... */
  rxVal=micros()-rxPrev; 
  attachInterrupt(RX_INT_PIN_THROTTLE,rxGoesHigh,RISING);
}

void setup(){
attachInterrupt(RX_INT_PIN_THROTTLE,rxGoesHigh,RISING); /*We begin by attaching a interrupt
to the throttle pin. the interrupt will fire when the pin goes high "RISING" (meaning the
start of the pulse). When that happens it will call the function rxGoesHigh.*/
}
void loop(){
//Nothing to do here!
}


Begin by reading the comments in setup, then go to the function rxGoesHigh and continue to the function rxGoesLow. Because interrupts are handling your pulse-length changes, all you have to do to get the latest pulse-length is read the variable rxVal.

If you need to read a lot of pins I can write something similar to explain how you can use PIN-CHANGE-INTERRUPTS instead..
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 08, 2013, 08:45 am
tnx . i will be great because this code is just for one channel and im sure i f go to edit this i will screw the code and everything go wrong :D .
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 08, 2013, 08:59 am
and some another question in this code we dont have any output pin ?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Sep 08, 2013, 09:53 am
Quote
tnx . i will be great because this code is just for one channel and im sure i f go to edit this i will screw the code and everything go wrong smiley-grin .


Sure I can write the pin-change-interrupt explanation, but I'm going to use my quadcopter code as an example (Arduino Leonardo).. Meaning it won't work on the UNO... If you only got 4 channels you can go with a Arduino Leonardo (it has 5 external interrupts) or Arduino Mega (has 6 external interrupts) and reuse my example code that I posted above... if you don't want to buy another board you can use this library which makes PC-Interrupts look like a walk in the park..The library for the pin-change-interrupts will simplify a lot and make the code look like the example I posted..
Here is the library: https://code.google.com/p/arduino-pinchangeint/


and some another question in this code we dont have any output pin ?


Well, no, because it's too simple really.. Here is a example of how to output PWM (combine this code with the previous example and give it a go)..

Code: [Select]

#define YOUR_OUTPUT_PIN 11
void setup(){
pinMode(YOUR_OUTPUT_PIN,OUTPUT);
}
void loop(){
int out = map(rxVal,1000,2000,0,255);
analogWrite(YOUR_OUTPUT_PIN,out);
}



But seriously, you clearly need to read and look at the different examples/tutorials in this forum and out there(internet of things).. I wouldn't mind writing the whole thing for you, but that won't teach you anything!

If you'd like, write your sketch and try it out and in-case it doesn't work and you've tried everything you can, post it here.. We would be more than happy to help you out..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 08, 2013, 01:02 pm
tnx . i mean it !!!! im working on it . and if goes wrong i will come and bothering you again . tnx
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 08, 2013, 01:39 pm
#define RX_INT_PIN_THROTTLE 3
#define YOUR_OUTPUT_PIN 11


volatile int rxPrev = 0; //variable that will contain the previous time
volatile int rxVal = 0; //variable that will contain the current throttle pulse length



void rxGoesHigh(){
  pinMode (YOUR_OUTPUT_PIN, OUTPUT);
/* As soon as we get into this function we measure the current time (with micros)
and put that value in our variable rxPrev. After that we re-attach the same interrupt
but this time we want it to fire when the pin goes low "FALLING". When that happens it
will call the function rxGoesLow */
  rxPrev=micros();
 
  attachInterrupt(RX_INT_PIN_THROTTLE,rxGoesLow,FALLING);
}
void rxGoesLow(){
/* As soon as we get into this function we measure the current time (with micros) and
subtract the previous time (rxPrev). By doing that we will get the length of the pulse,
from start to the end. We end this process by re-attaching the throttle pin to a RISING
interrupt, which will repeat the process again... */
  rxVal=micros()-rxPrev; 
  attachInterrupt(RX_INT_PIN_THROTTLE,rxGoesHigh,RISING);
 
}

void setup(){
attachInterrupt(RX_INT_PIN_THROTTLE,rxGoesHigh,RISING); /*We begin by attaching a interrupt
to the throttle pin. the interrupt will fire when the pin goes high "RISING" (meaning the
start of the pulse). When that happens it will call the function rxGoesHigh.*/
}
void loop(){
//Nothing to do here!
int out = map(rxVal,1000,2000,0,255);
analogWrite(YOUR_OUTPUT_PIN,out);
}




i done this and i got some signals on pin 11
it is my ppm signal from receiver
http://i44.tinypic.com/2v2ffb4.jpg

and it is what i got after your code combination
http://i44.tinypic.com/2qs9wcy.jpg


is this pwm or i did edit the code wrong ?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 08, 2013, 01:54 pm
:D i was wrong after i change the throtle on radio and signal never changes and when i unpluged the receiver the signal i had signal from pin 11 still like befor showing on scope
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Sep 08, 2013, 05:26 pm

:D i was wrong after i change the throtle on radio and signal never changes and when i unpluged the receiver the signal i had signal from pin 11 still like befor showing on scope


ya because you changed the interrupt pin number.. And why did you put pinMode (YOUR_OUTPUT_PIN, OUTPUT); in the interrupt routine??? You only have 2 interrupts on the UNO.. They have the numbers 0 and 1 and are located on pins (2 and 3).. so in the code change the number 3 to a 1 and leave everything as is.. I've fixed the sketch for you... Here is the code, just copy paste and run it..

Code: [Select]
#define RX_INT_PIN_THROTTLE 1
#define YOUR_OUTPUT_PIN 11


volatile int rxPrev = 0; //variable that will contain the previous time
volatile int rxVal = 0; //variable that will contain the current throttle pulse length



void rxGoesHigh(){
/* As soon as we get into this function we measure the current time (with micros)
and put that value in our variable rxPrev. After that we re-attach the same interrupt
but this time we want it to fire when the pin goes low "FALLING". When that happens it
will call the function rxGoesLow */
  rxPrev=micros();
 
  attachInterrupt(RX_INT_PIN_THROTTLE,rxGoesLow,FALLING);
}
void rxGoesLow(){
/* As soon as we get into this function we measure the current time (with micros) and
subtract the previous time (rxPrev). By doing that we will get the length of the pulse,
from start to the end. We end this process by re-attaching the throttle pin to a RISING
interrupt, which will repeat the process again... */
  rxVal=micros()-rxPrev; 
  attachInterrupt(RX_INT_PIN_THROTTLE,rxGoesHigh,RISING);
 
}

void setup(){
pinMode (YOUR_OUTPUT_PIN, OUTPUT);
attachInterrupt(RX_INT_PIN_THROTTLE,rxGoesHigh,RISING); /*We begin by attaching a interrupt
to the throttle pin. the interrupt will fire when the pin goes high "RISING" (meaning the
start of the pulse). When that happens it will call the function rxGoesHigh.*/
}
void loop(){
//Nothing to do here!
int out = map(rxVal,1000,2000,0,255);
analogWrite(YOUR_OUTPUT_PIN,out);
}




Edit: If this still doesn't work for you, I need you to show me how you hooked everything up.. Just draw a simple schematic.. And can you give me the name of your receiver/transmitter??? Just want to check and make sure that it's really PPM we are talking about..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 08, 2013, 06:27 pm
tnx . i didnt know if i change the pins it will go wrong . my radio is wfly wft06x-b and receiver is wfr04s , i will try it know and give you feed back. tnx
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 08, 2013, 07:45 pm
i tired your code this happend .... befor i connect receiver to pin1(tx) it has signal and after i connect signal it has change unormally and brushless motor dont work

i upload video of process ...
befor and after i connect receiver to arduino uno
http://www.youtube.com/watch?v=PnhHQjt_jss
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Sep 08, 2013, 08:39 pm

i tired your code this happend .... befor i connect receiver to pin1(tx) it has signal and after i connect signal it has change unormally and brushless motor dont work

i upload video of process ...
befor and after i connect receiver to arduino uno


Looking at the video I see that the duty cycle is changing from zero to 100%.. That means that it was hooked right the first time..
Did you read what I wrote in the previous post? Why did you connect the receiver to pin 1????? The code is calling for interrupt 1.. And interrupt 1 is on PIN 3.. Forget about the brushless motor for a second.. Connect the output (pin 11) to the oscilloscope and connect the receiver signal to PIN 3 on the UNO.. Dont change anything in the code, and reupload and test it again.. If you get the same results as in the video, then connect the output (PIN 11) to the ESC input signal and try again.. (Dont forget to connect the GND of the ESC to the GND on arduino)..

When you first start up the ESC remember to put the throttle on 0% (stick all the way down) for at least 3-5 seconds before fiddling with it..

Edit: If you got propellers on then remove them.. We don't want you to lose a finger now do we..?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Sep 08, 2013, 09:15 pm
yummmyyyyyy it seem work fine in the scope .... its late here and i cant start esc's bbeeping in home :D tomorrow morning i will test it ..... if it works fine i will start study arduino tommorow hardly .... .... <3 <3
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Sep 08, 2013, 09:30 pm

yummmyyyyyy it seem work fine in the scope .... its late here and i cant start esc's bbeeping in home :D tomorrow morning i will test it ..... if it works fine i will start study arduino tommorow hardly .... .... <3 <3


Glad to hear that.. Alright! Good luck with your project =)

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Sep 15, 2013, 12:33 pm
For those following this:  I've updated the code.. Made the sketch run more efficiently and reduced code size.. With this change I managed to find better PID values and thus get better/faster stabilization.. For those interested I've added pictures of the main board and hardware setup (see first post)..
Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Oct 01, 2013, 06:50 pm
Nice work!  :)

I am currently doing my own quad on a Arduino MEGA, everything is built and the code is mostly done (https://github.com/GoussLegend/quadcopter/tree/master/quad (https://github.com/GoussLegend/quadcopter/tree/master/quad)), I am just doig some PID tuning  :smiley-roll-sweat:

So I looked at your code, and if I think right you have got 2 modes (depending on the value of rateAngleSwitch).
One mode is a position control loop.
The other one is a rate control loop.

So now begin the questions  :) :
Which mode is the easiest to tune for a first time?
How did you actually do your tuning? Did you put your quad on some sort of ball joint ? Or did you hold it in your hand ?

thanks!

Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 01, 2013, 09:11 pm

So I looked at your code, and if I think right you have got 2 modes (depending on the value of rateAngleSwitch).
One mode is a position control loop.
The other one is a rate control loop.


That is correct my friend =)!



Which mode is the easiest to tune for a first time?


Now this question made me sad.. Because it means that you didn't read through my code correctly.. Let me explain how my closed-loop works..
I got 2 loops, yes, one is as you called it position loop (angle loop) and the other one is the rate loop.. But I like to also call them the slow/outer loop (angle) and the fast/inner loop (rate)..
I just drew a "map" in paint (MsPaint > PhotoShop =P) to make the process clear.. As you can see in the map, PID-rate is part of the inner loop which in turn controls the motors directly.. The reason for this is because of the update rate (400Hz) which is close to the motors PWM refresh rate (~480 to 500Hz)..
The PID-angle is part of the outer loop (because it's slow approx. 50Hz), which corresponds to the receiver refresh rate which in fact is 50Hz also! So PID-angle is like an auto-pilot for the position of the copter.. So to answer your question: You have to tune the rate-PID before the angle-PID!.. If the rate-PID isn't stable you won't get a stable copter with the angle-PID!

Note: I didn't read or see your code (something wrong with github, keep getting errors when I try to open your files).. My answer above assumes that you have one inner loop and one outer loop! Two separate inner loops will only lead to a slow response from the quadcopter which in turn will lead to bad PID values, which in turn will make the quadcopter uncontrollable in harsh environments!

How did you actually do your tuning? Did you put your quad on some sort of ball joint ? Or did you hold it in your hand ?


A ball joint would be the safest way.. But because I don't have a ball joint, I used a FAN-stand, like the one on this: http://www.tradeindeed.com/images/Stand-Fan_482-700.gif  And tied the copter to the stand top.. When I got the copter pretty stable, I took it out of the stand and held it in my hand during fine tuning (DON'T RECOMMEND THIS, I still got a bunch of scars all over my arms!)

//Basel

Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Oct 04, 2013, 11:07 pm
Thanks for the nice explanation!

Still one question though:
Quote
You have to tune the rate-PID before the angle-PID

I agree with this but how do you practically tune it? I mean with the angle-PID, it's easy to tune,  you can look at the angles values or even look at your quad to see if it's stable but with the rate-PID, I have no idea how to tune it.


Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 05, 2013, 12:16 am

Thanks for the nice explanation!

Still one question though:
Quote
You have to tune the rate-PID before the angle-PID

I agree with this but how do you practically tune it? I mean with the angle-PID, it's easy to tune,  you can look at the angles values or even look at your quad to see if it's stable but with the rate-PID, I have no idea how to tune it.


ya, I get what you're saying.. The method I'm using today is pretty advanced and requires some expensive software.. I basically made a Matlab script that sends data back and forth to the quadcopter and optimize the PID values..  Before that I did it by hand, this is my old method:

1 ) Put the quadcopter in rate mode
2 ) Increase the throttle until the quadcopter starts to hover on its own..
3 ) Increase the P-term until you observe oscillations..  Now subtract 10% of the value and set it as your P-term ..
4 ) Increase the D-term until you observe oscillations..  Now subtract 10-20% of the value (this is your D-term now)..
5 ) Now go back and increase the P-term with small steps until you observe oscillations.. Then subtract a couple of steps..
6 ) Increase the I-term until you observe oscillations.. These oscillations will have a lower frequency, so step up the I-term slowly.. And be careful when it starts to oscillate.. Because the P- and D-term will kick in, and increase the frequency of the oscillations.. So be careful! After that, substract approx. 10-15% of the value...
7 ) If you are satisfied with the results, then go out and take it for a spin, and observe how it flies and reacts to the wind etc.. Then go back and fine tune your copter if you observed any types of oscillations/control problems..
8 ) Buy me a beer!!!!!  :)


//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Oct 05, 2013, 10:15 am
About your old method of rate-PID tuning:
What is your speed setpoint/reference ? I guess 0 deg/s and before your have manually put your quad at 0 deg for roll and pitch angle?

Quote
The method I'm using today is pretty advanced and requires some expensive software.. I basically made a Matlab script that sends data back and forth to the quadcopter and optimize the PID values

I know well Matlab and I have got it on my laptop. (My dream would have been to use Simulink  :)). Anyway what do you do with your Matlab script? Transfer function?

Quote

8 ) Buy me a beer!!!!!  smiley

I will send you one to Sweden once my quad is flying   :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 05, 2013, 11:00 am

About your old method of rate-PID tuning:
What is your speed setpoint/reference ? I guess 0 deg/s and before your have manually put your quad at 0 deg for roll and pitch angle?


I have trouble understanding what you mean.. But I'll give it a shot.. When the quadcopter is in rate-mode, the set-point is determined by the RC-reciever.. Meaning you change the setpoint directly with the transmitter/Remote control.. For example, if you roll left then the setpoint will be something <0deg/s (negative angular rate), and the opposite if you roll right, >0deg/s (positive angular rate)..

If you're in angle mode, the reciever controls the setpoint of the angle-PID, and the angle-PID will in turn decide the setpoint for the rate-PID...


I know well Matlab and I have got it on my laptop. (My dream would have been to use Simulink  :)). Anyway what do you do with your Matlab script? Transfer function?


Simulink is slow and not optimal for something you run and optimize in real time.. Sure, you got the Real-Time toolbox, but if you ask me it sucks!

No it's not transfer functions, that would be optimal in-case i modeled the system.. But instead I did the following:

Arduino side: Wrote a whole new sketch that only handles inputs, outputs and gyro, acc calculations.. Meaning all the PID calculations are done in matlab..

Matlab side: I implemented some known PID tuning methods, like Ziegler-Nichols, SIMC, IMC etc.. They are easy to calculate.. It was just a matter of iterating and testing the results I got from the different methods..  The method that gave the best result for my quad. was the SIMC.. Still the results were not perfect, but it got me pretty close to something acceptable.. I know your going to ask why it didn't give me the optimal magical numbers =P! The reason is lag/delay in the system.. Matlab runs fast, a little too fast for the Serial-communication on the arduino.. So by the time arduino sends the data, the quadcopter would have changed its state drastically (not for the human eye maybe, but you can see it if you look at the data).. This kind of lag/delay can lead to early oscillations in the PID-tuning..

The optimal way to run this type of tuning is on the arduino itself.. So maybe write a PID optimizer for the arduino??

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Oct 14, 2013, 07:33 pm
hi again.
i have some question i fixed my receiver and now i have some question .
how we can change pid values?  is it compatible with multiwii gui ?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 14, 2013, 07:45 pm

hi again.
i have some question i fixed my receiver and now i have some question .
how we can change pid values?  is it compatible with multiwii gui ?


Hmm, if you're talking about my code then no.. To change the PID values you'll have to go to the Config.h file and change them there... You'll find these lines inside the file:

Code: [Select]
#define ROLL_PID_KP  0.250
#define ROLL_PID_KI  0.950
#define ROLL_PID_KD  0.011
#define ROLL_PID_MIN  -50.0
#define ROLL_PID_MAX  50.0

#define PITCH_PID_KP  0.250
#define PITCH_PID_KI  0.950
#define PITCH_PID_KD  0.011
#define PITCH_PID_MIN  -50.0
#define PITCH_PID_MAX  50.0

#define YAW_PID_KP  0.680
#define YAW_PID_KI  0.500
#define YAW_PID_KD  0.0001
#define YAW_PID_MIN  -50.0
#define YAW_PID_MAX  50.0

#define ANGLEX_KP 5.0
#define ANGLEX_KI 0.02
#define ANGLEX_KD -0.015
#define ANGLEX_MIN -100.0
#define ANGLEX_MAX 100.0

#define ANGLEY_KP 5.0
#define ANGLEY_KI 0.02
#define ANGLEY_KD -0.015
#define ANGLEY_MIN -100.0
#define ANGLEY_MAX 100.0


The first three sections is for the rate mode PID.. And the last two are for the angle mode PID..
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Oct 14, 2013, 08:28 pm
:D sorry bro how arm the quad ? i tried all the ways but quadcopter didnot armed and motors didint start anyway
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 14, 2013, 10:05 pm

:D sorry bro how arm the quad ? i tried all the ways but quadcopter didnot armed and motors didint start anyway


The copter will arm when the throttle is higher than 1100ms.. Just increase the throttle slowly until it arms..
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Oct 14, 2013, 10:31 pm
i changed pins because i use arduino uno and i think problem caused bcuz of that .....
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 14, 2013, 10:46 pm

i changed pins because i use arduino uno and i think problem caused bcuz of that .....


Hmm, then what pins did you change to?? You can find the pins definition in the Config.h file..  The throttle is on pin 7.. And it's a interrupt pin on the leonardo.. Did you come around the receiver code, and in that case did you implement it in the firmware???

If you need further help then please provide me with everything you have, so I know how to formulate my answers..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Oct 15, 2013, 08:03 am
i changed the motors to 3 9 10 11 pins
and throttle to pin 2 and other 3channel to 4 5 6
i think the interupt of arduino is pins 3 isnt it ?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 15, 2013, 10:14 am

i changed the motors to 3 9 10 11 pins
and throttle to pin 2 and other 3channel to 4 5 6
i think the interupt of arduino is pins 3 isnt it ?


I'm currently at work.. But i'll look at it as soon as I get home.. Will you be so kind and post all your code changes so I can take a look at them??? Just zip the whole project and post it here...

Edit: Just got back from work.. i looked over your pin choices.. Well yes the interrupts are on pin 2 and 3.. So that also means that you can't use pin 3 for one of the motors.. Why not leave the motor pins as is??? Did you write a new interrupt routine for the receiver? Because the current one won't work on the UNO..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Oct 15, 2013, 09:43 pm
i can unchange the pins but the uno dont have more than 13 pins ...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 15, 2013, 10:02 pm

i can unchange the pins but the uno dont have more than 13 pins ...


4 pins for the motors, 4 for the receiver, and 2 for the I2C.. that's 10 pins.. how many do you need??

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sk8amazing on Oct 15, 2013, 11:11 pm
that looks enough but i told that bcuz you said leave the pins as their default ..  ]:D
Title: Re: BlueCopter - Arduino Quadcopter
Post by: shsankha on Oct 18, 2013, 10:48 am
hello,
    I am sankha. i made qudocopter using Arduino mega bord. i am trying to make that using this code. but this code has compiling errors and i cant to find circuit diagram..... please help me to bild ub this qudo copter..... thank you.   
Title: Re: BlueCopter - Arduino Quadcopter
Post by: shsankha on Oct 18, 2013, 10:52 am
hello,
    I am sankha. i made qudocopter using Arduino mega board. i am trying to make that using this code. but this code has compiling errors and i cant to find circuit diagram..... please help me to bild ub this qudo copter..... thank you.   
Title: Re: BlueCopter - Arduino Quadcopter
Post by: nickgammon on Oct 18, 2013, 11:04 am
Huh? Why did you report yourself to the moderator?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 18, 2013, 04:22 pm

hello,
    I am sankha. i made qudocopter using Arduino mega board. i am trying to make that using this code. but this code has compiling errors and i cant to find circuit diagram..... please help me to bild ub this qudo copter..... thank you.   


Hey,

I've provided the circuit for the different connections in the attachment of my first post.. So go back and look at it.. The code is written for the arduino leonardo/micro.. And won't work out of the box with the mega..

I've got a lot of private messages like this, where people have tried getting this code running on boards other than leonardo/micro..
I'll rewrite/add the missing pieces, to the code in-order for it to work with the UNO and MEGA if I can get any volunteers that can test the code for me on their quadcopters..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Oct 30, 2013, 11:47 pm
Hi Basel,

I come back again (I have asked you a few questions some weeks ago). So I have made some progress  :). And now my quadcopter is stable on a testbed. Like you, I use an inner rate loop, and outer position loop.

So my problem is that, for now, both loops run at the same frequency (around 200Hz). The inner loop could run alone at (I guess) around 300Hz. And I would like the outer loop to run at around 50Hz. But I don't know how to structure my code to obtain this. I looked at your code, but it's not very clear to me how you do it.

Thanks for your help!
Romain
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 31, 2013, 01:00 am

So my problem is that, for now, both loops run at the same frequency (around 200Hz). The inner loop could run alone at (I guess) around 300Hz. And I would like the outer loop to run at around 50Hz. But I don't know how to structure my code to obtain this. I looked at your code, but it's not very clear to me how you do it.


Hey,

Well I do it by reading millis() and comparing that to the value 1000/FREQ (which equals to the duration of each loop in milliseconds).. For example:

Code: [Select]


#define RATE_FREQ  300 //Hz
#define ANGLE_FREQ  50 //Hz

long prevRate=millis();
long prevAngle=millis();

void updateValues(){

  if((millis()-prevRate)>(1000/RATE_FREQ)){
    //Run rate specific function
    prevRate = millis();
  }

  if((millis()-prevAngle)>(1000/ANGLE_FREQ)){
    //Run Angle specific function
    prevAngle = millis();
  }

}


void setup() {               

 
}

void loop() {
updateValues(); 
}


if you want to see it in my code, then look in the Sensor.ino (https://github.com/baselsw/BlueCopter/blob/master/BlueCopter/Sensor.ino)

On lines 15 (rate) and 19(angle)...

If you have further questions feel free to ask =)!

Edit: Just a small tip.. Use Micros for things with high frequency, like the rate loop.. Just to get better accuracy when it comes to timing =)!

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Oct 31, 2013, 09:54 am
Thanks for the quick answer again!

So ok you update your rate values at 300Hz and your angle values at 50Hz. When I looked at the main arduino loop:
Code: [Select]

void loop() {
  updateSensorVal();
  FlightControl();
}


It appears to me that you run FlightControl() even if the values (rates or angles) haven't change. I find this kinda strange.


Another thing, so let's say you rate update frequency is 300Hz and angle frequency is 50Hz. So you will update like this:

update rate 1
update rate 2
update rate 3
update rate 4
update rate 5
update rate 6
update angle 1
update rate 7
update rate 8
...

In my case the update angle takes some times (reading the accelero values) and I am not too sure if between update rate 6 and update rate 7 there will be really 1/300Hz = 3 mili sec. Did you have the same problem? Like when you update your angle, your rate update frequency will be a bit slower.

I hope this makes sense for you!



Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 31, 2013, 05:20 pm

Thanks for the quick answer again!

So ok you update your rate values at 300Hz and your angle values at 50Hz. When I looked at the main arduino loop:


Yes, the angle update freq. is 50Hz.. The rate update rate is 800Hz, reread the code ;)


It appears to me that you run FlightControl() even if the values (rates or angles) haven't change. I find this kinda strange.


Strong point there! If you think of it, it's both dumb and smart at the same time :).. The reason it is dumb is that you, as you said, run it even when the values haven't changed yet.. The reason it's smart: You save code space! Because it takes a few extra lines of code, to make the same "time check" procedure for the flightcontrol.. And I chose to optimize my code based on size, both to make it simple for the reader to follow along and to kind of compete with the exiciting open source solutions ;)...What if I put a "time check" there, what will I gain? Maybe better accuracy in the scale of microseconds.. But believe me, you don't need that kind of accuracy for perfectly stable flight!


Another thing, so let's say you rate update frequency is 300Hz and angle frequency is 50Hz. So you will update like this:

update rate 1
........................................

In my case the update angle takes some times (reading the accelero values) and I am not too sure if between update rate 6 and update rate 7 there will be really 1/300Hz = 3 mili sec. Did you have the same problem? Like when you update your angle, your rate update frequency will be a bit slower.

I hope this makes sense for you!



You shouldn't have that kind of delay.. Did you initialize your accelerometer right? Because, the accelerometer will update its values once each 1/50 seconds.. But the communication between the accelerometer and Arduino has a speed of atleast 100kHz (I2C)... So you should not get that kind of delay.. I don't know if you read my last post, but I gave you a tip to use micros() instead of millis() for the rate loop, when it comes to the "time-check".. So instead of 1000/FREQ, you'll have 1000000/FREQ..

If you don't figure out the reason for the problem, please post your code, so I can take a look at it.. Also, what kind of IMU are you using?

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Oct 31, 2013, 10:03 pm
Quote
The rate update rate is 800Hz,

Woow that's fast..  (I am a bit jealous since we use the same microcontroller  :) ). But ESCs refresh update rate are generally around 500Hz, so more than 500Hz is unnecessary?

Ok for "code size" strategy, I am not at this point yet :). My code looks way bigger than yours. But I have got warning LEDS, a security layer, some gyro drift calibration at the beginning.

For my IMU, I use an MPU 6050 and the nice library written by Jeff Rowberg https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 (https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050). So I did some measurements (with micros), and I get around:
1140 microsec to read either the 3 gyro values or the 3 acc values => 880Hz
1980 microsec to read the six values => 505Hz
Do you have something like that?




Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Oct 31, 2013, 11:30 pm

Woow that's fast..  (I am a bit jealous since we use the same microcontroller  :) ). But ESCs refresh update rate are generally around 500Hz, so more than 500Hz is unnecessary?


The rate update rate is 800Hz, going through a moving average filter which slows the update to 400Hz ;).. Which is a bit slower than the maximum update rate for the ESC.. You see what I did there ;)!?


1140 microsec to read either the 3 gyro values or the 3 acc values => 880Hz
1980 microsec to read the six values => 505Hz
Do you have something like that?


The micros sounds about right, for the gyro that is.. For the acc. it should be slower.. You shouldn't read the acc. more than 50 times per second (50Hz).. So it is not only the "angle-PID" calculations that you do 50 times per second, but actually the reading of the acc. itself also! Reading the acc. more than 50 times per second will lead to a lot of "gibberish" numbers..

If you want to keep reading the acc. that fast then i'd suggest that you put some kind of filter in code (I myself am using a first order low pass filter), just to smooth the output..

The MPU6050 is a good gyro+acc.. Actually better than what I'm using L3G4200D+ADXL345.. Are you doing all the math in your code, or are you using something included in the library (you know calculating angles and such)?

//Basel






Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Nov 01, 2013, 12:40 am
Quote
going through a moving average filter

I see. Actually I had a lots of problems with vibrations that I (kinda) solved by mechanical isolation, I also used the digital low pass filter embedded in the MPU 6050, and complementary filter (0.997 gyro  :) ).

Quote

Quote from: GoussLegend on Today at 10:03:02 pm
1140 microsec to read either the 3 gyro values or the 3 acc values => 880Hz
1980 microsec to read the six values => 505Hz
Do you have something like that?

The micros sounds about right, for the gyro that is.. For the acc. it should be slower..

I don't understand. These are only the times for reading the RAW values for the IMU. It is normal that it takes the same time to read 3 RAW gyro values or 3 RAW acc values!?

Actually I have got new values using Fastwire I2C (it goes to more than 1 000 kHz instead of 100 kHz if I understood correctly):
240 microsec to read either the 3 gyro RAW values or the 3 acc RAW values
240 microsec to read the six RAW values
Pretty fast  :) :)

When it comes to calculate the "real" angles (scale + filter and so) it takes 600 micro sec now (I do all the math in the code).
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Nov 01, 2013, 12:55 am

I don't understand. These are only the times for reading the RAW values for the IMU. It is normal that it takes the same time to read 3 RAW gyro values or 3 RAW acc values!?


Well, I wasn't talking about the time it takes to make an actual read.. If you want to read the data with 100, 400 or 1000 kHz is up to you and what the hardware can handle.. But what I meant is the time between each read, and that should be 1/50 seconds for the acc. and 1/800 for the rate..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Elmardus on Nov 03, 2013, 02:37 pm

I'll rewrite/add the missing pieces, to the code in-order for it to work with the UNO and MEGA if I can get any volunteers that can test the code for me on their quadcopters..
//Basel


Currently I am building a quadcopter for a school project, but I only have access to an Arduino UNO, so I would really appreciate it if you could rewrite the code. I would like to do it myself, but currently I'm not very experienced with arduino.
Then I volunteer to test the code  :)
Is it a lot of work for you to rewrite? I was looking at MultiWii, but the code is not very easy to understand.

Thanks :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Nov 03, 2013, 02:55 pm

Is it a lot of work for you to rewrite? I was looking at MultiWii, but the code is not very easy to understand.


Hey,

Well, I'm not very sure, didn't look directly at the differences.. But from the top of my head, I know that the receiving end needs a rewrite.. Everything else, I believe can be left as is.. I need to map all the available ports and see what needs to be changed.. I'll report back when I have something! =)

MultiWii, isnt meant to be understood =P! it's more a software LEGO.. Where you give it your available hardware (in config).. And everything else will be generated (macros) based on your choices... It's simple really..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Elmardus on Nov 03, 2013, 03:05 pm
yay thank you! :)

I was also thinking, could I use PPM? I have a dragonlink receiver that can output 12ch PPM or so. I have been looking how to implement that into your code, but I haven't managed to do that yet. Would then PPM only use 1 interrupt instead of 4?

Would that be an easier solution?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Nov 03, 2013, 04:19 pm

I was also thinking, could I use PPM? I have a dragonlink receiver that can output 12ch PPM or so. I have been looking how to implement that into your code, but I haven't managed to do that yet. Would then PPM only use 1 interrupt instead of 4?

Would that be an easier solution?


My code already use PPM.. I think what you meant is PPM-sum.. Which means that you have all the channel-signals sent with one wire... Well, it is easy to program, but I'm going to re-use as much as I can of the existing code.. So I'm not going to write it, sorry  :smiley-roll-blue: .. Maybe something for you to work out ;)?

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: djsaint on Nov 03, 2013, 06:57 pm


Tweeking takes time. Very good job I would say. Though the drawings are not clear to me at all.
Thats probably cause by my lack of knowledge
Jantje


Thx =).. By drawing I assume you mean the pinout? Well, it's simple.. I used the X-configuration (meaning the quad is flying in a X shape).. If you look at the pinout the motor pins should be,

Left upper motor: Pin 6
Left bottom motor: Pin 5
Right upper motor: Pin 10
Right bottom motor: Pin 9

For RX (receiver), PPM signal (Pulse-position modulation), The pins are as follows:
Roll: Pin 16
Pitch: Pin 14
Yaw: Pin 15
Throttle: Pin 7
AUX1: Pin 8
AUX2: Pin 0

I've also got a LED on pin 13, that indicates if the quad is in rate or level/angle mode..

And of course SDA/SCL for the sensors...

Currently the code only uses the accelerometer and gyrometer to make the quad stable during rate- and angle mode..

In the future I may implement heading hold (magnetometer) and altitude hold (barometer).. Not sure yet, cause I didn't have any need for them...



hey you seem pretty well knowledged with this topic. I was wondering if the pin layout would be same for an Arduino Uno.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Nov 03, 2013, 07:11 pm

hey you seem pretty well knowledged with this topic. I was wondering if the pin layout would be same for an Arduino Uno.


Hey, this code only works on the arduino leonardo (for the moment).. I'm working on a version for the UNO.. Stay tuned!

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: djsaint on Nov 03, 2013, 07:37 pm


hey you seem pretty well knowledged with this topic. I was wondering if the pin layout would be same for an Arduino Uno.


Hey, this code only works on the arduino leonardo (for the moment).. I'm working on a version for the UNO.. Stay tuned!

//Basel

I am not that experienced on this stuff, i can not order the parts yet. If I have an Arduino Uno as an interface board (seperate from control board of quadcopter) what type of signal will it have to put out to control the quadcopter.

Would it be PPM?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Nov 03, 2013, 08:30 pm



hey you seem pretty well knowledged with this topic. I was wondering if the pin layout would be same for an Arduino Uno.


Hey, this code only works on the arduino leonardo (for the moment).. I'm working on a version for the UNO.. Stay tuned!

//Basel

I am not that experienced on this stuff, i can not order the parts yet. If I have an Arduino Uno as an interface board (seperate from control board of quadcopter) what type of signal will it have to put out to control the quadcopter.

Would it be PPM?


There is no such feature in the code.. It is really up to you and what you want to implement..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Nov 05, 2013, 12:21 am
Quote
Well, I wasn't talking about the time it takes to make an actual read.. If you want to read the data with 100, 400 or 1000 kHz is up to you and what the hardware can handle.. But what I meant is the time between each read, and that should be 1/50 seconds for the acc. and 1/800 for the rate..


For the rate, I can go up to 450Hz now.
Getting the angles, integrating the gyro rates, using atan2 for acc values and finally using a complementary filter takes most of my loop time. I think you did a pretty good optimasation job in your code!

For reading the acc, I think I will read it at 450Hz too but then use a low-pass filter and use the filtered data in the Angle Control Loop at 50Hz only.


Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Nov 05, 2013, 01:10 am

For the rate, I can go up to 450Hz now.
Getting the angles, integrating the gyro rates, using atan2 for acc values and finally using a complementary filter takes most of my loop time. I think you did a pretty good optimasation job in your code!

For reading the acc, I think I will read it at 450Hz too but then use a low-pass filter and use the filtered data in the Angle Control Loop at 50Hz only.



All sounds good! Hope you have a video for us with the first-flight soon =)!

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Elmardus on Nov 28, 2013, 11:21 pm
I have modified the code to use PPM sum, it can be hooked up on pin 3, and it converts the PPM sum to seperate channels.
With this it only uses 1 interrupt, so this code is usable with the Arduino UNO.

The channels are like this:
1 THR
2 AIL
3 ELE
4 RUD
5 AUX1
6 AUX2

And of course more can be added easily. Up to 17channels from the PPM stream are put in to the rxVal array, and can be accessed in the code. There may be some bugs in the code now, beause I haven't been able to put it to the test on a quad yet. Currently it doesn't arm yet when the safe mode is defined, but that probably has something to do with my configuration.
If anybody spots a bug in the code changes I made to the original code, please tell me  :)

I'm not very experienced with arduino yet, so I'm sure there are many more improvements to make to the changes I made in the original code.

The code is attached to this post  :)

Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Nov 29, 2013, 12:20 am
First off, I want to apologize for the people waiting for the UNO/MEGA versions of this code.. I have a lot going on right now and simply not a lot of free time to work with this.. But I'm still open to answer any questions when I have time, so if any volunteers want to take a shot "like Elmardus" and write a UNO/MEGA version, then please go ahead, and I'll try to help along as much as I possibly can..

@Elmardus: I took a quick look around the code you wrote/changed.. And I have some feedback... First off, I'm happy that it didn't arm because if it did, that would have been dangerous.. The reason? Is the delay(3000) you put in "BlueCopter.ino" under setup().. If you want to initiate something and throw something out through serial and follow up with a delay then please do it before the following line: tp=millis(); or move tp=millis(); down to the very last line in the setup() section.. tp=millis() defines the start time-point for all of the PID's in the system... So if you follow up with a delay and the quadcopter moves/shakes or whatever when it's about to leave that delay, that will result in a huge controller output (which in a worst case scenario equals to the quadcopter running the motors at the current speed plus approx. 30-40%)..

Now as I said, I didn't read the whole thing, but just skipped through to the important parts.. I will assume that you know your way around timers, so I skipped checking the initializing part.. Now the reason it didn't arm can be many.. Let me start by asking you a couple of questions:

- Did you get your receiver code to work properly?
- If it is working, does the values that is in rxVal hit the proper configured intervals?? If you don't know which intervals I'm talking about then look in "Config.h" under RX Config, section.. You'll see for example, THROTTLE_RMIN, THROTTLE_RMAX, which means throttle read minimum and throttle read maximum.. Which corresponds to the minimum and maximum values possible in rxVal.. You'll have to read the RAW data coming from your controller with your code "of course" and type these values in the corresponding macro-variables..
- When all your controller macro-variables is set try to arm it again.. If it still doesn't work then try reading the output of the throttle during run-time.. Because the SAFE procedure uses the throttle value to arm/un-arm the quadcopter.. The arming procedure is in FlightCtrl.ino and Motor.ino and looks like this:

FlightCtrl.ino
Code: [Select]
#ifdef SAFE
  if(rxVal[0]<1100){
    motorArm();
  }
#endif

Motor.ino
Code: [Select]
while(rxVal[0]<1100){};

So as you see if the throttle raw value is under 1100ms then the quadcopter won't start! You can change these values if you'd like, or try to tune your controller output to somewhere in that range..

Edit: One more question, is your ESC calibrated for the PWM range of 125 to 254?? What ESC are you using?? Do they support PWM at a frequency of 480-500Hz??

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Nov 29, 2013, 03:18 am
Baselsw,
already changed the code and it's working perfectly with me, not only did much changed the interrpções as the pins they had available considering the ATMEGA 328 course capurei only 5 channels because I am also using a bluetooth that I will develop the flap it for now need to fly it, but as you said only 3 engines bore the output 0-254 and does not support, do not quite know why, because I have tested it on MEGA and had no problems, but when going for NANO simply does not work, or can also directly use the output of the receiver and use the "Servo library as WriteMicrosseconds" and continue with the outputs in + - 50, as it is know in code!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Nov 29, 2013, 03:27 am
Baselsw,
sorry but the code is attached, is working fine with me all the channels and my NANO is the ATMEGA 328!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Xeno on Nov 30, 2013, 06:47 pm
Hello.
Ive been building a quad since the past few days,mostly for fun. I'm using a leonardo the code worked pretty much flawlessly.
Now, I dont have an RC Transmitter and reciever so I want to control it using my laptop with bluetooth(or maybe even with android phone).
Could you suggest a simple setup to achieve this like the multiwii+nunchuk ,just instead maybe use an xbox controller or something?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Nov 30, 2013, 07:55 pm
@Satiro: Using the servo library is a bad choice.. It's simply to slow (50Hz vs the 500Hz PWM).. Anyway.. You'll probably be able to fly it in rate mode, but not angle mode.. Angle mode needs 500Hz PWM... Looking at your code you have 4 huge mistakes, in ControlV.ino:

Code: [Select]
 
  M1.write(throttle);
  M2.write(throttle);
  M3.write(throttle);
  M4.write(throttle);


It should be:
Code: [Select]
 
  M1.write(m1);
  M2.write(m2);
  M3.write(m3);
  M4.write(m4);


And you need to change the defined range for the PID's because the servo library takes values between 1000-2000us compared to the PWM 0-254... The start PID-values can be approx. by scaling the default values in the config.h with a scaling factor of (2000/254 = 7.9) .. But be careful though, if you'd like, start with half of the default PID values and work yourself up...

Another thing, you chose to use M1.write, but to send the right values I believe you'd have to change it to M1.writeMicroseconds for all of the motors..

@Xeno: I'm glad that it's working for you.. Well, bluetooth won't work out of the box assuming you're using a bluetooth modem (serial) module.. The reason is one of the serial pins is used by the receiver.. What you could do is maybe use SoftwareSerial together with a bluetooth modem.. The implementation is straight forward.. There is a lot of examples on how to use SoftwareSerial, so I suggest you start of by reading those...

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Xeno on Nov 30, 2013, 08:22 pm
Yes I know about software serial.
I just saw a sketch to generate PPM signals. Maybe I could add it to the code and control the arduino through Processing.
Appreciate the quick reply.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 01, 2013, 01:37 am
Baselsw,
you could fix the bugs I test here! Please know that you are quite busy, but it's been about 4 months working on this project and has hours hitting a desperation! changed the outputs of the engines in trottle on purpose, at the time I wrote to test the correct values??! you can change and send me back? from the PID to the engines!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 02, 2013, 12:52 pm
Basel,
where in the code would to insert a blinking LED to indicate low battery? and another thing, the setpoint angle mode is the output of the sensors? Zero "0" and "-7" and so rate is zero or the same? Because you crossed the ânguloX with gyro Y?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 02, 2013, 10:50 pm

Basel,
where in the code would to insert a blinking LED to indicate low battery?

Insert the LED code wherever you like.. There is no battery-status code, so feel free to write one, as long as the LED isn't LED 13.. Because LED 13 is tied to the angle/rate mode status...


and another thing, the setpoint angle mode is the output of the sensors? Zero "0" and "-7" and so rate is zero or the same? Because you crossed the ânguloX with gyro Y?


No, it's not the same.. I didn't cross angleX with gyro Y..  It is just the way I set up my coordinate system.. When you for example Roll you move the Z- and X axis while the Y axis is constant (because it's rotating around its own axis).. Staring at this picture for 5 minutes will make things clearer..
(http://www.azonano.com/work/Design%20and%20Characterisation%20of%20Nanometer%20Precision%20Mechanisms%20-%20Supplier%20Data%20by%20Queensgate%20Instrume_files/image004.gif)

So you calculate:

Accelerometer: AngleX_Acc = tan(accX/accZ)
Gyrometer: AngleX_Gyro = gyroY*dt + AngleX_Old
Comp-filter: AngleX = (CONSTANT)*Angle_Gyro + (1-CONSTANT)*Angle_Acc
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 03, 2013, 02:40 am
Basel,
LED's question was due to the issue of PID because you said a delay could increase output before, so I asked, but thought I would have some problems if you put a 50 millisecond blinking a led in the loop!

Basel,
  unable to calibrate the ESC´s to work with PWM as you had said, which still did not understand very properly is if you are zeroing the two values ​​of the angles "Pitch and Roll" or is leaving as setpoint values ​​are now output as "0 and -7 "(when capped)? it could reset the values ​​as some do by simply adding the corresponding void the output value when it is level!
Or is leaving the setpoint adjusted with the output of the sensors on the transmitter ... Type leaving the set "Zero" and "-7" in trasmissor at least in the angle mode?
Look, I got more stable values ​​with the Kalman filter, but are very similar to the complementary filter you are using!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 03, 2013, 01:40 pm

Basel,
LED's question was due to the issue of PID because you said a delay could increase output before, so I asked, but thought I would have some problems if you put a 50 millisecond blinking a led in the loop!


Yes I told you a delay would disrupt the PID timing and that is true.. But you don't need a delay to make a LED blink! Look at the example for "Blink without delay" http://arduino.cc/en/Tutorial/BlinkWithoutDelay ..


Basel,
  unable to calibrate the ESC´s to work with PWM as you had said, which still did not understand very properly is if you are zeroing the two values ??of the angles "Pitch and Roll" or is leaving as setpoint values ??are now output as "0 and -7 "(when capped)? it could reset the values ??as some do by simply adding the corresponding void the output value when it is level!
Or is leaving the setpoint adjusted with the output of the sensors on the transmitter ... Type leaving the set "Zero" and "-7" in trasmissor at least in the angle mode?
Look, I got more stable values ??with the Kalman filter, but are very similar to the complementary filter you are using!


You can set the offset of the angle in the config.h file.. You do that by making sure that your accelerometer and gyrometer are calibrated.. First make sure that your quad is leveled and not moving.. Read the gyrometer and accelerometer values.. And adjust the values in config.h accordingly.. The values that needs to be adjusted are:

Code: [Select]

#define ACC_X_OFFSET 19
#define ACC_Y_OFFSET 7
#define ACC_Z_OFFSET -73

#define GYRO_X_OFFSET 1.418431
#define GYRO_Y_OFFSET -1.05606
#define GYRO_Z_OFFSET -0.54401
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 03, 2013, 04:48 pm
Basel,
         first of all, thanks for pasciência that is dispensed me yet! but let me be clear! what I'm saying is that my IMU-g80-ye other devices are equal to your Quadcopter except for motors and ESC's that are 750KV and 25A, but the rest is the same! my question is: with it leveled Angle
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 03, 2013, 05:34 pm

my question is: with it leveled Angle
  • Output is "-0.35" and Angle [1] is "-6.92"! the question is: these are the Set-pitch and SetRoll should I consider? and if it could not as he spoke compesar adding positive values ​​to have both in Set's "Zero"?


Maybe I didn't make my self clear.. I understood your question previously and I suggested that you calibrate your accelerometer and gyrometer.. Even though we have the same hardware that doesn't mean our offsets are exactly the same.. These offsets can change with humidity, temperature, etc....
I see that Angle[0] and Angle[1] aren't zero when leveled.. This is of course wrong and an indication that you need to calibrate your sensors! No, please don't add a positive value to both.. It will initially compensate but because the angle calculation is an integral, this compensation will build up to become a huge error! So, I'm telling you again, calibrate your sensors..

Now before you make your next comment do this and report your results:

Set the following to zero:

Config.h
Code: [Select]

#define ACC_X_OFFSET  0
#define ACC_Y_OFFSET  0
#define ACC_Z_OFFSET  0

#define GYRO_X_OFFSET  0
#define GYRO_Y_OFFSET  0
#define GYRO_Z_OFFSET  0


Add the following lines in Sensor.ino
Code: [Select]

void updateAcc(){//High pass filter
  int buffer[3]; //Axl buffer
  MPU.getAxlData(buffer);
  buffer[0]=buffer[0]-ACC_X_OFFSET;
  buffer[1]=buffer[1]-ACC_Y_OFFSET;
  buffer[2]=buffer[2]-ACC_Z_OFFSET;

//---------ADD THESE LINES-------
Serial.print(F("AccX: "));
Serial.print(buffer[0]);
Serial.print('\t');
Serial.print(F("AccY: "));
Serial.print(buffer[1]);
Serial.print('\t');
Serial.print(F("AccZ: "));
Serial.println(buffer[2]);
//------------------------------
  accx_temp=(ACC_HPF_NR*accx_temp+(100-ACC_HPF_NR)*buffer[0])/100;
  accy_temp=(ACC_HPF_NR*accy_temp+(100-ACC_HPF_NR)*buffer[1])/100;
  accz_temp=(ACC_HPF_NR*accz_temp+(100-ACC_HPF_NR)*buffer[2])/100;
}


Now turn on Debug mode by un-commenting the following line in config.h
Code: [Select]

//#define DEBUG
//#define DEBUG_ANGLES
//#define DEBUG_GYRO
//#define DEBUG_PID
//#define DEBUG_RX
//#define DEBUG_SERIAL_CHART
Change it to:
#define DEBUG
//#define DEBUG_ANGLES
//#define DEBUG_GYRO
//#define DEBUG_PID
//#define DEBUG_RX
//#define DEBUG_SERIAL_CHART


Now disconnect your motors and upload the code to your quadcopter.. Now level your quadcopter and open the Serial monitor.. you should see the accelerometer values for X, Y and Z axis.. Type these down..

Now write your values in the config.h file where you previously zero'ed the values:

Code: [Select]

#define ACC_X_OFFSET  "TYPE THE X VALUE HERE"
#define ACC_Y_OFFSET  "TYPE THE Y VALUE HERE"
#define ACC_Z_OFFSET  "SEE COMMENT BELLOW"
For the Z value, you'll have to compensate so that the Z axis gives 265 when the quadcopter is perfectly leveled.. So if your output for the Z axis is 240, you calculate the offset with the following: OFFSET = YOUR_VALUE - 265; So for a value of 240 the offset will be OFFSET=240-265 = -25


Now delete the lines that we added to Sensor.ino because we are done with the accelerometer calibration.

For the gyrometer calibration, go to the config.h and un-comment the following lines:
Code: [Select]

//#define DEBUG
//#define DEBUG_ANGLES
//#define DEBUG_GYRO
//#define DEBUG_PID
//#define DEBUG_RX
//#define DEBUG_SERIAL_CHART
Change it to:
#define DEBUG
//#define DEBUG_ANGLES
#define DEBUG_GYRO
//#define DEBUG_PID
//#define DEBUG_RX
//#define DEBUG_SERIAL_CHART


Now upload the code and open the Serial monitor.. Make sure that the quadcopter is standing perfectly still and write down the gyro-values for the three axis..

Write these values in config.h:
Code: [Select]

#define GYRO_X_OFFSET  "TYPE THE X VALUE HERE"
#define GYRO_Y_OFFSET  "TYPE THE Y VALUE HERE"
#define GYRO_Z_OFFSET  "TYPE THE Z VALUE HERE"


When your all done with these steps, try outputting the angles again and see if they are zero.. If they are not zero, then please report here and type the new angles for the leveled quadcopter...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 03, 2013, 11:43 pm
Basel, you note is 1000! zeroed, but the roll is a bit negative! I guess I'll have to take the average of the values??!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 03, 2013, 11:52 pm

Basel, you note is 1000! zeroed, but the roll is a bit negative! I guess I'll have to take the average of the values​​!


Did it go well??? How much is a bit??? Give me some numbers.. You'll have to have some tolerance.. It won't be perfectly zero, +/- 0.2 to 0.3 is okay for the gyro.. If you have massive fluctuations try increasing the moving average filter number one step, until you're satisfied with the results.. But remember the more you average/higher filter numbers the slower response you'll get.. So you'll have to tune the PID values down in-order to get a stable copter..

With other words, you don't need to average, there is already a built in filter.. Just tweek the filter number..
In config.h
Code: [Select]
#define  GYRO_MAF_NR  2  //Moving average filter nr
//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 04, 2013, 01:59 am
Basel, the values ??were so! For acc:

# define ACC_X_OFFSET 20
# define ACC_Y_OFFSET -33
# define ACC_Z_OFFSET -37

Values ??were in Gyro:

# define GYRO_X_OFFSET 1,314
# define GYRO_Y_OFFSET -0596
# define GYRO_Z_OFFSET 0811

Look, I did not understand the value of 265 for the Acc Z? I did just as you suggested!

When I put zero to find onths values ??and then signed up the the output of Acc, were ranging from "0 to -1"

And Gyros were as follows:
Gx = between "1.22 and 1.45";
Gy = "between -0.57 and -0.8"
Gz = between "0.7 and 1.5"

Then I noticed that the Angle
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 04, 2013, 02:39 am

Then I noticed that the Angle
  • is between 0.2 and 0.3 and Angle [1] is between -0.1 and -0.4! you think these good values​​? I still think I can improve!

    Look, I can make the values ​​of integer angles and send to making treatment:
    Angle
  • = (int) Angle
  • ;
    angle [1] = (int) angle [1];


The 265 for the Z axis is just the maximum number that you can get when your quadcopter is leveled.. So I just asked you to calculate how much your current value deviates from that number and compensate for that..

All your values are good and reasonable.. The angle jumping between -0.1 and -0.4 is totally okay!! You don't need to play with it further.. I suggest that you try to hover your quadcopter and see if it tilts in some direction.. If it does tilt then you'll have to fine tune your calibration (just add or remove a couple of decimals from the offset).. I'm having approx. the same results as you.. So I think it will be fine..

No, don't make the angles an integer, you'll lose stability if you do so (the quadcopter will start to become jumpy and will lead you to reduce the PID-terms just to get it stable)..

Edit: Look at your gyro values.. The first one is reasonable.. The rest of them are way to big.. I think you missed a comma/point there.. They should be:

Code: [Select]

# define GYRO_X_OFFSET 1.314
# define GYRO_Y_OFFSET -0.596
# define GYRO_Z_OFFSET 0.811
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 04, 2013, 11:16 am
Basel,
my angles as you saw reached acceptable values​​! when released the part of the SET's values ​​setX, setY were with and Setz -4º, -5º and -5º ... Looking want to try to fly it this weekend! The question is the following! these values ​​have to be "zero" and then have to adjust the channels trasmissor the PID output should be "Zero" correct? and only responding to change the SET's at the correct trasmissor own? both the mode angle as in rate mode correct? I will capture the PID outputs after assembled to see if they will be responding to the SET's.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 04, 2013, 11:26 am

Basel,
my angles as you saw reached acceptable values??! when released the part of the SET's values ??setX, setY were with and Setz -4, -5 and -5 ... Looking want to try to fly it this weekend! The question is the following! these values ??have to be "zero" and then have to adjust the channels trasmissor the PID output should be "Zero" corrto? and only responding to change the SET's at the correct trasmissor own? both the mode angle as in rate mode correct? I will capture the PID outputs after assembled to see if they will be responding to the SET's.


Well, it won't be perfectly zero and right now the values doesn't say much to me because I don't know if you're in angle mode or rate mode.. One of the reasons that it isn't near zero could be that your controls aren't calibrated.. You really need to go through the config.h file and calibrate everything to suite your setup... Anyway you could try to fly it (BE CAREFUL and tie it down so it doesn't go all over the place)! And report your results here...

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 04, 2013, 02:53 pm
Basel,
as should be the values ??of Set's ... setX, and Setz setY angle mode and rate mode? I understand the config.h they should be "Zero" and angle so stay between + - 15 ° to + setX and setY and -45 ° to SetZ, and SetZ is independent of mode + -45 correct way? already in rate mode to change the angles and setX, setY  and + -45 ° and SetZ remains the same even if it is Basel?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 05, 2013, 07:20 am

Basel,
as should be the values ??of Set's ... setX, and Setz setY angle mode and rate mode? I understand the config.h they should be "Zero" and angle so stay between + - 15 ° to + setX and setY and -45 ° to SetZ, and SetZ is independent of mode + -45 correct way? already in rate mode to change the angles and setX, setY  and + -45 ° and SetZ remains the same even if it is Basel?


Yes, setZ is independent of mode, that is because there is no anhle to adjust here, only the angular rate... The 15degrees for setx and sety is both the angle and angular rate.. Meaning they represent both 15degrees and 15deg/s multiplied by a sensitivity factor..
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 05, 2013, 11:32 am
Basel,
          calibrated outputs trasmissor to rate how you spoke before then sent data setX, setY Setz for serial output, were well set going in the recommended range, then SET data sent over the three PID outputs, the PID outputs are initially in "zero" with Quadcopter level, but over time accumulate negative values ​​to saturate the output! have you observed these several times given her Quadcopter is this normal? when starting the engines or the values ​​will be similar and will only change when you change the Set's?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Jenzaah on Dec 05, 2013, 06:09 pm
Hi Basel!

For a school Project i'm making a Arduino Based Quadcopter, I'm working with a Arduino Uno so your code doesn't work out of the box for me. I'm making my own code based on yours. Now when the stabilization part begins, i don't understand the PID's.

First you got the angle mode?
Code: [Select]

if (rateAngleSwitch == 0){
   setX=(int)PIDangleX.Compute((float)setX+angles[0],gy_aver,(float)setX/RX_ANGLE_DAMPNING);
   setY=(int)PIDangleY.Compute((float)setY-angles[1],gx_aver,(float)setY/RX_ANGLE_DAMPNING);
 }

I don't understand what this part does, Can you explain what each part of the PID does? The confusing part is the gy_aver in the SetX-part and the gx_aver in de SetY part.

Then there is the rate mode?
Code: [Select]

 int PIDroll_val= (int)PIDroll.Compute((float)setX-gy_aver);
 int PIDpitch_val= (int)PIDpitch.Compute((float)setY-gx_aver);
 int PIDyaw_val= (int)PIDyaw.Compute((float)setZ-gz_aver);

Here you calculate the adjustments of the roll/pitch/yaw part, i understand that, but why do you do SetX-gy_aver? and not SetY-gy_aver?

Thank you for your time!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 07, 2013, 07:16 am
Hey,

Well, I don't know if you read the whole thread or not.. But if you go back and look at page 2, you'll see a picture that explains the whole flight control part.. Still I'll try to answer your questions as best as I can..


Now when the stabilization part begins, i don't understand the PID's.

First you got the angle mode?
Code: [Select]

if (rateAngleSwitch == 0){
    setX=(int)PIDangleX.Compute((float)setX+angles[0],gy_aver,(float)setX/RX_ANGLE_DAMPNING);
    setY=(int)PIDangleY.Compute((float)setY-angles[1],gx_aver,(float)setY/RX_ANGLE_DAMPNING);
  }

I don't understand what this part does, Can you explain what each part of the PID does? The confusing part is the gy_aver in the SetX-part and the gx_aver in de SetY part.


If you look at the picture on page 2 you'll see that the flight control is made by two loops.. Let us call them the rate loop and the angle loop.. The rate loop is always running and the angle loop is only turned on when you're in angle mode... You can think of it as if the rate PID's are the only ones existing in code and and the set points for these PID's are simply the receiver input.. When you switch over to angle mode you simply turn on two more PID's that auto-pilots your quadcopter (keep it leveled).. So the receiver input will instead be controlling the angles (set point for the angle PID's) and the angle-PID's will in turn control the set-points for the rate PID's.... I hope I didn't confuse you there =), but it's really hard to explain it better without a whiteboard =P... Now the reason for me doing it this way is because of the hardware! Gyro's are accurate at high frequency's (faster updates -> continuous loop) and accelerometers are accurate at low frequency's (slower updates == as slow as the receiver updates == 50Hz)..

The reason for the gy_aver on setX and vice versa is simply the way I've set up my coordinate system and the way I chose to set up the calculations.. See page 6, I've explained it there...


Then there is the rate mode?
Code: [Select]

  int PIDroll_val= (int)PIDroll.Compute((float)setX-gy_aver);
  int PIDpitch_val= (int)PIDpitch.Compute((float)setY-gx_aver);
  int PIDyaw_val= (int)PIDyaw.Compute((float)setZ-gz_aver);

Here you calculate the adjustments of the roll/pitch/yaw part, i understand that, but why do you do SetX-gy_aver? and not SetY-gy_aver?

Thank you for your time!

Because setX is the angular rate of the X axis (Roll) and it corresponds to the gyro's measurement on the Y axis.. I know it's confusing but look at the coordinate system I've attached on page 6 and you'll get it..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 08, 2013, 04:27 pm
Basel,
tried to fly with him today, but I could not! look in the test cavalote shaped "U" with a degree of freedom, he was responding well! then calibrated it on the floor and went testing in bed! but soon noticed that the speeds quickly changed and increased acceleration when it rose and fell quickly in bed as if a hand was unbalanced! how do I raise the flight! start angle mode or rate mode? you think I should change the values ??of PID?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 08, 2013, 04:34 pm

Basel,
tried to fly with him today, but I could not! look in the test cavalote shaped "U" with a degree of freedom, he was responding well! then calibrated it on the floor and went testing in bed! but soon noticed that the speeds quickly changed and increased acceleration when it rose and fell quickly in bed as if a hand was unbalanced! how do I raise the flight! start angle mode or rate mode? you think I should change the values ​​of PID?


That sounds like you need to calibrate your PID.. You always start with rate mode (because it's the main loop in code).. If rate mode isn't calibrated correctly you'll never get a stable copter with angle mode.. If you go back to page 3 you'll see a small guide to how to calibrate the PID's.. Anyway here is the same guide:

1 ) Put the quadcopter in rate mode
2 ) Increase the throttle until the quadcopter starts to hover on its own..
3 ) Increase the P-term until you observe oscillations..  Now subtract 10% of the value and set it as your P-term ..
4 ) Increase the D-term until you observe oscillations..  Now subtract 10-20% of the value (this is your D-term now)..
5 ) Now go back and increase the P-term with small steps until you observe oscillations.. Then subtract a couple of steps..
6 ) Increase the I-term until you observe oscillations.. These oscillations will have a lower frequency, so step up the I-term slowly.. And be careful when it starts to oscillate.. Because the P- and D-term will kick in, and increase the frequency of the oscillations.. So be careful! After that, substract approx. 10-15% of the value...
7 ) If you are satisfied with the results, then go out and take it for a spin, and observe how it flies and reacts to the wind etc.. Then go back and fine tune your copter if you observed any types of oscillations/control problems..
8 ) Do the same for Angle Mode..
9 ) Buy me a beer!!!!!   :)

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 08, 2013, 09:17 pm
Basel,
where to start! I reset the values ​​of ki and kd in terms config.h to PID.pitch, PIDRoll, PIDyaw, PIDAngleX, PIDAngleY​​? create a tab to send the data kp, ki and kd the serial to keep up? I find three sets values ​​of kp, ki, and kd correct, since the symmetry guarantees that the values ​​of pitch and roll are the same! the same for the angles X and Y. Look, attached below a picture of my Quad in CAVALOTE shaped "U".

At the exit of the engine, just let m1 = trottle + PIDpitch and m2 = trottle-PIDpitch? and I'm varying the values ​​of P until he started to oscillate as his Palace to palace? I'll start with P = 1, and see if it fluctuates.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 08, 2013, 09:56 pm

Basel,
where to start! I reset the values ??of ki and kd in terms config.h to PID.pitch, PIDRoll, PIDyaw, PIDAngleX, PIDAngleY??? create a tab to send the data kp, ki and kd the serial to keep up? I find three sets values ??of kp, ki, and kd correct, since the symmetry guarantees that the values ??of pitch and roll are the same! the same for the angles X and Y. Look, attached below a picture of my Quad in CAVALOTE shaped "U".


The simplest way is to change the values and re-upload..  The harder way is to open a new tab and write something that will change the values through serial.. Here is an UN-TESTED example:

Create a new tab and name the file: PID_Change_Serial.ino, type this code in the newly created file:
Code: [Select]

int kp=0;
int ki=0;
int kd=0;

void readAndChange(){
  if(Serial.available()>0){
    char a = Serial.read();
    a = a-'0';
    switch (a) {
    case 0:
      kp=kp+100;
      break;
    case 1:
      kp=kp-100;
      break;
    case 2:
      ki=ki+10;
      break;
    case 3:
      ki=ki-10;
      break;
    case 4:
      kd=kd+1;
      break;
    case 5:
      kd=kd-1;
      break;
    }
    PIDroll.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
    PIDpitch.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);
    Serial.print("Kp: ");
    Serial.print(kp);
    Serial.print('\t');
    Serial.print("Ki: ");
    Serial.print(ki);
    Serial.print('\t');
    Serial.print("Kd: ");
    Serial.println(kd);
  }
}


And in BlueCopter.ino, put this in the loop:

Code: [Select]
void loop() {
  updateSensorVal();
  FlightControl();
#ifdef DEBUG
  debugProcess();
  readAndChange()
#endif
}


Don't forget to enable DEBUG-mode from the config.h.. Set all the P, I and D values to zero in config.h..

Now hook up your quadcopter through USB, upload the code and turn everything on (power to the motors etc).. Open the Serial-monitor and type the following to change the P, I and D values for the roll and pitch.. When you've got everything stable on these axis we will go on and calibrate the YAW..

Now send the following through the Serial-monitor to adjust the P,I and D values:

Increase P: send a "0"
Decrease P: send a "1"
Increase I: send a "2"
Decrease I: send a "3"
Increase D: send a "4"
Decrease D: send a "5"

For each change the quadcopter will send the current P, I and D values..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 09, 2013, 02:52 am
Basel , both! In the palace the palace of PID tuning the palace 3 is not equal to the Palace 5 ? And the other in PID_Change_Serial I have done as you indicated , but the figures are more fast ! is not the case for adding the Serial.print PID_Change_Serial the tab next to Debug_Angle ! I can enchergar there ! else doing all values ??equal to " zero " .

# define ROLL_PID_KP 0
# define ROLL_PID_KI 0
# define ROLL_PID_KD 0
# define ROLL_PID_MIN -50.0
# define ROLL_PID_MAX 50.0

# define PITCH_PID_KP 0
# define PITCH_PID_KI 0
# define PITCH_PID_KD 0
# define PITCH_PID_MIN -50.0
# define PITCH_PID_MAX 50.0

# define YAW_PID_KP 0
# define YAW_PID_KI 0
# define YAW_PID_KD 0
# define YAW_PID_MIN -50.0
# define YAW_PID_MAX 50.0

# define ANGLEX_KP 0
# define ANGLEX_KI 0
# define ANGLEX_KD 0
# define ANGLEX_MIN -100.0
# define ANGLEX_MAX 100.0

# define ANGLEY_KP 0
# define ANGLEY_KI 0
# define ANGLEY_KD 0
# define ANGLEY_MIN -100.0
# define ANGLEY_MAX 100.0
No need to disable PID_int ( ) ? void setup there .
I can not understand how as the two PIDs will live together!
You can change my code ! He follows in the Annex !
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 09, 2013, 05:14 pm

Basel , both! In the palace the palace of PID tuning the palace 3 is not equal to the Palace 5 ? And the other in PID_Change_Serial I have done as you indicated , but the figures are more fast ! is not the case for adding the Serial.print PID_Change_Serial the tab next to Debug_Angle ! I can enchergar there ! else doing all values ??equal to " zero " .

No need to disable PID_int ( ) ? void setup there .
I can not understand how as the two PIDs will live together!
You can change my code ! He follows in the Annex !


No offence, but I'm having a really hard time to understand what you wrote here.. What is palace/place 3 or 5?

Anyway, you did the right thing to set all the PID's to zero.. While calibrating the PID's you can't debug anything else, like DEBUG_ANGLE and such, that explains why the values disappears so fast.. turn them all off.. Only leave DEBUG mode on... You don't need to touch the PID_init(), leave everything there as is.. Which two PID's do you mean??? Angle and rate PID's? What do you need me to change? Your code looks okay...

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 09, 2013, 06:01 pm
Basel,
sorry for not making myself clear! Look, I can tell you from afar you'd make a great teacher! it is pasciente and can explain things difficult even for those who do not know much! Parabens! But back ... Steps 3 and 5 of PID tuning you repeated twice in the topic seems a repeat! In step 5 you do not put values ​​... Type a percentage% but increase and decrease step ... How to change the P, as in 1, you can no longer get away with the term P?

Basel would not be appropriate to change the PID tab there writing :

PIDroll.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
   // PIDpitch.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);

//PIDyaw.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
    //PIDAngleX.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);
//PIDAngleY.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);   
There Degug_Angle write :
    Serial.print ( " Kp " ) ;
    Serial.print ( (float ) kp/1000.0 ) ;
    Serial.print ( '\ t ' ) ;
    Serial.print ( " Ki " ) ;
    Serial.print ( (float ) ki/1000.0 ) ;
    Serial.print ( '\ t ' ) ;
    Serial.print ( " KD " ) ;
    Serial.println ( (float ) kd/1000.0 ) ;
And Debug_Angle enabled to view real-time adjustment ?

For work with only one degree of freedom , so I need only two opposite motors ! hence the value found is for the two angles of pitch and roll !

Another thing is how will I be able to adjust PID Yaw , it is not necessary that the quad is suspended by a thread ? pos is the movement of yaw direction!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 09, 2013, 06:57 pm

But back ... Steps 3 and 5 of PID tuning you repeated twice in the topic seems a repeat! In step 5 you do not put values ??... Type a percentage% but increase and decrease step ... How to change the P, as in 1, you can no longer get away with the term P?


The reason that you go back and adjust the P-term in step 5 is that the D-term stabilizes you quadcopter.. So you would be able to increase the P-term a little more...
Well a typical step in BlueCopter firmware is around (for the P-term) is 0.20.. So if your oscillations start at let us say 5.0 then back off two to three steps down to 4.6-4.4..

For the I-term a typical step is 0.05 to 0.10... For the D-term a typical step is 0.002...


Basel would not be appropriate to change the PID tab there writing :

PIDroll.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
  // PIDpitch.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);

//PIDyaw.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);
   //PIDAngleX.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,PITCH_PID_MIN,PITCH_PID_MAX);
//PIDAngleY.ChangeParameters((float)kp/1000.0,(float)ki/1000.0,(float)kd/1000.0,ROLL_PID_MIN,ROLL_PID_MAX);    


If you're calibrating only one axis at a time then yes, you can change them that way...


There Degug_Angle write :
   Serial.print ( " Kp " ) ;
   Serial.print ( (float ) kp/1000.0 ) ;
   Serial.print ( '\ t ' ) ;
   Serial.print ( " Ki " ) ;
   Serial.print ( (float ) ki/1000.0 ) ;
   Serial.print ( '\ t ' ) ;
   Serial.print ( " KD " ) ;
   Serial.println ( (float ) kd/1000.0 ) ;
And Debug_Angle enabled to view real-time adjustment ?

Another thing is how will I be able to adjust PID Yaw , it is not necessary that the quad is suspended by a thread ? pos is the movement of yaw direction!


You don't need to view the angle because your calibrating the angle-rate.. Meaning that the Angle won't have any influence on your calibration yet.. When calibrating the Angle-PID's you can enable them, but you'll have some problems seeing the P, I and D values when they change, because the angle's are printed on the serial monitor as fast as possible, whereas the P, I and D terms are only printed when you change them... You don't need to view the angles in real time while adjusting.. If you have a lot of trouble finding optimal P, I and D values then you can enable them to see if there is something wrong...

We will leave the Yaw as the last thing to calibrate.. When you've calibrated the Roll and Pitch then we'll go ahead and calibrate the YAW axis.. To calibrate the YAW axis you'll have to hold the quadcopter in your hand... But to be able to safely do that you need to have a stable quadcopter (meaning calibrate the Roll and Pitch)...

Edit: Here is a video of how to calibrate your quadcopter PID's:
http://www.youtube.com/watch?v=aq1jXHMiJgg

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 10, 2013, 12:32 am
Basel, adjusting the values ??of Kp, Ki and Kd for one degree of freedom you think that the values ??can be inserted at angles of Pitch and Roll? or should I do both at the same time as the video? and another thing, after adjusting for the fly without the Yaw angle! because I'm thinking of adjust it only after adjusting the angles X and Y angle mode. What do you think?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: SuleymanSahin on Dec 10, 2013, 07:31 pm
Hi
I have a question for you.
How does Multiwii read receiver all signals from analog input pins? Which methods are they using?
Can we use their method?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 13, 2013, 10:14 pm
Basel ,
I think it took me longer than I'd like ! returning to Quadcopter ! Look, as you indicated I started increasing the value of Kp until it began to wobble as you said , my value was 0.4 , then the term Kp was 0.36 thereafter was weird ! changed in config.h Rescued values ??of 0.36 in each angle , then did the up-load and started changing the Kd values ??as you wrote ! what happened is that the first Kd value that I sent ... the Stcks not respoderam more! is this normal? then kept increasing the value of kd but not seen many swings , so I ask you! I'm on the right track ? still got to step 6 and went with increasing KI values ??of Kp and Kd = 0:38 = 0.0128 , my battery died and I had to recharge it ...
1st question ... I change all three values ??on the same loop or have to change , save and change back to go to next step?

2 What were your initial terms for Kp , Ki and Kd ?

3rd oscillations Kd are as visible as those of Kp ? and fluctuations of Ki are also clearly visible ?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: krooks86 on Dec 14, 2013, 10:25 pm
Hi Basel,
              Excellent article and nice explanation. I had some queries, about the motor control.

int m0_val=throttle+PIDroll_val+PIDpitch_val+PIDyaw_val;
 int m1_val=throttle-PIDroll_val+PIDpitch_val-PIDyaw_val;
 int m2_val=throttle+PIDroll_val-PIDpitch_val-PIDyaw_val;
 int m3_val=throttle-PIDroll_val-PIDpitch_val+PIDyaw_val;

If the quadrotor is in plus mode, then assuming m0 and m3 are on the y axis(controlling pitch) and m1 and m2 are on x axis(controlling roll), then m0 will have a +PIDpitch_val and m3 will have a - PIDPitch_val.
Similarly m1 will have a +PIDroll_val and m2 will have a -PIDroll_val.

For Yaw, the one axis motors will have higher speed, than the other axis motors will have a slower rpm.
So  y axis motors have higher speed and thus, the PIDYaw_val is added to the y axis motors and subtracted from x axis motors.

This is my understanding of how to control the orientation of the vehicle in plus mode.

What I do not understand is, if m0 and m3 are motors on the pitch axis, then why is the roll component PIDroll_val being added and subtracted from their throttle.
Also, if m1 and m2 are motors on the roll axis, then why do we add / subtract the pitch component from the roll axis motors.

Could you explain ? or provide a link to some material.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 16, 2013, 10:44 pm
Basel !!!!!!!!!!!!!!!!!!!!! help-me!!!!!!!!!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 16, 2013, 11:07 pm
Ohh, wow a lot of questions.. Sorry guys, I've been a little busy ..

@satiro: It's a long process to get to the optimal PID values, specially if you've never done it before, so have patience..  Your progress looks promising.. No the sticks should respond at all times, I have no idea why they're not responding when you're changing the Kd value.. Maybe it has something to do with RX_RATE_SENSITIVITY .. Try changing RX_RATE_SENSITIVITY from 3 to 1 and try again (you can find this macro-variable in Config.h)... My recommendation is to save the optimal PID value before jumping on to the next.. So if you, like you said, found 0.36 to be optimal, then change it in Config.h to 0.36 and reupload the code (but don't forget to remove the part of the code that changes the P-value in the serial-monitor, otherwise you'll just re-write this value when you start your quadcopter)...


@SuleymanSahin: They're not reading an analog value, but a digital one.. They're just using an analog input, instead of a digital one, which I assume is because of the lack of better choices...

@Krooks86: You're right about the plus-configuration, that's how it's done..! The reason that we add and substract from the throttle is to compensate for the change in orientation.. Let us say that throttle is about 50% and the quadcopter is leaning 30 degrees forward (pitch) and the supposed angle should be 0.. Then we need to add a little throttle to the motors in front (m0 and m1) to compensate for this error.. Now in-order for me to explain how I derived my equations, that would take some time, google is your friend in this case.. This article by Hefny is in my opinion good at explaining the difference: http://technicaladventure.blogspot.se/2012/09/quadcopter-stabilization-control-system.html

Edit: I'll be updating the BlueCopter firmware during the holidays (that's because I'll be working on a new miniature 3d printed quadcopter, so stay tuned!)..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 17, 2013, 03:36 am
Basel,
idea of how busy you are! but my questions were: What values ??of Kp, Ki and Kd initially you found? I find the three figures in the same loop? fluctuations Kd and Ki are as visible as the kp? after finding the three values ??is now possible to fly with him? after that I try to go to the angle mode and try again to find the other PID values ??and leave the setting Yaw last?
Basel, you talked about changing the value of Kp there at 0.36 in the config.h "PID_Change_Serial" tab?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 17, 2013, 04:14 pm
Well, I don't really remember, but it's something near the default values that comes with the firmware... No, I meant changing the value in config.h to 0.36 .. My recommendation is to calibrate the yaw axis before the angle PID's.. that way uou won't have any dependencies from the yaw axis while calibrating the angles...
//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 18, 2013, 12:04 am

Basel,
with PID Pitch and Roll adjusted it already is balanced? You can fly it?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 18, 2013, 01:38 am


Basel,
with PID Pitch and Roll adjusted it already is balanced? You can fly it?

You need to balance the yaw too... otherwise there is a risk that it will start to spin... When the yaw is calibrated you can go ahead and fly it :)...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 18, 2013, 03:21 am
More Basel,
yourself said you must first balance and then adjust the Yaw! can not then test to see if will be balanced in the air and then start of the PID Yaw?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 18, 2013, 12:48 pm

More Basel,
yourself said you must first balance and then adjust the Yaw! can not then test to see if will be balanced in the air and then start of the PID Yaw?

Yes, you can try it.. But it's not ready to fly per say.. But sure, go ahead and try it out =)!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 18, 2013, 05:18 pm
Basel,
can you tell me how to adjust the Yaw, type the walkthrough, because this weekend I want to take on the project in earnest! Look, stretch a wire in my room and I think you can hang it! You can adjust the yaw PID as well?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 18, 2013, 05:55 pm

Basel,
can you tell me how to adjust the Yaw, type the walkthrough, because this weekend I want to take on the project in earnest! Look, stretch a wire in my room and I think you can hang it! You can adjust the yaw PID as well?


I didn't hang my quadcopter.. I held it in my hand.. Just use the same guide as you did before, it will work fine.. Just be careful as always.. You'll have to hold it in your hand, change the desired P, I or D and try spinning it with your other hand and observe the respons.. At some point it will start oscillating (it will shake/vibrate a lot, usually you'll see that two motors, CW or the CCW motors will somehow take over and make the quad go back and forth).. It is really hard to explain but you'll see it when it comes =)! Again be careful and push down the throttle to zero if it gets out of hand..!!

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 18, 2013, 06:57 pm
Basel, it is kind of complicated, because how am I going to send data through the serial interface to handle with one hand and still girálo it on low speed until start to swing! is half difícel of view! I think it is as follows:

Connecting the quad;
increase the throttle to 40%;
Go varying Kp values ??until the system oscillates turning the quad left or right;
If ouver problems reduce to zero the throttle!

Do the same for the Kd and Ki!
  That basel ....?

Basel, the next video would clear enough!

I know that you have little time ... but it would help very much!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 18, 2013, 08:43 pm

Basel, it is kind of complicated, because how am I going to send data through the serial interface to handle with one hand and still girálo it on low speed until start to swing! is half difícel of view! I think it is as follows:

Connecting the quad;
increase the throttle to 40%;
Go varying Kp values ??until the system oscillates turning the quad left or right;
If ouver problems reduce to zero the throttle!

Do the same for the Kd and Ki!
  That basel ....?

Basel, the next video would clear enough!

I know that you have little time ... but it would help very much!


It won't oscillate left or right.. When it oscillates it will start to rock back and forth.. Yes, your method is a-okay! Yes, you do the same for Kd and Ki also! I couldn't find a suitable video for you, sorry for that.. But you need to start experimenting a little.. Don't be afraid to do something wrong (just don't cut of a finger =P ).. Try experimenting yourself and find a method that works for you, otherwise you won't learn anything..
Title: Re: BlueCopter - Arduino Quadcopter
Post by: HipOrc on Dec 19, 2013, 03:24 am
EDITED:
Hey Basel, I found out how to wire everything which was my original question. My new question is will this setup work and what changes would you make to it?

I own:
Spectrum dx7 transmitter/receiver
Arduino uno

I am planning on getting:
Hobbyking X525 V3 Glass Fiber Quadcopter Frame 600mm
Turnigy Aerodrive SK3 - 2826-1240kv Brushless Outrunner Motor
hobby king 20A speed controllers
any 8x4.5 prop
11.1v 3s 25c lipo batt

Will I also need a 9DOF? do i just need a gyro? or an accelerometer?  Is there something similar that would work better or anything cheaper?  I just want something that will keep it stable in the air so it will be much easier to handle. Also do i have to plug it into arduino or is there something that i could plug inline with my receiver to the arduino that will adjust the signal accordingly?

anything else i might need?

If you could also give me some insight on how to properly program my arduino for this setup too that would be greatly appreciated!
This is for a school project and i am looking to order tomorrow. There for my price range is restricted too.
Thank you sooo much for your time! ~Dustin
Title: Re: BlueCopter - Arduino Quadcopter
Post by: xSpamerx on Dec 21, 2013, 02:27 pm
HI!
I'm actually building a quadcopter on raspberry pi based on your code ( the fligth controll part )
Can You check my code please ? May be I have misunderstood the flight controlling part of your code.
Problem: I'm getting a little bit low speed on one motor...

The code: http://gfile.ru/a2PlF
First of all I initialize sensors , then arm motors  using deamon (pigpiod which sends pwm signals to motors) then read data from sensors and try to stabilize the quad.

A little bit later I will show the actual  data output may be that would help


Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 21, 2013, 10:19 pm

I own:
Spectrum dx7 transmitter/receiver
Arduino uno
hobby king 20A speed controllers

Will I also need a 9DOF? do i just need a gyro? or an accelerometer?  Is there something similar that would work better or anything cheaper?  I just want something that will keep it stable in the air so it will be much easier to handle. Also do i have to plug it into arduino or is there something that i could plug inline with my receiver to the arduino that will adjust the signal accordingly?

anything else i might need?


Hey Dustin,

The transmitter/reciever will work with my code.. Unfortunately the Arduino UNO isn't supported by my code.. To make it work with the UNO you'll need to re-write the entire receiver section (RX.ino) to support the UNO.. Otherwise you'll need to get a Arduino Leonardo/Micro to make my code work, out of the box...

Which ESC are you getting?? hobbyking 20A speed controllers can be anything.. ESC that will work and that I'm currently using is the BlueSeries ESC from hobbyking.. Here is the 20A version of the blueseries ESC i'm using: https://www.hobbyking.com/hobbyking/store/__13430__HobbyKing_20A_BlueSeries_Brushless_Speed_Controller.html
The reason you may ask? The reason is you need the ESC to support PWM signals.. And because I've used the blueseries ESC, I can personally guarantee that they will work..

For my current code you need at least a 6 DOF, more specifically the ADXL345 and L3G4200D (accelerometer and gyrometer)... you can find some cheap IMU's on ebay..  And yes, you need to plug the IMU directly to the arduino...


@xSpamerx: Because it's not a direct modified copy of my code, I can't just look at it and point something out.. With other words, I really would like to, if I had the time..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Dec 22, 2013, 06:26 am
hello Basel..!
if i use your code for Arduino Mega2560, whatt kind of problems would occur..??
Title: Re: BlueCopter - Arduino Quadcopter
Post by: xSpamerx on Dec 22, 2013, 03:51 pm
baselsw , Yep , not direct copy , but the idea is similar.
I must say that I'm not filtering the data , from sensors so nice as you , and I have not completely understood the controlling part of the code.

I would say that you should pay attention to sensor reading part ( filtering data )  and quad controlling part. Most of the controlling part (PID class i.e)  was copied from your code.

I will appreciate  your help because I have no one to ask for help , and the code from "aeroquad" and so on , is not so easy to understand.

Many thanks..
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 22, 2013, 03:53 pm

hello Basel..!
if i use your code for Arduino Mega2560, whatt kind of problems would occur..??


You'd have to re-write the entire receiver (RX.ino) section to support the mega.. otherwise everything else should be compatible..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Dec 22, 2013, 05:26 pm


hello Basel..!
if i use your code for Arduino Mega2560, whatt kind of problems would occur..??


You'd have to re-write the entire receiver (RX.ino) section to support the mega.. otherwise everything else should be compatible..

//Basel

thanks basel..!
can you help me by writing the algorithm of (RX) for mega2560..?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Dec 23, 2013, 12:50 am
Quote
can you help me by writing the algorithm of (RX) for mega2560..?


This website explains really well how to read a RC receiver with an arduino: http://rcarduino.blogspot.com.au/2012/01/how-to-read-rc-receiver-with.html (http://rcarduino.blogspot.com.au/2012/01/how-to-read-rc-receiver-with.html)
I used it on my own quadcopter code, works flawlessly!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: HipOrc on Dec 25, 2013, 09:31 am
Hey Basel,

Unfortunately i have to use the Arduino uno.
The exact esc's i am using are these ones: (99% sure they are the same ones) http://hobbyking.com/hobbyking/store/__13430__HobbyKing_20A_BlueSeries_Brushless_Speed_Controller.html

I now just need an imu, could you link me to a good one? (cheaper the better)
Can i get one from hobbyking? (prefered)

Could you draw me up a wiring diagram of where i should plug the imu, receiver, and esc's to the Arduino uno? That would make it 10x easier thank you. The last question i still have is the files... I use "bluecopter.ino" right?

I am 16 and very new to programming, what exactly is the main conflict with the rx code?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 27, 2013, 11:35 am
Basel,
the child Jesus bring peace and joy to your life and your family! keep it up! Merry christmas and a prosperous new year!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 29, 2013, 05:13 pm
Basel ,
is too strange because of som so it oscillates with the addition of the term " D " did as you told me , and nothing varied the RX_SENSITIVE , decreases to 1 and then increased to 2 and nothing ! one hours initiated in the same " loop " setting of the two values ​​at the same time , "P" and "D " to see if it still respendendo , in case that best P value of 0.315 was found and it continued by adding Kd Replying the stick but not swayed somehow got to add kd equal to 0.2 and nothing , so I uploaded again and tried to vary only the Kd and as before nothing happens on the stick , I think something in the code interferes with the setting of other parameters ! if he'd like to find the period of the oscillations could use the term P - Zilguer Niches to find the critical period ? can you help me !
Is it my trasmissor that has no configuration ?

The video explains well ! and provides for the osclilações , where the term P well they are visible, they are smaller in D and R even lower !

Can you help me ?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 30, 2013, 11:39 am

Can you help me ?


Hey,

It sounds like you have a small delay.. That delay could be the Serial interface.. So just put the D-term to 0.014 (I calculated this number) and try adjusting the I-term instead..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 30, 2013, 01:05 pm
Basel, as you did to get its values??? apneas used your step by step? used the serial interface? used some of matlab script and model of the plant? Yesterday I downloaded two batteries and can only find the right value of "P", it swings even!
How do I adjust without using the serial, after all you said that you have not tested this example, so it has no chance to even work. 'll Susbtituir values ??in config.h as you said P = 0.315 and D = 0.014 and I will try to find the value of I, if I could still talk today ahar something.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Dec 30, 2013, 01:51 pm
@satiro: I did use matlab.. I used the serial interface to get data for my model (taking all the delays into consideration in the plant model), then optimized the PID values for the plant model and used those values in my final design..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Dec 30, 2013, 06:10 pm
Basel, you can send me the Matlab script for me to try to find the values ??of PID? Look, what you did was find values ??in Matlab with your plan then test and optimize these values ??in the model real.Com time you can use Zilgler-Nichols to find the critical gain and critical period, was that what you did? if possible send scritp Simulink for satiromedeiros@yahoo.com.br.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 01, 2014, 01:52 am
Basel, tried with the value you suggested and got the Ki value = 0.83, have not tried to fly but tomorrow I will test for real! Look, I know sometimes I'm annoying, but it's for a good cause, I need your help because I'm trying to fly with this Quadcopter .. hey, he's my college work and then I want to thank your references as you should and send you a copy of my work! as I said I'm bothering you more than it should. Look also use Matlab and Simulink have a scrip in, just to test. You could look at it and suggest corrections to me, I am sending you attached, and as I said before, just answer me in satiromedeiros@yahoo.com.br. My version of Matlab is ra2011
Title: Re: BlueCopter - Arduino Quadcopter
Post by: zaferoznalbant on Jan 01, 2014, 01:49 pm
Greetings Basel,

Thanks for your great job and happy New Year.
I am a newbie in microcontrollers and arduino. Trying to learn day by day.  As I said I am a newbie, my question may be ridiculous. Sorry for that.
My first question is about analogwirte(). You used analogwrite() to trigger the motors' esc (am I wirte?), I am a bit confused because there some info says that the analogwrite() cannot be used to trigger the servos and esc (http://forum.arduino.cc/index.php/topic,5701.0.html). I tried to control my servo with analogeitre() but I couldn't. How did you control the escs with analogwrite()?I will appreciate if you explain this.

Regards,
zafer
Title: Re: BlueCopter - Arduino Quadcopter
Post by: HipOrc on Jan 03, 2014, 07:22 am
Greetings Basel,

I don't understand why the "rx.ino" needs to be re coded to work with an Arduino uno...

The one file i think i would need to re code is the "config.h" because i do not have any pins higher than 13 (for the last part of the code, rx defining)

Or at least that's the way i see it. Please help! :smiley-sad-blue:
Title: Re: BlueCopter - Arduino Quadcopter
Post by: zaferoznalbant on Jan 03, 2014, 09:05 am
Hi Basel. It's me again. I would like to ask a question about pinChangeInt. I upload two code below. In the first one I used attrachInterrupt to get signals from receiver. In the second one I used pinchangeInt. Two code are almost identical except the interrupt functions.

These two codes get different values from the receiver. I couldn't understand where the problem is. Could you help me to solve this problem?

I got the attachInterrupt code from the previous posts in this topic. 

Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 03, 2014, 05:37 pm
Basel!!!!!, Help-us!!!!!!!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 10, 2014, 04:17 am
Basel,
bad friend, is on vacation? sorry but could help us a bit? look, I'm having difficulty in PID tuning, got the best value of Ku 0.35 it my Kp is 0.315, the best way to adjust the PID is in hand or even as also I am doing the right! Only one axis as I told you before? looks you could pass me the settings? kind since the direction of movement of the propellers until the mode is "+" or "x" ...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 10, 2014, 04:26 am
Basel, their engines m0, m1, m2 and m3 are setup "+" in the figure and are as on the left side with m0 = m1, m3 m1 = m2 = m4, m3 = m2? and as to the senses? m0 and m3 are normal and m1 and m2 are reversed?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 13, 2014, 10:31 am
basel i neeeddd ur immediate help.....i bought a leonardo now.....but blue copter's code is not running on ittttt :(((((
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 13, 2014, 03:42 pm
will somebody tell me...????????????????????
why its not running...?????
no error in burning, no error in pinouts..like Vin, gnd, SCL, SDA......plzzzzzz help me...its my Final year project, ive to present on wednesdayyy...plzzzzzzzz sombody help meeeee
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 13, 2014, 05:34 pm
Muhammad, tell what your problems! Look, I know well the program of Basel and think I can help you! until he can respond again! Look, I've even changed the code to run on atmega 328 ... the only place that you must change the programming is RX.ino because of the interruptions that are different for each type of Arduino! the other must be mega PCINT's just change there ... gives a look at the previous posts and see the code that I put ... the basel explained very well! Look, his model is a quad-X ... you also have to be careful with orientation board  sensors... not to read axes reversed!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 13, 2014, 06:44 pm

Muhammad, tell what your problems! Look, I know well the program of Basel and think I can help you!


buudy at first i was trying basel's code on mega2560. its working, except the RX.ino
as it is my final year project and i have to present it on wednesday, im running out of time. for that reason i bought leonardo now. but this code is not running :'(
all other simple programs are running....but why it is not..?????
plzzzz help out meee
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 13, 2014, 07:01 pm
But what is happening! if you up-load of other program works exeto the Basel! is it? you did the assembly exactly as in the previous posts? are correct in their conxões GY-80 sensor? in config.h basel to view the data you have going on "macro DEBUG" and enable the data you want to see! and connect the receiver! the receiver for safety is the one who releases the visualization of data, but has other "macro at the beginning of the code in config.h that if you do not need to disable the radio receiver!'s it!'s early in config.h not only remember the name now!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 13, 2014, 09:38 pm
Wow, a lot of messages.. No, I'm not on vacation, it's just I usually visit this site when I get a notification email that says that I've got a new Post on the forum.. This didn't happen...

Anyhow to the problems:

@Satiro: I'm having a hard time knowing what you're after.. Do you want to fly it in + mode? In that case you'll have to modify the output of the PIDs to the motors.. You can find these in the following variables: in FlightCtrl.ino

Code: [Select]
  int m0_val=throttle+PIDroll_val+PIDpitch_val+PIDyaw_val;
  int m1_val=throttle-PIDroll_val+PIDpitch_val-PIDyaw_val;
  int m2_val=throttle+PIDroll_val-PIDpitch_val-PIDyaw_val;
  int m3_val=throttle-PIDroll_val-PIDpitch_val+PIDyaw_val;


You have to rearrange PIDroll, PIDpitch, PIDyaw accordinaly.. But I don't recommend you to do anything like that until you get your quadcopter working with my setup.. Because if you venture into something like that I can't be 100% sure each time I answer your questions..

What settings do you want me to pass you? Can you try out something for me? Try the following values and report back:

Code: [Select]

#define ROLL_PID_KP  0.200
#define ROLL_PID_KI  0.800
#define ROLL_PID_KD  0.00
#define ROLL_PID_MIN  -50.0
#define ROLL_PID_MAX  50.0

#define PITCH_PID_KP  0.200
#define PITCH_PID_KI  0.800
#define PITCH_PID_KD  0.00
#define PITCH_PID_MIN  -50.0
#define PITCH_PID_MAX  50.0

#define YAW_PID_KP  0.500
#define YAW_PID_KI  0.300
#define YAW_PID_KD  0.00
#define YAW_PID_MIN  -50.0
#define YAW_PID_MAX  50.0

#define ANGLEX_KP 3.0
#define ANGLEX_KI 0.02
#define ANGLEX_KD -0.015
#define ANGLEX_MIN -100.0
#define ANGLEX_MAX 100.0

#define ANGLEY_KP 3.0
#define ANGLEY_KI 0.02
#define ANGLEY_KD -0.015
#define ANGLEY_MIN -100.0
#define ANGLEY_MAX 100.0


If these settings don't work at all, then you maybe you have your IMU set in the wrong direction on the quadcopter.. Anyhow, try these settings and report back..


@MuhammadArslanKh: What's not working when you upload/run the code on the leonardo..? If you've connected everything right then it should run right out of the box.. Check your connections again and report back..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 14, 2014, 01:22 am
Basel, I think I did much wrong! and was doing much wrong! how you been out for at least 1.5 weeks! I had to turn around and got help with staff multiwii. I'll start telling you of my mistakes!

My quad was vibrating much of anything! then was driven and balance propellers, engines and contain the vibrations in the controller board!

So! checked the propellers (10X4.5) and were balanced! checked the engine-750KV with RC-Timer app for android "seismograph" and two of the engines were well unbalanced! I think it was one of the downfalls of trying to fly! but could also balancer! were two opposing and very accelerated when they cheered even more! also worked on the issue of my plate with the sensors ... in my haste I put metal washers and a piece of wood! may seem preciousness, but when you're just anything seems to be the right thing to do! So I watched an article about vibrations and the guy said that the best boards for amortecerdor was a gel called MooGel then were the foams, and Velcro all as anti-Danping systems! The guy ended the video saying it could put musepad foam on the board and so I did!

So far, about four errors already listed!

But do not stop there! in my first accident with attempt to fly! broke three propellers and was priate exchange traded only three! did not pay attention but the model was different though the same type! just found the error when I balance the propellers!

The grossest mistake was not seeing my card is like yours and is geared towards the "X" type and not the plus "+" ... just realized this because in the tests on the bench there was a time he wanted to rotate only! the face multiwii told me to do a test! and did, put it on the shaft and when I called back he gave a alone! my problem was, tried to adjust the PID like a plus "+" but was an "X" unless you rotate the plate! Another problem! I ended up with two lipo batteries in less than an hour test! then had an old font called here and now! To end I think once in your post you said his quad was "+" then when I saw the code muitiwii percebei it was "X".

Those PID values ??that you were told wrong, last night I went to bed late but found a value of 0.25 then the Ku Kp was set at 0.225! below is attached some photos!
Basel, now I guess I can try to adjust the PID, I made an arrangement as you can see from the photos with pots and my X axis is the one that is pictured pointing to the potentiometers!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 14, 2014, 01:33 am
Basel I is to test this values??? the way they are! Pitch and yaw-roll? looks through photos red propellers are a normal and another reverse and black anyway! my setup is as in muitWii! below follows more photos!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 14, 2014, 01:35 am
Fotos!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 14, 2014, 01:41 am
@satiro: well your post indicates that you didn't read through this thread before starting your quadcopter project.. Now, my software package isn't as complete as multiwii.. Because what I'm offering is a way to learn how everything works or how to make your own firmware plus hardware from scratch.. Multiwii doesn't give you that option because it's a complete software package with a nice and simple interface between PC and quadcopter.. When I answered your questions I was assuming that your ESC's, propellers, hardware in general were complete and your only problem were lying in software.. But clearly that wasn't the case.. If you've done everything right your PID values should have been very close to the ones in the original file.. As I said earlier, I'm working on a mini quadcopter that uses my bluecopter firmware.. Today I test flew it.. And it flew without any problems with the original PID values, no modifications.. I'll post the results very soon together with a flight video.. Just to compare, my original quadcopter is 660mm from motor to motor and weighs 1500g.. The mini quadcopter is 150mm and weighs 45g.. Anyhow, I'm glad your getting somewhere with your project.. Best of luck :)

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 14, 2014, 02:50 am
Basel, learned a lot from you! my model is 450mm 1000g but still presico your help! can take a look at the photos and see if there is something else wrong? You can be sure of one thing as I said before! you are a person who can explain difficult things and it is not for everyone!

How do I calibrate my ECS's? the means to make software? they are starting at 110 and not 125 as it is their problem?

My ex was like in multiwii quadX,

      motor[0] = PIDMIX(-1,+1,-1); //REAR_R      m0 pin 3
      motor[1] = PIDMIX(-1,-1,+1); //FRONT_R    m1 pin 10
      motor[2] = PIDMIX(+1,+1,+1); //REAR_L      m2 pin 11
      motor[3] = PIDMIX(+1,-1,-1); //FRONT_L    m3 pin 9

For the pins as I have told you different on Arduino Nano. "Used in RX.ino"

Just wanted to make a check list to not waste any more time and go straight to the PID settings.
Can still help me?

Where do I start and then go back to the settings of PID?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 14, 2014, 05:12 am
Basel, the tested values ??and seemed good! the problem is that I think my axles are still wrong! happening is that the engines brings "Red" will gradually stopping and are just trying to balance the two front "black" at full speed? and when the throttle down just after bipam they do not stop after a while is that bipam again! calibration is it? Do not enter values ??Yaw initially, but after inserting the test and did not change anything of behavior!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 14, 2014, 06:43 am

But what is happening! if you up-load of other program works exeto the Basel! is it? you did the assembly exactly as in the previous posts? are correct in their conxões GY-80 sensor? in config.h basel to view the data you have going on "macro DEBUG" and enable the data you want to see! and connect the receiver! the receiver for safety is the one who releases the visualization of data, but has other "macro at the beginning of the code in config.h that if you do not need to disable the radio receiver!'s it!'s early in config.h not only remember the name now!


yes i have enabled the DEBUG from config.h
when i burn basel's bluecopter code on leonardo, i gives nothing on serial monitor.... also the TX light on leonardo doesn't blink...which means the code is not reading anything...not even printing which i ve written in Void setup()

plzzz help out me
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 14, 2014, 06:49 am
@basel sw
i have everything alike u used for ur bluecopter. same transceiver, same imu, same leonardo, same esc n props...
help out me man...illllll b highly highly greatful to u :(
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 14, 2014, 06:36 pm
Basel, you could make a freehand drawing how is orientation of your board, sensors, their engines and their propellers and associated PID output! I think it kills so many questions! their propellers are blue and red, who is ahead and what part of the back? you can do it! and if possible answer me the above questions!

Another thing, as the engines were reversed as "+" need to calibrate the ECS again! as I told you before two of them are stopping and only two are trying to balance the flight!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Jan 15, 2014, 11:46 am
Hi Basel How are you?;

I have been working on quadcopter project for 2 months. Your work helped me a lot with this project. I'm using arduino due unless i mentioned earlier.

I have read all the pages about common problems in your thread but still remained questions in my mind.

First of all where is your kalman filter in your code? You have used high pass filter and low pass filter but where is the kalman filter? Didn't you use it? Or high pass filter is enough for the accelerometer and gyro noise??

And I am sorry I didn't really understand the way you calculate gyro and accelerometer in your code? Would you please tell me the exact algorithm you used to filter them.

second:
#include <avr/pgmspace.h>  there is no file like that. Is that a Arduino library?

I would be gladly appriciate reply from you because my project hand over is one week later so I am in a hurry.

Regards and respects;
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 15, 2014, 03:41 pm
@Muhammad... Disconnect the motors, turn off safe mode by commenting the line

Config.h
Code: [Select]
#define SAFE    //Arming procedure

Turn on debug mode and check and see if you get any response..

@Satiro: I'll be back with a better drawing of my setup..

@TheAviator.. I'm not using a kalman filter.. Instead I'm using a complementary filter.. You can see it at lines 27 and 28 in Sensor.ino .. I'm using a low-pass filter for the accelerometer and a two-step moving average filter for the gyrometer...

"avr/pgmspace.h" this file does exist if you're using avrgcc.. No it's not a arduino library, it's a header and is part of the avrgcc compiler..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 15, 2014, 04:37 pm
Basel, I think I'm finally getting on with only the adjustment of PID's! so I need to confirm your guidance! it already took a look at previous threads if your engines match your photos so I have to change my motors spin again! if you put a drawing board with gy-80 engines-color Héliès-axis direction and you can not go wrong!
Hugs!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 15, 2014, 07:47 pm
Here comes the updated photo:

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 15, 2014, 08:12 pm
Basel, you are the man!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 15, 2014, 08:37 pm
@ basel
yessss..!!!! u r the man basel....thanksssss
its working now...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 15, 2014, 08:41 pm

@ basel
yessss..!!!! u r the man basel....thanksssss
its working now...



This doesn't mean that it's working! There is something not working.. The SAFE procedure keeps your motors from spinning out of control as soon as you connect the battery! So don't connect your motors just yet!! Debug your transmitter (RX) and see that your controls give values between 1000 and 2000us. If they doesn't that means that you need to calibrate these values in config.h...

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 15, 2014, 10:46 pm
bro the values are between 1000 and 2000....im attaching the graph...do check it...
after that i connected 3 motors... one is running at medium throttle...2nd runs around maximum throttle....while the third dint strat...
why this so..??? :(

Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 15, 2014, 10:53 pm
@basel...check this out
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 15, 2014, 10:55 pm
@basel
wot i have to do now bro...???
kindly guide me...im very exited now
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 16, 2014, 11:59 am
Basel, my quad is like yours! and PID values ??seem good! yesterday I started testing after reversing the engines and adjust the IMU, look, he tried to equibrar the "X" axis Roll, but the engines 9 and 10 after a while began to accelerate and stop the engines alone 5 and 6. Thus engines 9 and 10 are at full throttle trying to balance the quad! You know it is the "I" PID action? or is it something in the engine after I reversed them? when they were so tried to stop lowering the stick to the minimum, but they do not stop "bipam" more? can you help?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: MuhammadArslanKhan on Jan 16, 2014, 07:37 pm
@basel
my motors are not running synchronously >(
every time when i connect the battry with quadcopter, and the start the transmitter, all motors are running very diffrently from each other....kindly tell me wot shd i dooo :(
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 16, 2014, 09:27 pm
@MuhammadArslanKhan: I told you to not connect the motors while SAFE mode is turned off.. Turn on SAFE MODE.. What you are experiencing is the ESC's not getting enough time to check for the PWM freq. and the PWM zero level.. What happens is the each ESC will be timed differently and thus give you this erratic behavior.. After turning on SAFE mode connect the motors and start up your quadcopter.. Give it 3-5 seconds (until the motors stop beeping).. Then increase the throttle to approximatley 10%.. If it still doesn't start increase it to 20%.. It should start as soon as the throttle signal is approx. 1100us.. Try it out..

@Satiro: I can't say for sure what the problem is.. It definitely has something to do with the PID's in some way.. Not necessarily the integral-action.. It could be that your quadcopter not getting enough throttle after the arming procedure.. Try increasing the MOTOR_ARM_START in config.h to let us say 150..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 17, 2014, 11:50 am
Basel, I had to set the ESC's again worked. Tonight beginning again trying to check their latest PID values​​!
Basel, how do I view the oscillations of Ku to determine other values​​! so would the frequency and would find the starting values​​! It is possible to visualize with MATLAB scripts? and what data to send to the serial port to view the oscillations? can help-me!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 17, 2014, 08:10 pm

Basel, I had to set the ESC's again worked. Tonight beginning again trying to check their latest PID values??!
Basel, how do I view the oscillations of Ku to determine other values??! so would the frequency and would find the starting values??! It is possible to visualize with MATLAB scripts? and what data to send to the serial port to view the oscillations? can help-me!


My matlab work was done on an old computer (that I passed on to another family member).. So unfortunately, I don't have anything for you in that department.. It is possible to do what you mentioned, but you will have to code it yourself.. it won't be pretty though because it'll be running faster than the serial interface, so you won't find a real optimum because of the delays.. I think you're making things hard on yourself.. Your optimal PID values should be very near mine (the ones that came with the firmware in the first place).. Worst case scenario, you'd have to reduce the gain and integral parts a notch.. As I mentioned earlier, I managed to run my code with minimal PID changes (only reduced the gain on the rate PIDs a little, because I didn't want that fast a response).. When I say a little I mean from 0.250 to 0.230.. And the Rx part on that small quadcopter is a whole new story for itself.. So even if you add/remove features from the firmware, as long as the timing, IMU and quadcopter configuration are the same you won't have to change the PID settings that much.. So use the original PID values and play around with the gain a little until you get successful lift off.. If you want to do it all from scratch then I maybe can give you some tips, because what you are talking about is a university course in itself, and as you understand would be difficult to teach in a forum..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 18, 2014, 04:52 pm
Basellllll he could fly! thank you! you're the same guy! but hey, he is wavering a bit and is a bit hard to keep it standing up! are they Kp values​​? will decrease and try again! look, I'm just using a battery of 3000mAh lipo with 20C discharge! Dude, if you can help me with the issues I thank MATLAB! as I told you is an academic work and have knowledge of the subject! then I'll post a video with the flight!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 18, 2014, 10:42 pm

Basellllll he could fly! thank you! you're the same guy! but hey, he is wavering a bit and is a bit hard to keep it standing up! are they Kp values??? will decrease and try again! look, I'm just using a battery of 3000mAh lipo with 20C discharge! Dude, if you can help me with the issues I thank MATLAB! as I told you is an academic work and have knowledge of the subject! then I'll post a video with the flight!


I'm glad to hear that =)! Try decreasing the Kp values (just do small changes, it shouldn't be a lot).. If it still wiggles a lot, try decreasing the Kp and Ki for the YAW axis (SMALL CHANGES HERE ALSO)!  I'll give you tips and help you with your matlab scripts.. But I don't have the time to write and test something for you, I hope you understand..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Jan 19, 2014, 01:38 am
Hi Basel;

now I must ask you an important question. I have an Altimu integrated circuit that does have L3GD20, LSM303DLHC, and LPS331AP on it. Here is the link:

http://www.pololu.com/product/1269

may be weeks I have been trying but couldn't get this sensor work properly. I am out of patience so I will try something different and crazy :)  I will change my sensors. I am going to use the same sensor as yours. Because you have written a good code that working with L3G4200D, ADXL345,HMC5883L & BMP085. Is that right? So I'm going to use that way.

Meanwhile I couldn't find all them in one circuit like this :
http://www.hobbyking.com/hobbyking/store/__26913__Arduino_10DOF_L3G4200D_ADXL345_HMC5883L_BMP085_Sensor_Stick_Breakout_for_MWC_KK_ACM.html

Therefore ; I will buy them seperately like

L3G4200D :
http://www.robotistan.com/L3G4200D-Voltaj-Regulatorlu-3-Eksen-Gyro-L3G4200D-3-Axis-Gyro-Carrier-with-Voltage-Regulator,PR-1134.html

ADXL345:
http://www.robotistan.com/ADXL345-3-Eksen-Ivme-Olcer-Triple-Axis-Accelerometer-Breakout-ADXL345,PR-1502.html

do you believe I can work them with your code without a problem? Please tell me it can work..

by the way maybe you will appreciate if I show you my progress..

I have designed a shield for the arduino due.
I am going to send you two pictures both mounted imu and without mounted imu.
I have soldered two pull up resistors for the SDA1 and SCL1 inputs.
What do you think about that? Here is the links: (sorry for the bad quality :) )

https://www.dropbox.com/s/9qecaxtm2b9nsk5/bos.jpg

https://www.dropbox.com/s/fnmf3k6zcdikwvc/imulu.jpg

What do you think about them?And of course here is my quadcopter:

https://www.dropbox.com/s/gni9v7hhnmjs4zq/3.jpg

This is not its final build.
I have mounted high landing skid and mounted the battery to its bottom.
Its an old picture.
And Finally my code, I have progressed so far.
I am accurately reading PPM signal from the receiver. And putting it to the ESC.

I haven't written the PWM output but its not a big deal. Just ESC1.write(throttle+pitch+roll+yaw);

https://www.dropbox.com/s/fiqzx6zmz0n4pmm/quadcopter.rar

Meanwhile, maybe for the bad quality, I want to tell my pin configuraiton. I have attached pitch, roll, throttle , yaw;respectively to the A0,A1,A2,A3. And ESC1,…… ESC4 to digital outputs from 7 to 4.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Jan 19, 2014, 11:46 am
Another thing is,

while compiling your original code, the compiler having errors about MPUlib. ( I have copied the MPUlib and PID  libraries to my library browser already ) .

this is the error ;

BlueCopter:25: error: expected ')' before '*' token
BlueCopter:25: error: expected ')' before '*' token
BlueCopter.ino: In function 'void setup()':
BlueCopter:49: error: request for member 'init' in '3758157200u', which is of non-class type 'MPU_Type*'
RX.ino: In function 'void rxInit()':
RX:13: error: 'PCICR' was not declared in this scope
RX:13: error: 'PCIE0' was not declared in this scope
RX:14: error: 'PCMSK0' was not declared in this scope
RX:14: error: 'PCINT1' was not declared in this scope
RX:14: error: 'PCINT2' was not declared in this scope
RX:14: error: 'PCINT3' was not declared in this scope
RX:14: error: 'PCINT4' was not declared in this scope
RX:15: error: 'sei' was not declared in this scope
Sensor.ino: In function 'void updateAcc()':
Sensor:30: error: request for member 'getAxlData' in '3758157200u', which is of non-class type 'MPU_Type*'
Sensor.ino: In function 'void updateGyro()':
Sensor:41: error: request for member 'getGyroData' in '3758157200u', which is of non-class type 'MPU_Type*'


How may I solve this problem?

And another question.  Are these buffers[], x,y,z respectively?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 19, 2014, 12:53 pm
@TheAviator: Sure thing.. Even if the sensors come separately they will work.. What's important here is that you think of the orientation of the sensors when soldering them! The library initializes the compass sensor (HMC5883L), so if it's not present that will maybe cause some problems on the I2C bus (not sure, but maybe).. So you either buy one compass sensor or you'll have to go into the library and remove it altogether..  I bought my IMU on ebay, and as of now, there are a lot of 10DOF sensors like mine on there, so check it out..

Everything as far as I can see looks fine on the pictures (cool quad btw =) )..

The reason for the Errors in MPULib is that the MPU "name" is already used by something else in the DUE jungle of library's and core! But not only the MPU "name" but also the buffer name.. Change all the "MPU" to small letters "mpu" everywhere in the sketch (mostly in Sensor.ino and BlueCopter.ino).. And change buffer to buffer0 instead.. This will make it compile without any problems..

Yes, the buffer-array consist of the x,y,z coordinates respectively..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 19, 2014, 01:13 pm
Basel, I am still improving the PID values??, but as you did to test it in flight? you went to a very large place! I say this because when he raises is not hovering flight is falling in some direction! how do I get stopped flying quietly? are the PID settings yet?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Jan 19, 2014, 05:01 pm

@TheAviator: Sure thing.. Even if the sensors come separately they will work.. What's important here is that you think of the orientation of the sensors when soldering them! The library initializes the compass sensor (HMC5883L), so if it's not present that will maybe cause some problems on the I2C bus (not sure, but maybe).. So you either buy one compass sensor or you'll have to go into the library and remove it altogether..  I bought my IMU on ebay, and as of now, there are a lot of 10DOF sensors like mine on there, so check it out..

Everything as far as I can see looks fine on the pictures (cool quad btw =) )..

The reason for the Errors in MPULib is that the MPU "name" is already used by something else in the DUE jungle of library's and core! But not only the MPU "name" but also the buffer name.. Change all the "MPU" to small letters "mpu" everywhere in the sketch (mostly in Sensor.ino and BlueCopter.ino).. And change buffer to buffer0 instead.. This will make it compile without any problems..

Yes, the buffer-array consist of the x,y,z coordinates respectively..

//Basel



It worked!!! :D thanks basel, now I believe myself to finish this project but finally I hav another question, especially a problem.
I'm still having this problem :

RX:13: error: 'PCICR' was not declared in this scope
RX:13: error: 'PCIE0' was not declared in this scope
RX:14: error: 'PCMSK0' was not declared in this scope
RX:14: error: 'PCINT1' was not declared in this scope
RX:14: error: 'PCINT2' was not declared in this scope
RX:14: error: 'PCINT3' was not declared in this scope
RX:14: error: 'PCINT4' was not declared in this scope
RX:15: error: 'sei' was not declared in this scope

haven't they already defined in config or in another thing? Do you think this is also a Due problem? And how may i solve it? Please give me information about it?

And should I really use this magnetometer? Please tell me where exactyl should I remove magnetometer code from your code?

I'm in hope again basel.I promise you , when I will be finished this project , I will buy you a beer :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 19, 2014, 06:29 pm
@Satiro: If it's not hovering then your not giving it enough throttle, push it a little more.. Post a video of the quad. in action.. I need to see what you're talking about..

@TheAviator: I saw this error in the log you posted before, and ignored it because I thought you knew what it meant.. You got that error because the pin change interrupts are not defined for the DUE.. Just as I said a couple of times before, if you're trying to port the code to another board than the leonardo you'd have to go ahead and re-write the entire RX-section..  So that is what you'd have to do..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 19, 2014, 11:01 pm
Basel, I will try to go for a clearing place! Here I try to make a short film and am sending you next! Look, posted a scrip matlab previously, but as said can not open! if you could you would see that I can read the "1 degree of freedom" sensors and then enters the digital PID will then link to the serial communication, all in Simulink! turn behind can download it! Tell me how you did to get the basic values ??as you already said before! they are a starting point! was scropt MATLAB or Simulink was in?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 19, 2014, 11:05 pm

Basel, I will try to go for a clearing place! Here I try to make a short film and am sending you next! Look, posted a scrip matlab previously, but as said can not open! if you could you would see that I can read the "1 degree of freedom" sensors and then enters the digital PID will then link to the serial communication, all in Simulink! turn behind can download it! Tell me how you did to get the basic values ??as you already said before! they are a starting point! was scropt MATLAB or Simulink was in?


It was entirely in MATLAB.. I don't like simulink.. Graphical programming has never been my favorite thing to work with..  I need a close-up of the quadcopter in action (so I can observe the response)..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Naoki7 on Jan 20, 2014, 01:49 pm
I was browsing  through your PID library and I was confused by one of the controller constructs defined for the Rate Level Mode; could you discuss how it works?

Code: [Select]
double PIDCont::Compute(double mError,double dError,double setP) {
unsigned long tn = millis();
double dt=(double)(tn-tp);
 double P = (double) kp * mError;
 double D = (double) (kd *((setP*1000/dt)-dError));
 pError = mError;
 double I = (double) (Ip + ki * mError * dt /1000.0);
 double U = (double) (P + I + D);
 Ip = I;
 tp=tn;
 if(U>Hval){
   U = Hval;
 }
 else if (U<Lval){
   U = Lval;
 }
return U;
}



I admire your using the Arduino microcontrollers for quads, and hopefully I can get bang out the kinks in my own code bit by bit!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 21, 2014, 02:28 am
Basel, man excuse me, but did not ... took to take a flight in the open, and it was cool at first but I discovered that I suck at driving and happened to put the throttle to maximum and when I saw he was away a lot then fell and break the frame! I was very sad! I was very confused in the control of pitch and roll and I think I screwed up when placed at full throttle! if he had altitude control might be different! I now have to buy a new frame!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Naoki7 on Jan 21, 2014, 08:58 am
Is there a reason why the code uses analogWrite instead of the Servo library's .write command?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 21, 2014, 11:06 am

I was browsing  through your PID library and I was confused by one of the controller constructs defined for the Rate Level Mode; could you discuss how it works?


@Naoki7: Sure thing.. I had some problems with the derivate part of the PID and the controls.. I wanted a large derivate action for the signal and some kind of dampning for the controls.. So I split the derivate part into the control part (setP) and signal part (dError).. The reason for analogWrite is that it's faster! Servo Write works at 50Hz and analogWrite at 500Hz.. I've already answered these questions previously.. For a detailed explanation you'd have to search this thread!

@Satiro: I'm sorry to hear that.. But you shouldn't have done this to begin with.. You need to be able to control it, as well as control it from a distance (this needs training obviously).. But how did it fly in the beginning then.. Was it stable?

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Jan 21, 2014, 11:20 am
Hi Basel!;

I am going to use the servo library too, like

Code: [Select]


#include <Servo.h>

Servo ESC1;
Servo ESC2;
Servo ESC3;
Servo ESC4;

void setup(){
ESC1.attach(ESC1_OUT_PIN);
ESC2.attach(ESC2_OUT_PIN);
ESC3.attach(ESC3_OUT_PIN);
ESC4.attach(ESC4_OUT_PIN);
}
void loop(){
ESC1.write(throttle+pitch...............


You said early pages that it is wrong and slow, you can use it only in the rate mode. Its okay for me not a problem. But I am using this mode because I couldn't run the Brushless DC motors and ESC without a servo library. simple analog.write didn't work for me. Do you know why? Can you explain this to me?

Arduino Due has 96 Mhz processor, can I run it properly?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 21, 2014, 11:49 am
Basel, as it was yes! quite stable, was on a football field with a lot of wind and it got good reactions! only that it was difficult to control the directions! I bought a glue earlier today ... I will try to paste, but I also bought an arm ... now just arrive and subtituir my injury were two propellers and an arm ... I bought a very light foam and will make a landing gear too! basel Either way, I really appreciate your patience!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 21, 2014, 11:00 pm
@TheAviator and others that are considering to use the Servo library:

I do not, recommend using the servo library! Doesn't matter what I said, it's just to slow! Even if the Due is running at 84Mhz that won't matter because the Servo library is set to work at 50Hz on all boards (it's calculated inside the library depending on the frequency the system is running at).. Now even if you speed up the servo library to let us say 500Hz, I don't really know how your ESC will respond to that.. It may not respond at all because it's expecting a 50Hz signal.. But sure thing try it out if you'd like (hell I'm starting to get interested too :) ).. The reason that I'm not recommending the Servo library is because I started out my code with the Servo library =P .. So I know what will happen (control-wise), if you slow down the output signal to 50Hz.. I managed to get the rate-mode to work (if I remember it right).. And it's not easy to fly the quadcopter in rate-mode as a beginner..! But again, I'm here to give you some tips, it's up to you to do what ever you want to do in the end =P..

@Satiro: Now that is good news.. Did you use the original PID-values or did you change them all?? And in that case, can you please post your final PID values (all of them)..
It's hard to fly the quadcopter in windy conditions without any training.. I did the same thing one time, but I managed to fly against the wind by tilting the quadcopter in the opposite direction and increasing the throttle a notch and finally emergency landed the thing (you do that by simply decreasing the throttle a lot and increasing it a lot again 2-3meters above the ground followed by decreasing it slowly =)! Sounds like you simply need a lot of training =)..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 22, 2014, 01:18 am
Basel, have an ultrasonic sensor "HC-SR04" and was thinking of doing for a PID altitude control type on-off to keep it at least 3 feet tall ... what do you think? I will check that speeds the engines need to be to keep 3 feet tall so I try to automate the throttle! but I'm still waiting for help in MATLAB? Basel, you can write the script that testo here! do not you worry! and also tell me where to change the code in the arduino I change that too!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Jan 22, 2014, 11:29 am
Hi Basel!;

Thanks for your answers patiently, really thank you :D

I have to ask you a simple question now, may I feed the sensor's GND and VCC with digital pins? Like

Code: [Select]

void setup(){
pinMode(17,OUTPUT);
pinMode(16,OUTPUT);

digitalWrite(17,HIGH);// to use as VCC
digitalWrite(16,LOW);// to use as GND
}


Is that possible? :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 22, 2014, 10:18 pm
@Satiro: If you have the same IMU as me then use the pressure sensor for the altitude.. This type of implementation would need some serious re-writing of the firmware.. You'd have to put in the sensor reading code, time the reading sequence right (this have to be measured) write a loop that won't interfere with the other sensors and finally add a new PID for the altitude.. This would take some time to write and test (time that I don't really have).. If I even consider implementing this kind of thing then it won't be until summer time that I start to work with it..

@TheAviator: If you read the datasheet for the several components you can find out the answers to these questions yourself.. Anyway, from the Arduino Due page, http://arduino.cc/en/Main/arduinoBoardDue , You can clearly see that some pins can source 15mA and others 3mA.. These pins can also sink 6- or 9mA.. The current needed to run the sensors is above these limits (see the datasheet for the sensors), which in fact means that it won't work.. If you need to turn off/on the sensors in code then you'd have to connect GND to Due's GND and VCC to a mosfet which in turn you control with one of Due's many pins with a code similar to the one you wrote above..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Jan 23, 2014, 02:15 am
Basel, my friend! do not you worry you've done enough! only asked for your help one more thing "MATLAB" issue is kind of barometer complicated as you said, but I'm thinking of doing this with the ultrasonic sensor! already took a look at Multiwii and it automates the throttle with the barometer and do as you sujeriu a separate PID! the throttle is there as "thrttle + PIDAlt" but leaves it to what I thought was there, making a on-off control to keep it in certain altitude! but if quise give me the tips I think I can implement it! PID values ??I used in flight were kp = 0.2, ki = 0.85 and kd = 0:08, guess who got a response a little slow but was more stable!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: ekale on Jan 29, 2014, 10:06 pm
Hi Basel,

Is it true for arduino mega?

//Motor Pins
#define MOTOR0  8
#define MOTOR1   9
#define MOTOR2  10
#define MOTOR3  11

//.......RX PINS............
#define RX_PIN_ROLL  51 
#define RX_PIN_PITCH  50   
#define RX_PIN_YAW  52     
#define RX_PIN_THROTTLE  19
#define RX_PIN_AUX1  8   
#define RX_PIN_AUX2  3 
#define RX_INT_AUX2  1
#define RX_INT_THROTTLE 4
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Feb 01, 2014, 12:05 am
Basel! help me ... look ... I think the code has a serious bug! when we try to make a move whatever it is! pitch or roll type engines do not return to zero after the set back to zero? that's right! I did a test with it stopped and when I make a moviment roll the engines respond correctly but when the set back to zero they return not continue accelerating! you understand me? I will handle your code and will only replace RX.ino and I will test!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Feb 02, 2014, 03:03 pm
Hello Basel;

I have been working for a sample code for seperate L3G4200D and ADXL345 sensors. I'm assembling your code and original library codes. But before going any further, I need to ask few questions. And here is my code and outcomes from the sensors.

I have updated my code and serial output. Not just individual outcomes. Every single step of it.

I have noticed very interesting thing about the outcome. Outputs are both betwenn 0-65536. How these become an angle? I don't really understand about it. I need to write angle detector between -90 and 90. Is that correct?  What was your way to fly the quadcopter?

As you can see the outputs. Angle[0] and angle[1] is weird. Please how can i read -90 , 90 degree?

Here is the code :
Code: [Select]

//Arduino 1.0+ only

#include <Wire.h>

#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24

#define DEVICE (0x53) // Device address as specified in data sheet
#define SPLIT  0.99 //COMP-filter nr
#define RadToDeg 180.0/PI
#define  ACC_HPF_NR  98  //high pass filter nr
#define  GYRO_HPF_NR 0   //high pass filter nr
#define  GYRO_MAF_NR  2  //Moving average filter nr

byte _buff[6];

char POWER_CTL = 0x2D;        //Power Control Register
char DATA_FORMAT = 0x31;
char DATAX0 = 0x32;        //X-Axis Data 0
char DATAX1 = 0x33;        //X-Axis Data 1
char DATAY0 = 0x34;        //Y-Axis Data 0
char DATAY1 = 0x35;        //Y-Axis Data 1
char DATAZ0 = 0x36;        //Z-Axis Data 0
char DATAZ1 = 0x37;        //Z-Axis Data 1

int L3G4200D_Address = 105; //I2C address of the L3G4200D
int x,y,z,accx,accy,accz;

float gx_temp[GYRO_MAF_NR]={
 0.0,0.0};
float gy_temp[GYRO_MAF_NR]={
 0.0,0.0};
float gz_temp[GYRO_MAF_NR]={
 0.0,0.0};
 
float gx_aver=0;
float gy_aver=0;
float gz_aver=0;

float angles[2]={0.0,0.0};

int accx_temp=0;
int accy_temp=0;
int accz_temp=0;

unsigned long tp;

unsigned long ts=millis();
unsigned long tf=micros();
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = 1000;  

void setup(){

 Wire.begin();
 Serial.begin(9600);

 Serial.println("starting up L3G4200D");
 setupL3G4200D(2000); // Configure L3G4200  - 250, 500 or 2000 deg/sec
 //Put the ADXL345 into +/- 4G range by writing the value 0x01 to the DATA_FORMAT register.
 writeTo(DATA_FORMAT, 0x01);
 //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL register.
 writeTo(POWER_CTL, 0x08);
 
 tp=millis(); //for updateSensorVal

 delay(1500); //wait for the sensor to be ready
}

void loop(){
unsigned long currentMillis = millis();
 if((micros()-tf)>1300){


   getGyroValues();
   tf=micros();
}

 
 if((millis()-ts)>20){

   readAccel(); // read the x/y/z tilt
   ts=millis();
   }
   
 unsigned long t = millis();
 float dt = (float)(t-tp)/1000.0;
 float accelx = atan2(accx_temp,accz_temp)*RadToDeg;
 float accely = atan2(accy_temp,accz_temp)*RadToDeg;
 angles[0]=SPLIT*(-gy_aver*dt+angles[0])+(1.0-SPLIT)*accelx;
 angles[1]=SPLIT*(gx_aver*dt+angles[1])+(1.0-SPLIT)*accely;
 tp=t;    
 
 if(currentMillis - previousMillis >= interval) {
   //save the last time you blinked the LED
 previousMillis = currentMillis;  
 Serial.print(" X:");
 Serial.print(x);
 Serial.print(" Y:");
 Serial.print(y);
 Serial.print(" Z:");
 Serial.println(z);
 Serial.println("");
 Serial.print(" gX_temp[0]:");
 Serial.print(gx_temp[0]);
 Serial.print(" gY_temp[0]:");
 Serial.print(gy_temp[0]);
 Serial.print(" gZ_temp[0]:");
 Serial.println(gz_temp[0]);
 Serial.println("");
 Serial.print(" gX_temp[1]:");
 Serial.print(gx_temp[1]);
 Serial.print(" gY_temp[1]:");
 Serial.print(gy_temp[1]);
 Serial.print(" gZ_temp[1]:");
 Serial.println(gz_temp[1]);
 Serial.println("");
 Serial.print(" gx-aver: ");
 Serial.print( gx_aver );
 Serial.print(" gy-aver: ");
 Serial.print( gy_aver );
 Serial.print(" gz-aver: ");
 Serial.println( gz_aver );
 Serial.println("");
 Serial.print(" accx: ");
 Serial.print( accx );
 Serial.print(" accy: ");
 Serial.print( accy );
 Serial.print(" accz: ");
 Serial.println( accz );
 Serial.println("");
 Serial.print(" accx_temp: ");
 Serial.print( accx_temp );
 Serial.print(" accy_temp: ");
 Serial.print( accy_temp );
 Serial.print(" accz_temp ");
 Serial.println( accz_temp );  
 Serial.println("");
 Serial.print(" angles[0]:  ");
 Serial.print(angles[0]);
 Serial.print(" angles[1]:  ");
 Serial.print(angles[1]);
 
}

}
void readAccel() {
//   unsigned long currentMillis = millis();

 uint8_t howManyBytesToRead = 6;
 readFrom( DATAX0, howManyBytesToRead, _buff); //read the acceleration data from the ADXL345

 // each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
 // thus we are converting both bytes in to one int
 accx = (((int)_buff[1]) << 8) | _buff[0];  
 accy = (((int)_buff[3]) << 8) | _buff[2];
 accz = (((int)_buff[5]) << 8) | _buff[4];

 accx_temp=(ACC_HPF_NR*accx_temp+(100-ACC_HPF_NR)*accx)/100;
 accy_temp=(ACC_HPF_NR*accy_temp+(100-ACC_HPF_NR)*accy)/100;
 accz_temp=(ACC_HPF_NR*accz_temp+(100-ACC_HPF_NR)*accz)/100;
}
void getGyroValues(){

 byte xMSB = readRegister(L3G4200D_Address, 0x29);
 byte xLSB = readRegister(L3G4200D_Address, 0x28);
 //x = ((xMSB << 8) | xLSB);
 gx_temp[1] = ((xMSB << 8) | xLSB);
 byte yMSB = readRegister(L3G4200D_Address, 0x2B);
 byte yLSB = readRegister(L3G4200D_Address, 0x2A);
 //y = ((yMSB << 8) | yLSB);
 gy_temp[1] = ((yMSB << 8) | yLSB);
 byte zMSB = readRegister(L3G4200D_Address, 0x2D);
 byte zLSB = readRegister(L3G4200D_Address, 0x2C);
 //z = ((zMSB << 8) | zLSB);
 gz_temp[1] = ((zMSB << 8) | zLSB);
   for(byte i=0;i<(GYRO_MAF_NR-1);i++){
   gx_temp[i]=gx_temp[i+1];
   gy_temp[i]=gy_temp[i+1];
   gz_temp[i]=gz_temp[i+1];
 }
 gyroMAF();
}
void gyroMAF(){//Moving average filter
#if GYRO_HPF_NR > 0
 float gx_old=gx_aver;
 float gy_old=gy_aver;
 float gz_old=gz_aver;
#endif
 gx_aver=0;
 gy_aver=0;
 gz_aver=0;
 for(byte i=0;i<GYRO_MAF_NR;i++){
   gx_aver=gx_aver+gx_temp[i];
   gy_aver=gy_aver+gy_temp[i];
   gz_aver=gz_aver+gz_temp[i];
 }  
 gx_aver=(float)gx_aver/GYRO_MAF_NR;
 gy_aver=(float)gy_aver/GYRO_MAF_NR;
 gz_aver=(float)gz_aver/GYRO_MAF_NR;

#if GYRO_HPF_NR > 0
 gx_aver=(GYRO_HPF_NR*gx_old+(100.0-GYRO_HPF_NR)*gx_aver)/100.0;
 gy_aver=(GYRO_HPF_NR*gy_old+(100.0-GYRO_HPF_NR)*gy_aver)/100.0;
 gz_aver=(GYRO_HPF_NR*gz_old+(100.0-GYRO_HPF_NR)*gz_aver)/100.0;
#endif
}
int setupL3G4200D(int scale){
 //From  Jim Lindblom of Sparkfun's code

 // Enable x, y, z and turn off power down:
 writeRegister(L3G4200D_Address, CTRL_REG1, 0b00001111);

 // If you'd like to adjust/use the HPF, you can edit the line below to configure CTRL_REG2:
 writeRegister(L3G4200D_Address, CTRL_REG2, 0b00000000);

 // Configure CTRL_REG3 to generate data ready interrupt on INT2
 // No interrupts used on INT1, if you'd like to configure INT1
 // or INT2 otherwise, consult the datasheet:
 writeRegister(L3G4200D_Address, CTRL_REG3, 0b00001000);

 // CTRL_REG4 controls the full-scale range, among other things:

 if(scale == 250){
   writeRegister(L3G4200D_Address, CTRL_REG4, 0b00000000);
 }else if(scale == 500){
   writeRegister(L3G4200D_Address, CTRL_REG4, 0b00010000);
 }else{
   writeRegister(L3G4200D_Address, CTRL_REG4, 0b00110000);
 }


 writeRegister(L3G4200D_Address, CTRL_REG5, 0b00000000);
}

void writeRegister(int deviceAddress, byte address, byte val) {
   Wire.beginTransmission(deviceAddress); // start transmission to device
   Wire.write(address);       // send register address
   Wire.write(val);         // send value to write
   Wire.endTransmission();     // end transmission
}

int readRegister(int deviceAddress, byte address){

   int v;
   Wire.beginTransmission(deviceAddress);
   Wire.write(address); // register to read
   Wire.endTransmission();

   Wire.requestFrom(deviceAddress, 1); // read a byte

   while(!Wire.available()) {
       // waiting
   }

   v = Wire.read();
   return v;
}


void writeTo(byte address, byte val) {
 Wire.beginTransmission(DEVICE); // start transmission to device
 Wire.write(address);             // send register address
 Wire.write(val);                 // send value to write
 Wire.endTransmission();         // end transmission
}


void readFrom(byte address, int num, byte _buff[]) {
 Wire.beginTransmission(DEVICE); // start transmission to device
 Wire.write(address);             // sends address to read from
 Wire.endTransmission();         // end transmission

 Wire.beginTransmission(DEVICE); // start transmission to device
 Wire.requestFrom(DEVICE, num);    // request 6 bytes from device

 int i = 0;
 while(Wire.available())         // device may send less than requested (abnormal)
 {
   _buff[i] = Wire.read();    // receive a byte
   i++;
 }
 Wire.endTransmission();         // end transmission
}



I'm getting really close to finish this project. Thank you..
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Feb 02, 2014, 09:15 pm
Here is the serial output :

Code: [Select]


gX_temp[0]:269.00 gY_temp[0]:64422.00 gZ_temp[0]:65197.00

gX_temp[1]:269.00 gY_temp[1]:64422.00 gZ_temp[1]:65197.00

gx-aver: 269.00 gy-aver: 64422.00 gz-aver: 65197.00

accx: 54 accy: 65532 accz: 109

accx_temp: 40536 accy_temp: 35160 accz_temp 82

angles[0]:  -3691.98 angles[1]:  104.24 X:0 Y:0 Z:0

gX_temp[0]:65480.00 gY_temp[0]:1234.00 gZ_temp[0]:106.00

gX_temp[1]:65480.00 gY_temp[1]:1234.00 gZ_temp[1]:106.00

gx-aver: 65480.00 gy-aver: 1234.00 gz-aver: 106.00

accx: 53 accy: 65531 accz: 108

accx_temp: 22130 accy_temp: 31942 accz_temp 82

angles[0]:  22.83 angles[1]:  2734.10 X:0 Y:0 Z:0

gX_temp[0]:1155.00 gY_temp[0]:122.00 gZ_temp[0]:22.00

gX_temp[1]:1155.00 gY_temp[1]:122.00 gZ_temp[1]:22.00

gx-aver: 1155.00 gy-aver: 122.00 gz-aver: 22.00

accx: 65470 accy: 10 accz: 70

accx_temp: 41819 accy_temp: 28598 accz_temp 78

angles[0]:  -488.05 angles[1]:  196.29 X:0 Y:0 Z:0

gX_temp[0]:30.00 gY_temp[0]:64352.00 gZ_temp[0]:65524.00

gX_temp[1]:30.00 gY_temp[1]:64352.00 gZ_temp[1]:65524.00

gx-aver: 30.00 gy-aver: 64352.00 gz-aver: 65524.00

accx: 65532 accy: 8 accz: 103

accx_temp: 52830 accy_temp: 16523 accz_temp 79

angles[0]:  -3760.52 angles[1]:  3958.10 X:0 Y:0 Z:0

gX_temp[0]:65388.00 gY_temp[0]:159.00 gZ_temp[0]:225.00

gX_temp[1]:65388.00 gY_temp[1]:159.00 gZ_temp[1]:225.00

gx-aver: 65388.00 gy-aver: 159.00 gz-aver: 225.00

accx: 65514 accy: 65488 accz: 96

accx_temp: 35118 accy_temp: 35404 accz_temp 77

angles[0]:  35.92 angles[1]:  4027.53 X:0 Y:0 Z:0

gX_temp[0]:65121.00 gY_temp[0]:65016.00 gZ_temp[0]:457.00

gX_temp[1]:65121.00 gY_temp[1]:65016.00 gZ_temp[1]:457.00

gx-aver: 65121.00 gy-aver: 65016.00 gz-aver: 457.00

accx: 65534 accy: 10 accz: 135

accx_temp: 27313 accy_temp: 20846 accz_temp 82

angles[0]:  -3651.00 angles[1]:  1919.61 X:0 Y:0 Z:0

gX_temp[0]:6.00 gY_temp[0]:0.00 gZ_temp[0]:8.00

gX_temp[1]:6.00 gY_temp[1]:0.00 gZ_temp[1]:8.00

gx-aver: 6.00 gy-aver: 0.00 gz-aver: 8.00

accx: 1 accy: 10 accz: 117

accx_temp: 15617 accy_temp: 11364 accz_temp 82

angles[0]:  -2463.31 angles[1]:  554.14
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Feb 03, 2014, 06:38 pm
@Satiro: There's no bug in the code that I provided.. Maybe something you picked up while changing the code to work with your UNO... Anyway, something you can try is to de-activate the software expo.. Just comment out #define RX_EXPO, and try again..

@TheAviator: There is something wrong with your y-axis.. Did you solder these chips yourself? Or did you buy some kind of module? Instead of mixing together all my parts from the bluecopter firmware.. Try the example sketch that I've provided in the examples folder in the MPU library folder.. Or rather instead, try this sketch and report the serial output:

Code: [Select]

#include <MPULib.h>
#include <Wire.h>


MPULib MPU;
// the setup routine runs once when you press reset:
void setup() {               
Serial.begin(115200);
while(!Serial);
MPU.init();
}

// the loop routine runs over and over again forever:
void loop() {
int buffer[3];
float buffer2[3];
MPU.getAxlData(buffer);
MPU.getGyroData(buffer2);
Serial.print("AX: ");
Serial.print(buffer[0]);
Serial.print('\t');
Serial.print("AY: ");
Serial.print(buffer[1]);
Serial.print('\t');
Serial.print("AZ: ");
Serial.print(buffer[2]);
Serial.print('\t');
Serial.print("GX: ");
Serial.print(buffer2[0]);
Serial.print('\t');
Serial.print("GY: ");
Serial.print(buffer2[1]);
Serial.print('\t');
Serial.print("GZ: ");
Serial.println(buffer2[2]);
delay(10);
}


//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Feb 03, 2014, 08:17 pm


@TheAviator: There is something wrong with your y-axis.. Did you solder these chips yourself? Or did you buy some kind of module? Instead of mixing together all my parts from the bluecopter firmware.. Try the example sketch that I've provided in the examples folder in the MPU library folder.. Or rather instead, try this sketch and report the serial output:

//Basel



Here is the Serial Output:  (while measuring, I have rotated sensors along all angles)
Code: [Select]


AX: 123 AY: 65422 AZ: 83 GX: 332.01 GY: 195.79 GZ: 4540.13
AX: 41 AY: 65495 AZ: 26 GX: 241.36 GY: 159.32 GZ: 4536.91
AX: 65467 AY: 65417 AZ: 240 GX: 221.76 GY: 116.83 GZ: 4554.90
AX: 65512 AY: 50 AZ: 327 GX: 372.40 GY: 109.90 GZ: 4573.10
AX: 65512 AY: 50 AZ: 327 GX: 381.22 GY: 149.24 GZ: 4558.61
AX: 29 AY: 77 AZ: 305 GX: 351.61 GY: 162.96 GZ: 4540.13
AX: 32 AY: 78 AZ: 213 GX: 310.24 GY: 146.72 GZ: 4529.63
AX: 65514 AY: 66 AZ: 150 GX: 264.74 GY: 121.59 GZ: 4526.69
AX: 65503 AY: 95 AZ: 150 GX: 230.58 GY: 101.36 GZ: 4526.69
AX: 65508 AY: 136 AZ: 174 GX: 175.91 GY: 82.25 GZ: 4521.79
AX: 65508 AY: 136 AZ: 174 GX: 114.45 GY: 69.23 GZ: 4519.06
AX: 65500 AY: 146 AZ: 182 GX: 79.73 GY: 56.63 GZ: 4522.28
AX: 65505 AY: 110 AZ: 144 GX: 48.09 GY: 38.15 GZ: 4534.81
AX: 65478 AY: 104 AZ: 122 GX: 16.10 GY: 19.46 GZ: 4549.93
AX: 65481 AY: 113 AZ: 85 GX: 4582.06 GY: 4578.07 GZ: 4563.51
AX: 65481 AY: 113 AZ: 85 GX: 4552.66 GY: 4538.80 GZ: 4570.79
AX: 65477 AY: 130 AZ: 85 GX: 4501.21 GY: 4497.43 GZ: 4576.46
AX: 65461 AY: 122 AZ: 49 GX: 4438.28 GY: 4448.71 GZ: 4583.67
AX: 65473 AY: 113 AZ: 129 GX: 4350.78 GY: 4401.25 GZ: 5.32
AX: 65513 AY: 49 AZ: 189 GX: 4271.89 GY: 4362.12 GZ: 21.42
AX: 65 AY: 26 AZ: 222 GX: 4213.65 GY: 4344.55 GZ: 31.36
AX: 65 AY: 26 AZ: 222 GX: 4180.19 GY: 4339.16 GZ: 26.39
AX: 94 AY: 65518 AZ: 152 GX: 4170.39 GY: 4330.48 GZ: 23.31
AX: 99 AY: 65460 AZ: 232 GX: 4174.73 GY: 4341.12 GZ: 29.05
AX: 125 AY: 65451 AZ: 296 GX: 4190.55 GY: 4372.62 GZ: 29.96
AX: 112 AY: 65419 AZ: 352 GX: 4217.50 GY: 4426.31 GZ: 24.78
AX: 112 AY: 65419 AZ: 352 GX: 4317.74 GY: 4492.32 GZ: 23.10
AX: 98 AY: 65417 AZ: 291 GX: 4424.77 GY: 4549.93 GZ: 34.44
AX: 103 AY: 65426 AZ: 200 GX: 4491.55 GY: 4574.85 GZ: 42.77
AX: 113 AY: 65439 AZ: 166 GX: 4524.45 GY: 4572.12 GZ: 48.37
AX: 107 AY: 65445 AZ: 242 GX: 4504.29 GY: 4564.35 GZ: 49.77
AX: 115 AY: 65419 AZ: 258 GX: 4495.54 GY: 4576.32 GZ: 49.56
AX: 115 AY: 65419 AZ: 258 GX: 4535.79 GY: 15.19 GZ: 50.96
AX: 119 AY: 65388 AZ: 248 GX: 42.91 GY: 44.80 GZ: 55.79
AX: 120 AY: 65391 AZ: 244 GX: 141.19 GY: 80.71 GZ: 61.04
AX: 128 AY: 65406 AZ: 281 GX: 216.72 GY: 118.09 GZ: 60.97
AX: 110 AY: 65407 AZ: 255 GX: 271.46 GY: 149.24 GZ: 54.95
AX: 76 AY: 65440 AZ: 177 GX: 321.02 GY: 158.55 GZ: 51.03
AX: 76 AY: 65440 AZ: 177 GX: 308.49 GY: 142.45 GZ: 44.87
AX: 43 AY: 65479 AZ: 158 GX: 296.52 GY: 110.67 GZ: 32.90
AX: 65532 AY: 65518 AZ: 196 GX: 289.31 GY: 95.20 GZ: 20.86
AX: 65521 AY: 31 AZ: 198 GX: 265.79 GY: 97.37 GZ: 7.49
AX: 65514 AY: 48 AZ: 193 GX: 197.68 GY: 92.82 GZ: 4583.11
AX: 65514 AY: 48 AZ: 193 GX: 164.15 GY: 87.08 GZ: 4577.09
AX: 65520 AY: 15 AZ: 133 GX: 151.27 GY: 59.50 GZ: 4575.90
AX: 65499 AY: 34 AZ: 56 GX: 113.12 GY: 2.10 GZ: 4582.34
AX: 65485 AY: 25 AZ: 88 GX: 73.43 GY: 4531.10 GZ: 1.12
AX: 65495 AY: 30 AZ: 177 GX: 22.96 GY: 4501.91 GZ: 5.88
AX: 65531 AY: 87 AZ: 113 GX: 4579.68 GY: 4484.41 GZ: 4.34
AX: 65531 AY: 87 AZ: 113 GX: 4544.96 GY: 4440.52 GZ: 4583.60
AX: 104 AY: 42 AZ: 361 GX: 4434.85 GY: 4441.92 GZ: 0.21
AX: 101 AY: 79 AZ: 490 GX: 4312.42 GY: 4505.41 GZ: 4587.17
AX: 124 AY: 65498 AZ: 341 GX: 4257.96 GY: 4556.16 GZ: 21.07
AX: 39 AY: 65496 AZ: 94 GX: 4232.41 GY: 4555.67 GZ: 45.99
AX: 39 AY: 65496 AZ: 94 GX: 4401.39 GY: 4521.09 GZ: 38.50
AX: 3 AY: 65531 AZ: 29 GX: 4575.13 GY: 4479.44 GZ: 15.89
AX: 62 AY: 65522 AZ: 196 GX: 39.76 GY: 4473.84 GZ: 6.37
AX: 89 AY: 65510 AZ: 308 GX: 12.53 GY: 4506.11 GZ: 13.09
AX: 99 AY: 65485 AZ: 252 GX: 4561.34 GY: 4532.92 GZ: 21.91
AX: 75 AY: 65457 AZ: 220 GX: 4558.47 GY: 4546.85 GZ: 35.28
AX: 75 AY: 65457 AZ: 220 GX: 4554.48 GY: 4549.09 GZ: 45.64
AX: 60 AY: 65467 AZ: 238 GX: 4549.93 GY: 4555.95 GZ: 45.43
AX: 41 AY: 65510 AZ: 245 GX: 4549.16 GY: 4571.70 GZ: 33.53
AX: 32 AY: 65523 AZ: 227 GX: 4566.03 GY: 3.01 GZ: 14.77
AX: 48 AY: 65504 AZ: 198 GX: 13.23 GY: 22.40 GZ: 4582.55
AX: 48 AY: 65504 AZ: 198 GX: 45.85 GY: 31.50 GZ: 4571.07
AX: 66 AY: 65488 AZ: 172 GX: 74.83 GY: 29.33 GZ: 4566.87
AX: 69 AY: 65503 AZ: 166 GX: 80.43 GY: 15.47 GZ: 4564.07
AX: 81 AY: 65502 AZ: 178 GX: 69.93 GY: 3.92 GZ: 4565.47
AX: 73 AY: 4 AZ: 165 GX: 62.16 GY: 4581.64 GZ: 4569.53
AX: 78 AY: 2 AZ: 154 GX: 75.11 GY: 4569.18 GZ: 4569.04
AX: 78 AY: 2 AZ: 154 GX: 114.94 GY: 4557.98 GZ: 4570.72
AX: 84 AY: 22 AZ: 160 GX: 161.42 GY: 4545.52 GZ: 4568.76
AX: 101 AY: 20 AZ: 189 GX: 43.05 GY: 4543.14 GZ: 4573.52
AX: 209 AY: 65525 AZ: 132 GX: 4487.56 GY: 56.49 GZ: 4575.06
AX: 359 AY: 65528 AZ: 203 GX: 15.68 GY: 48.93 GZ: 4575.69
AX: 114 AY: 27 AZ: 185 GX: 4577.58 GY: 44.66 GZ: 5.74
AX: 114 AY: 27 AZ: 185 GX: 4562.18 GY: 26.04 GZ: 12.25
AX: 45 AY: 33 AZ: 222 GX: 4538.10 GY: 15.96 GZ: 3.43
AX: 41 AY: 65531 AZ: 222 GX: 4502.40 GY: 5.18 GZ: 4582.62
AX: 226 AY: 65484 AZ: 317 GX: 4535.93 GY: 20.23 GZ: 4582.13
AX: 33 AY: 65509 AZ: 207 GX: 5.60 GY: 56.35 GZ: 4582.90
AX: 33 AY: 65509 AZ: 207 GX: 6.79 GY: 47.74 GZ: 0.77
AX: 89 AY: 65484 AZ: 223 GX: 6.44 GY: 35.00 GZ: 9.45
AX: 72 AY: 65490 AZ: 227 GX: 7.28 GY: 22.40 GZ: 24.64
AX: 24 AY: 65517 AZ: 226 GX: 8.19 GY: 19.53 GZ: 30.94
AX: 65526 AY: 6 AZ: 225 GX: 9.66 GY: 29.40 GZ: 33.46
AX: 91 AY: 20 AZ: 223 GX: 9.94 GY: 37.52 GZ: 30.38
AX: 91 AY: 20 AZ: 223 GX: 5.60 GY: 49.21 GZ: 21.14
AX: 68 AY: 27 AZ: 217 GX: 4573.52 GY: 132.51 GZ: 4580.31
AX: 77 AY: 36 AZ: 197 GX: 4545.59 GY: 257.11 GZ: 4548.39
AX: 154 AY: 65336 AZ: 371 GX: 4185.16 GY: 149.66 GZ: 4481.47
AX: 213 AY: 224 AZ: 128 GX: 4179.07 GY: 4347.07 GZ: 4507.72
AX: 213 AY: 224 AZ: 128 GX: 4561.48 GY: 4530.61 GZ: 4582.48
AX: 5 AY: 65373 AZ: 272 GX: 4582.34 GY: 31.64 GZ: 4570.79
AX: 119 AY: 65498 AZ: 232 GX: 4570.79 GY: 129.99 GZ: 4562.88
AX: 346 AY: 65492 AZ: 245 GX: 133.63 GY: 92.12 GZ: 4583.39
AX: 155 AY: 41 AZ: 237 GX: 4540.90 GY: 25.69 GZ: 4576.39
AX: 65209 AY: 183 AZ: 236 GX: 4535.44 GY: 7.42 GZ: 4581.08
AX: 65209 AY: 183 AZ: 236 GX: 4585.07 GY: 17.99 GZ: 4582.69
AX: 65438 AY: 65528 AZ: 271 GX: 4582.34 GY: 1.05 GZ: 4586.33
AX: 0 AY: 65510 AZ: 230 GX: 0.91 GY: 3.22 GZ: 0.77
AX: 65534 AY: 65511 AZ: 237 GX: 2.17 GY: 4586.47 GZ: 0.77
AX: 65532 AY: 65511 AZ: 238 GX: 0.77 GY: 0.35 GZ: 0.84
AX: 65532 AY: 65518 AZ: 231 GX: 4587.31 GY: 4586.40 GZ: 0.84
AX: 65532 AY: 65518 AZ: 231 GX: 4587.03 GY: 4587.03 GZ: 0.84
AX: 65528 AY: 65517 AZ: 232 GX: 0.07 GY: 0.28 GZ: 1.12
AX: 65526 AY: 65522 AZ: 229 GX: 0.28 GY: 0.00 GZ: 0.91
AX: 65526 AY: 65519 AZ: 230 GX: 0.00 GY: 4587.45 GZ: 1.19
AX: 65527 AY: 65522 AZ: 231 GX: 4587.38 GY: 4587.10 GZ: 0.98
AX: 65527 AY: 65522 AZ: 231 GX: 4587.24 GY: 4587.17 GZ: 1.05
AX: 65528 AY: 65521 AZ: 230 GX: 0.21 GY: 4587.24 GZ: 0.77
AX: 65528 AY: 65520 AZ: 230 GX: 0.21 GY: 4587.17 GZ: 0.98
AX: 65527 AY: 65521 AZ: 229 GX: 0.07 GY: 4587.38 GZ: 0.77
AX: 65526 AY: 65519 AZ: 231 GX: 4587.45 GY: 4587.31 GZ: 0.91
AX: 65526 AY: 65520 AZ: 232 GX: 4587.31 GY: 4587.24 GZ: 0.98
AX: 65526 AY: 65520 AZ: 232 GX: 0.21 GY: 4587.03 GZ: 0.98
AX: 65527 AY: 65518 AZ: 234 GX: 0.00 GY: 4587.45 GZ: 1.19
AX: 65528 AY: 65524 AZ: 227 GX: 0.07 GY: 4587.31 GZ: 0.84
AX: 65529 AY: 65517 AZ: 232 GX: 0.14 GY: 4587.31 GZ: 1.05
AX: 65527 AY: 65523 AZ: 228 GX: 0.14 GY: 4587.24 GZ: 0.91
AX: 65527 AY: 65523 AZ: 228 GX: 0.14 GY: 4587.24 GZ: 0.91
AX: 65527 AY: 65518 AZ: 235 GX: 0.21 GY: 4587.45 GZ: 0.84
AX: 65527 AY: 65523 AZ: 227 GX: 0.07 GY: 4587.31 GZ: 0.91
AX: 65526 AY: 65519 AZ: 233 GX: 0.42 GY: 4587.45 GZ: 0.49
AX: 65526 AY: 65522 AZ: 230 GX: 0.21 GY: 4587.17 GZ: 0.77
AX: 65529 AY: 65522 AZ: 232 GX: 0.21 GY: 4587.24 GZ: 0.91
AX: 65529 AY: 65522 AZ: 232 GX: 4587.24 GY: 4587.03 GZ: 0.70
AX: 65528 AY: 65527 AZ: 231 GX: 4586.96 GY: 0.07 GZ: 0.91
AX: 65527 AY: 65519 AZ: 232 GX: 4586.61 GY: 4587.03 GZ: 0.91
AX: 65527 AY: 65520 AZ: 229 GX: 4586.47 GY: 0.07 GZ: 0.98
AX: 65526 AY: 65516 AZ: 231 GX: 4586.75 GY: 0.14 GZ: 0.84
AX: 65526 AY: 65516 AZ: 231 GX: 4586.82 GY: 4587.38 GZ: 0.98



It seems fine. And now how could I measure angles? I didn't understand the low pass filter and average filter process.
I don't want to write any code without understanding. Could you please explain steps until measure angles?
Here is the pictures of sensors and arduino.

https://www.dropbox.com/s/c1fu20e3br9etwf/030220141314.jpg

https://www.dropbox.com/s/cobjr6o23a5cax7/030220141316.jpg
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Feb 03, 2014, 08:25 pm
Basel, the only thing that changed in the code was the RX.ino, managed to capture all the channels! You understand me when I spoke? Do a test! arm the motors and move the sticks to the sides! if I'm wrong motors will stop when the sticks return to center position! correct?

My RX.ino:( Arduino Nano Atmega 328 )
PROGMEM const byte rxPins[6]={
  RX_PIN_YAW,RX_PIN_ROLL,RX_PIN_PITCH,RX_PIN_AUX1,RX_PIN_AUX2,RX_PIN_THROTTLE};
volatile byte rxState[6]={
  0,0,0,0,0,0};
volatile int rxPrev[8]={
  0,0,0,0,0,0,0,0};

void rxInit(){
  for(byte i=0;i<8;i++){
    pinMode(pgm_read_byte(&rxPins),INPUT);
    digitalWrite(pgm_read_byte(&rxPins),HIGH);
  }
  PCICR |= (1 << PCIE0);
  PCMSK0 |= (1 << PCINT0);
  PCICR |= (1 << PCIE2); 
  PCMSK2 |= (1 << PCINT20)|(1 << PCINT21)|(1 << PCINT22)|(1 << PCINT23);
  sei();
  //attachInterrupt(RX_INT_AUX2,rxGoesHigh0,RISING);
  attachInterrupt(RX_INT_THROTTLE,rxGoesHigh1,RISING);
}

void rxGoesHigh0(){
  //attachInterrupt(RX_INT_AUX2,rxGoesLow0,FALLING);
  //rxPrev[4]=micros();
}
void rxGoesLow0(){
  //attachInterrupt(RX_INT_AUX2,rxGoesHigh0,RISING);
  //rxVal[4]=micros()-rxPrev[4]; 
}

void rxGoesHigh1(){
  attachInterrupt(RX_INT_THROTTLE,rxGoesLow1,FALLING);
  rxPrev[5]=micros();
}
void rxGoesLow1(){
  attachInterrupt(RX_INT_THROTTLE,rxGoesHigh1,RISING);
  rxVal[5]=micros()-rxPrev[5]; 
}

ISR(PCINT2_vect)
{
  for(byte i=0;i<4;i++){
    byte rxtemp=digitalRead(pgm_read_byte(&rxPins));
    if((rxState == 0) & (rxtemp==1)){
      rxPrev=micros();
      rxState=1;
    }//if
    else if((rxState == 1) & (rxtemp==0)){
      rxVal=micros()-rxPrev;
      rxState=0;
    }//elseif
  }//for
}//ISR
ISR(PCINT0_vect)
{
  for(byte i=4;i<5;i++){
    byte rxtemp=digitalRead(pgm_read_byte(&rxPins));
    if((rxState == 0) & (rxtemp==1)){
      rxPrev=micros();
      rxState=1;
    }//if
    else if((rxState == 1) & (rxtemp==0)){
      rxVal=micros()-rxPrev;
      rxState=0;
    }//elseif
  }//for
}
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Feb 03, 2014, 08:46 pm

It seems fine. And now how could I measure angles? I didn't understand the low pass filter and average filter process.
I don't want to write any code without understanding. Could you please explain steps until measure angles?


it's not fine.. These aren't rotations.. These are the sensors getting banged against a table.. There is something wrong with the measurements.. And I'm not really sure where the problem lies.. You measured the angles correctly in the previous code you posted "as far as I could see".. You need to look into your sensors and the reason for the outrageous outputs..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Feb 04, 2014, 01:14 pm
Basel, had time to take the test? I'm trying to say is that the PID should go to zero when the SET's back to zero! and this should happen even with him armed and standing on the ground! ie, the engines must turn to meet the variation of SET'se when the SET again be zero if they are off! correct?

Basel, I am finishing writing my work for university and would like to formally thank you!

I need information about you my friend!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Feb 06, 2014, 05:14 pm


It seems fine. And now how could I measure angles? I didn't understand the low pass filter and average filter process.
I don't want to write any code without understanding. Could you please explain steps until measure angles?


it's not fine.. These aren't rotations.. These are the sensors getting banged against a table.. There is something wrong with the measurements.. And I'm not really sure where the problem lies.. You measured the angles correctly in the previous code you posted "as far as I could see".. You need to look into your sensors and the reason for the outrageous outputs..

//Basel



Hello Basel,

Good news!! :D

I have been looking for some answers and finally I had some :) The reason of getting enormous numbers from accelerometer readings is Arduino Due!! Yeah I have checked and compared it from other arduino boards and discovered strange things.

One of them while getting equal of the byte readings to integers. Like

Code: [Select]

int buffer[3];
float buffer2[3];
MPU.getAxlData(buffer);
MPU.getGyroData(buffer2);

In most arduino boards integer represents 8 or 16 bit resolution. But in the arduinu due integer represents 32 bit data resolution. To fix this I have changed the "int" to "uint8_t" so I am just getting 8 bits data.

My output is

Code: [Select]

4 4 233
4 3 236
5 4 236
3 5 235
4 5 233
5 4 236
6 6 237
4 5 232
5 2 235
5 3 239
3 6 234
4 3 235
6 5 238
5 5 235
3 5 233
6 4 238
5 5 237
3 5 231
4 3 234
5 4 235
4 4 233
68 173 241
5 47 238
255 29 243
221 27 211
3 35 235
9 38 234
12 9 241
24 236 245
86 157 186
14 14 230
11 14 234
255 8 212
250 208 204
3 235 240
255 11 235
4 30 237
249 30 218
2 12 7
9 4 253
44 211 40
12 42 194
1 227 221
19 187 40
250 243 201
246 61 35
1 12 229
7 235 213
238 180 44
33 95 206


So is this normal now? If they are, how should I getting to the angle measurements
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Feb 06, 2014, 06:29 pm
@Satiro: Yes, and I don't have the problems that you're describing.. Did you try to disable the software RX expo? Do you want my information to send me a beer or invite me to your examination ceremony =P?

@TheAviator: I forgot that you're using a Due.. Yeah, those numbers look a lot better.. Just use the code that you posted earlier and hopefully that's all what's needed to get angles..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TheAvitator on Feb 06, 2014, 08:58 pm


@TheAviator: I forgot that you're using a Due.. Yeah, those numbers look a lot better.. Just use the code that you posted earlier and hopefully that's all what's needed to get angles..

//Basel


I just have one more question about it. If we examine the X axis, while rotating clockwise it started to have values from 0 to 125, so its ok. But, while rotating counter clockwise its values from 256 to 125 or more lower.

My question is shouldn't be it like -125,0,125. I can understand that zero is the middle point while parallel to the ground. The values should be like -1 -2 -3 ... -25 ... -40 in the counter clockwise rotation. Am I right?

How was yours?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Feb 06, 2014, 09:38 pm

I just have one more question about it. If we examine the X axis, while rotating clockwise it started to have values from 0 to 125, so its ok. But, while rotating counter clockwise its values from 256 to 125 or more lower.

My question is shouldn't be it like -125,0,125. I can understand that zero is the middle point while parallel to the ground. The values should be like -1 -2 -3 ... -25 ... -40 in the counter clockwise rotation. Am I right?

How was yours?


You simply need to calibrate your sensor.. I don't have my quadcopter around.. So can't really look up the exact range.. Simply google it or start another thread with your question in hand.. Let us keep this thread specific to the BlueCopter firmware, so that we don't fill it with information other users don't have use of (this will make other users ask the same questions over and over and over again because they simply don't want to browse this huge thread)..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Feb 07, 2014, 02:24 am
Basel, with its answer only gave even laugh! kkkkkkkkk! but what I would like is to know where you are? Your e-mail? your profession? so i can send you my written work! and if to thank you for helping me! would not a beer but a Whisky 18! if you can send me an email: satiromedeiros@yahoo.com.br .... As I said before! You're the Man!
I am an engineering student of 28 years in the last year! and my wife is pregnant!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Feb 07, 2014, 07:23 pm

Basel, with its answer only gave even laugh! kkkkkkkkk! but what I would like is to know where you are? Your e-mail? your profession? so i can send you my written work! and if to thank you for helping me! would not a beer but a Whisky 18! if you can send me an email: satiromedeiros@yahoo.com.br .... As I said before! You're the Man!
I am an engineering student of 28 years in the last year! and my wife is pregnant!


I'd love to see your written work.. I'll e-mail you with my info..!

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Elmardus on Feb 08, 2014, 05:10 pm
Hello Basel,

Currently I am trying to make your code work for the arduino UNO. I have managed to get my own RX.ino code working. It decodes a PPM-SUM  signal correctly, using only 1 interrupt, and then write it to the rxval array.
But I am still having some trouble with outputting a good signal to the ESC's. It seems like I can't get the analogWrite(MOTOR?,m?_val) to work with my ESC's. I am using Turnigy Plush 18A ESC's, so those should work with what I'm trying to do, but it just doesn't.

When I start up everything the speed controllers do not arm correctly, they just continuously beep, and do nothing else. I wrote some code to display the mX_val that is written with analogWrite. The values I am getting out of that (when going from 0 throttle to max thr quicly) are as follows:

Code: [Select]

Motors initalized
Motors safe
Setup Success!
MOTOR 1:  166 MOTOR 2:  166 MOTOR 3:  166 MOTOR 4:  166
MOTOR 1:  166 MOTOR 2:  166 MOTOR 3:  166 MOTOR 4:  166
MOTOR 1:  166 MOTOR 2:  166 MOTOR 3:  166 MOTOR 4:  166
MOTOR 1:  166 MOTOR 2:  166 MOTOR 3:  166 MOTOR 4:  166
MOTOR 1:  166 MOTOR 2:  166 MOTOR 3:  166 MOTOR 4:  166
MOTOR 1:  185 MOTOR 2:  185 MOTOR 3:  185 MOTOR 4:  185
MOTOR 1:  185 MOTOR 2:  185 MOTOR 3:  185 MOTOR 4:  185
MOTOR 1:  185 MOTOR 2:  185 MOTOR 3:  185 MOTOR 4:  185
MOTOR 1:  185 MOTOR 2:  185 MOTOR 3:  185 MOTOR 4:  185
MOTOR 1:  185 MOTOR 2:  185 MOTOR 3:  185 MOTOR 4:  185
MOTOR 1:  203 MOTOR 2:  203 MOTOR 3:  203 MOTOR 4:  203
MOTOR 1:  203 MOTOR 2:  203 MOTOR 3:  203 MOTOR 4:  203
MOTOR 1:  203 MOTOR 2:  203 MOTOR 3:  203 MOTOR 4:  203
MOTOR 1:  203 MOTOR 2:  203 MOTOR 3:  203 MOTOR 4:  203
MOTOR 1:  203 MOTOR 2:  203 MOTOR 3:  203 MOTOR 4:  203
MOTOR 1:  235 MOTOR 2:  235 MOTOR 3:  235 MOTOR 4:  235
MOTOR 1:  235 MOTOR 2:  235 MOTOR 3:  235 MOTOR 4:  235
MOTOR 1:  235 MOTOR 2:  235 MOTOR 3:  235 MOTOR 4:  235
MOTOR 1:  235 MOTOR 2:  235 MOTOR 3:  235 MOTOR 4:  235
MOTOR 1:  254 MOTOR 2:  254 MOTOR 3:  254 MOTOR 4:  254


This should be correct? And what should be the MOTOR_ZERO_LEVEL value? It is currently set at 125, and the MOTOR_ARM_START is 140. Do you have any idea what might be wrong?
Also, when I move the copter, the motor values that are outputted, sometimes go far beyond 300, that can't be right, can it? And then when the copter is still, some of the motor values are still above 254, is that okay?

I read I can't use the servo library as an alternative for analogWrite, if I can't get this to work, but could I then use some different code that generates a servo PWM signal with the right 20ms pulse spacing, or would that be too slow and need another interrupt of whitch I have only 1 left.

I hope you can help me, thanks in advance!

Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Feb 09, 2014, 01:22 am


Currently I am trying to make your code work for the arduino UNO. I have managed to get my own RX.ino code working. It decodes a PPM-SUM  signal correctly, using only 1 interrupt, and then write it to the rxval array.
But I am still having some trouble with outputting a good signal to the ESC's. It seems like I can't get the analogWrite(MOTOR?,m?_val) to work with my ESC's. I am using Turnigy Plush 18A ESC's, so those should work with what I'm trying to do, but it just doesn't.

When I start up everything the speed controllers do not arm correctly, they just continuously beep, and do nothing else. I wrote some code to display the mX_val that is written with analogWrite. The values I am getting out of that (when going from 0 throttle to max thr quicly) are as follows:


This should be correct? And what should be the MOTOR_ZERO_LEVEL value? It is currently set at 125, and the MOTOR_ARM_START is 140. Do you have any idea what might be wrong?
Also, when I move the copter, the motor values that are outputted, sometimes go far beyond 300, that can't be right, can it? And then when the copter is still, some of the motor values are still above 254, is that okay?

I read I can't use the servo library as an alternative for analogWrite, if I can't get this to work, but could I then use some different code that generates a servo PWM signal with the right 20ms pulse spacing, or would that be too slow and need another interrupt of whitch I have only 1 left.

I hope you can help me, thanks in advance!




If they are beeping continuously that means that they didn't have enough time to check for the signal type.. Most ESC (with a atmega8) can handle both PWM and standard servo signals.. But in-order for it to determine the type of signal, it needs some kind of delay directly after it gets power (the delay should be as long as they are still beeping).. This is taken care of in-code by stopping any changes in outputs to the motors (this happens in SAFE/armed mode).. So as long as the quad is in safe mode the quadcopter will send a MOTOR_ZERO_LEVEL signal to the ESC.. Most ESC doesn't like PWM signals less than 100 (so I set it to 125, I got this number by trying the limits of the ESC).. It shouldn't though be too high, because you'll lose a lot of resolution.. The MOTOR_ARM_START is the PWM signal sent to the motors as soon as you leave SAFE mode.. This will make the motors spin with a low velocity (and will also be your controller zero).. This is because the PID-controller and ESC doesn't like when the motors stop completely.. With other words it is dangerous to stop them completely (some ESC will think that the host is disconnected and later not respond to any signals sent).. So it is important to have some margins for error..

Your outputs look ok, no problem there.. Yes, the outputs can exceed 254 (this is because of the integral part of the PID).. But you don't have to worry, because Arduino's awesome analogWrite contains a boundry check.. So if you send 300 through analogWrite, then 254 will be sent.. The same goes for negative numbers.. If you send anything less than zero, then the library will send 0 and nothing else...

To solve your problem, start up your quadcopter in safe mode (don't un-arm it yet).. Wait for the beeping to go away, THEN and only then un-arm/leave safe mode..

And no, I don't recommend the servo library..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: GoussLegend on Feb 11, 2014, 10:54 am
Hi Basel,

I was wondering what was the performance of your "hover stability". I mean if you put the quad into attitude control mode and don't touch the roll and pitch inputs, will your quad drift a bit in a direction? And how much?

Did you think about getting the "actual position of your quad using GPS or by integrating twice from the accelerometer (I don't know how accurate it will be  because of the vibrations.. ). Then with this position input you can add a new outer position loop which should make the quad more stable. I mean this a control stucture that have seen in a lot of papers and that makes sense (to me at least, I hope I was clear  :)).

Cheers,
Romain
Title: Re: BlueCopter - Arduino Quadcopter
Post by: travispluse on Feb 13, 2014, 12:51 am
Can you please post a youtube video to show how to do it step by step
from start
Please

Thanks
:smiley-eek:
Title: Re: BlueCopter - Arduino Quadcopter
Post by: praveen713268 on Feb 15, 2014, 07:40 am
u have done a great job...........
Title: Re: BlueCopter - Arduino Quadcopter
Post by: SnakoM on Feb 15, 2014, 05:16 pm
Wow!  That is a very good project.  I tried to make one of these once but as soon as it got off the ground it crashed into a lake.   :0
Title: Re: BlueCopter - Arduino Quadcopter
Post by: mhurt on Feb 16, 2014, 04:50 am
Hi Basel,

Do you have a parts list (BOM) for your quadcopter?
    Part numbers for motors, ESCs, radio, etc?

Do yo have a schematic or system-level hook-up diagram?

If these are available, how can I get them?

Thanks,
mike
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Feb 16, 2014, 05:37 am
Thank you everyone for your kind words..

@GoussLegend: Well, it is very fast.. It might drift a little (but nothing noticeable because the I-term kicks in very fast and counters the changes).. I've optimised the PID-controller (so haven't got any problems as of yet..

Well, it is clear to me too.. But using the accelerometer is an bad idea (as you said, because of the vibrations and such).. Theoretically if everything is stable it might work (you can calculate it).. But I'm sure that it's too slow to make it control something.. GPS would be a better choice (and sorry no, I'm not to keen on making this happen for my quadcopter soon)..

@mhurt: You can find everything on the first page of this thread.. My first post contains all the connection diagrams and a couple of posts down you'll find my BOM..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Naoki7 on Feb 16, 2014, 03:44 pm
hey basel, I recently got my hands on what I think is the same IMU you've described in your first post...
so do I just need to use 4 wires (vin/gnd/sda/scl), or do i need to ground the rest of the pins?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Feb 16, 2014, 04:12 pm

hey basel, I recently got my hands on what I think is the same IMU you've described in your first post...
so do I just need to use 4 wires (vin/gnd/sda/scl), or do i need to ground the rest of the pins?


Hey, You can keep them floating.. Just make sure that Vin is coupled to 5V and V3.3 is coupled to 3.3V..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Naoki7 on Feb 16, 2014, 05:07 pm
shoot... I was planning on using one of the Arduinos that operates on 3.3V, is it necessary for me to have 5V too? Should i just connect 3.3V to both?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Feb 16, 2014, 05:31 pm

shoot... I was planning on using one of the Arduinos that operates on 3.3V, is it necessary for me to have 5V too? Should i just connect 3.3V to both?


In that case connect both to 3.3V yes..
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on Feb 20, 2014, 02:11 am
Hi Basel,

As many others, I'm also new to microcontrollers, arduino, quadcopter etc. Before starting practical part, I'm trying to understand every single part of Your code.

In MPULib.h I can't understand what this line stands for?
#define READALLSIX  0x28 | (1 << 7)
Is it a setting to read from all six axis at the same time? I tried to find 0x28 | (1 << 7) or 0xa8 or 10101000 in the datasheet. Found some quote on web, but still not sure:
To improve the quality of data set BDU (0x80) on CTRL4_REG (0x23) and use multi-byte reads of 6 bytes at once via register 0x28|0x80 (i.e., 0xA8). This is the read-burst version of the X_LOW register

Thanks in Advance,
Ed
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on Feb 28, 2014, 11:43 am

@Satiro: Yes, and I don't have the problems that you're describing.. Did you try to disable the software RX expo? Do you want my information to send me a beer or invite me to your examination ceremony =P?

//Basel


Hi, Basel!
I'm experiencing the same problem as Satiro. I soldered circuit board with headers for motors & receiver. I also included LED with resistor. I'm using Leonardo board, same IMU as You and Turnigy 9 channel TX & RX. I even took it out for a flight and actually for some seconds it was hovering very nicely. But when there's any disturbance (external from wind or internal from RX), PID values are changing & not coming back to 0. This leads to some motors stopping or rotating at max. Of course after that there's a crash.

I even tried to download code once more without changing anything. Leaving it without  ACC & GYRO calibration. I noticed the same behavior with values not coming back to 0 and PID values were counting up to the maximum very fast and staying there. With calibration the same happened as in the first attempt.

I didn't touch PID configuration values at all, in any case. The only thing I did - I calibrated RX inputs (althought they were fine anyway), ACC & GYRO.

At the same time when PID deviates from zero and does not come back:
Title: Re: BlueCopter - Arduino Quadcopter
Post by: dizzwold on Feb 28, 2014, 01:19 pm
Hi Basel.
I'm in the process of collecting the electronics to build a quadcopter "eventually".
I know nothing of programming arduino's, but have many ebooks regarding and in the process of reading although somewhat misleading and don'y correct you when wrong.
What I would like to do is take sketches "written with thanks, by the likes of yourself", bit-by-bit for each component to see how it works and to try to understand the code.
My first question is regarding the 10dof IMU on-route. Cheap Chinese MPU6050 with HMC5883L and MS5611.
I've found the FreeIMU Library-2012/11/22 written by Fabio. http://www.varesano.net/files/FreeIMU-20121122_1126.zip
This file contains 2 folders, Libraries and Processing. Libraries (adxl345driver, bma180, bmp085, debugutils, freeimu etc).
Do I need all this information, or just for the parts I've listed above, also folders FreeIMU & I2Cdev?
Like I say complete newbie.

Dizzwold.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 03, 2014, 10:16 pm
@neinteresee: It sounds like you're having some problems with your calibrations.. The PID shouldn't start increasing/decreasing by its own..  It could also be that your RX (transmitter/receiver) is transmitting something that isn't zero (corresponds to a signal of 1500ms), thus explaining your fenomenon.. I can't really say anything more than this based on the information you've provided..  Satiro is finished with his quadcopter, he even sent me a video showing of the quadcopter first flight during his thesis presentation.. The quadcopter flew without any problems as far as I could see.. I don't know if it's okay to post his video without his permission, so if your still reading this thread Satiro, will you please post your video here..

@dizzwold: Based on the information you've provided it doesn't sound like you're ready for a project like this.. This project isn't for beginners (I'm sorry to say).. I would love to help you, but that would be a full time job in this case.. Try out something simpler to begin with.. When you're ready, read about quadcopters (dynamics and how other have done it etc etc.. There is a lot of information about this topic on the internets!).. When you're a arduino guru, start looking at my code and understand it.. If you've got further questions after that, then I'll be happy to help..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on Mar 03, 2014, 10:50 pm
Thanks, Basel, for reply!
With calibration did You mean only sensors or also PIDs?
In attachement as an example You can see my GYRO Z readings (2500 measurements). You will see that they are jumping a little bit. (http://GYRO.png)
My GYRO_Z_OFFSET  -0.78. I see that You have more numbers after decimal point. How did You exactly find precise offset? How many measurements? Did You take some average value? I see that gyro average value is drifting away a little bit by time. You gave advice to increase the moving average filter number, but as You said that Your small quadro is flying without any changes, I wanted to leave it as it is at the beggining.
Also probably the problem is in my sensors. Maybe they are damaged. Could it  be so? Could the problem be also incoorect placement on my circuit board? (Please don't laugh about my terrible circuit board:D)
With TX/RX everything should be fine. Debugging shows nice values(1500+/-4), calibration is good. I also tested it with KK.2.1 board, didn't have any issues.
I added also debugging results in .txt file. You will see my angles, gyro values RX and PID values, when quadcopter is leveled. You will see that when different yaw/roll/pitch signal from receiver is received, PID values are changing accordingly, but not coming back to zero, when rods are in neutral positions.
Regarding PID values - they are not increasing decreasing on their own if sensors are calibrated. They stay there where set by receiver (e.g. 40) or by tilted angle (quadcopter tilted). I'm able to return these PID values by moving rods in opposite direction.
Satiro - what did lead You to the success? How did You manage to fix this problem?
(http://board.jpg)


Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 03, 2014, 11:57 pm
I found all my decimal points as you did.. By averaging a bunch of values.. I'm a freak of numbers, you don't actually need that many decimals.. I've tried analyzing the data you provided.. First off, I think that you don't have your motors on (because your gyro and angles aren't moving).. The dependency between your receiver and PIDroll, PIDpitch and PIDyaw looks normal.. Still I can't see what or where the problem is.. Try turning on the motors and hover the quadcopter (I assume that you will tie it down somehow, be careful)... Put it in Angle mode let it just hover don't move the joysticks and log the data as you did before.. And post it here..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: praveen713268 on Mar 04, 2014, 07:01 am
hi,i am building a quadcopter with the following
board: mutiwiii 32u4
Features:
• ATmega32U4 based with Leonardo Bootloader
• MPU-6050 (GYRO/ACC)
• HMC-5883L (MAG)
• MS5611-01BA03 (BARO)

i hav 2 questuion.,1.whether your code works for reaymade flight controller board mutiwii 32u4 with variant acc & gyro.
                                   2.,does mutiwii 32u4 has compatibility for xigbee & 5 ultrasonic sensors.
i request you to anwser my question.
thank u
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Mar 04, 2014, 06:07 pm
Basel, confess to make that flight had to install a flight simulator on my PC, to become more familiar with the moves! after at least three days playing in the simulator I plucked up courage to fly again with quadricóptero! what you said about the radio is correct! My values ​​were ranging far! was slowly setting and they were all in "Zero" as it should be! Hence when I scored my advocacy work of completion was good at the controls! follows the video QuadIII! I appreciate the pasciência that Basel had me! On vacation without pressure'll add the FPV.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Mar 04, 2014, 06:18 pm
Attached is my photos! I would also remind them that my PID values ??stayed a little different from Bluecopter! but as Basel talked before how these values ??he has managed to fly with another model! so what you had found IRAM is something around the values ??of basel! unless they seek a computational approach using MATLAB and the model of the plant! A big hug to everyone!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on Mar 04, 2014, 07:59 pm
Thanks guys for update! I really appreciate Your help!
By the way, nice flight of Your quadro, satiro!
I just extended my USB cable, because previous was too short to debug my quadcopter inside my house. . Unfortunately, found that battery must be charged, but I will post my debugged values as soon as possible (tonight or tomorrow evening after work). Stay tuned!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 04, 2014, 08:13 pm
@Satiro: Thank you for posting your awesome results =)! The simulator is actually a good idea! I had to do it the hard way! Changing a lot of propellers (because of crashes =) )..

@praveen713268: It won't work out of the box.. You need to re-write it to work with MPU-6050 (ACC/GYRO COMBO).. If you manage to do that I'm sure it will work..
I think xbee needs Serial to work.. The Serial pins in my code are used by the receiver .. So again it won't work out of the box.. You'll have to write something on your own.. I'm not sure what you want to do with the ultrasonic sensors.. Do you want to use the ultrasonic sensors to sense how close your quad is to walls perhaps? In that case, again, it's not supported in my code but I'm sure you can write something to make it work..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Mar 04, 2014, 08:28 pm
Basel's funny because once you told me that I should train before flying! I thought you were talking about your own experience! right away thought I should procular a flight simulator, type REAL FLIGHT OR AEROFLIGHT ..... for train! I say to lonhge which is very close to fly it for real!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: praveen713268 on Mar 05, 2014, 05:28 am
thank u basel.,
i would like to clarify one more thing.,i found an online code for mpu 6050.,i am sure its very raw.,but if i modify it for your code will it work.,..what all areas shuold i change.
i once again thank u for ur guidance.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on Mar 07, 2014, 07:50 am
Good morning, guys!
I would like to apologize, because I promised to post my debugged values already 2days ago, but I didn't do it.
I had 2 tough days at work and also I managed to brake my terrible circuit board by crashing my quad. I repaired it and finally had chance to test it.

Summary:
Basel, You were right, motors were not connected in the first time. Now I connected them, tested it in my house with propellers on and it was hovering and responding to inputs very nicely.  So please excuse me for my fake alert and stupidity, code is working perfectly.  :) If You have time, maybe You still could check my debugged values, probably You see what could be improved.

I only noticed 2 things:
I have problems resetting all values to zero. When I arm my quadcopter and motors start turning, usually not all of them start to turn evenly. Maybe one or two of them is turning at all. I must arm my quad and put back to safe mode several times to get motors turn evenly and start takeoff. I understand that answer should be in the code, but unfortunately I can't understand where exactly. Could be the problem in my throttle calibration? Or Motor ARM or ZERO levels?

Second thing is that at some parts of the flight quad is shaking I little bit. As understand, the answer lies in PID calibration, correct? I my case probably it is because I have AFRO high speed response ESCs. Could it be so?

Attached only half of debugged values because file turned out to be too large. Second part in the next post.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on Mar 07, 2014, 07:56 am
Second part of debugging.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: surendharajeeth on Mar 08, 2014, 06:29 pm
i read your code.. really gr8 work i was able to understand it much better than the multiwii code .. anyways i do still have a lot of doubts here nd there ,nd im verry new to quadrotor,though i just no the dynamics a little . is it possible for you to send me your mail id at :Surendharajeeth@gmail.com
Title: Re: BlueCopter - Arduino Quadcopter
Post by: satiro on Mar 09, 2014, 02:45 am
Basel, I am using the simulator "Heli-x5" is free and can be used with playstation controls! that cost no more than $ 15! and version 5.0 quadricopter has to simulate the flight! then just enter the site and train! greetings to all!

http://www.heli-x.net/
Title: Re: BlueCopter - Arduino Quadcopter
Post by: praveen713268 on Mar 09, 2014, 04:28 am
hi basel,
i am running out of time...can u suggest me a flight controller that can run your code bcoz dont have time to mount imu over arduino leonardo like u did.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Bovolino on Mar 10, 2014, 12:05 am
Hello Basel,
I'm currently working on a quadcopter project using an Arduino Uno and a MPU6050 IMU. I have really appreciated the way you have organized your code which is the simplest I've found so far and that means a lot for a newbie as I am.
Of course I don't want to ask you to adapt the code to make it work with a MPU6050 and I'd like to do it myself and then publish the results :)
But, as I told before, I'm a newbie and I'm not really sure of what is not working. What do I have to do to make the code compatible with the MPU6050? Do I have to basically rewrite the Sensor.ino file so that the rest of the code can read the data coming from the sensorboard?

Thank you in advance,
Marco
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Bovolino on Mar 10, 2014, 10:33 pm
Hello again Basel and everyone,
I'm sorry to be so stressful to you
I just found out that maybe I can just modify the MPULib.h library so that the same variables can correctly match the MPU6050 addresses. Most of the variables in MPULib.h  and MPU6050.h have almost the same name the only problem is that I don't get where do you get the accelerometer data. Can you please explain this part of the lib with a little comment?

Code: [Select]
// <---------ADXL345-------------->
#define ADXL_addr 0x53  //addr-pin LOW

#define REG_DATA_FORMAT  0x31
#define REG_PWR_CTL  0x2D
#define REG_BW_RATE 0x2C

#define DATAX0  0x32  //LSB
#define DATAX1  0x33  //MSB
#define DATAY0  0x34  //LSB
#define DATAY1  0x35  //MSB
#define DATAZ0  0x36  //LSB
#define DATAZ1  0x37  //MSB
// <-------------------------------->

// <---------L3G4200D-------------->

#define L3G4_addr 0x69  //SDO-pin HIGH

#define CTRL_REG1  0x20
#define CTRL_REG2 0x21
#define CTRL_REG4  0x23
#define CTRL_REG5 0x24
#define L3G4_HPF 0x13
#define L3G4_LPF 0x34
#define L3G4_BW_ENAX 0x8F
#define MODE_250  0x00
#define MODE_500  ((0x01)<<4)
#define MODE_2000 ((0x03)<<4)
#define SCALE_250  (8.75/1000.0)
#define SCALE_500  (17.5/1000.0)
#define SCALE_2000  (70.0/1000.0)

#define READALLSIX  0x28 | (1 << 7)
#define OUT_X_L  0x28
#define OUT_X_H  0x29
#define OUT_Y_L  0x2A
#define OUT_Y_H  0x2B
#define OUT_Z_L  0x2C
#define OUT_Z_H  0x2D
// <-------------------------------->

In the MPU6050.h lib I found these variables:
Code: [Select]
#define MPU6050_RA_GYRO_XOUT_H      0x43
#define MPU6050_RA_GYRO_XOUT_L      0x44
#define MPU6050_RA_GYRO_YOUT_H      0x45
#define MPU6050_RA_GYRO_YOUT_L      0x46
#define MPU6050_RA_GYRO_ZOUT_H      0x47
#define MPU6050_RA_GYRO_ZOUT_L      0x48

They look pretty similar to the last six above, do you think changing the addresses will be sufficient for the code to work?
I've also read that the L3G4200D sensor is an angular rate sensor. Does it mean it's basically a gyroscope the same way as the MPU6050? (This mean that I won't have to make further change to the code, right?)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: kadirsevil on Mar 12, 2014, 03:55 pm
Hi Basel , thank you for your helping.I have a quadrotor project and ? mingle with apm1 copter for a while ,so ? have many experience about quad.Now , i want to build my own quad.I have found your code,and i really like it , because yor code is convenient to developing.I have MPU6050 imu ,so i replaced with your imu.I deleted your codes that control your imu, and i write my codes that controls MPU6050 it works fine.I write kalman filter for filtering accel datas and i refresh accel and gyro data each 1 ms.It works fine as well.There is a gyro value problem because of it different from your imu.Acc do not,because both imus proportion with 2 axis.It is ok,but i want to know that what value your imu returns.Does it return gyro values as a deg/second or particular values.For example my imu return special value and i divide with 131.0 and i get values as deg/s.What do you offer me for integrating MPU6050 to code.Thank you for already now.I hope, other people benefit this topic.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: wing-it on Mar 14, 2014, 06:34 pm
Catalin, the code you show is for an X config. For a + config, you would have 2 motors to control pitch and 2 for roll. As you can see in the bluecopter code, all motors are used for both pitch and roll.

  int m0_val=throttle+PIDroll_val+PIDpitch_val+PIDyaw_val;
  int m1_val=throttle-PIDroll_val+PIDpitch_val-PIDyaw_val;
  int m2_val=throttle+PIDroll_val-PIDpitch_val-PIDyaw_val;
  int m3_val=throttle-PIDroll_val-PIDpitch_val+PIDyaw_val;
Title: Re: BlueCopter - Arduino Quadcopter
Post by: kadirsevil on Mar 15, 2014, 11:10 am
Hi guys,
Can anyone tell me what RX_EXPO macro  is working for?, i do not understand clearly in despite of i look at the codes.
Thank you in advance :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: praveen713268 on Mar 15, 2014, 06:45 pm
Hi kadirsevil
I hav been working really hard to replace basels imu with mpu 6050 if u could share ur code immediately that would be really helpful..
Thank u
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 18, 2014, 11:41 am
@kadirsevil: Yes, the library is outputting the gyro measurements in deg/s.. RX_expo is a smoothing function for the RX signals.. The reason for the smoothing is to get a smooth response from the PID's.. Some people have built in RX expo's in their receivers, so I made it optional..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: arshu16 on Mar 18, 2014, 11:59 am
@Basel thank you for all your efforts but i have a problem. I'm using 6DOF sensor instead of 10DOF. What are the changes that i'll have to make in the code to make it work.
And one more thing, i can't seem to understand the connections of the receiver, i'm using arduino leonardo.
Please help.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 18, 2014, 12:38 pm

@Basel thank you for all your efforts but i have a problem. I'm using 6DOF sensor instead of 10DOF. What are the changes that i'll have to make in the code to make it work.
And one more thing, i can't seem to understand the connections of the receiver, i'm using arduino leonardo.
Please help.


if it's the same accelerometer and gyrometer then all you have to do is remove the initialization of the magnetometer from the library and you're set to fly =)!.. What's the problem with the connections of the receiver?

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: arshu16 on Mar 18, 2014, 01:03 pm
I can't seem to set my connections with the receiver can you tell me exactly how to connect the esc's and the receiver channels?
one more thing the MPULib has the address of Accelerometer as 0x53 whereas the i2c library has 0x3b. i'm confused as to what to use and that's why can't make it work.
Please can you help step by step. Thanking you in advance, i'm totally new to this.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 18, 2014, 03:29 pm

I can't seem to set my connections with the receiver can you tell me exactly how to connect the esc's and the receiver channels?
one more thing the MPULib has the address of Accelerometer as 0x53 whereas the i2c library has 0x3b. i'm confused as to what to use and that's why can't make it work.
Please can you help step by step. Thanking you in advance, i'm totally new to this.

Did you even look at the first post of this thread? There is a picture showing the connections.. The adress of the acc and gyro depend on some adress pins.. Read the datasheet and compare with your imu..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: arshu16 on Mar 18, 2014, 06:36 pm
Yeah i have basel and i have made the connections also but can't get my sensor to work with MPULib.
i'm trying to use i2c and trying  to integrate with your code but the problem is i can't get the receiver to collect input from transmitter ,that's the problem.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 18, 2014, 07:19 pm
Really having trouble understanding the problem.. I'll assume nothing is working.. What you should do is to forget about my code for the moment and try to make the IMU and receiver work.. Read through this thread.. I've explained how these signals look like and even provided arduino code to test the different functions.. My MPU library even includes a example that should work for the acc and gyro.. So you can test the different functions before jumping in to my code.. If you can't solve these problems on your own then maybe this project is still too complicated for you.. Read read read, run all the different examples and then and only then try to tackle this project..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: arshu16 on Mar 19, 2014, 07:00 am
Basel plz check if these values are correct. I think the angles are way off. I'm truly motivated to do this project even if this is difficult.
Please help me
Title: Re: BlueCopter - Arduino Quadcopter
Post by: arshu16 on Mar 19, 2014, 08:01 am
One more thing how are pins 2 and 4 connected? They are interrupts right?
but how are they connected?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: arshu16 on Mar 20, 2014, 06:10 am
Hi Basel, sorry to bug you again. I have modified your code to work with MPU6050 and i think the values are pretty accurate. I've made the connections on frame(see the attached pic). There's one problem , YAW,PITCH,ROLL are working fine but throttle is not working and that's why motors aren't working .Please help.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: arshu16 on Mar 25, 2014, 12:00 pm
@Basel, Please help me . One interrupt is working and the other is not. Aux2 is working and throttle is not.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 25, 2014, 03:23 pm

@Basel, Please help me . One interrupt is working and the other is not. Aux2 is working and throttle is not.


Some Arduino IDE versions had some problems with interrupt on pin 7 (i think, this is just out of my head, I'm still at work :) ).. Update your Arduino IDE to at least version 1.0.5 and try again.

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on Mar 25, 2014, 04:24 pm
Hi, Basel!
Some questions to You:
1)In Your PID library there is a term dError. What does that stands for? Is it a gyro drift error or derivative error?

2)I am looking at Your Flight Control scheme and I see that Roll and Pitch inputs are +/-30deg. According to Your config.h, aren't they +/-15 deg?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 26, 2014, 04:07 pm

Hi, Basel!
Some questions to You:
1)In Your PID library there is a term dError. What does that stands for? Is it a gyro drift error or derivative error?

2)I am looking at Your Flight Control scheme and I see that Roll and Pitch inputs are +/-30deg. According to Your config.h, aren't they +/-15 deg?


1) It's not the gyro drift.. It's just simply the derivate of the angles (which is simply the gyro values deg/s).. The reason for me doing it that way is because I need some kind of damping for the D-term on the receiver side.. Think of it, sometimes you decide to rock the joystick fast and sometimes slow.. So what I did is implement a damping term that compensates for that (to be able to control the quad. without fluctuations)..

2) Well, you got me there =).. The control scheme is old (I changed a couple of these values, but still the scheme is the same).. The reason is because 30 deg tilt angle was too much.. So I decreased it to 15 deg after a couple of scary flights =) ..

I hope that I answered your questions to your satisfaction =)!


//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on Mar 27, 2014, 07:07 am
Thank You, Basel! Answer is perfect! :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: zaferoznalbant on Mar 27, 2014, 10:25 am
Hi Basel,
I have been trying to build my own quadcopter for a while. I am a newbie and using your code (thanks a lot for your code). I organized your code for myself but I have some problems. (By the way I am using UNO)

Could you please have a look at my code and share your opinions with me.

My problems are unwanted receiver pulses and the IMU readings. I get radio signals very good but it pulses unwantedly. Secondly, I am using Pololu minIMU9. I can use it while motors are off but when motors run, vibration affects it very badly. I used mean average but it still doesn't work.

(Note: I am sorry for my Turkish comment, but if you need explanation I will.)

Best regards,
zafer
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Mar 27, 2014, 03:30 pm

Hi Basel,
I have been trying to build my own quadcopter for a while. I am a newbie and using your code (thanks a lot for your code). I organized your code for myself but I have some problems. (By the way I am using UNO)

Could you please have a look at my code and share your opinions with me.

My problems are unwanted receiver pulses and the IMU readings. I get radio signals very good but it pulses unwantedly. Secondly, I am using Pololu minIMU9. I can use it while motors are off but when motors run, vibration affects it very badly. I used mean average but it still doesn't work.

(Note: I am sorry for my Turkish comment, but if you need explanation I will.)

Best regards,
zafer



I'll take a look at the code a little later.. It would be easier if you could provide some debug-data (show me the outputs inputs when it's running okay and when the problems occur).. The IMU giving irratic response after the motors are running sounds like bad grounding/noise from the motors affecting the IMU or as you said vibrations.. I can't really specify where it is coming from because you didn't provide me with any pictures/connection diagrams.. One reason could be that the battery (minus) is very near the IMU GND.. A capacitor may solve this or a long wire.. If it's vibration try putting a foam (like the one that comes with electronic components) under the IMU to dampen the vibrations..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: zaferoznalbant on Mar 27, 2014, 05:07 pm
Hi Basel, thanks for your rapid reply.

I upload the connection diagram, the IMU output graph for about 900 samples and some photos of my quad and board on it. (one of the pictures is an + config but I cahnged it to x config. I put the picture for UNO view.)
I put a kind of foam under the IMU but maybe I need to try a softer one. This one could be a bit hard.
I use a small breadboard for wiring. The breadboard power and ground lines are connected the power and ground of UNO. All the other ESC ground to the breadboard ground (indirectly UNO ground). I supply UNO by 4s lipo which also supplies the motors.
Receiver is supplied from UNO (via breadboard power and ground lines).

I am not sure the IMU graph is the last version output but it could give you an idea how it is bad. If you look closer at the beginning of the IMU graph you can see the smooth "0" value. This is because I did not run the motors. When I run the motors all values goes crazy. After some trying I put a kind of averaging but then the measurement slowed down.

I could not find a receiver output I will send the receiver sample as soon as I can. (I crahsed my quad so it maybe takes a while :( ) 

Best regards,
zafer
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on Mar 27, 2014, 09:07 pm
Hi, Basel!
I'm still trying to understand every small detail of Your code, so I have new questions for You:
1)gz_temp - is it temporary gyro output value? What does temp stands for? (I assume, that gz_old is previous value, correct?)
2) I see that gyro HPF is not used in Your config, correct? What was Your reason to avoid using gyro HPF?
3) Moving Average Filter - I read, that when going through MAF, frequency is lowered from 800Hz to 400Hz. Could, You tell me, please, how does is happens? Is it MAF NR 2, which is dividing gyro frequency by 2 and so getting 400Hz?
There's just so much of information outside there, so I don't really know where to start.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: frodo01 on Mar 28, 2014, 09:04 pm
Has anyone managed to modify this code to work with MPU6050?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baudday on Mar 30, 2014, 03:58 am
First of all I just want to say thank you for this! I've been looking for some readable code that I can use to learn the basics of all this stuff. I built my quad around the same time you first posted this and have yet to see it take its maiden flight. Other things have just kind of gotten in the way . I'm looking forward to giving this a go tomorrow!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: ashish_bait on Apr 11, 2014, 07:08 pm
hey,
  will you please tell me what is rxval in the programme?????is it a receiver's value.if it is then what are those no.{1500,1500,1500,0,0,1000} are indicating???thank you.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Apr 11, 2014, 07:20 pm

hey,
  will you please tell me what is rxval in the programme?????is it a receiver's value.if it is then what are those no.{1500,1500,1500,0,0,1000} are indicating???thank you.

Hello =)

They're indicating how long the HIGH proportion of the signal is in milliseconds. 1000 ms equals zero and 2000ms equals 100% (for the throttle)..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: PhamHungCuong on Apr 17, 2014, 01:47 pm
If i can like for you 1000 times, i would do it  XD XD , i am so excited to do this project. i have only small question :
1. can i use the Arduino Yun to be the brain (flight control)

thank you again for this post and video, because i see some arduino with quadcopter but it is not successful, you are exceptional  8) 8) 8)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Apr 17, 2014, 02:28 pm

If i can like for you 1000 times, i would do it  XD XD , i am so excited to do this project. i have only small question :
1. can i use the Arduino Yun to be the brain (flight control)

thank you again for this post and video, because i see some arduino with quadcopter but it is not successful, you are exceptional  8) 8) 8)


Thank you.. That's kind of you =).. But still there is a lot of good arduino based quadcopters out there.. There is for example the MultiWii and ArduCopter which are two of the biggest/best code/platform for arduino..

I have never used the Arduino Yun.. But my short answer is: if it's fast enough then it will work.. But yet again, you'll have to do the research yourself.. Look up the differences between the Leonardo and Yun (in hardware that is).. But if I know the arduino folks right then I'm sure it will be compatible..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: arshu16 on Apr 20, 2014, 11:14 am
please check the angle values are they ok? these are angle[0] angle[1]
please reply asap. :-)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: lucasv97 on Apr 21, 2014, 06:42 pm
hey there!! i'm a student from barcelona and i want to build a drone with arduino for my school project  :) what do you think would be the best to start with? what kind of quadcopter? how i build the drone? how i program the code??
thanks!!!!!!!

--
Lucas
Title: Re: BlueCopter - Arduino Quadcopter
Post by: trika03 on Apr 24, 2014, 02:52 pm
Any hints why the serial monitor doesn't show anything while i'm in debug mode?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Henni1000 on Apr 28, 2014, 10:53 am
Hi,
currently I am trying to get the BlueCopter code running on the Yun, which has the same µC on board as the Leonardo uses (ATmega32u4) so I had no problems compiling and flashing your code on the Yun with the AtmelStudio via USB.
But now I have a few problems when I am looking into the Debug output.

So at first only throttle and AUX1 are read by the µC the others are just staying the same (eg.1500 for Yaw, Roll and Pitch and 12 for AUX2). I have already tested the RX and connected each channel to the throttle input and got correct values for the channels, so the RX is working. So seems like there is something wrong with the way the board is or the way the code is setup... Any idea why this problem is occurring?

Another problem, which I have and don't know where I don’t know a solution for, is that the DEBUG_ANGLES is giving me strange readings.
The output is oscillating between -22 and  -115 for both XT and YT simultaneously (but with a little difference in amplitude). It is visualized in DEBUG_ANGLES Output.png and I have put the raw data into the Debug_Outputs.xlsx File.
Apparently the DEBUG_PID Output is a little strange as well, but I suppose this is basically coming from the fact that the angles sensor is oscillating in a negative area, so that the code is trying to compensate it by continuously increasing the PID values. (Visualization is attached as DEBUG_PID Output.png)

Any idea, what I could do to get the code running correctly?

---
Henni
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Nrets on May 02, 2014, 12:41 am
I've been following this project pretty closely, and have gone through all the source code and must first praise you for making your code as well organized and as readable as you have.

I'm not sure if this has been asked, but I was hoping to use a single Arduino, running a modified version of BlueCopter, to act as both a flight controller and a gimbal controller. The gimbal will have it's own IMU that I had original intended to feed into the same I2C pins as the flight IMU, but am now realizing there will be address conflicts...

That problem aside, do you think the code would be fast enough to handle both flight and gimbal stabilization?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Fragmaster on May 09, 2014, 09:54 pm
Hello everyone!

I recently burned out my KK2 multirotor controller (it was quite an impressive fizzle). While I wait for my replacement board to arrive from China, I wanted to see if I could use one of my Arduino Pro Micros to drive my motors.

I have a 3.3V Pro Micro and a 5V Pro Micro. Which sould I use for this project? I want to use hardware that is the same as Basel's so that I can be up and flying as soon as possible. Will this IMU work? http://www.ebay.com/itm/1-PC-OF-A-10DOF-L3G4200D-ADXL345-HMC5883L-BMP085-NINE-AXIS-MODULE-/251225554989?pt=LH_DefaultDomain_0&hash=item3a7e35c02d (http://www.ebay.com/itm/1-PC-OF-A-10DOF-L3G4200D-ADXL345-HMC5883L-BMP085-NINE-AXIS-MODULE-/251225554989?pt=LH_DefaultDomain_0&hash=item3a7e35c02d)

Thanks for your help.

It would be nice to assemble a list of functioning builds from this thread. Basel only listed his hobbyking parts list so I'm not entirely sure what IMU package he uses other than the adxl345 and L3G4200D are on the board. If everyone who got a BlueCopter running could post their components list and link to their custom code, that would be awesome!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on May 16, 2014, 05:39 pm

Hello everyone!

I recently burned out my KK2 multirotor controller (it was quite an impressive fizzle). While I wait for my replacement board to arrive from China, I wanted to see if I could use one of my Arduino Pro Micros to drive my motors.

I have a 3.3V Pro Micro and a 5V Pro Micro. Which sould I use for this project? I want to use hardware that is the same as Basel's so that I can be up and flying as soon as possible. Will this IMU work? http://www.ebay.com/itm/1-PC-OF-A-10DOF-L3G4200D-ADXL345-HMC5883L-BMP085-NINE-AXIS-MODULE-/251225554989?pt=LH_DefaultDomain_0&hash=item3a7e35c02d (http://www.ebay.com/itm/1-PC-OF-A-10DOF-L3G4200D-ADXL345-HMC5883L-BMP085-NINE-AXIS-MODULE-/251225554989?pt=LH_DefaultDomain_0&hash=item3a7e35c02d)

Thanks for your help.

It would be nice to assemble a list of functioning builds from this thread. Basel only listed his hobbyking parts list so I'm not entirely sure what IMU package he uses other than the adxl345 and L3G4200D are on the board. If everyone who got a BlueCopter running could post their components list and link to their custom code, that would be awesome!


Hey,

I've used the Pro Micro 3.3V on a smaller quadcopter without any problems.. If your using a ESC in your quad. then go ahead and use the 5V version, it will work mostly out of the box. That IMU is the same as mine.. So go ahead and get one of those.. Other people posting their modification is a fantastic idea.. I've tried talking to them but they are clearly not that keen on sharing like the rest of us  :smiley-sad-blue: .. Many of the successful ports/modifications of my code has been made by University students as their "thesis" and maybe explain why they didn't share their results.

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Fragmaster on May 18, 2014, 06:21 pm
It's a shame that others aren't as open to sharing their experiences as we are, but it may also be due to the lack of commitment to continue commenting in this thread. Many people may come to this thread, implement your code, ask a few debugging questions, and move on to expand on their project once their copter is functioning. They may just forget about us after they get in the air  :(

I just set up my 5V Pro Micro according to your wiring diagram on the first post and everything appears to be powered correctly. The receiver will bind to my controller and the Micro turns on.

I downloaded your project from github, extracted it, and ran the BlueCopter project. When I tried to upload your project to the board I was given this long error log during compile:

BlueCopter:32: error: 'PIDCont' does not name a type
BlueCopter:33: error: 'MPULib' does not name a type
BlueCopter.ino: In function 'void setup()':
BlueCopter:57: error: 'MPU' was not declared in this scope
FlightCtrl.ino: In function 'void FlightControl()':
FlightCtrl:16: error: 'PIDangleX' was not declared in this scope
FlightCtrl:17: error: 'PIDangleY' was not declared in this scope
FlightCtrl:80: error: 'PIDangleX' was not declared in this scope
FlightCtrl:81: error: 'PIDangleY' was not declared in this scope
FlightCtrl:83: error: 'PIDroll' was not declared in this scope
FlightCtrl:84: error: 'PIDpitch' was not declared in this scope
FlightCtrl:85: error: 'PIDyaw' was not declared in this scope
Motor.ino: In function 'void motorArm()':
Motor:21: error: 'PIDroll' was not declared in this scope
Motor:22: error: 'PIDpitch' was not declared in this scope
Motor:23: error: 'PIDyaw' was not declared in this scope
Motor:24: error: 'PIDangleX' was not declared in this scope
Motor:25: error: 'PIDangleY' was not declared in this scope
PID.ino: In function 'void PID_init()':
PID:3: error: 'PIDroll' was not declared in this scope
PID:4: error: 'PIDpitch' was not declared in this scope
PID:5: error: 'PIDyaw' was not declared in this scope
PID:6: error: 'PIDangleX' was not declared in this scope
PID:7: error: 'PIDangleY' was not declared in this scope
Sensor.ino: In function 'void updateAcc()':
Sensor:34: error: 'MPU' was not declared in this scope
Sensor.ino: In function 'void updateGyro()':
Sensor:45: error: 'MPU' was not declared in this scope


I made no changes to the code. I simply extracted the .zip file and ran the BlueCopter file with Arduino 1.0.5 IDE.
Do you have any idea why these errors are occurring? I'm not very proficient at Arduino coding, but it looks like PIDCont.h and MPULib.h did not compile in the project.

Thanks.

Edit: I put the "MPULib" and "PIDCont" folders into the "libraries" directory and now everything compiles.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Fragmaster on May 18, 2014, 09:40 pm
I have not attached propellers to my quad because I am still testing the control setup before I can calibrate the settings.

Is there a step-by-step process from uploading the code, pairing the transmitter, and calibrating to finally taking a test flight?

Is config.h the only method to set the signal values and calibrate? Is there an automatic calibration mode to set stick throws as one would calibrate an ESC, or must all calibration be done manually by altering config.h values?

After uploading the sketch to the 5V Pro Micro, everything seems to be working except for the controls. The motors will spin, but they do so at strange levels of throttle. One motor only spins when at full throttle, another only spins when at zero throttle.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on May 18, 2014, 11:49 pm

I have not attached propellers to my quad because I am still testing the control setup before I can calibrate the settings.

Is there a step-by-step process from uploading the code, pairing the transmitter, and calibrating to finally taking a test flight?

Is config.h the only method to set the signal values and calibrate? Is there an automatic calibration mode to set stick throws as one would calibrate an ESC, or must all calibration be done manually by altering config.h values?

After uploading the sketch to the 5V Pro Micro, everything seems to be working except for the controls. The motors will spin, but they do so at strange levels of throttle. One motor only spins when at full throttle, another only spins when at zero throttle.


Yes, it's only manually through config.h.. I won't answer the rest of the questions because I've already answered them 1000 times in this thread.. Please read through it..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on May 19, 2014, 02:56 pm




The 265 for the Z axis is just the maximum number that you can get when your quadcopter is leveled.. So I just asked you to calculate how much your current value deviates from that number and compensate for that..


Hi, Basel!
Just a small question - why 265(not 256) for the z axis compensation?
Is is something related to supply voltage?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on May 19, 2014, 05:06 pm





The 265 for the Z axis is just the maximum number that you can get when your quadcopter is leveled.. So I just asked you to calculate how much your current value deviates from that number and compensate for that..


Hi, Basel!
Just a small question - why 265(not 256) for the z axis compensation?
Is is something related to supply voltage?


Read the datasheet for ADXL345.. There you'll find that the z-axis is 265 at 1g..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: neinteresee on May 20, 2014, 12:24 am






The 265 for the Z axis is just the maximum number that you can get when your quadcopter is leveled.. So I just asked you to calculate how much your current value deviates from that number and compensate for that..


Hi, Basel!
Just a small question - why 265(not 256) for the z axis compensation?
Is is something related to supply voltage?


Read the datasheet for ADXL345.. There you'll find that the z-axis is 265 at 1g..

//Basel


Thanks for quick reply :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Fragmaster on May 23, 2014, 03:10 am
I just wanted to stop by and report a successful maiden flight of my quad!  : XD

One thing I noticed is that it would not hold altitude at a constant throttle position. I needed to constantly correct for its tendency  to drift up or down. Perhaps this is normal, or my own inexperience.

Also, after debugging the RX, the motors do not stop at zero throttle. I must trim the throttle down a couple notches for all of the motors to stop twitching and spinning. I tried setting the minimum throttle value in config.h to just over the actual minimum, but this didn't help. What should I do to ensure that the motors stop when I set the throttle to zero?

Where in the code do I set "rate mode"?

My rudder control is nearly unresponsive, do I need to calibrate the yaw PID values to increase the gain?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on May 24, 2014, 02:09 am

One thing I noticed is that it would not hold altitude at a constant throttle position. I needed to constantly correct for its tendency  to drift up or down. Perhaps this is normal, or my own inexperience.


It shouldn't drift.. The reason? Well, could be your RX..


Also, after debugging the RX, the motors do not stop at zero throttle. I must trim the throttle down a couple notches for all of the motors to stop twitching and spinning. I tried setting the minimum throttle value in config.h to just over the actual minimum, but this didn't help. What should I do to ensure that the motors stop when I set the throttle to zero?


That's because you arm/disarm the motors with the throttle... So the motors stop when the throttle signal is bellow 1100ms (standard value in firmware).. Maybe you need to put another value in your case..


Where in the code do I set "rate mode"?


Rate mode is controlled by AUX2 (it's a switch on my RX controller and equals to channel 5 in this case).. You can set it manually by changing the variable rateAngleSwitch.. If you set it to 0 then it's angle mode and 1 equals to rate mode..


My rudder control is nearly unresponsive, do I need to calibrate the yaw PID values to increase the gain?


Yes..

//Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Fragmaster on May 24, 2014, 10:40 pm
:smiley-yell: I just don't understand why!  :smiley-yell:  :0

Now the quadcopter will not hover whatsoever. I changed nothing in the code from my successful flight, the receiver works fine, the pro micro outputs values correctly, the hardware setup is unchanged. And it refuses to fly. Motors 2 and 4 now throttle up until the quad flips over.

Last night, motors 1 and 2 would throttle up until the quad tilted ~20 degrees backward, then motors 3 and 4 would kick in and compensate while motors 1 and 2 throttled down.

I tried redownloading the code and only calibrating the RX in debug, but the exact same problems arose.

Basel, do you have any idea why the quad would spontaneously change its flight characteristics?

When it did fly a couple of days ago, I noticed that I would need to slowly throttle up from a full stop. The quad would begin to tilt on the ground but trim itself level. Then it would hover fine. Now, when I arm the quad, motors 2 and 4 simply go wild, gradually increasing their thrust until the quad flips over.

Edit: 11:52pm(GMT) The quad has now reverted to its behavior from last night. After arming (not even throttling up), motors 1 and 2 increase thrust and motors 3 and 4 stop turning until the quad begins to tilt backwards at 15 degrees. Then motors 3 and 4 spin up while motors 1 and 2 spin down. It oscillates like this with a frequency of about five per minute. I haven't let it continue to do so for very long out of fear that it will violently accelerate.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Fragmaster on May 25, 2014, 08:35 pm
Update: My quad will now hover again. I still have not made any changes to the code.
The quad seems to believe that level flight requires it to pitch 10 degrees up and roll about 5 to the left. I don't know how to compensate for this other than with course correction by moving the stick. Transmitter trim doesn't seem to level it out, only cause it to flip at takeoff.

It seems that I must take of quickly. All motors spin up if I quickly throttle up from full-stop. If I throttle up too slowly, motors 3 and 4 will stop spinning and the quad will pitch over. It seems that the controller needs immediate accy_z data in order orient itself and keep all four motors providing thrust.

I have noticed an odd pattern with takeoff success. After connecting the battery while the quad is on level ground, the first time I try to take off, the quad will inevitable tip over onto its side because only two motors will spin up. After righting the quad, the second attempt will be successful (all motors will spin up). After landing from the successful flight, if I allow all motors to stop, the next takeoff will result in another tip-over. After righting the quad once again, the takeoff will be successful. Takeoff success seems to toggle back and forth in this pattern.

Where do I debug angles? As in, where do I put angle offsets? It seems that I need to put -10 degrees x-axis and +5 degrees y-axis.

Update 2: Flying in rate-mode doesn't require trimming in order to fly level. I do see some oscillations, but not too many. The oscillations don't interfere with flight control because they only arise for a couple seconds at a time.

I think I need to reprogram my motor ESCs because the motors cut out completely when the battery voltage drops below 11V. The low-voltage-cutoff should be set to "slow down" rather than "turn of". However, it seems odd to cutoff at such a high voltage.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Fragmaster on May 26, 2014, 09:35 pm
Basel,

I have MATLAB. May I use your PID-optimising program and Arduino code to set the best values for my quad?

Update: After holding the quad and testing it in angle and rate-mode there is a weird quirk with the stabilization. If any outside force (wind) or control command causes motor number 1 to dip below the others, rather than increase thrust from motor 1 to bring it back into plane with the others, motor 1 turns off, causing the quad to crash onto the motor 1 arm. If motor 3 (opposite motor 1) dips below the other motors, its thrust increases to bring the quad level again.

If an outside force (wind) causes the quad to yaw to the right, motors 2 and 4 increase speed to correct yaw. However, if an outside force (wind) causes the quad to yaw to the left, motor 1 turns off and the quad crashes onto the motor 1 arm.
This is strange because yaw controls still work.

Motor diagram
1              2
    \  ^  /
       |X|
    /      \ 
4            3
Title: Re: BlueCopter - Arduino Quadcopter
Post by: victorjrp on May 29, 2014, 06:32 pm
Hy, Iam from Argentina  yo have a goooooood idea. Can you tell me the pin conection for the Arduino Mega 2560 and Gy-80 ?
Thankyou very very much. Victor
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Sharan on Jun 05, 2014, 06:56 pm
Hey guys,
I am new and don't no a lot, i want to start of this project, as there are many files of code can anyone one tell me which one i put into my arduino( i have the uno r3) and could anyone tell me if i need anything else to make my remote to control it. And if you guys know how to wire it and post it it would be really useful.

Thanks
Title: Re: BlueCopter - Arduino Quadcopter
Post by: softjobs on Jun 14, 2014, 03:27 pm
Awesome project. Thank you Basel for both trying this out and educating the rest of us. Very well done!

I have been working on it for the past few weeks, replacing the components I bought before you started this thread with the one's you are using... A lot of hurdles to cross along the way and once I am fully done, I am going to write them all up for others to take note.

After spending many hours to try to tune it, I tried a different approach yesterday to figure out what was going on. While the quad is on the ground and running the motors at a set throttle, I tried to lift up the rear two motors manually with a long screw driver (varied the pitch). I noticed that the front motors started to slow and the rear ones starting to increase in speed. This seemed wrong and so, I checked out what the PID controller was putting out for the PITCH. To my surprise, it was a negative value. So, in the calculation to come up with the final motor output, wherever the Pitch value was added, I subtracted and vice versa. Now, I am able to at least get it off the ground if I throttle quickly. If I increase the throttle smoothly, it tends to move sideways, but has a stable life. Before adjusting the calculation for pitch, it would simply oscillate back and forth (pitch variations).

I am wondering if my IMU model (GY 80) has anything to do with it. I checked my connections numerous times and everything matches to what you have.

I am using this IMU: 10DOF 9-Axis Attitude L3G4200D ADXL345 HMC5883L BMP085 Sensor Module for Arduino, cheap one found on eBay...

I am getting more parts from hobbyking today and will build this again on a new frame, using the same motors that you use. With that, I would match what you built to almost 90%, except that I will be using a Leonardo Pro Micro and the IMU that I mentioned above.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: sowee on Jun 20, 2014, 12:31 am
Heya Basel! Your code is awesome. I'm right now converting it to use with a different mpu library, so I can use the 9150. My only question is, when you do MPU.getAxlData(buffer) with your library using those cheap sensors, what is saved to the buffer vector? Raw data? If so, what is the range?

The gyro is working fine so far.

Thanks in advance!

Title: Re: BlueCopter - Arduino Quadcopter
Post by: RicardoGaOr on Jul 19, 2014, 01:58 am
Hi, your development is awesome, but I've got one question... Can you tell me How is the connection of the brushless & ESC? directly parallel to the ProMini 5v output or voltage distribution board?

Tanks for your time =D
Title: Re: BlueCopter - Arduino Quadcopter
Post by: RiMi on Aug 07, 2014, 11:37 am
Hello,
I am familiar with the arduino, but I don't have too much experience with it.
I have a Arduino Leoanrdo and I don't know what cable goes where for the quad.
Need some help, thanks :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Devbrat on Aug 09, 2014, 02:44 pm
Hi,

I also want to make a Bluetooth controlled Arduino Quadcopter, kindly help me...I'm a newbie..............plz

Regards
Devbrat Mandal
Title: Re: BlueCopter - Arduino Quadcopter
Post by: surya009 on Aug 12, 2014, 07:27 am
what ts tf and tp doing in code....??
what are there significance in code?
i m kind of new to this large code programming... :smiley-roll-sweat:
help me out plzz
Title: Re: BlueCopter - Arduino Quadcopter
Post by: surya009 on Aug 17, 2014, 08:19 am

what ts tf and tp doing in code....??
what are there significance in code?
i m kind of new to this large code programming... :smiley-roll-sweat:
help me out plzz
Title: Re: BlueCopter - Arduino Quadcopter
Post by: TerenceEB on Aug 18, 2014, 05:32 pm
Basel
i am trying to make a model in matlab..whats the sampling rate of the program/sensors,i cant seem to figure out the update rate of the sensors in your program mean what should i put in the feedbcak path,thats the path for measuring the output using the the two sensors or i should just assume its fast enough?I am trying to make it as realistic as possible
Title: Re: BlueCopter - Arduino Quadcopter
Post by: quike_gon on Sep 04, 2014, 06:26 pm
Great Job!

I am working on a quadcopter, but it doesn't get stable. I get output values from PID for each movement (Pitch, Yaw, Roll) and then introduce them in the motors:

Code: [Select]
PIDYaw.Compute();
PIDPitch.Compute();
PIDRoll.Compute();

throttleFL = throttle - OutPitch + OutRoll - OutYaw;
throttleFR = throttle - OutPitch - OutRoll + OutYaw;
throttleBL = throttle + OutPitch + OutRoll + OutYaw;
throttleBR = throttle + OutPitch - OutRoll - OutYaw;

motorFL.write(throttleFL);
motorFR.write(throttleFR);
motorBL.write(throttleBL);
motorBR.write(throttleBR);


Must I make any step between PID and motors?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: mo328i on Sep 06, 2014, 02:27 am
Hello,

I am new in quadcopter field and i am buinding one from scratch. I want the configure the Quadcopter in X Configuration and i would like to know in Which direction the MPU6050 6 dof should be pointing. The pitch and roll directions detected accros the frame moving direction or across the frame's "legs".

Should i plug the arduino and the MPU6050 like this, in this direction -->
http://blog.tkjelectronics.dk/wp-content/uploads/QuadCopter-XConfig.jpg
(seems better for me and easier to strech it and implement PID tuniing and testing)..

Because i have seen some has the sensors in this direction ->
http://i.ytimg.com/vi/U4eyFEekMco/maxresdefault.jpg

Sorry if the quetion is a little bit dumb...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Shiddu on Sep 10, 2014, 08:11 am
Hi guys,
Have any of you tried to program your arduino quadcopter in such a way that, at certain altitude, even if you move ur throttle, the altitude will still remain the same and it will continue to hover at the same level.
Do anyone of you have the code for this?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Shiddu on Sep 11, 2014, 03:54 am

Hi guys,
Have any of you tried to program your arduino quadcopter in such a way that, at certain altitude, even if you move ur throttle, the altitude will still remain the same and it will continue to hover at the same level.
Do anyone of you have the code for this?
I think using the interrupt function can make this work but how? Any ideas or suggestions guys?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: jensreekmans on Sep 11, 2014, 11:16 pm
Hey.

I am a student in my last year of high school in Belguim.
The project I chose was building a quatcopter from scratch.
I love your project and it will help me alot in this last year.
There are a few problems tough I can't just copy and paste your code into mine and have 0 programming skills.
Could you please tell me some pointers where I should look at and maybe some tips or some tricks and tell me in what programming language you wrote it?
It would help allot Thank You

Greetings Jens
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Shiddu on Sep 19, 2014, 08:18 am

#include <Servo.h>


#include "drone_ping.h"
#define LED 13

#define STICK_DISTANCE 70 //was 30


#define DEBUG x

Servo AIL;
Servo ELE;
Servo THR;
Servo RUD;
Servo AUX;

double InputZ, InputR, InputL, hoverHeight, latDiff, ratio, error;
int recAIL;
int recELE;
int recTHR;
int recRUD;
int recAUX;

int max_rec;
int min_rec;
int mid_rec;
int ref_aux;
int thr, ail;

unsigned long x_prev_time;
unsigned long y_prev_time;
unsigned long x_curr_time;
unsigned long x_elap_time;
unsigned long y_elap_time;
unsigned long y_curr_time;

int counter;

void setup(){

  // set up serial baud rate
  Serial.begin(9600);

  //set up the pins for controls and inputs
  pinMode(trigZ, OUTPUT);
  pinMode(echoZ, INPUT);
  pinMode(trigR, OUTPUT);
  pinMode(echoR, INPUT);
  pinMode(trigL, OUTPUT);
  pinMode(echoL, INPUT);
  pinMode(trigF, OUTPUT);
  pinMode(echoF, INPUT);
  pinMode(trigB, OUTPUT);
  pinMode(echoB, INPUT);

  //set up the pins for flight controller
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
 
  //attaching servos
  AIL.attach(9);
  ELE.attach(10);
  THR.attach(11);
  RUD.attach(12);

  //calibrate input and find the average value after taking 10 samples
  recAIL = pulseIn(3, HIGH, 20000);
  for (int i = 0; i < 10; i++) {
    mid_rec += recAIL;
  }
  ref_aux = pulseIn(7, HIGH, 20000);
  mid_rec = mid_rec / 10;//average
  min_rec = mid_rec - 450;//minimum value
  max_rec = mid_rec + 450;//maximum value
 
  Serial.print("AIL AVG VAL: ");
  Serial.println(mid_rec);
  Serial.print("AUX AVG VAL: ");
  Serial.println(ref_aux);
  x_prev_time = millis();
  delay(500);

  hoverHeight=60;//target hover height that we want the unit to go

  fakePulse();
  delay(500);

}

void loop(){

  //reading recievers value from remote control
  recAIL = pulseIn(3, HIGH, 20000);
  recELE = pulseIn(4, HIGH, 20000);
  recTHR = pulseIn(5, HIGH, 20000);
  recRUD = pulseIn(6, HIGH, 20000);
  recAUX = pulseIn(7, HIGH, 20000);

  //check if aux switch is flipped. if so trigger auto pilot
  if(recAUX > 0 && recAUX < (ref_aux - 400)  ){

      digitalWrite(LED,HIGH);
      autoPilot();
    }
    else{
      //else, pass remote control signals to flight controller
      digitalWrite(LED, LOW);
      THR.writeMicroseconds(recTHR);
    }
    // pass ail, ele, rud signal values from remote control to flight controller
    AIL.writeMicroseconds(recAIL);
    ELE.writeMicroseconds(recELE);
    RUD.writeMicroseconds(recRUD);

}

void fakePulse(){
  AIL.writeMicroseconds(1500);
  delay(10);
  ELE.writeMicroseconds(1500);
  delay(10);
  THR.writeMicroseconds(1100);
  delay(10);
  RUD.writeMicroseconds(1500);
  delay(10);
}


void autoPilot(){

  flight_z(); //apply hover algorithmn

}

void flight_z(){

  // if user intervenes using Throttle, the values from the remote controll will overright the autopilot.
  if(recTHR > min_rec + STICK_DISTANCE){
    THR.writeMicroseconds(recTHR);
  }
  else{
    //measure height
    InputZ = pingZ();
   
    if( InputZ > 180){
      thr = min_rec;
    }
    else if( InputZ < hoverHeight - (hoverHeight * 0.20) ){ //below hoverHeight
      error = ((hoverHeight - InputZ)/hoverHeight) * 100;
      thr = map(error, 0, 100, mid_rec, (mid_rec + 200));
    }
    else if( ( InputZ > hoverHeight + (hoverHeight * 0.20) ) && thr >= (mid_rec - 100) ){ // above hoverHeight
      thr-= 6;
    }

    else if( InputZ > hoverHeight - (hoverHeight * 0.20) && InputZ < hoverHeight + (hoverHeight * 0.20) ) { //within hoverHeight
        thr = mid_rec - 100;
    }

    //pass the computed throttle power to the flight controller
    THR.writeMicroseconds(thr);

  }

}





// GUYS, CAN ANYONE SPOT ANY MISTAKE IN MY CODING HERE BECAUSE I AM TRYING TO GET THIS CODE TO RUN ONTO MY ARDUINO QUADCOPTER. THIS IS MY SCHOOL'S FINAL YEAR PROJECT AND ITS WORTH LOTS.
THANKS!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: rockeronline00 on Sep 28, 2014, 10:10 pm
Is there anyone who knows how to tune cascaded PID?  My quadcopter project is similar to BlueCopter but I can't get of the bottom of this.

Thank you
Title: Re: BlueCopter - Arduino Quadcopter
Post by: nicnac on Oct 10, 2014, 10:26 pm

Is there anyone who knows how to tune cascaded PID?  My quadcopter project is similar to BlueCopter but I can't get of the bottom of this.

Thank you


You start innerst -> outwards. Since with cascades you assume the inner ones are infinitely fast, you first make sure they are nice, then go outwards.

Sample rates of 200-50 Hz are realistic. The feedback path has to include the state information: Angles and Rates. If it is raw "measurements" with noise added, depends on if you include a filtering model.

Oh an quike_gon: If you are in X configuration, it is correct. And pitch is defined as 'lean back', so if the front rises up.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: lucky6618 on Oct 20, 2014, 07:40 pm
BlueCopter - Arduino Quadcopter
Could you please tell me , how to connect INU(GY_80) board to arduino
And wht is AUX1 & AUX0 which is at pin 8 & 0.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: mrnarcoticz on Nov 18, 2014, 12:57 am
hey im very new to this uas building or quadcopter. im currently in a group of students attending fairmont highschool. we have competed in a competition but are still beginning. we have it up and running but its very unstable. it requires constant correction. we havent written a sketch. we have only adjusted the pid values. we thought a sketch might make our quad fly smoother. two of our motors are spinning significantly faster than the rest. i wanted to know how might i go about getting a sketch for arduino that might fix our issues? please respond thank you.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Khanrad on Nov 29, 2014, 02:32 pm
Hi, i have a little problem.
I don't undersand how works this HPF:

Code: [Select]
#define  ACC_HPF_NR  98  //high pass filter nr
int accx_temp=0;
//...
buffer[0]=buffer[0]-ACC_X_OFFSET;
 accx_temp=(ACC_HPF_NR*accx_temp+(100-ACC_HPF_NR)*buffer[0])/100;
//...


So i didn't find any place that "reset" accx_temp, so it stack endless, until end of Integer, right?
How it works, only this part with HPF, can someone help me?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: rockeronline00 on Dec 05, 2014, 12:43 pm
You start innerst -> outwards. Since with cascades you assume the inner ones are infinitely fast, you first make sure they are nice, then go outwards.

Sample rates of 200-50 Hz are realistic. The feedback path has to include the state information: Angles and Rates. If it is raw "measurements" with noise added, depends on if you include a filtering model.

Oh an quike_gon: If you are in X configuration, it is correct. And pitch is defined as 'lean back', so if the front rises up.
thank you nicnac.
I improved the PID of this quadcopter and simplified the cascaded-PID configuration. When all will work perfectly I'll write a post with these mods
Title: Re: BlueCopter - Arduino Quadcopter
Post by: hashmi on Dec 16, 2014, 05:02 pm
Hey, thanks Nick =)..  Couldn't figure out where to start the topic..  Good thing you moved it..

//Basel
hello sir i am new to arduino software n i want to build a quadcopter as my final year project can u please help me to complete my project please....
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Buxtonsims on Dec 22, 2014, 12:35 am
Hi Basel.

I've just recently gotten my quadrotor into the air (5v pro mini, mpu9150). I want to thank you for posting your code and being so forthcoming with explanation. I used your method of reading the RC receiver by pin change interrupt - took me quite a while to understand it let me tell you! - but it's given me a valuable introduction to what's going on behind the scenes with arduino code.

I have read widely on the internet in order to get to this point and have gleaned information from so many sources. The first being my eldest son coming home and saying something like "Dad, our engineering teacher showed us these Arduino micro controllers....". Where was this stuff when I was a boy :-) ?

So once again, thanks Basel! It's contributors like yourself that help the less cluey such as myself achieve our goals.

Sincerely,

Graham.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: future92 on Dec 27, 2014, 07:09 am
Hi,

Really, it is very helpful post. Thank you so much Mr. Baselsw.

I bought Leonardo,  ADXL345 and L3G4200D  chips separately. Could you explain to me how the connections and the code will differ, please?


Best Regards,
future92
Title: Re: BlueCopter - Arduino Quadcopter
Post by: ArduCopterArduino on Jan 09, 2015, 07:46 am
Hi Basel,

I am doing a Science fair project and was inspired by you. I want to make my copter hover in the air for 3 seconds and then descend down. I was wondering if you can help me with this and show me some codes and how to do it. This would really help me and I won't end up failing  :smiley-razz: .

Thank you so much! ;D  ;D  ;D  :D  :D  :D
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jan 28, 2015, 01:02 pm
Hi all!

This thread is growing like crazy! I'm sorry guys for not being here and answering all the questions. I'm very busy with work and don't have enough spare time to be more active in this wonderful community. I'm going to try looking at these posts every now and then but would also encourage people with knowledge about this to jump in.

I see that many of the questions here have already been answered. I would like to encourage you to go back in this thread and read the posts made by at least me before asking a question.

@ Future92: That shouldn't be a problem. Just make sure the address pins are set correctly and that both chips are connected to the same I2C bus.

@ArduCopterArduino: Would love too but because of the limited time that I have, I really can't.

/ Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: dasarath on Feb 01, 2015, 04:05 am
nice project!!

i'm a high school student and i want to build this.

i'm also new to arduino.

so can u pls provide all the step by step tutorial including programming and making for completing this pls.?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: rishi_ragu on Feb 15, 2015, 03:57 pm
Hello sir. Great job you have done here. Could you please explain me the whole code? Like some comment lines in the code itself. I am actually trying to write my own code for the quad. Please help me sir.
Or else it will be grateful if you suggest me some of the references you used while writing the whole code.
Thanks in advance.

Regards,
Rishi.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: firozsha18 on Mar 10, 2015, 09:34 am
hii basel,
appreciate your amazing work
iam working on a similar project as yourz,n iam trying to understand your code it has pitch yaw and roll
but the actual prob comes while understanding what are the angle x and angle y? also wmin wmax are implying what??
would be a grt help if u clarify these thanks in advance
Title: Re: BlueCopter - Arduino Quadcopter
Post by: ko2001911 on Mar 12, 2015, 07:23 am
Hi Baselsw,

Some simple questions about your Bluecopter.
1. Can I use the code with Arduino Leonardo with a Sparkfun 6DOF IMU+Logic level board?? Is it the same and no changes need to be done?

2. As I am new and quite not sure about the Arduino. I want to add two more RC servo for other purpose. There is still pins left for me to add it, right? And I can still do some minor changes to the code in order to control the two RC servo.

I have overestimated myself and get into troubles in making a DIY quadcopter, and now I just trying to build a simple quadcopter that can fly as my project mainly concerns is what the extra two RC servo are going to do.

Please help me!!

If anyone else can help me with these problems, please answer!! Thank you very much!!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: dipanjan05biswas on Mar 15, 2015, 02:00 pm
sir tell me how to use coreless dc motors with this....i want to use mosfets instead of esc.....please help
Title: Re: BlueCopter - Arduino Quadcopter
Post by: luismejiare on Mar 26, 2015, 08:47 pm
Hi, how are you?.  I'm from Aguascalientes Mexico, I am developing my code for a drone, and leaned on his project because I have to hand it to my school, I wonder if you used a unit of R / C. ¿or used one smartphone? thanks. congratulations for you code. you helped so much, thanks one more time


 :D  :D  :D  :D
Title: Re: BlueCopter - Arduino Quadcopter
Post by: John_Tan86 on Apr 01, 2015, 06:22 pm
Hi I saw from your picture, what board it that? Looks like it have a wireless module attach on it ???
Title: Re: BlueCopter - Arduino Quadcopter
Post by: luismejiare on Apr 05, 2015, 04:32 am
hello how are you, I wonder how the receiver is connected to the arduino,

1 the pins pwm, of arduino is connected to one of the 3 wires that has the ESC.
the other is (+), (-) negative is connected to GND, the (+) where is connecting?

2nd how it is distributed receiver with the pins arduino, o the auxiliary pins in the Arduino bluecopter code,


greatly appreciate it if you show me a picture of how this connected the circuit please
since I'm just starting with arduino please, help me
Title: Re: BlueCopter - Arduino Quadcopter
Post by: tibike262 on Apr 14, 2015, 12:16 am
Hi Basel,

first of all let me thank you for this thread. Im working on a quadcopter first prototype from plastic is crashed, Im currently waiting for my custom 600x600x5mm piece of aluminium body part which should be precisely cut till Saturday and i have gone through your code. What i have found is that you are using falling and rising interrupt assigning but you can just use:

attachInterrupt(THRO_SIGNAL_IN,calcInput1,CHANGE);

and then:
Code: [Select]

void calcInput1()
{
 if(digitalRead(THRO_SIGNAL_IN_PIN) == HIGH)
 {
   ulStartPeriod1 = micros();
 }
 else
 {
   if(ulStartPeriod1)
   {
     nThroIn = (int)(micros() - ulStartPeriod1);
     ulStartPeriod1 = 0;
   }
 }
}

Im wondering which method is faster / better :)
Im using PWM receiver not PPM

For the one's looking for what to put in from gyro/accelometer to the code:
accelometer measurements in mg/LSB
gyro measurements in DPS = degree per second

I cant get good angle values currently fighting with the gyro - solved = dont needed to cast the values to float

Also found out that my IMU has ACCx = GYROy and ACCy = GYROx same as yours (AltIMU-10v4)

Code done for arduino MEGA 2560. Rewriten almost the whole code still need some parts to rewrite.
Optimized the libraries for the IMU a bit to work faster.

Copter weight = 2,35 kg. Motors should cary acrobat planes with 850 grams up to 1kg.

Sample of my debug is in the attachments. Also some photos included.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Apr 24, 2015, 06:12 am
Hi

Are you still up for questions?

Title: Re: BlueCopter - Arduino Quadcopter
Post by: tibike262 on Apr 24, 2015, 09:22 pm
yes sure Thagz. If i can help i will.

> edit: added my code of Arduino Mega 2560 so enjoy

PWM based receiver with 6 channels - i can only use 4 interrupts as the I2C takes the pins 20 and 21 on my board

motors connected to the ports 8-11

in the main code the setup() is also setting some pins to HIGH as i need them for my ESC's and the IMU (dont know why but they need 5V on the red wire to start even as they suppose to drive the receiver)

configuration of motors>
0   1
\^/
 X
/  \
2   3
The IMU is in this direction>
^
||


LINK TO GITHUB:
https://github.com/tibike262/Bluecopter-2560 (https://github.com/tibike262/Bluecopter-2560)


P.S> crashed it today as my motors are getting 1 value on m0 and m3, but the m1 stops and m2 goes to full speed so the copter flips around 1 axis so use this code as reference but dont forget to debug the motor values before the first flight

P.S.2> I will update the code when i get it working.

Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on May 05, 2015, 06:34 am
May i ask what does .Compute means? I am new to arduino and i want to learn the programming language.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 09, 2015, 01:32 am
Hi
I am trying to plan a quadcopter. I modified the code to use a MPU6050 and a UNO. I am wondering if I could use 2 1300 mAH batteries. Would this work correctly?
Thanks,
-Isaac
Title: Re: BlueCopter - Arduino Quadcopter
Post by: cyclegadget on May 09, 2015, 05:41 am
 @Isaac96

 Here is a quote from the first page:

Quote
I'm using a double 2200mAh (3 cells, LiPo, coupled in parallel).. It gave me approx. 15min of flight
I was able to run for a short period of time on one 2500mAh battery but, I think the motors require a large amount of current and you will need batteries that can handle the load. Therefore, I am running two 2500mAh batteries in parallel on my quadcopter (still working out the bugs).

Mark
Title: Re: BlueCopter - Arduino Quadcopter
Post by: tibike262 on May 09, 2015, 11:33 am
Hi
I am trying to plan a quadcopter. I modified the code to use a MPU6050 and a UNO. I am wondering if I could use 2 1300 mAH batteries. Would this work correctly?
Thanks,
-Isaac

You can use whichever batery capacity that you want but keep in mind that this affects the flight time of your quad. Find a quadcopter flight time calculator on the internet and you can calculate how much time it will fly in still position. The bigger the motors the bigger the battery requirement. I have currently 2x 4900mAh bateries on my quad.


May i ask what does .Compute means? I am new to arduino and i want to learn the programming language.
I was first wondering too but the compute is used for the computation of power needed on every axis roll / pitch  and it is a custom library written by basel. The library is found here https://github.com/baselsw/BlueCopter/tree/master/BlueCopter/libraries/PIDCont in basel's bluecopter.


UPDATE FOR MY WORK:
i have figured out the computation of the angles, acceleration and gyro
the outputs for these is as folows:
acceleration should be 0 when the copter is still - adjust it with the variable in the PINS.h from my code
gyro should be the same
angles = 0-90 but if you tilt the copter than it goes terribly fast to 90 but then when you tilt it even more the values go from 90 to 80 or something like that. I havent figured out this. Currently my motors are vibrating so much that the copters gyro is crazy and tillts it to the front every time.

I have crashed 1st time for adding a little too much power and broke 2 props.

2nd time i was aware of this but the copter flipped because of vibrations/weight distribution (i have to figure this out but most probably it is for the vibrations in the skelet) props not broken because i have brake function on my servos and i put throtle to 0 in quick enough time to stop the props.

Noise dumpening is done on my copter with 4 rubber bands attached to 4 poles and hanging in the middle section of the copter.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: cyclegadget on May 09, 2015, 04:27 pm

 Battery requirements should be based off of the motors current usage. I am using a 11.1V battery so my current will be about 14.2A per motor. Multiple that number by 4 (the count of motors) and you will get 56.8A. You need a battery that can handle that load. If the battery is too small you can damage the battery or even set the battery on fire.

 A bigger battery than is required will just be an increase of lifting load. As long as you don't have too much weight, bigger batteries are fine.


Motor Specs:
Model: NTM Prop Drive Series 2826 1350kv
Kv: 1350rpm/v
Poles: 3
Motor Wind: 14T
Max current: 18A
Max Power: 227W @ 11.1V (3S) / 302W @ 15V (4S)
Shaft: 3mm
Weight: 56g
ESC: 25~30A
Cell count: 3s~4s Lipoly
Bolt holes: 16mm & 19mm
Bolt thread: M3
Connection: 3.5mm Bullet-connector

Prop Test Data:
8x3.8 - 11.1V / 158W / 14.2A / 0.736kg thrust
8x3.8 - 14.8V / 310W / 21A / 1.1kg thrust
Title: Re: BlueCopter - Arduino Quadcopter
Post by: cyclegadget on May 09, 2015, 04:32 pm
 @tibike262

 If you have not already, I recommend reading pages 3 and 6 of this thread. I was having similar problems like yours and those pages gave me the answers.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 09, 2015, 04:56 pm
Ok, so 2*1300 will be 2600mAH and I will get ~ 7mins of flight time. Correct?
Also, the C rating is 50C (so 65 amps), which should be plenty.(BTW, they are 3S).
Thanks!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: tibike262 on May 09, 2015, 05:39 pm
@tibike262

 If you have not already, I recommend reading pages 3 and 6 of this thread. I was having similar problems like yours and those pages gave me the answers.
already read through that once but not all of it so now im going through the posibilities to tie my quad to something. Its 60 cm wide so its a bit harder :D
Title: Re: BlueCopter - Arduino Quadcopter
Post by: cyclegadget on May 11, 2015, 01:36 am
Ok, so 2*1300 will be 2600mAH and I will get ~ 7mins of flight time. Correct?
Also, the C rating is 50C (so 65 amps), which should be plenty.(BTW, they are 3S).
Thanks!
Based on Basel's information from earlier posts, I think your guess of 7mins of flight time is reasonable.

 If your batteries are both 50C then, they can produce 65 amps each. If you wire them in parallel, you will have 130 amps available. It sounds like your batteries should work very well.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on May 12, 2015, 07:20 am
How about the 2 angle[0] and angle[1]?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 13, 2015, 06:15 am
Hello all,

I am new to this so forgive my lack of understanding but I am having trouble with the setup. I have all the parts listed and I have them set up as shown in the attachment. Would someone please help me out by telling me where I have gone wrong? I would really appreciate it!

Thanks!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: cyclegadget on May 15, 2015, 03:08 am

 Did you bind the Transmitter with the Receiver?

 It is discussed in this thread http://www.rcgroups.com/forums/showthread.php?t=1122224
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 15, 2015, 05:15 am
Are you sure the I2C is wired up right? It needs to be attached to the SCL/SDA pins near AREF.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on May 15, 2015, 11:23 am
Hello all,

I am new to this so forgive my lack of understanding but I am having trouble with the setup. I have all the parts listed and I have them set up as shown in the attachment. Would someone please help me out by telling me where I have gone wrong? I would really appreciate it!

Thanks!
Hey,

The motors should be connected to pins D5,D6,D9,D10. The IMU should be connected to SCL/SDA and not D2/D3 (this is not a UNO board). The RC-receiver should be connected to the following pins: D0,D7,D8,D14,D15,D16 (the last 3 pins are on the ICSP header). In order to see which pin is which look in the config.h file.

I'm mesmerized by how this thread/code are becoming popular (my email is getting bombarded with messages). I'm sorry for not being here and helping you guys with all of your questions. I've helped a lot of people with porting my code to other boards like the UNO and Mega and even helped them achieve stable flight with their quads. It's a shame that they didn't share their code/experience with the rest of the community. Or even stick around to answer questions.  :( ...

Much love to all of you guys that are trying to decrypt my code and help others here!

/Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 15, 2015, 03:02 pm
Yes I realized the SCL/SDA were misplaced on my board. I haven't had any luck since changing them to their proper pins. Is there anything I'm missing at all?

And yes I have the transmitter and receiver bound and tested.

Did I wire the ESC's properly? Is there anything I need to do with those that I'm not aware of?

Thank you very much for the help!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 15, 2015, 03:54 pm
I think you have the power hooked up wrong to the receiver.
Positive should be in the middle. I think ground is in the right place.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 15, 2015, 04:13 pm
Isaac96,

You are absolutely correct, I will check this as soon as I get the chance. I think it's wrong in my diagram but I think I have it the correct way on my quad.

Thanks!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 16, 2015, 12:40 am
Awesome!
(I finally gave somebody helpful advice :D )
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Vladgone on May 17, 2015, 04:57 pm
Hi, can someone help me please  :smiley-confuse: , I tried the code on my arduino leonardo but it doesn't work, i use the RX701 receiver. Thanks
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 17, 2015, 06:12 pm
Could you post a picture of your circuit?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Vladgone on May 17, 2015, 07:05 pm
Ok, i put some pictures here, and thanks for your response.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Vladgone on May 17, 2015, 09:31 pm
That one could help, thanks for helping :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 18, 2015, 03:28 am
It doesn't work? Do the motors not spin? Uncomment DEBUG on line 81 of config.h. Uncomment what you need to see, maybe DEBUG_RX to see if you are getting input from the receiver.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: cyclegadget on May 18, 2015, 05:17 am
Hi, can someone help me please  :smiley-confuse: , I tried the code on my arduino leonardo but it doesn't work, i use the RX701 receiver. Thanks
What ESCs are you using? Your ESCs do not look like the ones Basil used and recommended.

  Are all of your Grounds (-) connected? The grounds of the ESCs, receiver, batteries, and Leonardo.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Vladgone on May 18, 2015, 10:32 am
Thanks all of you, i met a big problem with my receiver, it blew up ( wrong connection ) :'( , i try to fix or buy another one.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: dicarloj on May 22, 2015, 02:53 am

I've ported the receiver code to the arduino UNO which handles pin change interrupts and ISR's a little bit differently if anybody is interested.  This works with the six analog pins, but it can work with other pins if you modify the ISR and the pin assignments.  There are also some comments explaining how it all works.

More importantly, it has a method to detect if the remote is out of range.  This works with my 6 channel hobbyking HK-T6A V2 remote very nicely.  If you put "checkForDeath" in your loop() method, the code inside will run when you go out of range or run out of controller batteries.



Code: [Select]


//format for all the pin arrays
const byte rxPins[6] = {RX_PIN_PITCH, RX_PIN_ROLL, RX_PIN_YAW, RX_PIN_AUX1, RX_PIN_AUX2, RX_PIN_THROTTLE};
//stores if each of the pins was high or low last time
volatile byte rxPrevState[6] = {0, 0, 0, 0, 0, 0};
//stores the system time when the pin last went high
volatile long rxPrevTime[6] = {0, 0, 0, 0, 0, 0};

//method to configure a pin for PCICR. 
void setupPin(byte pin){
    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
    PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
    PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
}

ISR (PCINT1_vect){
  //an analog pin changed state
  //iterate through all the possible pins it could have been
  for(int i = 0; i < 6; i++){
    //store the state of the pin we're checking
    byte rxCurrentState = digitalRead(rxPins[i]);
   
   
    //if it currently is high, but was low last time...
    if(rxCurrentState == 1 && rxPrevState[i] == 0){
      //the pin just went high, so we store the time at which it went high
      rxPrevTime[i] = micros();
    }
   
    //if it currently is low, but was high last time
    if(rxCurrentState == 0 && rxPrevState[i] == 1){
      //the pin just went low, so we subtract
      //the current time from the time it went high
      //to find the pulse length
     
      //store the pulse length in the rx values array
      rxVal[i] = micros() - rxPrevTime[i];
    }
   
    //store the state (high/low) for next itme
    rxPrevState[i] = rxCurrentState;
  }
}

void initReceiver(){
  //setup interrupts on the analog pins
  for(int i = 0; i < 6; i++){
    pinMode(rxPins[i], INPUT);
    digitalWrite(rxPins[i], HIGH);
    setupPin(rxPins[i]);
  }
 
 
 
}

//call this method from loop().
//you can handle losing connection however you want.
void checkForDeath(){
  if((micros() - rxPrevTime[5]) > 100000){
    //code in here runs if we lose connection
  }
  }
 

}


Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 22, 2015, 03:09 pm
You know what, I've done that same exact thing, but with the PinChangeInterrupt library. Here's my receiver code:
Code: [Select]

PROGMEM const byte rxPins[6]={
  RX_PIN_YAW,RX_PIN_ROLL,RX_PIN_PITCH,RX_PIN_AUX1,RX_PIN_AUX2,RX_PIN_THROTTLE};
volatile byte rxState[4]={
  0,0,0,0};
volatile int rxPrev[6]={
  0,0,0,0,0,0};

void rxInit(){
  for(byte i=0;i<6;i++){
    pinMode(pgm_read_byte(&rxPins[i]),INPUT);
    digitalWrite(pgm_read_byte(&rxPins[i]),HIGH);
  }
  attachPinChangeInterrupt(RX_PIN_YAW,rxGoesHigh1,RISING);
  attachPinChangeInterrupt(RX_PIN_ROLL,rxGoesHigh2,RISING);
  attachPinChangeInterrupt(RX_PIN_PITCH,rxGoesHigh3,RISING);
  attachPinChangeInterrupt(RX_PIN_AUX1,rxGoesHigh4,RISING);
  attachPinChangeInterrupt(RX_PIN_AUX2,rxGoesHigh5,RISING);
  attachPinChangeInterrupt(RX_PIN_THROTTLE,rxGoesHigh6,RISING);
}
void rxGoesHigh1(){
  attachPinChangeInterrupt(RX_PIN_YAW,rxGoesLow1,FALLING);
  rxPrev[0]=micros();
}
void rxGoesLow1(){
  attachPinChangeInterrupt(RX_PIN_YAW,rxGoesHigh1,RISING);
  rxVal[0]=micros()-rxPrev[0];
}
void rxGoesHigh2(){
  attachPinChangeInterrupt(RX_PIN_ROLL,rxGoesLow2,FALLING);
  rxPrev[1]=micros();
}
void rxGoesLow2(){
  attachPinChangeInterrupt(RX_PIN_ROLL,rxGoesHigh2,RISING);
  rxVal[1]=micros()-rxPrev[1];
}
void rxGoesHigh3(){
  attachPinChangeInterrupt(RX_PIN_PITCH,rxGoesLow3,FALLING);
  rxPrev[2]=micros();
}
void rxGoesLow3(){
  attachPinChangeInterrupt(RX_PIN_PITCH,rxGoesHigh3,RISING);
  rxVal[2]=micros()-rxPrev[2];
}
void rxGoesHigh4(){
  attachPinChangeInterrupt(RX_PIN_AUX1,rxGoesLow4,FALLING);
  rxPrev[3]=micros();
}
void rxGoesLow4(){
  attachPinChangeInterrupt(RX_PIN_AUX1,rxGoesHigh4,RISING);
  rxVal[3]=micros()-rxPrev[3];
}
void rxGoesHigh5(){
  attachPinChangeInterrupt(RX_PIN_AUX2,rxGoesLow5,FALLING);
  rxPrev[3]=micros();
}
void rxGoesLow5(){
  attachPinChangeInterrupt(RX_PIN_AUX2,rxGoesHigh5,RISING);
  rxVal[3]=micros()-rxPrev[3]; 
}

void rxGoesHigh6(){
  attachPinChangeInterrupt(RX_PIN_THROTTLE,rxGoesLow6,FALLING);
  rxPrev[5]=micros();
}
void rxGoesLow6(){
  attachPinChangeInterrupt(RX_PIN_THROTTLE,rxGoesHigh6,RISING);
  rxVal[5]=micros()-rxPrev[5]; 
}



 8)  8)  :P
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 24, 2015, 05:02 pm
I recently took apart a computer battery and found 8 18650 cells. Could I use them to power a quad?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: dicarloj on May 25, 2015, 02:42 pm
Probably not.  When you put those batteries in series, like you'll have to in order to get enought voltage, you can't add their discharge current.  Those little batteries aren't rated for much, so I doubt they could power a reasonably sized quad copter.  A decent 2200mah 25C battery from hobby king is only like $12 and would probably work much better
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 26, 2015, 05:00 am
Well, I already have other batteries :P
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 30, 2015, 06:36 pm
Hello all,

I have everything in the proper orientation now and I still get nothing. Do the ESC's need to be initialized or something? I just put it all together thinking it would be factory set up. I don't get any noise or anything. I tried turning SAFE mode off and everything but I still have no response. Any info on the subject would be great!

Thanks!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 30, 2015, 06:46 pm
pnichols, try uncommenting DEBUG on line 81 of config.h. Post the serial monitor output in code tags.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 30, 2015, 08:13 pm
Which debug process should I uncomment? Just uncommenting the DEBUG on line 81 doesn't give me anything on the serial monitor.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 30, 2015, 08:26 pm
Try them all one by one. You can use DEBUG_RX to see if your receiver is working properly.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 30, 2015, 08:36 pm
I'm not getting anything from any of them.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 30, 2015, 09:38 pm
Do you have the right baud rate set? Open the Serial Monitor and take a screenshot of it, then post the pic here.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 31, 2015, 12:04 am
Yeah it's set to 115200. Are there any changes in software I need to do to make the code work? With the hardware?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 31, 2015, 12:28 am
So nothing is happening? OK, stupid question: do you have the right serial port chosen?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 31, 2015, 12:31 am
Yeah, I think its getting stuck somewhere in the update sensor value and its not coming out. Not a bad question, but I did verify the serial port. 
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 31, 2015, 01:52 am
I'm pretty sure my issues are coming from the gyro. Is there anything in the code that needs to be done to initialize the gyro? When I comment out updateSensorValue, the ESC's will keep beeping.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 31, 2015, 06:49 pm
Have you changed anything from the original sketch? If so, please post it here.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 31, 2015, 10:33 pm
Nope, it's all the same. I am using the MPU-6050 breakout board as the sensor. Is that not compatible with this?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on May 31, 2015, 11:06 pm
MPU-6050: I found code for that: https://github.com/itsdvw/BlueCopterClone (https://github.com/itsdvw/BlueCopterClone) but I do not know if it works.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on May 31, 2015, 11:43 pm
Awesome thanks! I'll give it a try and report back.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pnichols on Jun 01, 2015, 12:13 am
Well that seemed to have the same problem. Maybe I need a new chip. I think I was giving it 5v when I first started, and the data sheet says 3.3v. I think it's cooked so I'll try and get a new one. Thanks for your help!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Jun 01, 2015, 05:00 am
If you are going to get new sensors why not buy the recommended ADXL345 and L3G4200D sensors?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Jun 04, 2015, 06:01 am
Guess what I discovered! Bluecopter is the 3rd hit on Google if you look up "arduino quadcopter"!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Jun 22, 2015, 06:29 pm
When rateAngle is 0? Does that mean that it is on rate or angle?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jun 23, 2015, 11:18 am
Guess what I discovered! Bluecopter is the 3rd hit on Google if you look up "arduino quadcopter"!
Exciting isn't it =)?

When rateAngle is 0? Does that mean that it is on rate or angle?
It means it's on Angle.

/ Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Jakko on Jun 23, 2015, 07:57 pm
Hello Basel

Tested out your code today but can't seem to get the bluecopter code to talk with the Serial Monitor. Hell i don't even know if the rest works.

I changed



The code compiles without errors and everything.

What could be wrong?

I know Serial.Print works because i tested with my own code. I have the sensor but right now it's not even worth wiring it.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jun 24, 2015, 12:25 am
Tested out your code today but can't seem to get the bluecopter code to talk with the Serial Monitor. Hell i don't even know if the rest works.
Hey,

I'm assuming that you're using the exact same setup as me (Leonardo/micro board, ADXL345, L3G4200D).

There are three different places that the code can freeze, one of them is failed communications between the accelerometer/gyro through I2C. Other problems could be the following:

BlueCopter.ino
Code: [Select]
while(!Serial);
This line is waiting for the serial monitor to be opened. You can try to remove/comment that line and see if that solves the problem (even though I doubt it).


Motor.ino
Code: [Select]
while(rxVal[5]<1100){};
This line is the arming procedure. It means that motors won't turn on (freeze/wait) unless the throttle signal is over 1100us. Try and check that you're throttle signal is connected to the right port, after that try increasing the throttle slowly until the motors spins or serial monitor start throwing out the debug data. You can also disable the arming procedure by commenting the first line in Config.h (#define SAFE) (This is not recommended unless your motors are disconnected or your quadcopter secured).

In case the above fixes fail, check the connection between arduino and the sensors. To make sure that your sensors are working fine try googling for example sketches and try them with your current setup.

/ Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Jakko on Jun 24, 2015, 07:55 am
Hey,

I'm assuming that you're using the exact same setup as me (Leonardo/micro board, ADXL345, L3G4200D).

There are three different places that the code can freeze, one of them is failed communications between the accelerometer/gyro through I2C. Other problems could be the following:

BlueCopter.ino
Code: [Select]
while(!Serial);
This line is waiting for the serial monitor to be opened. You can try to remove/comment that line and see if that solves the problem (even though I doubt it).


Motor.ino
Code: [Select]
while(rxVal[5]<1100){};
This line is the arming procedure. It means that motors won't turn on (freeze/wait) unless the throttle signal is over 1100us. Try and check that you're throttle signal is connected to the right port, after that try increasing the throttle slowly until the motors spins or serial monitor start throwing out the debug data. You can also disable the arming procedure by commenting the first line in Config.h (#define SAFE) (This is not recommended unless your motors are disconnected or your quadcopter secured).

In case the above fixes fail, check the connection between arduino and the sensors. To make sure that your sensors are working fine try googling for example sketches and try them with your current setup.

/ Basel

Hello Basel

Sorry for not being totally clear about my situation but I'm trying to do this slowly so I can learn as much as possible. So right now I only got the sensor (Sensor Module Arduino L3G4200D ADXL345 HMC5883L BMP085 M9) and the Arduino Leonardo.

Right now I got nothing wired to the arduino leonardo, is that a problem? I tested just the sensor once but could'nt get any information in the serial monitor so i removed it and now I'm just trying to figure out whats wrong.

Best Regards




Title: Re: BlueCopter - Arduino Quadcopter
Post by: Jakko on Jun 24, 2015, 08:38 am
Basel I'm sorry but I'm an idiot...

I read endif as else and forgot to comment out some of the code in the main loop :( sorry for wasting your time.

I however would like to test out the sensor by debugging it, which "classes/functions" are needed for the sensor?

I got


Code: [Select]

void setup() {
#ifdef DEBUG  
  Serial.begin(115200);
  //while(!Serial);
  
#endif
  MPU.init();
  //motorInit();
  leds_init();
  //rxInit();
  //motorArm();
  PID_init();
  tp=millis(); //for updateSensorVal

}

void loop() {
  updateSensorVal();
  //FlightControl();
#ifdef DEBUG
  debugProcess();
#endif
}



But serial monitor is empty, If comment out //updateSensorVal(); the serial monitor spits out (GX:0.00 GY:0.00 GZ:0.00)

Am I missing something?

Best Regards



I finally got my sensor to spit some numbers! hurray! :) Someone uploaded a image how to wire the sensor but it was for Arduino UNO which was wrong for me since I'm using the Leonardo.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Jun 28, 2015, 06:28 am
How to know the offset of your accelerometer?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jun 29, 2015, 10:19 am
@Jakko: Glad it worked out for you.

@thagz: Place your quadcopter on a flat surface. Print the following variables with Serial.print: accx_temp, accy_temp, accz_temp. You'll find these variables in Sensors.ino under updateAcc(). Use the printed numbers as your offsets.

Don't forget to zero out the offset macros before you do this (ACC_X_OFFSET, ACC_Y_OFFSET, ACC_Z_OFFSET)

/ Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Jun 30, 2015, 11:05 am
Thanks Basel,

So sorry to ask you this but is the angle 0 will be taking values like more than thousand? cause my one keep stacking until the number become so big. I saw this on printed values.

Thanks again.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: anshulsanam on Jul 05, 2015, 05:25 am

I designed a mini quadcopter which is about 4.5x4.5cm(Main Body). The main body is the PCB.

(http://i.stack.imgur.com/2TCry.jpg)

It weighs about ~20 grams with the battery. I'm using the MPU6050 with the DMP using the i2cDevLib. I am using raw radians for pitch, roll, and yaw these measures are read from the MPU6050's DMP. The motors are attached to the body using electrical tape(Black thing around motors). The motors are 8.5mm in diameter and are driven by a n-channel mosfet. The mode of control right now is bluetooth(HC-05 module). The code being used is my own. I have a control loop on all axes, the pitch and roll have the same values since the quadcopter is symmetrical. The problem I have is that PID tuning is next to impossible, the best I got was a ~2 second flight (Video in slow-motion).

At first I was using my own code for the control loop, but it wasn't as effective as the Arduino PID library.

The output of the PID loops are mapped to -90 to 90 on all axes. This can be seen in the code

myPID.SetOutputLimits(-90, 90); //Y angle   
myPID1.SetOutputLimits(-90, 90); // X angle
myPID2.SetOutputLimits(-90, 90); // Yaw angle
myPID.SetMode(AUTOMATIC);
myPID1.SetMode(AUTOMATIC);
myPID2.SetMode(AUTOMATIC);


My full code is attached, but what do you think the problem is?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Vladgone on Jul 15, 2015, 05:27 pm
Hi, can somebody help me ? I would like do the same project but i use ITG/MPU 3 axis, can i just modify the "sensor.ino " file and can someone  explain how that file (sensor.ino) work ? Sorry for the English. :)

Thanks
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Jul 18, 2015, 10:24 am
Hi anyone here had problem with the motors not spinning at the same rate. Are motors really have to be spinning at the same rate with this program?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: lacanau on Jul 18, 2015, 11:12 am
Hi anyone here had problem with the motors not spinning at the same rate. Are motors really have to be spinning at the same rate with this program?

I'm having the same problem. I guess it's impossible to have all the motors running at the same speed after you run current through them because of inherent variations in the physical design of them. Small as they may be.

My plan is to rig my quad with some rope and pulleys so that it cant fly off too far to the side anywhere and then play with the values until I'm happy.

What I really want however is for my MPU6050 (accelorometre, gryo) to be able to recognise the tilt and compensate for it. That would be the best design I reckon. If you don't have one / aren't plannign on using one then probably it's best to just play with the values until you are happy.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Jul 20, 2015, 10:34 am
But if you got unbalanced motor output, would it not lead to unreliable PID Values?
 
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Jul 20, 2015, 09:21 pm
Is this possible to be done by a small quad? the problem i got is that the values of my PID wont oscillate if it is lesser than 0.1, but after doing so, the quad only can output small value for motors after coming back from pid algorithm.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jul 22, 2015, 09:48 am
thagz: Which values are you printing? The code works fine with ordinary to small quadcopters.

To the others, I can try to answer questions about the BlueCopter code. I cannot and do not have the time to read a highly customized code or create any tutorials at the moment.

/ Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Jul 24, 2015, 10:44 am
I found out the problem is not on pid but instead on the polarity of my aux2 which is for rate angle switch. Really sorry. Anyways does the gyroscope change values on different places? When I calibrate it inside my lab it was okay, but after I go out it is not the same numbers. Shouldn't I expect for a zero on my start up? Is there any possible way why I cannot raise my pid values for roll and pitch above 0.1? And how should I proceed on tuning the yaw axis?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Jul 29, 2015, 02:36 pm
Basel, Is the accelerometer z axis really unstable? im getting like real big fluctuation. Anyways does the PID values you got can be used for small quad? if so my quad is really oscillating even though it is really as low as  0.1 for P, 0.011 for D and 0.004 for I, this is for my PITCH AND ROLL, and Yaw got 0.1 -P and 0.002 for I. Im stuck at tuning this.
One more thing the moving average filter, if it is equals 2, does that mean that the update rate equals to 400hz, if i raise it to 4, does that mean that Am I actually dividing the update rate by 4??
Title: Re: BlueCopter - Arduino Quadcopter
Post by: baselsw on Jul 30, 2015, 09:35 am
@thagz: Read my post here: http://forum.arduino.cc/index.php?topic=184503.msg1413036#msg1413036

and also read my post here: http://forum.arduino.cc/index.php?topic=184503.msg1416196#msg1416196


/ Basel
Title: Re: BlueCopter - Arduino Quadcopter
Post by: thagz on Jul 30, 2015, 12:22 pm
I got it lift off already with a bit of fast oscillation. After this, once i get the rate mode right then thats when i go for angle mode?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: tarkesh2shar on Oct 26, 2015, 09:10 pm
hey guys ,
i am.working on a quadcoptor,using xbees for wireless control ,i have been successful  in setting accelerometer (adxl345),using PID library for my quadcoptor ,i am now planning  to use Mpu 6050 6axis chip ,getting the Gyrometer data ,the only problem is how to get these two sensors working together  ,and the PID  integrated  into both these sensors, and yeah i get a little noise in accelerometer angle ,just need an outer view ,thnks guys
Title: Re: BlueCopter - Arduino Quadcopter
Post by: ayaki34 on Oct 29, 2015, 11:23 pm
im  trying made a quadcopter,  I ordered the same materials as your quadcopter and MultiWii  ATmega32U4 Micro Flight Controller and i ll try to fly it. after that i ll try to write my own code  if i use MultiWii  ATmega32U4 Micro Flight Controller or others for quadcopter with your code, will it work? otherwise, what should i do?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: bisuhrs15 on Nov 01, 2015, 05:09 am
Could you please share a schematic of the code given in "https://github.com/baselsw/BlueCopter"?my email id = bisuhrs15@gmail.com
Title: Re: BlueCopter - Arduino Quadcopter
Post by: bisuhrs15 on Nov 01, 2015, 05:25 am
Could you please send the schematic of the code given in "https://github.com/baselsw/BlueCopter"
in email id : bisuhr15@gmail.com
Title: Re: BlueCopter - Arduino Quadcopter
Post by: fierywinter on Nov 17, 2015, 07:18 am
Is there  a way this code could be adapted to accept straight Pitch and Roll?  I have already created code which generates this (including Yaw), and don't want to go back and reinvent any wheel. 

Thank you in advance for your help, this project is amazing  and has helped many individuals out. :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: michalbanan on Dec 26, 2015, 07:17 pm
Hello
I know u already have explained how your PID control loops are working. I am a little bit confused about implementing angle mode. I am trying to do my own flight controller using ArduinoUNO. I have managed to do rate mode controller and everything seems to work perfect. Now its time to control quad using angles, not angular rate.
I have mapped my transmitter values to range of <-30;30> (degrees) and use it as PID inputs. Then after calculating PID outputs my angle controller feeds inputs of my already tuned PID rate controller.
I have used refresh rate of calculating angular velocities using gyro (250Hz) and angle with accelerometer (50Hz).
Am i thinking right way?
I will post some code (pitch angle controller) to let you understand what i have done.
Code: [Select]

//ANGLE PID
pid_pitch_setpoint = map(receiver_input_channel_2, 1000, 2000, -30, 30);
...
CALCULATING PID OUTPUT
...
pid_pitch_stab_output = pid_p_gain_stable_roll * error + pid_i_mem_roll + pid_d_gain_stable_roll * (error - pid_last_roll_d_error);

//RATE PID
error = pid_pitch_stab_output - gyro_pitch;
...
CALCULATING PID OUTPUT
...
 
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Judlet on Dec 27, 2015, 03:05 am
I can't upload the code to my Arduino UNO because there are so many ERRORs HELP!

thanks,
-JUDLET
Title: Re: BlueCopter - Arduino Quadcopter
Post by: mrarmyman on Jan 01, 2016, 01:53 am
Hey baselsw,

I want to say great job on the project. It is by far one of the best DIY projects that I could find out there! I just have one question. Did you have any issues with timing in terms of PID updates and motor updates? I have a very similar code base and I have issues getting my quad to balance, especially in angle mode. I'm using the Arduino UNO + MPU6050 and using the internal DMP algorithm to determine the the angles. However I noticed that no matter what PID values I try in angle mode it simply starts oscillating with increasing amplitude. I've checked all the signs and the motors fight movements in each direction, so it is not positive feedback. I'm hypothesizing that the either my ESCs are not able to handle updates (300+Hz) or I'm just not computing PIDs fast enough.

EDIT: Also I'm using pin change interrupts for the receiver, I wonder if that is interrupting the PID/motor updates.

Any hints would be appreciated.
Thanks in advance!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: yashshah99 on Mar 05, 2016, 10:39 am
when the quadcopter is at angle mode does it use the angular rate for better satbility???
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Mar 11, 2016, 01:46 am
In angle mode, the quad is self-leveling. Therefore, it is easier to fly. In rate mode, the stick controls the pitch/roll speed instead of angle, and so it can do flips and stuff like that.
OMG! Edison! :) :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Thanos9456 on Mar 12, 2016, 08:53 pm
One question would like me to do about FlightCtrl.ino,apply that

"Volatile int rxVal [6] = {1500,1500,1500,0,0,1000};" => "Volatile int rxVal [6] = {yaw, roll, pitch, aux1, aux2, throttle};"

Writes in FlightCtrl.ino:

if (rxVal [4] <1500) {     =====> rxVal[4] = value aux2
     rateAngleSwitch = 0;
     leds_status (0);
   }
   else {
     rateAngleSwitch = 1;
     leds_status (1);
     PIDangleX.resetI ();
     PIDangleY.resetI ();
   }

where compares the value of aux2,what is the aux2 where they get that value??Where is the aux2 at transmitter??

Thanks in advance!
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Mar 13, 2016, 09:21 pm
Aux2 is a 6th channel. It can be controlled by a knob or switch. I use Aux 1 and Aux 2 for flaps and gear on planes.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Thanos9456 on Mar 13, 2016, 09:57 pm
Thanks isaac96,so with the aux2 chooses mode using for bluecopter??
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Mar 22, 2016, 01:29 am
Yup. Hopefully  :)
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Mahdouch_Mab on Jul 06, 2016, 11:42 am
hi,
Thank you for sharing us your quadcopter firmware.
it 's very simple for reading but i'm not understand some lines like :
"RX_PIN_YAW,RX_PIN_ROLL,RX_PIN_PITCH,RX_PIN_AUX1,RX_PIN_AUX2,RX_PIN_THROTTLE"
Is this the communication between the RC receiver and the arduino??
thank you. 
 
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Jul 12, 2016, 08:02 pm
Yes it is. 
Some RXs have a TAER channel order, while others output AETR.
(Throttle, Aileron, Elevator, Rudder, then Aileron, Elevator, Throttle, Rudder)
Hook up a couple of servos to check.

Title: Re: BlueCopter - Arduino Quadcopter
Post by: mexpi on Aug 23, 2016, 09:55 am
Hi, all!
I'm trying to make this project to run on my quad, but  i can't get the same gyro/acc (i'm using arduino micro)  :smiley-confuse: , instead i'm using MPU6050 combo gyro/acc i looked trough all post  and saw some of you trying it with the same sensor, can any of you help me to change the code so it can work with MPU6050. I have less than 3 weeks to make it work its my final year project, so i will really appreciate your help!!
Thank you in advance !  
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Aug 23, 2016, 04:42 pm
multiwii.com
Title: Re: BlueCopter - Arduino Quadcopter
Post by: mexpi on Aug 23, 2016, 07:09 pm
multiwii.com
thanks but no. :D i don't like the multiwii i used it for fun and that's it. After tweaking around i managed to set my MPU  but when  start the  serial monitor to check if i get proper readings from it  serial monitor shows me only  the reversed  defined offsets :

Code: [Select]
#define ACC_X_OFFSET  19
#define ACC_Y_OFFSET  7
#define ACC_Z_OFFSET  -73

and also i used the mpu6050_raw  example to get the acc and gyro values
 accelgyro.getAcceleration(&ax, &ay, &az);
 accelgyro.getRotation(&gx, &gy, &gz);

    Serial.print("a/g:\t");
    Serial.print(ax); Serial.print("\t");
    Serial.print(ay); Serial.print("\t");
    Serial.print(az); Serial.print("\t");
    Serial.print(gx); Serial.print("\t");
    Serial.print(gy); Serial.print("\t");
    Serial.println(gz);


maybe the problem comes from the fact that there is no data stored in the buffer and  when in the following line the code subtracts the offset values thas why i get the revers values

 
Code: [Select]
buffer[0]=buffer[0]-ACC_X_OFFSET;
  buffer[1]=buffer[1]-ACC_Y_OFFSET;
  buffer[2]=buffer[2]-ACC_Z_OFFSET; 


i will mess around with it till morning and hopefully will make it work and again i will really appreciate any  help or tips 
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Aug 23, 2016, 07:33 pm
thanks but no. :D i don't like the multiwii i used it for fun and that's it. 
???
Pointless. Why use this? Multiwii is better and easier to customize.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: mexpi on Aug 23, 2016, 09:47 pm
It will be overkill and when the time comes to  show my thesis in front of the professors, they sure will be pleased with my "effort" to  upload some ready made code .... true while using the blue copter one isn't much different but i can say  hare and there i did some stuff beside of assembling the drone and making my own pcb for the  FC ...
Title: Re: BlueCopter - Arduino Quadcopter
Post by: AliceTayllor on Sep 16, 2016, 01:24 am
If you need some help on this touchy subject, here is an article that might help http://mydronelab.com/blog/arduino-quadcopter.html
Title: Re: BlueCopter - Arduino Quadcopter
Post by: umar9192 on Oct 12, 2016, 09:31 am
-- Pretty high.. I didn't measure the distance yet.. But it's so high that it starts to look like a small fly in the sky (cant see the orientation of the quad, nothing)..
-- I'm using a double 2200mAh (3 cells, LiPo, coupled in parallell).. It gave me approx. 15min of flight..
-- Well I lost contact with it when I pushed the throttle to the max! (meaning it flew very high).. Nothing special happens.. It will stay leveled in the air until battery begins to run out, and it will descend (depending on the ESC ur using, it can descend slowly(ESC cutting power slowly) or it will suddenly stop (ESC cuts the power alltogether)).

And here's my parts list (all from hobbyking.com):


Item/PartPcs
20CM Male to Male Servo Lead (JR) 26AWG (10pcs/set)
1
Hobby King 2.4Ghz 6Ch Tx & Rx V2 (Mode 2)
1
Turnigy 2200mAh 3S 25C Lipo Pack
2
NTM Prop Drive 28 Series Accessory Pack
4
Hobby King Quadcopter Power Distribution Board
1
NTM Prop Drive 28-26 1350KV / 310W
4
HobbyKing 30A BlueSeries Brushless Speed Controller
4
Hobbyking X666 Glass Fiber Quadcopter Frame 666mm
1
8045 SF Props 2pc Standard Rotation/2 pc RH Rotation (Blue)
1


And consider buying spares of ex. propellers and such (if you're a beginner you'll need it)..

//Basel
how to connect the Power Distribution Board to the arduino
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Oct 23, 2016, 08:14 pm
The PDB is what connects the speed controllers to the battery. If the PDB has a 5V output, connect that to the 5V and GND pins on the Arduino.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: rryba on Dec 09, 2016, 10:04 pm
Hello, i am building a 3dof helicopter standpoint, maybe could you help me ? I got problem with PID regulator, when pitch angle reach 0 value (its a setpoint), output form regulator sets PWM to 0 too. As a result i got oscilation all the time and cant stabilize helicopter.  I think about 2 states of regulator, first to start and second to stabilize with seted output limits on some PWM value. How do you solved taht problem ?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Jan 14, 2017, 04:12 am
Helicopter? This code is for a quad.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: nadaanas1988 on Jan 14, 2017, 04:16 pm
Hi Basel

I want to ask you if I'm going to use arduino mega2560 can I use your code.

I have this firm for my drone can I deal with it as a quadcopter?

Thank you
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Jan 26, 2017, 01:17 am
Somebody else made a Mega quad. Honestly, just use Ardupilot. It is full-featured and supports GPS and alt. hold and waypoints.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: pysdave on Feb 01, 2017, 09:59 am
what kind of arduino ? i have here arduino uno
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Feb 13, 2017, 04:40 am
Ardupilot runs on a Mega, but the official board is better. It has built-in sensors, some have GPS, and it has a PPM/PWM decoder chip as well. It can do waypoints and autonomos flight.
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Quadrone123 on Mar 06, 2017, 02:41 am
What changes would you make to the code if you are using an Arduino uno, I tried changing the #define values to match the pin # but that didnt work.(I probably did something wrong) Also I'm working with a MPU6050 where would I attach that to on the board?
Title: Re: BlueCopter - Arduino Quadcopter
Post by: Isaac96 on Mar 22, 2017, 04:40 am
I changed the code to use GreyGnome's EnableInterrupt library. PM me and I'll post it from my other device.
I think it also uses the MPU6050. However, I have no idea if it will work at all.