Pages: 1 ... 12 13 [14] 15 16 ... 20   Go Down
Author Topic: BlueCopter - Arduino Quadcopter  (Read 96602 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

I have been looking for some answers and finally I had some smiley 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:
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:
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
Logged

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

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

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


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

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

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
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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
Logged

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

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:
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!

Logged

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


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
Logged

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

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

Cheers,
Romain
Logged

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

Can you please post a youtube video to show how to do it step by step
from start
Please

Thanks
 smiley-eek
Logged

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

u have done a great job...........
Logged

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

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

-SnakoM

Pages: 1 ... 12 13 [14] 15 16 ... 20   Go Up
Jump to: