Pages: 1 [2] 3 4 ... 20   Go Down
Author Topic: BlueCopter - Arduino Quadcopter  (Read 100774 times)
0 Members and 2 Guests are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Sweden
Offline Offline
Sr. Member
****
Karma: 13
Posts: 257
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

tnx . i mean it !!!! im working on it . and if goes wrong i will come and bothering you again . tnx
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#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 ?
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

smiley-grin 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
Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 13
Posts: 257
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

smiley-grin 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:
#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
« Last Edit: September 08, 2013, 10:29:38 am by baselsw » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 13
Posts: 257
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..?
« Last Edit: September 08, 2013, 01:42:13 pm by baselsw » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Sweden
Offline Offline
Sr. Member
****
Karma: 13
Posts: 257
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yummmyyyyyy it seem work fine in the scope .... its late here and i cant start esc's bbeeping in home smiley-grin 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
Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 13
Posts: 257
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

France
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice work!  smiley
 
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), 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  smiley :
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!

Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 13
Posts: 257
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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



* FlightControl_Explained.png (53.26 KB, 1004x1363 - viewed 668 times.)
« Last Edit: October 01, 2013, 02:51:03 pm by baselsw » Logged

Pages: 1 [2] 3 4 ... 20   Go Up
Jump to: