
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: m3Dpi mbed-rtos mbed MbedJSONValue
Revision 11:ccb8653e285f, committed 2015-12-19
- Comitter:
- sillevl
- Date:
- Sat Dec 19 13:28:17 2015 +0000
- Parent:
- 7:9068fc754a0b
- Child:
- 13:d6374484b953
- Commit message:
- add reporter interface
Changed in this revision
--- a/lib/jsonReporter.cpp Thu Dec 03 17:53:04 2015 +0000 +++ b/lib/jsonReporter.cpp Sat Dec 19 13:28:17 2015 +0000 @@ -1,6 +1,6 @@ #include "jsonReporter.h" -JsonReporter::JsonReporter(mbed::Stream* _out, const char _id[]) : out(_out), id(_id) +JsonReporter::JsonReporter(mbed::Stream* _out, const char _id[]) : Reporter(_out, _id) { }
--- a/lib/jsonReporter.h Thu Dec 03 17:53:04 2015 +0000 +++ b/lib/jsonReporter.h Sat Dec 19 13:28:17 2015 +0000 @@ -1,21 +1,25 @@ #pragma once +#include "reporter.h" #include "mbed.h" #include "MbedJSONValue.h" #include "M3Dpi.h" // TODO: only report if value is different? -class JsonReporter +class JsonReporter : public Reporter { mbed::Stream* out; const char* id; public: JsonReporter(mbed::Stream* _out, const char _id[]); + + virtual void time(time_t seconds); + virtual void distance(m3dpi::Distance distance); + virtual void acceleration(m3dpi::Acceleration acc); + virtual void direction(m3dpi::Direction direction); + virtual void rotation(m3dpi::Rotation rotation); + +protected: MbedJSONValue* jsonFactory(); void print(MbedJSONValue* json); - void time(time_t seconds); - void distance(m3dpi::Distance distance); - void acceleration(m3dpi::Acceleration acc); - void direction(m3dpi::Direction direction); - void rotation(m3dpi::Rotation rotation); }; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/reporter.cpp Sat Dec 19 13:28:17 2015 +0000 @@ -0,0 +1,6 @@ +#include "reporter.h" + +Reporter::Reporter(mbed::Stream* _out, const char _id[]) : out(_out), id(_id) +{ + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/reporter.h Sat Dec 19 13:28:17 2015 +0000 @@ -0,0 +1,18 @@ +#pragma once + +#include "mbed.h" +#include "M3Dpi.h" + +// TODO: only report if value is different? +class Reporter +{ + mbed::Stream* out; + const char* id; +public: + Reporter(mbed::Stream* _out, const char _id[]); + virtual void time(time_t seconds) = 0; + virtual void distance(m3dpi::Distance distance) = 0; + virtual void acceleration(m3dpi::Acceleration acc) = 0; + virtual void direction(m3dpi::Direction direction) = 0; + virtual void rotation(m3dpi::Rotation rotation) = 0; +}; \ No newline at end of file
--- a/m3Dpi.lib Thu Dec 03 17:53:04 2015 +0000 +++ b/m3Dpi.lib Sat Dec 19 13:28:17 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/sillevl/code/m3Dpi/#b2fe3a2545bf +http://mbed.org/users/sillevl/code/m3Dpi/#6f2440be5aa4
--- a/main.cpp Thu Dec 03 17:53:04 2015 +0000 +++ b/main.cpp Sat Dec 19 13:28:17 2015 +0000 @@ -1,5 +1,4 @@ #include "mbed.h" -#include "rtos.h" #include "M3Dpi.h" #include "jsonReporter.h" @@ -7,7 +6,12 @@ M3Dpi robot; Serial pc(USBTX,USBRX); -JsonReporter report(&pc, M3DPI_ID); +Reporter* report = new JsonReporter(&pc, M3DPI_ID); + +m3dpi::Distance distance; +m3dpi::Direction direction; +m3dpi::Rotation rotation; +m3dpi::Acceleration acceleration; void setLeds(m3dpi::Distance distance) @@ -20,31 +24,29 @@ robot.setLeds(colors); } -void read_sensors_thread(void const * args) +void read_sensors_thread() { robot.setStatus(Color::GREEN); - m3dpi::Distance distance = robot.getDistance(); - setLeds(distance); - - report.distance(distance); - report.direction(robot.getDirection()); - report.rotation(robot.getRotation()); - report.acceleration(robot.getAcceleration()); - - report.time(robot.getTime()); - robot.setStatus(Color::OFF); + ::distance = robot.getDistance(); + direction = robot.getDirection(); + rotation = robot.getRotation(); + acceleration = robot.getAcceleration(); + setLeds(::distance); + robot.setStatus(Color::BLACK); } int main() { pc.baud(115200); - - // for testing... - pc.printf("Device ID is: 0x%02x\n", robot.accelerometer.getDevId()); - pc.printf("Gyro id: 0x%02x\n", robot.gyro.getWhoAmI()); - - RtosTimer periodicThread(read_sensors_thread, osTimerPeriodic); - periodicThread.start(50); - - Thread::wait(osWaitForever); + + while(true){ + read_sensors_thread(); + report->distance(::distance); + report->direction(direction); + report->rotation(rotation); + report->acceleration(acceleration); + //pc.printf("report send time: %d us\n", t.read_us()); + //report.time(robot.getTime()); + wait_ms(500); + } } \ No newline at end of file
--- a/mbed.bld Thu Dec 03 17:53:04 2015 +0000 +++ b/mbed.bld Sat Dec 19 13:28:17 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c \ No newline at end of file