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

Files at this revision

API Documentation at this revision

Comitter:
sillevl
Date:
Thu Dec 03 07:58:50 2015 +0000
Child:
1:de1359755562
Commit message:
initial commit

Changed in this revision

M3Dpi.cpp Show annotated file Show diff for this revision Revisions of this file
M3Dpi.h Show annotated file Show diff for this revision Revisions of this file
drivers/ADXL345_I2C.lib Show annotated file Show diff for this revision Revisions of this file
drivers/HMC5583L.lib Show annotated file Show diff for this revision Revisions of this file
drivers/ITG3200.lib Show annotated file Show diff for this revision Revisions of this file
drivers/PCA9547.lib Show annotated file Show diff for this revision Revisions of this file
drivers/TLC59116.lib Show annotated file Show diff for this revision Revisions of this file
drivers/VL6180x.lib Show annotated file Show diff for this revision Revisions of this file
drivers/xbee.lib Show annotated file Show diff for this revision Revisions of this file
lib/LedRing.cpp Show annotated file Show diff for this revision Revisions of this file
lib/LedRing.h Show annotated file Show diff for this revision Revisions of this file
lib/RGB-fun.lib Show annotated file Show diff for this revision Revisions of this file
lib/StatusLed.cpp Show annotated file Show diff for this revision Revisions of this file
lib/StatusLed.h Show annotated file Show diff for this revision Revisions of this file
lib/vl6180xManager.cpp Show annotated file Show diff for this revision Revisions of this file
lib/vl6180xManager.h Show annotated file Show diff for this revision Revisions of this file
m3pi.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/M3Dpi.cpp	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,96 @@
+
+#include "M3Dpi.h"
+
+M3Dpi::M3Dpi() :
+    status(STATUS_RED,STATUS_GREEN,STATUS_BLUE),
+    compass(SDA, SCL, 0x3D),
+    gyro(SDA, SCL),
+    accelerometer(SDA,SCL),
+    leds(SDA, SCL),
+    distance(SDA, SCL),
+    xbee(XBEE_TX, XBEE_RX, XBEE_RESET)
+{
+    xbee.baud(XBEE_BAUD);
+    xbee.reset();
+    
+    gyro.setLpBandwidth(LPFBW_42HZ);
+
+    //Go into standby mode to configure the device.
+    accelerometer.setPowerControl(0x00);
+    wait(.001);
+    //Full resolution, +/-16g, 4mg/LSB.
+    accelerometer.setDataFormatControl(0x0B);
+    wait(.001);
+    //3.2kHz data rate.
+    accelerometer.setDataRate(ADXL345_3200HZ);
+    wait(.001);
+    //Measurement mode.
+    accelerometer.setPowerControl(0x08);
+    wait(.001);
+}
+
+void M3Dpi::setStatus(Color* color)
+{
+    status.setColor(color);
+}
+
+void M3Dpi::setStatus(int color)
+{
+    status.setColor(color);
+}
+
+
+void M3Dpi::setLeds(int* colors)
+{
+    leds.setAll(colors);
+}
+
+int* M3Dpi::getDistance(int data[])
+{
+    return distance.getAllDistance(data);;
+}
+
+int* M3Dpi::getDirection(int data[])
+{
+    coord c;
+    c = compass.getCompass();
+    data[0] = c.x;
+    data[1] = c.y;
+    data[2] = c.z;
+    return data;
+}
+
+int* M3Dpi::getRotation(int data[])
+{
+    data[0] = gyro.getGyroX();
+    data[1] = gyro.getGyroY();
+    data[2] = gyro.getGyroZ();
+    return data;
+}
+
+int* M3Dpi::getAcceleration(int data[])
+{
+    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;
+}
+
+int M3Dpi::_putc(int c)
+{
+    return xbee.putc(c);
+}
+
+int M3Dpi::_getc()
+{
+    return xbee.getc();
+}
+
+char* M3Dpi::getTime(char buffer[])
+{
+    time_t seconds = time(NULL);
+    strftime(buffer, 32, "%d-%m-%Y %T", localtime(&seconds));
+    return buffer;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/M3Dpi.h	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,57 @@
+#pragma once
+
+#include "m3pi.h"
+
+#include "StatusLed.h"
+#include "Color.h"
+#include "LedRing.h"
+#include "hmc5583l.h"
+#include "ITG3200.h"
+#include "ADXL345_I2C.h"
+#include "PCA9547.h"
+//#include "vl6108x.h"
+#include "vl6180xManager.h"
+#include "xbee.h"
+
+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[]);
+    
+    // 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;
+    static const PinName XBEE_RX = p14;
+    static const PinName XBEE_RESET = p12;
+    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/drivers/ADXL345_I2C.lib	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/nimbusgb/code/ADXL345_I2C/#92fa975dab32
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/HMC5583L.lib	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+drivers/HMC5583L#91f08ac76444
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/ITG3200.lib	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/aberk/code/ITG3200/#f27e66e954dd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/PCA9547.lib	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/okano/code/PCA9547/#c716fb3ccb8d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/TLC59116.lib	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+drivers/TLC59116#52a1996ad711
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/VL6180x.lib	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+drivers/VL6180x#84c73bed7d92
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/xbee.lib	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/sillevl/code/xbee-made-simple/#a4621ef93d99
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/LedRing.cpp	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,72 @@
+#include "LedRing.h"
+
+
+LedRing::LedRing(PinName sda, PinName scl): driver1(sda, scl, DRIVER_1_ADDRESS), driver2(sda, scl, DRIVER_2_ADDRESS)
+{
+    driver1.enable();
+    driver2.enable();
+    
+    setBrightness(0.05);
+}
+
+void LedRing::setColor(int led, Color* color)
+{
+    led--; // zero indexed from now on
+    led = led % 8;
+    
+    int channelMap[8] = {0, 3, 6, 0, 3, 6, 9, 9};
+    int driverMap[8]  = {1, 1, 1, 2, 2, 2, 2, 1};
+    
+    TLC59116* driver = (driverMap[led] == 1) ? &driver1 : &driver2;
+    int startChannel = channelMap[led];
+        
+    setLed(driver, startChannel, color);
+}
+
+void LedRing::setColor(int led, int color)
+{
+    Color* _color = new Color(color);
+    setColor(led, _color);
+    delete _color;
+}
+
+void LedRing::setAll(Color* color)
+{
+    for(int i = 0; i < 8; i++){
+        setColor(i+1, color);
+    }
+}
+
+void LedRing::setAll(int color)
+{
+    Color* _color = new Color(color);
+    setAll(_color);
+    delete _color;
+}
+
+void LedRing::setAll(int* colors)
+{
+    for(int i = 0; i < 8; i++){
+        setColor(i+1, colors[i]);
+    }
+}
+
+void LedRing::setLed(TLC59116* driver, int startChannel, Color* color)
+{
+    driver->setChannel(startChannel + 0, color->getRed() / 255.0);
+    driver->setChannel(startChannel + 1, color->getGreen() / 255.0);
+    driver->setChannel(startChannel + 2, color->getBlue() / 255.0);    
+}
+
+void LedRing::setBrightness(float brightness)
+{
+    driver1.setBrightness(brightness);
+    driver2.setBrightness(brightness);
+}
+
+void LedRing::greenRedGradient(int led, int value)
+{
+    Color* _color = new Color(255 - value, value, 0);
+    setColor(led, _color);
+    delete _color;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/LedRing.h	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,41 @@
+#pragma once
+
+#include "mbed.h"
+#include "TLC59116.h"
+#include "Color.h"
+
+enum DistanceSensor{
+    FRONT_LEFT,
+    FRONT_MIDDLE_LEFT,
+    BACK_MIDDLE_LEFT,
+    BACK_LEFT,
+    BACK_RIGHT,
+    BACK_MIDDLE_RIGHT,
+    FRONT_MIDDLE_RIGHT,
+    FRONT_RIGHT  
+}; 
+
+class LedRing{
+    public:
+    LedRing(PinName sda, PinName scl);
+    
+    void setColor(int led, Color* Color);
+    void setColor(int led, int color);
+    void setAll(int color);
+    void setAll(Color* color);
+    void setAll(int* colors);
+    void setBrightness(float brightness);
+    
+    void greenRedGradient(int led, int value);
+    
+    protected:
+    void setLed(TLC59116* driver, int startChannel, Color* color);
+    
+    private:
+    TLC59116 driver1;
+    TLC59116 driver2;
+    
+    static const int DRIVER_1_ADDRESS = 0xC0;
+    static const int DRIVER_2_ADDRESS = 0xC2;
+    
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/RGB-fun.lib	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/sillevl/code/RGB-fun/#d10cfeb2f18e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/StatusLed.cpp	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,21 @@
+
+#include "StatusLed.h"
+
+StatusLed::StatusLed(PinName r_pin, PinName g_pin, PinName b_pin) : r_out(r_pin), g_out(g_pin), b_out(b_pin)
+{
+
+}
+
+void StatusLed::setColor(Color* color){
+    r_out = !color->getRed();
+    g_out = !color->getGreen();
+    b_out = !color->getBlue();
+}
+
+void StatusLed::setColor(int color){
+    setColor(new Color(color));
+}
+
+void StatusLed::off(){
+    setColor(Color::BLACK);   
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/StatusLed.h	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "Color.h"
+#include "mbed.h"
+
+class StatusLed{
+    public:
+    StatusLed(PinName r_pin, PinName g_pin, PinName b_pin);
+    
+    void setColor(Color* color);
+    void setColor(int color);
+    void off();
+    
+    private:
+    DigitalOut r_out;
+    DigitalOut g_out;
+    DigitalOut b_out;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/vl6180xManager.cpp	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,27 @@
+#include "vl6180xManager.h"
+
+
+VL6180xManager::VL6180xManager(PinName sda, PinName scl) : mux(sda, scl), i2c(sda, scl), sensor(sda, scl)
+{
+    i2c.frequency(400000);   
+    for(int i = 0; i < SENSOR_COUNT; i++) {
+        select(i);
+        sensor.initialize();
+    }
+}
+
+void VL6180xManager::select(int index)
+{
+    mux.select(index);
+}
+
+int* VL6180xManager::getAllDistance(int data[])
+{
+    for(int i = 0; i < 8; i++) {
+        mux.select(i);
+        data[i] = sensor.getDistance();
+    }
+    return data;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/vl6180xManager.h	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,44 @@
+#pragma once
+
+#include "mbed.h"
+#include "PCA9547.h"
+#include "vl6180x.h"
+
+/*enum DistanceSensor{
+    FRONT,
+    FRONT_RIGHT,
+    RIGHT,
+    BACK_RIGHT,
+    BACK,
+    BACK_LEFT,
+    LEFT,
+    FRONT_LEFT
+}; */
+
+class VL6180xManager
+{
+public:
+    VL6180xManager(PinName sda, PinName scl);
+    void select(int index);
+    int* getAllDistance(int data[]);
+
+protected:
+
+/*    enum DistanceSensor {
+        FRONT,
+        FRONT_RIGHT,
+        RIGHT,
+        BACK_RIGHT,
+        BACK,
+        BACK_LEFT,
+        LEFT,
+        FRONT_LEFT
+    };*/
+    PCA9547 mux;
+    I2C i2c;
+    int address;
+    VL6180x sensor;
+
+    static const int SENSOR_COUNT = 8;
+    static const int VL6180X_ADDRESS = 0x52;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m3pi.lib	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/chris/code/m3pi/#4b7d6ea9b35b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 03 07:58:50 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b
\ No newline at end of file