Pages: [1]   Go Down
Author Topic: Controlling quadcopter over serial  (Read 917 times)
0 Members and 1 Guest are viewing this topic.
Finland
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!

My question is in my arduino site, because it was too long to this forum. http://eliasarduino.wordpress.com/2013/05/21/question-about-quadcopter-serial-code/

Please don't take care of   Wordpress made them for some reason.

Thank you for help!
Logged

Elias Ojala

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3632
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If I download that code to arduino it works fine, but if I download the whole quadcopter code with gyroscope and accellometer I can only send one time pwm value over serial to arduino.
It sounds to me that it is doing a lot of processing, (not surprised though), that is a lot of code.

Can you make it a little more friendly on the eyes? Better yet, put it in the proper format and make it an attachment. Do it for both the good code and the bad one.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26324
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(pin == 03)
Why octal?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

Is this better now?

* gyro_quadcopter_2.ino (10.78 KB - downloaded 21 times.)
Logged

Elias Ojala

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

Quote
Code:
if(pin == 03)
Why octal?

What do you mean with octal? And code which contains
Code:
if(pin == 03)
works fine.
Logged

Elias Ojala

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3632
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes. Im able to compare your two codes and I noticed that the "bad one" is using an array to collect the data and then convert it, while the working on just gets a '1', '2' ... directly.

Also the bad one has a lot more Serial.prints, which will slow down the arduino's serial communication. Using an array is fine, in fact it is perferred, but you need to know how to send, receive and distribute the data correctly. Try something small scale and see if you can send data from the serial monitor to the arduino and have it split the data and send it back.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Mid-Atlantic, USA
Offline Offline
God Member
*****
Karma: 30
Posts: 515
"Remember kids, the only difference between Science and screwing around is writing it down." - Adam Savage
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
if(pin == 03)
Why octal?

What do you mean with octal? And code which contains
Code:
if(pin == 03)
works fine.

He is asking (yet not explaining why he is asking for the uninitiated) why you are using an octal (base 8 ) value. This is because standard C syntax states that any numeric values that start with a zero which is not followed by an 'x' or a 'b' is interpreted as octal. In your case it really doesn't matter that much (but can lead to a bad habit) because the actual value is less than 8, but if you had 011 then that would equate to 9 in decimal, so 011 + 03 would equal 12 (in decimal), not 15. It's not quite defined (meaning different compilers may handle it differently) what would happen if you used 08 or 09. Some compilers may choke on this seemingly inexplicably unless one is familiar with octal notation, and others may assume that the coder really meant decimal and not mention the possible bad interactions if the bad habit isn't corrected.

(Too bad octal notation hasn't been depreciated into oblivion. It's use is such a special case now that most people group binary into sets of 4 bits instead of sets of 3 bits.)
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26324
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
yet not explaining why he is asking for the uninitiated
It's a useful technique for calibrating the level of "initiation".
There may have been a reason for the use of octal  (DEC background?) - I wanted to find that reason.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Mid-Atlantic, USA
Offline Offline
God Member
*****
Karma: 30
Posts: 515
"Remember kids, the only difference between Science and screwing around is writing it down." - Adam Savage
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
yet not explaining why he is asking for the uninitiated
It's a useful technique for calibrating the level of "initiation".
There may have been a reason for the use of octal  (DEC background?) - I wanted to find that reason.

I've never used it, but it was demonstrated to me in classes (in the '90s) as used with 6-bit processors (so, yeah, old PDPs). With a 6bit processor, two octal digits is used just like we use 2 hex digits with 8bit processors. But that is all pretty much ancient history as far as computers and technology anymore. Even our language is sets-of-4 centric: nibble == 4 bits, byte == 2*4 bits, etc. I have no idea what 3 bits or 2*3 bits are or were called.

As interesting as it is, this history lesson is probably drifting way off target for this thread on quadcopters. Oooo.. I just thought of a modern use for octal... motor on/off state flags for a tri-copter. (Yay! That's a little closer to the thread topic...) Maybe not... smiley-razz
Logged


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

Thank you for your answers! No everything works fine. I changed 02 to '2' and 03 to '3' etc. Ready code is in attachment.

* gyro_quadcopter_2.ino (10.65 KB - downloaded 18 times.)
Logged

Elias Ojala

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26324
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int pin = Serial.read();
      char buffer1[] = {' ',' ',' '}; // Receive up to 3 bytes
      while(!Serial.available());
      Serial.readBytesUntil('\n', buffer1, 3);
      int pwm = atoi(buffer1);
This is worrying.
I don't think "readBytesUntil" terminates the array and you aren't terminating it explicitly, so it isn't valid to call "atoi".

I think a clean-up of code, concentrating on better (and correct) use of arrays would result in much shorter code - can you see how code like
Code:
if(pin == '2') {
        pwm2 = pwm;
        Serial.print("2: ");
        Serial.println(pwm2);
repeats with only tiny differences? Some arrays would sort that out, and make it easier to concentrate on the real issues.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: