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

Dependents:   m3Dpi-helloworld

Committer:
sillevl
Date:
Thu Dec 03 16:34:59 2015 +0000
Revision:
4:b2fe3a2545bf
Parent:
0:9f02ae958e20
Child:
6:b60a3c005d3c
Child:
10:4200a8140b10
return data structures for sensor values instead of array pointers

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 0:9f02ae958e20 1
sillevl 0:9f02ae958e20 2 #include "M3Dpi.h"
sillevl 0:9f02ae958e20 3
sillevl 0:9f02ae958e20 4 M3Dpi::M3Dpi() :
sillevl 0:9f02ae958e20 5 status(STATUS_RED,STATUS_GREEN,STATUS_BLUE),
sillevl 0:9f02ae958e20 6 compass(SDA, SCL, 0x3D),
sillevl 0:9f02ae958e20 7 gyro(SDA, SCL),
sillevl 0:9f02ae958e20 8 accelerometer(SDA,SCL),
sillevl 0:9f02ae958e20 9 leds(SDA, SCL),
sillevl 0:9f02ae958e20 10 distance(SDA, SCL),
sillevl 0:9f02ae958e20 11 xbee(XBEE_TX, XBEE_RX, XBEE_RESET)
sillevl 0:9f02ae958e20 12 {
sillevl 0:9f02ae958e20 13 xbee.baud(XBEE_BAUD);
sillevl 0:9f02ae958e20 14 xbee.reset();
sillevl 0:9f02ae958e20 15
sillevl 0:9f02ae958e20 16 gyro.setLpBandwidth(LPFBW_42HZ);
sillevl 0:9f02ae958e20 17
sillevl 0:9f02ae958e20 18 //Go into standby mode to configure the device.
sillevl 0:9f02ae958e20 19 accelerometer.setPowerControl(0x00);
sillevl 0:9f02ae958e20 20 wait(.001);
sillevl 0:9f02ae958e20 21 //Full resolution, +/-16g, 4mg/LSB.
sillevl 0:9f02ae958e20 22 accelerometer.setDataFormatControl(0x0B);
sillevl 0:9f02ae958e20 23 wait(.001);
sillevl 0:9f02ae958e20 24 //3.2kHz data rate.
sillevl 0:9f02ae958e20 25 accelerometer.setDataRate(ADXL345_3200HZ);
sillevl 0:9f02ae958e20 26 wait(.001);
sillevl 0:9f02ae958e20 27 //Measurement mode.
sillevl 0:9f02ae958e20 28 accelerometer.setPowerControl(0x08);
sillevl 0:9f02ae958e20 29 wait(.001);
sillevl 0:9f02ae958e20 30 }
sillevl 0:9f02ae958e20 31
sillevl 0:9f02ae958e20 32 void M3Dpi::setStatus(Color* color)
sillevl 0:9f02ae958e20 33 {
sillevl 0:9f02ae958e20 34 status.setColor(color);
sillevl 0:9f02ae958e20 35 }
sillevl 0:9f02ae958e20 36
sillevl 0:9f02ae958e20 37 void M3Dpi::setStatus(int color)
sillevl 0:9f02ae958e20 38 {
sillevl 0:9f02ae958e20 39 status.setColor(color);
sillevl 0:9f02ae958e20 40 }
sillevl 0:9f02ae958e20 41
sillevl 0:9f02ae958e20 42
sillevl 0:9f02ae958e20 43 void M3Dpi::setLeds(int* colors)
sillevl 0:9f02ae958e20 44 {
sillevl 0:9f02ae958e20 45 leds.setAll(colors);
sillevl 0:9f02ae958e20 46 }
sillevl 0:9f02ae958e20 47
sillevl 4:b2fe3a2545bf 48 m3dpi::Distance M3Dpi::getDistance()
sillevl 0:9f02ae958e20 49 {
sillevl 4:b2fe3a2545bf 50 return distance.getAllDistance();
sillevl 0:9f02ae958e20 51 }
sillevl 0:9f02ae958e20 52
sillevl 4:b2fe3a2545bf 53 m3dpi::Direction M3Dpi::getDirection()
sillevl 0:9f02ae958e20 54 {
sillevl 4:b2fe3a2545bf 55 m3dpi::Direction direction;
sillevl 0:9f02ae958e20 56 coord c;
sillevl 0:9f02ae958e20 57 c = compass.getCompass();
sillevl 4:b2fe3a2545bf 58 direction.x = c.x;
sillevl 4:b2fe3a2545bf 59 direction.y = c.y;
sillevl 4:b2fe3a2545bf 60 direction.z = c.z;
sillevl 4:b2fe3a2545bf 61 return direction;
sillevl 0:9f02ae958e20 62 }
sillevl 0:9f02ae958e20 63
sillevl 4:b2fe3a2545bf 64 m3dpi::Rotation M3Dpi::getRotation()
sillevl 0:9f02ae958e20 65 {
sillevl 4:b2fe3a2545bf 66 m3dpi::Rotation rotation;
sillevl 4:b2fe3a2545bf 67 rotation.x = gyro.getGyroX();
sillevl 4:b2fe3a2545bf 68 rotation.y = gyro.getGyroY();
sillevl 4:b2fe3a2545bf 69 rotation.z = gyro.getGyroZ();
sillevl 4:b2fe3a2545bf 70 return rotation;
sillevl 0:9f02ae958e20 71 }
sillevl 0:9f02ae958e20 72
sillevl 4:b2fe3a2545bf 73 m3dpi::Acceleration M3Dpi::getAcceleration()
sillevl 0:9f02ae958e20 74 {
sillevl 4:b2fe3a2545bf 75 m3dpi::Acceleration acc;
sillevl 0:9f02ae958e20 76 int values[3] = {0};
sillevl 0:9f02ae958e20 77 accelerometer.getOutput(values);
sillevl 4:b2fe3a2545bf 78 acc.x = (int16_t) values[0];
sillevl 4:b2fe3a2545bf 79 acc.y = (int16_t) values[1];
sillevl 4:b2fe3a2545bf 80 acc.z = (int16_t) values[2];
sillevl 4:b2fe3a2545bf 81 return acc;
sillevl 0:9f02ae958e20 82 }
sillevl 0:9f02ae958e20 83
sillevl 0:9f02ae958e20 84 int M3Dpi::_putc(int c)
sillevl 0:9f02ae958e20 85 {
sillevl 0:9f02ae958e20 86 return xbee.putc(c);
sillevl 0:9f02ae958e20 87 }
sillevl 0:9f02ae958e20 88
sillevl 0:9f02ae958e20 89 int M3Dpi::_getc()
sillevl 0:9f02ae958e20 90 {
sillevl 0:9f02ae958e20 91 return xbee.getc();
sillevl 0:9f02ae958e20 92 }
sillevl 0:9f02ae958e20 93
sillevl 4:b2fe3a2545bf 94 time_t M3Dpi::getTime()
sillevl 0:9f02ae958e20 95 {
sillevl 4:b2fe3a2545bf 96 return time(NULL);
sillevl 0:9f02ae958e20 97 }