Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of IMU_code_7_14 by
Diff: IMU_code.cpp
- Revision:
- 1:0672f84101e4
- Parent:
- 0:22fc81041056
- Child:
- 2:b00adea2187b
--- a/IMU_code.cpp Fri Jun 09 17:31:10 2017 +0000
+++ b/IMU_code.cpp Fri Jun 30 18:32:10 2017 +0000
@@ -2,12 +2,14 @@
#include "MODSERIAL.h"
Serial IMU(p13,p14); //tx, rx for IMU
-//Serial PC1(USBTX, USBRX);
-
+
//FUNCTION DECLARATION for what is used below in IMU
double double_from_le_bytes(unsigned char * p_to_double);
float float_from_le_bytes(unsigned char * p_to_float);
+const double GRAVITY = 9.80665; //new placement 6/22/2017
+float stab_accel[3];
+
#include <string> //FOR STRINGS
using namespace std;
@@ -19,7 +21,6 @@
//functions
string IMU_code::IMU_run()
{
- //PC1.baud(9600);
unsigned char current, last, cb1=0, cb2=0, data[MAXPACKETSIZE];
int packetlength=MAXPACKETSIZE; //Redefined for each packet payod length below
int mode=0,count=0;
@@ -38,27 +39,26 @@
int dv_pos;
descripts[2]=0x08;
//CF Stablized Accel Vector (up) (0x0e,0x11)
- float stab_accel[3];
+ //float stab_accel[3]; //TROY: I MADE THIS GLOBAL 6/22/17
int sa_pos;
descripts[3]=0x0c;
//If adding/removing stuff, change NUMDESCRIPTS above
IMU.baud(9600);
current=0;
last=0;
- //PC1.printf("I'm alive\n");
+ //PC.printf("I'm alive\n");
std::string imu_string = "";
while(1)
{
- //PC1.printf("while loop\n");
if(IMU.readable()>0)
{
+ //PC.printf("IMU readable");
last=current;
current=IMU.getc();
if(mode==0&¤t==0x65&&last==0x75)
{
- //PC1.printf("First packet recieved.\n");
mode=1;
data[0]=last;
data[1]=current;
@@ -127,7 +127,7 @@
}
timestamp=double_from_le_bytes(&data[6]);
//Relevant data to send back to ground station
- //PC1.printf("\nT: %f SA:(%d) Roll: %9.6f Pitch: %9.6f Yaw:%9.6f\n\n",timestamp,sa_pos,stab_accel[0],stab_accel[1],stab_accel[2]);
+ //PC.printf("\nT: %f SA:(%d) Roll: %9.6f Pitch: %9.6f Yaw:%9.6f\n\n",timestamp,sa_pos,stab_accel[0],stab_accel[1],stab_accel[2]);
//PC.printf("\nT: %f SA:(%d) Roll: %9.6f Pitch: %9.6f Yaw:%9.6f\n",timestamp,sa_pos,stab_accel[0],stab_accel[1],stab_accel[2]);
char char_buffer [60];
sprintf(char_buffer,"T: %f SA:(%d) Roll: %9.6f Pitch: %9.6f Yaw: %9.6f",timestamp,sa_pos,stab_accel[0],stab_accel[1],stab_accel[2]);
@@ -150,7 +150,11 @@
}
}
}
- //return "TEST STRING"; //unreachable
+}
+
+float IMU_code::IMU_pitch()
+{
+ return stab_accel[1];
}
double double_from_le_bytes(unsigned char * p_to_double)
