Hi All!

I have been working on creating my first drone. I began this project by testing my own arduino based PID controller. Then I moved on to actually installing the PID and accelerometer/gyroscope into an RC glider to test for level flight (http://www.instructables.com/id/Intro-to-Model-Airplane-Autopilot/). I am moving on to a powered plane(I am starting with an E-flite UltraStick, and moving on to a water plane I have built once I have successful beta testing). I want to use cascading PIDs and a GPS to set the attitude my plane needs to reach desired waypoints. 

The problem is: my accelerometer and gyroscope refresh at about 20Hz while my GPS only refreshes at about 1Hz- I am using a parallax PMB 648, a cheapy, I know. In my loop function I tell the controller to get the accelerometer/gyroscope data (which comes in almost instantly), and then I have to wait a full second for the GPS data. So the plane would be unable to monitor and control its attitude while the GPS is refreshing. Is there a way to solve this problem without buying a faster GPS??

I tried setting up an interrupt function last night, but I couldjnot get it to work. In addition, the GPS communicates with the arduino serially, and from what I have heard this is not ideal for setting up interrupts. 

Any help would be much appreciated!!!

Thanks

Views: 531

Reply to This

Replies to This Discussion

Your best bet is to think hard about what is happening and when.

Use paper and pencil to figure it out, cycle by cycle through the loop until you get the pattern of what is happening.

You say the GPS was refreshing more than once per second. Are you sure it wasn't just processing your print statement every time it read a single character? ;) Perhaps you should've scheduled a print/update task to run every 200-1000 ms ?

Again, write down, think through, fully understand what is happening and when. Figure out precisely when you want things to happen, then determine how to code it to do that.

You say refresh rate is excellent. What's that based on, serial output? Ok that's fine for a human reading the info. But that doesn't guarantee the timings are right for calculating anything.  Is it running the code on a proper schedule? It has to if you want to have any hope of correctly calculating time-dependent variables, like calculating heading from heading rate (gyro).

The expression (now%100)>0 means that it will run anytime millis() isn't a multiple of 100. So it will run at least once every millisecond except at 100, 200, 300, 400, ...  In other words 197, 198, 199, 201, 202, ... 298, 299, 301, 

Is that really what you wanted?

If not, spend time understanding how modulo works. Write test code on a more accessible platform; like C, Perl, Python, etc., on your PC.

If you want a task to run every 100ms there's a few ways to do it. Modulus (remainder) is what I've used in the past.

I used the expression if ((timeNow % 100) == 0) because it evaluates true at multiples of 100. If you want to run something every 100ms but at say 150, 250, 350, 450...  use ((timeNow % 100) == 50)

I wrote a perl script to demonstrate this.

http://pastebin.com/ejjpK6Ew

You can use that to play around more to better understand modulo and scheduling tasks.

Meanwhile here's a quiz :D Let's say I have something like this:

void loop () {

int timeNow = millis();

if ((timeNow%10) == 0) do1();

if ((timeNow%20) == 0) do3();

}

How often will do1() and do2() run if...

  • do1() takes 20 milliseconds to execute and do2() takes 1ms to operate?
  • do1() takes 1ms and do2() takes 20ms?
  • do1() and do2() take 0.1 millisecond to run?

Hm, I think I'm going to have to write a blog article about this topic...

I timed all of my functions to see how long they would take to run. I was almost ready to set up the duty cycles like you said, when I ran into a new problem!
I know I am getting a little off topic here, but I need help...
I tried mounting my sensors to the plane to make sure I would not have issues with electronic interference. As it turns out, I am having mechanical interference. When I hold the sensors above the plane, no problems. As soon as the sensor make contact with the plane with the motor running, my sensor values go all over the place. What should I do!!!
I am leaving for a trip to Idaho next weekend, where I was planning the maiden flight of my system. If need be I can order new sensors to be delivered to our property...
I am using some osepp brand sensor I bought from frys. They run an ADXL345 (accelerometer) and MPU 3050(gyroscope).
I wrote a program to try and filter the values. I filled an array of the 20 previous values and took the median. This worked on an earlier project but is no longer sufficient. In addition, it creates a sizable delay in my sensor values...
What should I do?

RSS

Social Networking

Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

Groups

Advertisement

© 2013   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service