Greg Abdo / Mbed 2 deprecated quadCommand

Dependencies:   mbed PID MMA8451Q

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers quadCommand.h Source File

quadCommand.h

00001 /************************* quadCommand.h *********************************/
00002 /*                                                                       */
00003 /*************************************************************************/
00004 
00005 #ifndef QUAD_COMMAND_H
00006 #define QUAD_COMMAND_H
00007 
00008 #include "mbed.h"
00009 #include "motor.h"
00010 #include "com.h"
00011 #include "sensors.h"
00012 #include "PID.h"
00013 
00014 #define TRIM_VALUE .05
00015 
00016 // Motor constants.
00017 #define MOTOR1              PTD4        // Pin used for motor 1.
00018 #define MOTOR2              PTA12       // Pin used for motor 2.
00019 #define MOTOR3              PTA4        // Pin used for motor 3.
00020 #define MOTOR4              PTA5        // Pin used for motor 4.
00021 
00022 // Xbee constants.
00023 #define TXPIN               PTA2        // Pin used for xbee TX.
00024 #define RXPIN               PTA1        // Pin used for xbee RX.
00025 
00026 
00027 // Sensor constants.
00028 #define MMA8451_I2C_ADDRESS (0x1d<<1)   // Address of I2C accelerometer.
00029 #define ACCSDA              PTE25       // Pin for accelerometer SDA line.
00030 #define ACCSCL              PTE24       // Pin for accelerometer SCL line.
00031 
00032 // PID constants.
00033 #define DEFAULT_WINDUP_GUARD 5.0        // Integral windup.
00034 #define PID_P 2.0                       // Proportional gain.
00035 #define PID_I 0.0                       // Integral gain.
00036 #define PID_D 0.0                       // Derivative gain.
00037 #define MOTOR_UPDATE       150.0        // Motor update speed.
00038 
00039 class quadCommand 
00040 {
00041     public:
00042         quadCommand();                  // Constructor.
00043         void run();                     // The main loop.
00044         void rxInput();                 // Receive data from the Xbee.
00045         void updateMotors();            // Send PID values to the motors.
00046         void updateCurrent();           // Update the current telemetry.
00047         
00048     private:
00049         motor *myMotors[4];             // Array of motor objects.
00050         com *myCom;                     // The com object for Xbee communication.
00051         sensors *world;                 // Sensors used to observe the world.
00052         
00053         PID *pidPitch;                   // PID for pitch.
00054         PID *pidRoll;                    // PID for roll.
00055         PID *pidYaw;                     // PID for yaw.
00056         
00057         Ticker motorProcess;            // Timer for updating the motors.
00058 
00059         float currentThrottle;          // Current throttle.
00060         float currentPitch;             // Current pitch.
00061         float currentRoll;              // Current roll.
00062         float currentYaw;               // Current yaw.
00063         
00064         float pitchTrim;                // Trim the pitch.
00065         float rollTrim;                 // Trim the roll.
00066         float yawTrim;                  // Trim the yaw.
00067         
00068         float targetThrottle;           // Desired throttle.
00069         float targetPitch;              // Desired pitch.
00070         float targetRoll;               // Desired roll.
00071         float targetYaw;                // Desired yaw. 
00072 };
00073 
00074 #endif