Go Down

Topic: Controlling quadcopter over serial (Read 1 time) previous topic - next topic

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!
Elias Ojala

HazardsMind

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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

AWOL

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

Elias Ojala

Quote

Code: [Select]

if(pin == 03)

Why octal?


What do you mean with octal? And code which contains
Code: [Select]

if(pin == 03)
works fine.
Elias Ojala

HazardsMind

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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Sembazuru


Quote

Code: [Select]

if(pin == 03)

Why octal?


What do you mean with octal? And code which contains
Code: [Select]

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.)
http://www.catb.org/jargon/html/I/I-didn-t-change-anything-.html

AWOL

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

Sembazuru


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... :P
http://www.catb.org/jargon/html/I/I-didn-t-change-anything-.html

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

AWOL

Code: [Select]
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: [Select]
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.
"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.

Go Up