Latest version of my quadcopter controller with an LPC1768 and MPU9250.

Dependencies:   mbed

Currently running on a custom PCB with 30.5 x 30.5mm mounts. There are also 2 PC apps that go with the software; one to set up the PID controller and one to balance the motors and props. If anyone is interested, send me a message and I'll upload them.

Committer:
Anaesthetix
Date:
Tue Jul 31 20:36:57 2018 +0000
Revision:
8:981f7e2365b6
Parent:
0:0929d3d566cf
Switched from Madgwick to Mahony as I'm having trouble with slow oscillations caused by the madgwick filter. Fixed an error on the PID algorithm also.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anaesthetix 0:0929d3d566cf 1 #pragma once
Anaesthetix 0:0929d3d566cf 2
Anaesthetix 0:0929d3d566cf 3 // This is a buffered serial reading class, using the serial interrupt introduced in mbed library version 18 on 17/11/09
Anaesthetix 0:0929d3d566cf 4
Anaesthetix 0:0929d3d566cf 5 // In the simplest case, construct it with a buffer size at least equal to the largest message you
Anaesthetix 0:0929d3d566cf 6 // expect your program to receive in one go.
Anaesthetix 0:0929d3d566cf 7
Anaesthetix 0:0929d3d566cf 8 class SerialBuffered : public Serial
Anaesthetix 0:0929d3d566cf 9 {
Anaesthetix 0:0929d3d566cf 10 public:
Anaesthetix 0:0929d3d566cf 11 SerialBuffered( size_t bufferSize, PinName tx, PinName rx );
Anaesthetix 0:0929d3d566cf 12 virtual ~SerialBuffered();
Anaesthetix 0:0929d3d566cf 13
Anaesthetix 0:0929d3d566cf 14 int getc(); // will block till the next character turns up, or return -1 if there is a timeout
Anaesthetix 0:0929d3d566cf 15
Anaesthetix 0:0929d3d566cf 16 int readable(); // returns 1 if there is a character available to read, 0 otherwise
Anaesthetix 0:0929d3d566cf 17
Anaesthetix 0:0929d3d566cf 18 void setTimeout( float seconds ); // maximum time in seconds that getc() should block
Anaesthetix 0:0929d3d566cf 19 // while waiting for a character
Anaesthetix 0:0929d3d566cf 20 // Pass -1 to disable the timeout.
Anaesthetix 0:0929d3d566cf 21
Anaesthetix 0:0929d3d566cf 22 size_t readBytes( uint8_t *bytes, size_t requested ); // read requested bytes into a buffer,
Anaesthetix 0:0929d3d566cf 23 // return number actually read,
Anaesthetix 0:0929d3d566cf 24 // which may be less than requested if there has been a timeout
Anaesthetix 0:0929d3d566cf 25
Anaesthetix 0:0929d3d566cf 26
Anaesthetix 0:0929d3d566cf 27 private:
Anaesthetix 0:0929d3d566cf 28
Anaesthetix 0:0929d3d566cf 29 void handleInterrupt();
Anaesthetix 0:0929d3d566cf 30
Anaesthetix 0:0929d3d566cf 31
Anaesthetix 0:0929d3d566cf 32 uint8_t *m_buff; // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end
Anaesthetix 0:0929d3d566cf 33 uint16_t m_contentStart; // index of first bytes of content
Anaesthetix 0:0929d3d566cf 34 uint16_t m_contentEnd; // index of bytes after last byte of content
Anaesthetix 0:0929d3d566cf 35 uint16_t m_buffSize;
Anaesthetix 0:0929d3d566cf 36 float m_timeout;
Anaesthetix 0:0929d3d566cf 37 Timer m_timer;
Anaesthetix 0:0929d3d566cf 38
Anaesthetix 0:0929d3d566cf 39 };
Anaesthetix 0:0929d3d566cf 40