Derek McLean / Mbed 2 deprecated uwb-quadcopter

Dependencies:   mbed ESC SR04 TSI

Committer:
gabdo
Date:
Sun Jun 09 02:41:27 2013 +0000
Revision:
32:d2b973c8d196
Updated June 8 2013

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gabdo 32:d2b973c8d196 1 /******************************* com.h ***********************************/
gabdo 32:d2b973c8d196 2 /* Version: 1.0 */
gabdo 32:d2b973c8d196 3 /* Last Updated: June 1, 2013 */
gabdo 32:d2b973c8d196 4 /* */
gabdo 32:d2b973c8d196 5 /* The com class implements reliable data transfer between two nodes */
gabdo 32:d2b973c8d196 6 /*using a checksum and a sequence number for guaranteed message delivery */
gabdo 32:d2b973c8d196 7 /*over an xbee modem connected to the passed in tx and rx pins. Messages */
gabdo 32:d2b973c8d196 8 /*are received and placed in the rxBuffer to be read when convenient. */
gabdo 32:d2b973c8d196 9 /*Messages are encoded by sending a byte with the value of the command */
gabdo 32:d2b973c8d196 10 /*then and int of the command. */
gabdo 32:d2b973c8d196 11 /* */
gabdo 32:d2b973c8d196 12 /* Commands: 0 -> Ack, does not get placed in rxQueue. */
gabdo 32:d2b973c8d196 13 /* 1 -> Throttle */
gabdo 32:d2b973c8d196 14 /* 2 -> Pitch */
gabdo 32:d2b973c8d196 15 /* 3 -> Roll */
gabdo 32:d2b973c8d196 16 /* 4 -> Yaw */
gabdo 32:d2b973c8d196 17 /*************************************************************************/
gabdo 32:d2b973c8d196 18
gabdo 32:d2b973c8d196 19 //Example code
gabdo 32:d2b973c8d196 20 //
gabdo 32:d2b973c8d196 21 //com myCom( PTD3, PTD2 ); // Setup the com port.
gabdo 32:d2b973c8d196 22 //
gabdo 32:d2b973c8d196 23 //while( true )
gabdo 32:d2b973c8d196 24 //{
gabdo 32:d2b973c8d196 25 // if( myCom.isData() )
gabdo 32:d2b973c8d196 26 // {
gabdo 32:d2b973c8d196 27 // char * command = myCom.read();
gabdo 32:d2b973c8d196 28 //
gabdo 32:d2b973c8d196 29 // if( command[0] == 1 )
gabdo 32:d2b973c8d196 30 // for( int i = 0; i < 4; i++ )
gabdo 32:d2b973c8d196 31 // myMotors[ i ]->setSpeed( command[2] );
gabdo 32:d2b973c8d196 32 // }
gabdo 32:d2b973c8d196 33 //}
gabdo 32:d2b973c8d196 34
gabdo 32:d2b973c8d196 35 #ifndef COM_H
gabdo 32:d2b973c8d196 36 #define COM_H
gabdo 32:d2b973c8d196 37
gabdo 32:d2b973c8d196 38 #include "mbed.h"
gabdo 32:d2b973c8d196 39 #include "queue.h"
gabdo 32:d2b973c8d196 40
gabdo 32:d2b973c8d196 41 const int BAUDRATE = 38400;
gabdo 32:d2b973c8d196 42
gabdo 32:d2b973c8d196 43 class com
gabdo 32:d2b973c8d196 44 {
gabdo 32:d2b973c8d196 45 public:
gabdo 32:d2b973c8d196 46 com( PinName, PinName ); // Setup the com serial port. (tx, rx)
gabdo 32:d2b973c8d196 47 bool isData(); // Is there data to be read?
gabdo 32:d2b973c8d196 48 void write( char, int ); // Write to the port.
gabdo 32:d2b973c8d196 49 char * read(); // Read from the queue.
gabdo 32:d2b973c8d196 50
gabdo 32:d2b973c8d196 51 private:
gabdo 32:d2b973c8d196 52 void callback(); // Handle the interrupts.
gabdo 32:d2b973c8d196 53 void packetBuilder(); // Called by callback to place commandes into the queue.
gabdo 32:d2b973c8d196 54
gabdo 32:d2b973c8d196 55 char buffer[50]; // Buffer for holding serial data.
gabdo 32:d2b973c8d196 56 int bLength; // Location in the buffer to place next data.
gabdo 32:d2b973c8d196 57 Serial xbee; // tx - DIN, rx - DOUT
gabdo 32:d2b973c8d196 58
gabdo 32:d2b973c8d196 59
gabdo 32:d2b973c8d196 60 queue *rxBuffer; // queue of commands ready to be read.
gabdo 32:d2b973c8d196 61 };
gabdo 32:d2b973c8d196 62
gabdo 32:d2b973c8d196 63 #endif