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
main.cpp@11:ccb8653e285f, 2015-12-19 (annotated)
- Committer:
- sillevl
- Date:
- Sat Dec 19 13:28:17 2015 +0000
- Revision:
- 11:ccb8653e285f
- Parent:
- 7:9068fc754a0b
- Child:
- 13:d6374484b953
add reporter interface
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sillevl | 7:9068fc754a0b | 1 | #include "mbed.h" |
sillevl | 1:6f620263c9f8 | 2 | #include "M3Dpi.h" |
sillevl | 7:9068fc754a0b | 3 | #include "jsonReporter.h" |
sillevl | 6:414e1fea64f3 | 4 | |
sillevl | 6:414e1fea64f3 | 5 | const char M3DPI_ID[] = "1234567890"; |
sillevl | 6:414e1fea64f3 | 6 | |
sillevl | 7:9068fc754a0b | 7 | M3Dpi robot; |
sillevl | 7:9068fc754a0b | 8 | Serial pc(USBTX,USBRX); |
sillevl | 11:ccb8653e285f | 9 | Reporter* report = new JsonReporter(&pc, M3DPI_ID); |
sillevl | 11:ccb8653e285f | 10 | |
sillevl | 11:ccb8653e285f | 11 | m3dpi::Distance distance; |
sillevl | 11:ccb8653e285f | 12 | m3dpi::Direction direction; |
sillevl | 11:ccb8653e285f | 13 | m3dpi::Rotation rotation; |
sillevl | 11:ccb8653e285f | 14 | m3dpi::Acceleration acceleration; |
sillevl | 6:414e1fea64f3 | 15 | |
sillevl | 6:414e1fea64f3 | 16 | |
sillevl | 6:414e1fea64f3 | 17 | void setLeds(m3dpi::Distance distance) |
sillevl | 6:414e1fea64f3 | 18 | { |
sillevl | 6:414e1fea64f3 | 19 | int colors[8] = {distance.front, distance.front_right, distance.right, distance.back_right, distance.back, distance.back_left, distance.left, distance.front_left}; |
sillevl | 6:414e1fea64f3 | 20 | // shift distance value to get red colors |
sillevl | 6:414e1fea64f3 | 21 | for(int i = 0; i < 8; i++){ |
sillevl | 6:414e1fea64f3 | 22 | colors[i] = colors[i] << 16; |
sillevl | 6:414e1fea64f3 | 23 | } |
sillevl | 6:414e1fea64f3 | 24 | robot.setLeds(colors); |
sillevl | 6:414e1fea64f3 | 25 | } |
sillevl | 6:414e1fea64f3 | 26 | |
sillevl | 11:ccb8653e285f | 27 | void read_sensors_thread() |
sillevl | 6:414e1fea64f3 | 28 | { |
sillevl | 7:9068fc754a0b | 29 | robot.setStatus(Color::GREEN); |
sillevl | 11:ccb8653e285f | 30 | ::distance = robot.getDistance(); |
sillevl | 11:ccb8653e285f | 31 | direction = robot.getDirection(); |
sillevl | 11:ccb8653e285f | 32 | rotation = robot.getRotation(); |
sillevl | 11:ccb8653e285f | 33 | acceleration = robot.getAcceleration(); |
sillevl | 11:ccb8653e285f | 34 | setLeds(::distance); |
sillevl | 11:ccb8653e285f | 35 | robot.setStatus(Color::BLACK); |
sillevl | 6:414e1fea64f3 | 36 | } |
sillevl | 0:ab0ce9ab81bf | 37 | |
sillevl | 1:6f620263c9f8 | 38 | int main() |
sillevl | 6:414e1fea64f3 | 39 | { |
sillevl | 1:6f620263c9f8 | 40 | pc.baud(115200); |
sillevl | 11:ccb8653e285f | 41 | |
sillevl | 11:ccb8653e285f | 42 | while(true){ |
sillevl | 11:ccb8653e285f | 43 | read_sensors_thread(); |
sillevl | 11:ccb8653e285f | 44 | report->distance(::distance); |
sillevl | 11:ccb8653e285f | 45 | report->direction(direction); |
sillevl | 11:ccb8653e285f | 46 | report->rotation(rotation); |
sillevl | 11:ccb8653e285f | 47 | report->acceleration(acceleration); |
sillevl | 11:ccb8653e285f | 48 | //pc.printf("report send time: %d us\n", t.read_us()); |
sillevl | 11:ccb8653e285f | 49 | //report.time(robot.getTime()); |
sillevl | 11:ccb8653e285f | 50 | wait_ms(500); |
sillevl | 11:ccb8653e285f | 51 | } |
sillevl | 0:ab0ce9ab81bf | 52 | } |