library for m3Dpi robot, based on the Pololu 3pi and m3pi. m3Dpi has multiple distance sensors, gyroscope, compass and accelerometer sensor to be fully aware of its environment. With the addition of xbee or nrf24n01 module it has wireless communication capabilities.
Dependencies: m3pi ADXL345_I2C HMC5583L ITG3200 PCA9547 TLC59116 VL6180x RGB-fun xbee
Revision 4:b2fe3a2545bf, committed 2015-12-03
- Comitter:
- sillevl
- Date:
- Thu Dec 03 16:34:59 2015 +0000
- Parent:
- 3:d35dc4d2f243
- Child:
- 5:a75574090b59
- Child:
- 7:448de3b31a48
- Commit message:
- return data structures for sensor values instead of array pointers
Changed in this revision
--- a/M3Dpi.cpp Thu Dec 03 08:19:42 2015 +0000 +++ b/M3Dpi.cpp Thu Dec 03 16:34:59 2015 +0000 @@ -45,37 +45,40 @@ leds.setAll(colors); } -int* M3Dpi::getDistance(int data[]) +m3dpi::Distance M3Dpi::getDistance() { - return distance.getAllDistance(data);; + return distance.getAllDistance(); } -int* M3Dpi::getDirection(int data[]) +m3dpi::Direction M3Dpi::getDirection() { + m3dpi::Direction direction; coord c; c = compass.getCompass(); - data[0] = c.x; - data[1] = c.y; - data[2] = c.z; - return data; + direction.x = c.x; + direction.y = c.y; + direction.z = c.z; + return direction; } -int* M3Dpi::getRotation(int data[]) +m3dpi::Rotation M3Dpi::getRotation() { - data[0] = gyro.getGyroX(); - data[1] = gyro.getGyroY(); - data[2] = gyro.getGyroZ(); - return data; + m3dpi::Rotation rotation; + rotation.x = gyro.getGyroX(); + rotation.y = gyro.getGyroY(); + rotation.z = gyro.getGyroZ(); + return rotation; } -int* M3Dpi::getAcceleration(int data[]) +m3dpi::Acceleration M3Dpi::getAcceleration() { + m3dpi::Acceleration acc; int values[3] = {0}; accelerometer.getOutput(values); - data[0] = (int16_t) values[0]; - data[1] = (int16_t) values[1]; - data[2] = (int16_t) values[2]; - return data; + acc.x = (int16_t) values[0]; + acc.y = (int16_t) values[1]; + acc.z = (int16_t) values[2]; + return acc; } int M3Dpi::_putc(int c) @@ -88,9 +91,7 @@ return xbee.getc(); } -char* M3Dpi::getTime(char buffer[]) +time_t M3Dpi::getTime() { - time_t seconds = time(NULL); - strftime(buffer, 32, "%d-%m-%Y %T", localtime(&seconds)); - return buffer; + return time(NULL); } \ No newline at end of file
--- a/M3Dpi.h Thu Dec 03 08:19:42 2015 +0000 +++ b/M3Dpi.h Thu Dec 03 16:34:59 2015 +0000 @@ -12,34 +12,36 @@ //#include "vl6108x.h" #include "vl6180xManager.h" #include "xbee.h" +#include "datatypes.h" -class M3Dpi : public m3pi{ - - public: +class M3Dpi : public m3pi +{ + +public: M3Dpi(); - + void setStatus(int color); void setStatus(Color* color); - + void setLeds(int* colors); - int* getDistance(int data[]); - int* getDirection(int data[]); // compass - int* getRotation(int data[]); // gyro - int* getAcceleration(int data[]); - char* getTime(char buffer[]); - + m3dpi::Distance getDistance(); + m3dpi::Direction getDirection(); // compass + m3dpi::Rotation getRotation(); // gyro + m3dpi::Acceleration getAcceleration(); + time_t getTime(); + // buttonhandler (interrupt based?) - + //protected: // public for hardware testing only StatusLed status; LedRing leds; - + HMC5583L compass; ITG3200 gyro; ADXL345_I2C accelerometer; VL6180xManager distance; Xbee xbee; - + static const PinName SDA = p28; static const PinName SCL = p27; static const PinName XBEE_TX = p13; @@ -48,10 +50,10 @@ static const PinName STATUS_RED = p18; static const PinName STATUS_GREEN = p19; static const PinName STATUS_BLUE = p20; - + static const int XBEE_BAUD = 115200; virtual int _putc(int c); virtual int _getc(); - + }; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/datatypes.h Thu Dec 03 16:34:59 2015 +0000 @@ -0,0 +1,34 @@ +#pragma once + +namespace m3dpi +{ +struct Distance { + int front; + int front_right; + int right; + int back_right; + int back; + int back_left; + int left; + int front_left; +}; + +struct Acceleration{ + int x; + int y; + int z; +}; + +struct Rotation{ + int x; + int y; + int z; +}; + +struct Direction{ + int x; + int y; + int z; +}; + +} \ No newline at end of file
--- a/lib/vl6180xManager.cpp Thu Dec 03 08:19:42 2015 +0000 +++ b/lib/vl6180xManager.cpp Thu Dec 03 16:34:59 2015 +0000 @@ -15,13 +15,24 @@ mux.select(index); } -int* VL6180xManager::getAllDistance(int data[]) +m3dpi::Distance VL6180xManager::getAllDistance() { - for(int i = 0; i < 8; i++) { - mux.select(i); - data[i] = sensor.getDistance(); - } - return data; + m3dpi::Distance distance; + distance.front = getDistance(0); + distance.front_right = getDistance(1); + distance.right = getDistance(2); + distance.back_right = getDistance(3); + distance.back = getDistance(4); + distance.back_left = getDistance(5); + distance.left = getDistance(6); + distance.front_left = getDistance(7); + return distance; +} + +int VL6180xManager::getDistance(int index) +{ + mux.select(index); + return sensor.getDistance(); }
--- a/lib/vl6180xManager.h Thu Dec 03 08:19:42 2015 +0000 +++ b/lib/vl6180xManager.h Thu Dec 03 16:34:59 2015 +0000 @@ -3,6 +3,7 @@ #include "mbed.h" #include "PCA9547.h" #include "vl6180x.h" +#include "datatypes.h" /*enum DistanceSensor{ FRONT, @@ -20,7 +21,8 @@ public: VL6180xManager(PinName sda, PinName scl); void select(int index); - int* getAllDistance(int data[]); + m3dpi::Distance getAllDistance(); + int getDistance(int index); protected: