Colin Stearns
/
qcControl
QC Control software
Fork of dgps by
Revision 9:da906eeac51e, committed 2014-04-03
- Comitter:
- dylanembed123
- Date:
- Thu Apr 03 17:15:29 2014 +0000
- Parent:
- 8:28b866df62cf
- Child:
- 10:c4745ddaaf6a
- Commit message:
- Fix compile errors
Changed in this revision
--- a/flight/flightControl.cpp Tue Apr 01 17:58:35 2014 +0000 +++ b/flight/flightControl.cpp Thu Apr 03 17:15:29 2014 +0000 @@ -1,4 +1,4 @@ -#include "mbed.h" +#include "flightControl.h" PwmOut throttle(p21); PwmOut roll(p22); @@ -7,50 +7,50 @@ PwmOut arm(p25); PwmOut baroHold(p26); - //TODO see if pwm output gets initialized - public void FlightControl::startPwm(){ - throttle.period_ms(20); - roll.period_ms(20); - pitch.period_ms(20); -// yaw.period_ms(20); - arm.period_ms(20); - } - - public void FlightControl::stopPwm(){ - throttle.pulsewidth_us(0); - roll.pulsewidth_us(0); - pitch.pulsewidth_us(0); +//TODO see if pwm output gets initialized +void FlightControl::startPwm(){ + throttle.period_ms(20); + roll.period_ms(20); + pitch.period_ms(20); + // yaw.period_ms(20); + arm.period_ms(20); +} + +void FlightControl::stopPwm(){ + throttle.pulsewidth_us(0); + roll.pulsewidth_us(0); + pitch.pulsewidth_us(0); // yaw.pulsewidth_us(0); - throttle.pulsewidth_us(0); - } + throttle.pulsewidth_us(0); +} + +//-500 means full back; 500 means full forward +void FlightControl::setPitch(int val){ + if (val > 500) val = 500; + else if (val < -500) val = 0; + pitch.pulsewidth_us(1500 + val); +} - //-500 means full back; 500 means full forward - public void FlightControl::setPitch(int val){ - if (val > 500) val = 500; - else if (val < -500) val = 0; - pitch.pulsewidth_us(1500 + val); - } - - //-500 means full left; 500 means full right - public void FlightControl::setRoll(int val){ - if (val > 500) val = 500; - else if (val < -500) val = 0; - roll.pulsewidth_us(1500 + val); - } - - //0 means no throttle, 1000 means full throttle - public void FlightControl::setThrottle(int val){ - if (val > 1000) val = 1000; - else if (val < 0) val = 0; - throttle.pulsewidth_us(1000 + val); - } - - public void FlightControl::setArmState(bool armState){ - if (armState) arm.pulsewidth_us(2000); - else arm.pulsewidth_us(1000); - } - - public void FlightControl::setHoldAltitude(bool hold){ - if (hold) baroHold.pulsewidth_us(2000); - else baroHold.pulsewidth_us(1000); - } \ No newline at end of file +//-500 means full left; 500 means full right +void FlightControl::setRoll(int val){ + if (val > 500) val = 500; + else if (val < -500) val = 0; + roll.pulsewidth_us(1500 + val); +} + +//0 means no throttle, 1000 means full throttle +void FlightControl::setThrottle(int val){ + if (val > 1000) val = 1000; + else if (val < 0) val = 0; + throttle.pulsewidth_us(1000 + val); +} + +void FlightControl::setArmState(bool armState){ + if (armState) arm.pulsewidth_us(2000); + else arm.pulsewidth_us(1000); +} + +void FlightControl::setHoldAltitude(bool hold){ + if (hold) baroHold.pulsewidth_us(2000); + else baroHold.pulsewidth_us(1000); +} \ No newline at end of file
--- a/flight/flightControl.h Tue Apr 01 17:58:35 2014 +0000 +++ b/flight/flightControl.h Thu Apr 03 17:15:29 2014 +0000 @@ -1,6 +1,9 @@ +#include "mbed.h" + class FlightControl{ public: - void startPWM(); + void startPwm(); + void stopPwm(); //-500 means full back; 500 means full forward void setPitch(int vel); @@ -13,4 +16,4 @@ void setArmState(bool arm); void setHoldAltitude(bool hold); -} \ No newline at end of file +}; \ No newline at end of file
--- a/handle/dataLocation.cpp Tue Apr 01 17:58:35 2014 +0000 +++ b/handle/dataLocation.cpp Thu Apr 03 17:15:29 2014 +0000 @@ -1,34 +1,43 @@ - - -DataLocation* LocHolder::locs=NULL; -DataLocation* LocHolder::targ=NULL; -DataLocation* LocHolder::base=NULL; +#include "dataLocation.h" -DataLocation* LocHolder::getLocs(){ - if(locs==NULL)locs=new DataLocation[MAXNUMLOCS]; - return locs; -} - -DataLocation* LocHolder::getTarg(){ - if(targ==NULL)targ=new DataLocation[MAXNUMLOCS]; - return targ; -} - -DataLocation* LocHolder::getBase(){ - if(base==NULL)base=new DataLocation[MAXNUMLOCS]; +DataLocation* LocHolder::get(LHType type){ + if(type==LHType_locs){ + return locs; + }else if(type==LHType_targ){ + return targ; + }else if(type==LHType_base){ + return base; + } return base; } -unsigned int LocHolder::getRealIndex(int index,int offset=0){ - return (index+offset)%MAXNUMLOCS; +unsigned int LocHolder::getRealIndex(LHType type,int index,int offset,bool useSize){ + return (index+offset)%(useSize?getI(type,LHIType_size):MAXNUMLOCS); +} + +DataLocation& LocHolder::getC(LHType type,int offset){ + return get(type)[getRealIndex(type,offset)]; } -DataLocation& LocHolder::getCurrentLocs(int offset=0){ - return getLocs()[getRealIndex(headLocs,offset)]; +unsigned int& LocHolder::getI(LHType type,LHIType indexType){ + if(indexType==LHIType_head){ + // Grab proper header + if(type==LHType_locs){return headLocs;}else if(type==LHType_targ){return headTarg;}else if(type==LHType_base){return headBase;} + }else if(indexType==LHIType_size){ + // Grab proper size + if(type==LHType_locs){return sizeLocs;}else if(type==LHType_targ){return sizeTarg;}else if(type==LHType_base){return sizeBase;} + } + return headLocs; } -DataLocation& LocHolder::getCurrentTarg(int offset=0){ - return getTarg()[getRealIndex(headTarg,offset)]; + +void LocHolder::inc(LHType type,int amount,bool abs){ + unsigned int& index=getI(type); + index=getRealIndex(type,(abs?0:index),amount);//((abs?0:index)+amount)%getI(type,LHIType_size); + getI(type)=index; } -DataLocation& LocHolder::getCurrentBase(int offset=0){ - return getBase()[getRealIndex(headBase,offset)]; -} + +void LocHolder::add(LHType type,DataLocation newLoc){ + getI(type)=getI(type,LHIType_size); + getI(type,LHIType_size)++; + getC(type)=newLoc; +} \ No newline at end of file
--- a/handle/dataLocation.h Tue Apr 01 17:58:35 2014 +0000 +++ b/handle/dataLocation.h Thu Apr 03 17:15:29 2014 +0000 @@ -1,3 +1,7 @@ +/** + * \brief Data location data holder + **/ + #define MAXNUMLOCS 256 // Storage of data location @@ -5,31 +9,63 @@ private: // Current value of lat lon and alt double lat,lon,alt; + double timestamp; public: + DataLocation(){} + DataLocation(double latA,double lonA,double altA,double timestampA=0):lat(latA),lon(lonA),alt(altA),timestamp(timestampA){} double& getLat(){return lat;} double& getLon(){return lon;} double& getAlt(){return alt;} -} +}; + +/// \brief Location holder type +enum LHType{ + LHType_locs=0, + LHType_targ, + LHType_base +}; + +/// \brief Location holder index type +enum LHIType{ + LHIType_head=0, + LHIType_size +}; // Singleton location holder class LocHolder{ private: // Actual Locations (absolute) - static DataLocation locs[MAXNUMLOCS]; + DataLocation locs[MAXNUMLOCS]; // Target Locations (relative to base station -> base station is at 0,0,0) - static DataLocation targ[MAXNUMLOCS]; + DataLocation targ[MAXNUMLOCS]; // Base Station Locations (absolute) - static DataLocation base[MAXNUMLOCS]; + DataLocation base[MAXNUMLOCS]; // Index of the head of the circular buffers - static unsigned int headLocs,headTarg,headBase; + unsigned int headLocs,headTarg,headBase; + // Number of locations + unsigned int sizeLocs,sizeTarg,sizeBase; public: - static DataLocation* getLocs(); - static DataLocation* getTarg(); - static DataLocation* getBase(); + /// \brief Default constructor + LocHolder():headLocs(0),headTarg(0),headBase(0),sizeLocs(0),sizeTarg(0),sizeBase(0){} + + /// \brief Get locations type + DataLocation* get(LHType type); + + /// \brief Get Current value + DataLocation& getC(LHType type,int offset=0); + + /// \brief Get Index + unsigned int& getI(LHType type,LHIType indexType=LHIType_head); - DataLocation& getCurrentLocs(int offset=0); - DataLocation& getCurrentTarg(int offset=0); - DataLocation& getCurrentBase(int offset=0); + /// \brief Fix an index that might be out of bounds; + unsigned int getRealIndex(LHType type,int index,int offset=0,bool useSize=true); + + /// \brief Increment index + void inc(LHType type,int amount=1,bool abs=false); - -}; \ No newline at end of file + /// \brief Append a location to the end. + void add(LHType type,DataLocation newLoc); +}; + +static LocHolder mainLocHolder; +static LocHolder& Locs(){return mainLocHolder;} \ No newline at end of file
--- a/handle/handleCamera.cpp Tue Apr 01 17:58:35 2014 +0000 +++ b/handle/handleCamera.cpp Thu Apr 03 17:15:29 2014 +0000 @@ -17,7 +17,7 @@ int i; for(i=0;i<size;){ // read 32 bytes at a time; - uint8_t bytesToRead = min(64, size-i); // change 32 to 64 for a speedup but may not work with all setups! + uint8_t bytesToRead = std::min(64, size-i); // change 32 to 64 for a speedup but may not work with all setups! uint8_t bytesRead=0; uint8_t* buffer = cam.readPicture(bytesToRead,&bytesRead); for(int a=0;a<bytesRead;a++){USB::getSerial().putc(buffer[a]);}
--- a/handle/handleCamera.h Tue Apr 01 17:58:35 2014 +0000 +++ b/handle/handleCamera.h Thu Apr 03 17:15:29 2014 +0000 @@ -3,6 +3,7 @@ #include "adapt/usb.h" #include "adapt/camera.h" +#include <algorithm> class ImageHandle{ private: Camera cam;
--- a/handle/handleGPS.cpp Tue Apr 01 17:58:35 2014 +0000 +++ b/handle/handleGPS.cpp Thu Apr 03 17:15:29 2014 +0000 @@ -1,40 +1,39 @@ -#include "mbed.h" +#include "handleGPS.h" -Serial gps(p28,p27); +//Serial gps(p28,p27); void GPSHandle::setup(){ - gps.baud(57600); + gps.getSerial().baud(57600); sendGpsCommand("PMTK301,1"); - gps.attach(this, &handleUpdate, Serial::RxIrq); + //gps.getSerial().attach(this, handleUpdate, Serial::RxIrq); //cs: Send other standard init commands? Not strictly speaking necessary, // but forces "up to date documentation" in the form of always knowing // gps config. } void GPSHandle::handleUpdate(){ - { static bool reading = false; - static stringstream line; + static std::stringstream line; - char c = gps.getc(); + char c = gps.getSerial().getc(); if (reading) { if (c == '*') { //sentence buffer complete; we're ignoring the checksum - string field; + std::string field; std::getline(line, field, ','); //GPGGA std::getline(line, field, ','); //time - gpsData.time = stringToDecimal(field); + double time = atof(field.c_str()); std::getline(line, field, ','); //latitude - gpsData.latitude = stringToDecimal(field); + double latitude = atof(field.c_str()); std::getline(line, field, ','); //N or S std::getline(line, field, ','); //longitude - gpsData.longitude = stringToDecimal(field); + double longitude = atof(field.c_str()); std::getline(line, field, ','); //E or W std::getline(line, field, ','); //skip std::getline(line, field, ','); //skip std::getline(line, field, ','); //skip std::getline(line, field, ','); //altitude - gpsData.altitude = stringToDecimal(field); + double altitude = atof(field.c_str()); //update whatever needs updating when gps updates // pc.printf("My GPS data: Lat: %d, Lon: %d, Alt: %d, Time:%d\r\n", @@ -54,21 +53,20 @@ } //sends: "$<command>*<checksum>\r\l" -void sendGpsCommand(string command) -{ +void GPSHandle::sendGpsCommand(std::string command){ uint8_t checksum = 0; - pc.printf("Sending command to gps: "); - gps.putc('$'); - pc.putc('$'); + //pc.printf("Sending command to gps: "); + gps.getSerial().putc('$'); + //pc.putc('$'); char c; for (int i = 0; i < command.length(); i++) { c = command[i]; checksum ^= c; - gps.putc(c); - pc.putc(c); + gps.getSerial().putc(c); + //pc.putc(c); } - gps.putc('*'); - pc.putc('*'); + gps.getSerial().putc('*'); + //pc.putc('*'); string checkSumString; while (checksum > 0) { uint8_t checksumChar = checksum & 0x0F; @@ -83,13 +81,13 @@ } for (int i = checkSumString.length() - 1; i >= 0; i--) { - gps.putc(checkSumString[i]); - pc.putc(checkSumString[i]); + gps.getSerial().putc(checkSumString[i]); + //pc.putc(checkSumString[i]); } - gps.putc('\r'); - pc.putc('\r'); - gps.putc('\n'); - pc.putc('\n'); + gps.getSerial().putc('\r'); + //pc.putc('\r'); + gps.getSerial().putc('\n'); + //pc.putc('\n'); } int stringToDecimal(string s)
--- a/handle/handleGPS.h Tue Apr 01 17:58:35 2014 +0000 +++ b/handle/handleGPS.h Thu Apr 03 17:15:29 2014 +0000 @@ -2,10 +2,14 @@ #define _HANDLEGPS_H_ #include "adapt/usb.h" -#include "adapt/camera.h" +#include "adapt/gps.h" +#ifndef _HANDLE_GPS_H_ +#define _HANDLE_GPS_H_ +#include <string> +#include <sstream> class GPSHandle{ private: - GPS gps + GPS gps; bool initialized; /// \brief Setup @@ -14,7 +18,9 @@ bool check(); public: /// \brief Constructor - ImageHandle():initialized(false){} + GPSHandle():initialized(false){} + + void sendGpsCommand(std::string command); //handle incoming com from GPS hardware void handleUpdate(); @@ -22,5 +28,5 @@ /// \brief Run an instance of this void run(); }; - +#endif #endif \ No newline at end of file
--- a/main.cpp Tue Apr 01 17:58:35 2014 +0000 +++ b/main.cpp Thu Apr 03 17:15:29 2014 +0000 @@ -2,7 +2,8 @@ #include <string> #include <sstream> #include "adapt/usb.h" -#include "adapt/camera.h" +#include "handle/handleCamera.h" +#include "handle/handleGPS.h" Serial pc(USBTX,USBRX); Serial xbee(p9,p10);//tx, rx @@ -103,7 +104,7 @@ int main() { ImageHandle imageHand; - GPSHand gpsHand; + GPSHandle gpsHand; /// Main Loop while(true) { @@ -115,6 +116,7 @@ while(true) { pc.putc(gps.getc()); } - gps.attach(&handleGpsData, Serial::RxIrq); - xbee.attach(&handleXbeeGps, Serial::RxIrq)//; + //gps.attach(&handleGpsData, Serial::RxIrq); + //xbee.attach(&handleXbeeGps, Serial::RxIrq)//; } +}