most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown
Dependencies: mbed MODSERIAL FATFileSystem
IMU/IMU.h@11:3b241ecb75ed, 2017-10-27 (annotated)
- Committer:
- danstrider
- Date:
- Fri Oct 27 00:37:32 2017 +0000
- Revision:
- 11:3b241ecb75ed
- Parent:
- 10:085ab7328054
This version has been in the pool, working with all the hardware. Had occasional string pot problems and got stuck in RISE, letting the battery stall out against the endcap.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mkelly10 | 9:d5fcdcb3c89d | 1 | #include "mbed.h" |
mkelly10 | 9:d5fcdcb3c89d | 2 | #include "MODSERIAL.h" |
mkelly10 | 9:d5fcdcb3c89d | 3 | |
danstrider | 11:3b241ecb75ed | 4 | // for Microstrain's MIPS protocol, try this link, or search on microstrain.com |
danstrider | 11:3b241ecb75ed | 5 | // http://www.microstrain.com/sites/default/files/3dm-gx5-45_dcp_manual_8500-0064_0.pdf |
danstrider | 11:3b241ecb75ed | 6 | |
mkelly10 | 9:d5fcdcb3c89d | 7 | #define _PI ((float) 3.14159265359) |
mkelly10 | 9:d5fcdcb3c89d | 8 | |
danstrider | 10:085ab7328054 | 9 | // state machine states |
danstrider | 10:085ab7328054 | 10 | #define SYNC0 0 // first sync byte state |
danstrider | 10:085ab7328054 | 11 | #define SYNC1 1 // second sync byte state |
danstrider | 10:085ab7328054 | 12 | #define SET 2 // aka descriptor set |
danstrider | 10:085ab7328054 | 13 | #define LEN 3 // payload length |
danstrider | 10:085ab7328054 | 14 | #define PAY 4 // getting the payload data |
danstrider | 10:085ab7328054 | 15 | #define CRC0 5 // crc high byte |
danstrider | 10:085ab7328054 | 16 | #define CRC1 6 // crc low byte |
danstrider | 10:085ab7328054 | 17 | |
danstrider | 10:085ab7328054 | 18 | // data set descriptors |
danstrider | 11:3b241ecb75ed | 19 | #define IMU_DATA_SET 0x80 |
danstrider | 10:085ab7328054 | 20 | #define GNSS_DATA_SET 0x81 |
danstrider | 10:085ab7328054 | 21 | |
danstrider | 10:085ab7328054 | 22 | // enumerations for the Euler angle packet we care about |
danstrider | 10:085ab7328054 | 23 | #define EULER_CF_LENGTH 14 |
danstrider | 10:085ab7328054 | 24 | #define EULER_CF_DESCRIPTOR 0x0C |
danstrider | 10:085ab7328054 | 25 | #define ROLL_OFFSET 0 |
danstrider | 10:085ab7328054 | 26 | #define PITCH_OFFSET 4 |
danstrider | 10:085ab7328054 | 27 | #define YAW_OFFSET 8 |
danstrider | 10:085ab7328054 | 28 | |
danstrider | 10:085ab7328054 | 29 | // enumerations for the lat-lon-alt packet we care about |
danstrider | 10:085ab7328054 | 30 | #define LLH_POSITION_LENGTH 44 |
danstrider | 10:085ab7328054 | 31 | #define LLH_POSITION_DESCRIPTOR 0x03 |
danstrider | 10:085ab7328054 | 32 | #define LATITUDE_OFFSET 0 |
danstrider | 10:085ab7328054 | 33 | #define LONGITUDE_OFFSET 8 |
danstrider | 10:085ab7328054 | 34 | #define HEIGHT_MSL_OFFSET 16 |
danstrider | 10:085ab7328054 | 35 | #define VALID_FLAG_OFFSET 40 |
danstrider | 10:085ab7328054 | 36 | |
danstrider | 10:085ab7328054 | 37 | // enumerations for the lat-lon-alt packet we care about |
danstrider | 10:085ab7328054 | 38 | #define GNSS_FIX_INFO_LENGTH 8 |
danstrider | 10:085ab7328054 | 39 | #define GNSS_FIX_INFO_DESCRIPTOR 0x0B |
danstrider | 10:085ab7328054 | 40 | #define FIX_TYPE_OFFSET 0 |
danstrider | 10:085ab7328054 | 41 | #define NUM_SV_OFFSET 1 |
danstrider | 10:085ab7328054 | 42 | #define VALID_FLAGS_OFFSET 4 |
danstrider | 10:085ab7328054 | 43 | |
danstrider | 10:085ab7328054 | 44 | class IMU { |
mkelly10 | 9:d5fcdcb3c89d | 45 | public: |
danstrider | 10:085ab7328054 | 46 | IMU(PinName Tx, PinName Rx); |
mkelly10 | 9:d5fcdcb3c89d | 47 | void initialize(); |
mkelly10 | 9:d5fcdcb3c89d | 48 | void update(); |
mkelly10 | 9:d5fcdcb3c89d | 49 | void start(); |
mkelly10 | 9:d5fcdcb3c89d | 50 | void stop(); |
danstrider | 10:085ab7328054 | 51 | |
danstrider | 10:085ab7328054 | 52 | float getRoll(); |
danstrider | 10:085ab7328054 | 53 | float getPitch(); |
danstrider | 10:085ab7328054 | 54 | float getHeading(); |
mkelly10 | 9:d5fcdcb3c89d | 55 | |
danstrider | 10:085ab7328054 | 56 | bool getIsValid2dFix(); |
danstrider | 10:085ab7328054 | 57 | bool getIsValid3dFix(); |
danstrider | 10:085ab7328054 | 58 | char getNumSV(); |
danstrider | 10:085ab7328054 | 59 | double getLatitude(); |
danstrider | 10:085ab7328054 | 60 | double getLongitude(); |
danstrider | 10:085ab7328054 | 61 | double getAltitudeMSL(); |
danstrider | 11:3b241ecb75ed | 62 | |
danstrider | 11:3b241ecb75ed | 63 | protected: |
mkelly10 | 9:d5fcdcb3c89d | 64 | Ticker interval; |
mkelly10 | 9:d5fcdcb3c89d | 65 | MODSERIAL _rs232; |
danstrider | 10:085ab7328054 | 66 | |
danstrider | 10:085ab7328054 | 67 | char byte; |
danstrider | 11:3b241ecb75ed | 68 | |
danstrider | 11:3b241ecb75ed | 69 | unsigned char state, len, descriptor, i, packet[256]; |
danstrider | 11:3b241ecb75ed | 70 | unsigned int checksum, crc0, crc1; |
danstrider | 11:3b241ecb75ed | 71 | |
danstrider | 11:3b241ecb75ed | 72 | /* unsigned char state, len, descriptor, i, crc0, crc1, payload[30]; |
danstrider | 11:3b241ecb75ed | 73 | unsigned int checksum;*/ |
mkelly10 | 9:d5fcdcb3c89d | 74 | |
danstrider | 10:085ab7328054 | 75 | float euler[3]; |
danstrider | 10:085ab7328054 | 76 | double latLonAlt[3]; |
danstrider | 10:085ab7328054 | 77 | bool is2dFixValid; |
danstrider | 10:085ab7328054 | 78 | bool is3dFixValid; |
danstrider | 10:085ab7328054 | 79 | char numSV; |
mkelly10 | 9:d5fcdcb3c89d | 80 | |
danstrider | 11:3b241ecb75ed | 81 | void processPayload(char type, char length, unsigned char * payload); |
danstrider | 11:3b241ecb75ed | 82 | void processEulerCfPacket(char length, unsigned char * payload); |
danstrider | 11:3b241ecb75ed | 83 | void processLatLonAltPacket(char length, unsigned char * payload); |
danstrider | 11:3b241ecb75ed | 84 | void processGnssFixInformation(char length, unsigned char * payload); |
danstrider | 10:085ab7328054 | 85 | |
danstrider | 10:085ab7328054 | 86 | unsigned int calcChecksum(unsigned char * mip_packet, char checksum_range); |
danstrider | 10:085ab7328054 | 87 | |
danstrider | 10:085ab7328054 | 88 | float floatFromChar(unsigned char * value); |
danstrider | 10:085ab7328054 | 89 | double doubleFromChar(unsigned char * value); |
danstrider | 10:085ab7328054 | 90 | }; |