Quadcopter flight controller problem! please help!

Hello everybody!
I am making my first Quad and I decided to program the flight Controller myself using snippets of published code in hope to learn a thing or two. I am almost finished with the code, however I ran into a problem that I have been unable to solve.

When I have the arduino plugged into my CP via USB cable, the PID calculations run on the Motors, however as soon as I plug the Lithium Polymer battery in, I can only run the motors without the gyro readings. That also makes the PID calculations useless.

Does anyone know why I can't run the motors and read the gyro at the same time?

I thank you in advance for your help!

Chris

Here is the code that I'm using. (Mostly combinations of published code)

gyro_test_4.ino (3.65 KB)

pid_calc.ino (1.24 KB)

update_gyro.ino (3.55 KB)

update_motors.ino (873 Bytes)

the PID calculations run on the Motors

What kind of Motors do you have that can perform PID calculations?

Does anyone know why I can't run the motors and read the gyro at the same time?

How do you know you can't?

Motors: 920kv Multistar Elite

What I meant was that I can see the calculations sending the correct pulse to the motors in the Serial Port, however , the Motors don't react to the pulse unless i take the Sensor readings away from the program.

Timer conflict? I'd suggest checking over your libraries to see what timers are being used. If two separate libraries are trying to use the same timer then that is of course bad.

That is a concern of mine. However, I wasn't able to find too much out other than that the Servo library has a 16 bit timer.

It's going to depend on the chip in use. Below is from the file named "ServoTimers.h" which will be included with your Arduino IDE:

// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define _useTimer5
#define _useTimer1
#define _useTimer3
#define _useTimer4
typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t;

#elif defined(__AVR_ATmega32U4__)
#define _useTimer1
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;

#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
#define _useTimer3
#define _useTimer1
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t;

#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
#define _useTimer3
#define _useTimer1
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t;

#else  // everything else
#define _useTimer1
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;
#endif

I don't see where (in Servo.cpp) there's an option to disable or use a different timer; I think the best course in that regard would be to manually edit ServoTimers.h.

I'd expect you'll see similar code blocks in your sensor libraries. Just dig through the code, find out what timers they are using, then ensure that all of your libraries are using separate timers.

Thank you for the help! I'll keep nagging at it until I find the timer Problem.. However, it is confusing that there doesn't seem to be a Problem UNLESS my Lithium battery is plugged in. The Motors move very slow when it is connected via USB because of the lack of power, however they work accordingly. Wouldn't the timer issue be playing a role there as well?

What model Arduino are you using? How many cells in your LiPo? How do you power the Arduino from the LiPo?