Roomba that displays room data to a C# GUI
Dependencies: LSM9DS1_Library_cal mbed
Fork of 4180Lab2Part4 by
Revision 2:516dd8a72972, committed 2017-04-30
- Comitter:
- CRaslawski
- Date:
- Sun Apr 30 18:09:43 2017 +0000
- Parent:
- 1:aeb42bbdac27
- Commit message:
- started IMU->BT
Changed in this revision
4DGL-uLCD-SE.lib | Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/4DGL-uLCD-SE.lib Wed Mar 01 06:01:10 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- a/main.cpp Wed Mar 01 06:01:10 2017 +0000 +++ b/main.cpp Sun Apr 30 18:09:43 2017 +0000 @@ -1,6 +1,5 @@ #include "mbed.h" #include "LSM9DS1.h" -#include "uLCD_4DGL.h" #define PI 3.14159 // Earth's magnetic field varies by location. Add or subtract // a declination to get a more accurate heading. Calculate @@ -8,9 +7,12 @@ // http://www.ngdc.noaa.gov/geomag-web/#declination #define DECLINATION -4.94 // Declination (degrees) in Atlanta,GA. +//Serial pc(USBTX, USBRX); +RawSerial pc(USBTX, USBRX); +RawSerial dev(p28,p27); //tx, rx DigitalOut myled(LED1); -Serial pc(USBTX, USBRX); -uLCD_4DGL uLCD(p28,p27,p29); +DigitalOut led2(LED2); +DigitalOut led4(LED4); // Calculate pitch, roll, and heading. // Pitch/roll calculations taken from this app note: // http://cache.freescale.com/files/sensors/doc/app_note/AN3461.pdf?fpsp=1 @@ -39,44 +41,58 @@ pitch *= 180.0 / PI; roll *= 180.0 / PI; - pc.printf("Pitch: %f, Roll: %f degress\n\r",pitch,roll); - pc.printf("Magnetic Heading: %f degress\n\r",heading); + //~pc.printf("Pitch: %f, Roll: %f degress\n\r",pitch,roll); + //~pc.printf("Magnetic Heading: %f degress\n\r",heading); } -float tempX = 0.0; -float tempY = 0.0; -float oldtempX; -float oldtempY; +/* +void dev_recv() +{ + led2 = !led2; + while(dev.readable()) { + pc.putc(dev.getc()); + } +} + +void pc_recv() +{ + led4 = !led4; + while(pc.readable()) { + dev.putc(pc.getc()); + } +}*/ int main() { + //IMU setup LSM9DS1 IMU(p9, p10, 0xd6, 0x3c); - //LSM9DS1 IMU(p28, p27, 0xD6, 0x3C); IMU.begin(); if (!IMU.begin()) { pc.printf("Failed to communicate with LSM9DS1.\n"); } IMU.calibrate(1); IMU.calibrateMag(0); + + //bluetooth setup + pc.baud(9600); + dev.baud(9600); + + /*pc.attach(&pc_recv, Serial::RxIrq); + dev.attach(&dev_recv, Serial::RxIrq);*/ + while(1) { - - uLCD.locate(25,25); - //uLCD.color(WHITE); - uLCD.circle(64,64,60,0xFFFFFF); - while(!IMU.tempAvailable()); - IMU.readTemp(); while(!IMU.magAvailable(X_AXIS)); IMU.readMag(); while(!IMU.accelAvailable()); IMU.readAccel(); while(!IMU.gyroAvailable()); IMU.readGyro(); - pc.printf("\nIMU Temperature = %f C\n\r",25.0 + IMU.temperature/16.0); - pc.printf(" X axis Y axis Z axis\n\r"); - pc.printf("gyro: %9f %9f %9f in deg/s\n\r", IMU.calcGyro(IMU.gx), IMU.calcGyro(IMU.gy), IMU.calcGyro(IMU.gz)); - pc.printf("accel: %9f %9f %9f in Gs\n\r", IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.ay), IMU.calcAccel(IMU.az)); - pc.printf("mag: %9f %9f %9f in gauss\n\r", IMU.calcMag(IMU.mx), IMU.calcMag(IMU.my), IMU.calcMag(IMU.mz)); + pc.puts(" X axis Y axis Z axis\n\r"); + dev.puts(" X axis Y axis Z axis\n\r"); + //pc.printf("gyro: %9f %9f %9f in deg/s\n\r", IMU.calcGyro(IMU.gx), IMU.calcGyro(IMU.gy), IMU.calcGyro(IMU.gz)); + //pc.printf("accel: %9f %9f %9f in Gs\n\r", IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.ay), IMU.calcAccel(IMU.az)); + //pc.printf("mag: %9f %9f %9f in gauss\n\r", IMU.calcMag(IMU.mx), IMU.calcMag(IMU.my), IMU.calcMag(IMU.mz)); printAttitude(IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.ay), IMU.calcAccel(IMU.az), IMU.calcMag(IMU.mx), IMU.calcMag(IMU.my), IMU.calcMag(IMU.mz)); myled = 1; @@ -84,16 +100,12 @@ myled = 0; wait(0.5); - oldtempX = tempX; - oldtempY = tempY; - uLCD.filled_circle(floor(128*oldtempX), floor(128*oldtempY), 6, 0x000000); // erase old bubble - tempX = IMU.calcAccel(IMU.ax); - tempX = (tempX+1.0)/2.0; - tempY = IMU.calcAccel(IMU.ay); - tempY = (tempY+1.0)/2.0; + + //uLCD.filled_circle(floor(128*oldtempX), floor(128*oldtempY), 6, 0x000000); // erase old bubble + //draw filled circle based on info from IMU //draw new bubble - uLCD.filled_circle(floor(128*tempX), floor(128*tempY), 6, 0xFFFFFF); + //uLCD.filled_circle(floor(128*tempX), floor(128*tempY), 6, 0xFFFFFF); } }