This project aims at hacking a remote controlled car by replacing the tx/rx and navigation systems. This project implements the car side.
Dependencies: mbed-rtos mbed ssWi
This project consists of a remote controller which pilots a car holding a video camera onboard. It is divided in two main parts:
- user side: the microcontroller reads the user input from the joystick (four potentiometers), elaborates them and then sends those commands through the wireless connection (using a XBee module);
- car side: the microcontroller receives the sent commands (using a XBee module), elaborates them and adjusts the main engine, the steering servomotor and the two servos which move the X-Y axis of the onboard video camera.
Here are a image of the hardware and a video I recorderd and edited.
Concerning the part related to the user side, the project is the following.
Import programrover_pc
This project aims at hacking a remote controlled car by replacing the tx/rx and navigation systems. This project implements the pc side.
The communication protocol I exploited to make the two parts communicate each other is ssWi.
Import libraryssWi
A simple wireless protocol to let my examples communicate each other. ssWi stands for Shared Slotted Wireless protocol
main.cpp@0:97d3a2b0ff58, 2013-03-12 (annotated)
- Committer:
- mariob
- Date:
- Tue Mar 12 07:35:28 2013 +0000
- Revision:
- 0:97d3a2b0ff58
rover project - car side; MB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mariob | 0:97d3a2b0ff58 | 1 | #include "mbed.h" |
mariob | 0:97d3a2b0ff58 | 2 | #include "rtos.h" |
mariob | 0:97d3a2b0ff58 | 3 | |
mariob | 0:97d3a2b0ff58 | 4 | #include "xbee.hpp" |
mariob | 0:97d3a2b0ff58 | 5 | #include "ssWiSocket.hpp" |
mariob | 0:97d3a2b0ff58 | 6 | #include "car.hpp" |
mariob | 0:97d3a2b0ff58 | 7 | |
mariob | 0:97d3a2b0ff58 | 8 | |
mariob | 0:97d3a2b0ff58 | 9 | #define PORT_MOTOR 20 |
mariob | 0:97d3a2b0ff58 | 10 | #define PORT_SERVO 30 |
mariob | 0:97d3a2b0ff58 | 11 | #define PORT_SERVO_CAMERA_X 40 |
mariob | 0:97d3a2b0ff58 | 12 | #define PORT_SERVO_CAMERA_Y 50 |
mariob | 0:97d3a2b0ff58 | 13 | |
mariob | 0:97d3a2b0ff58 | 14 | #define UPDATING_FUNCTION_MS 200 |
mariob | 0:97d3a2b0ff58 | 15 | |
mariob | 0:97d3a2b0ff58 | 16 | |
mariob | 0:97d3a2b0ff58 | 17 | ssWiSocket* socket_motor; |
mariob | 0:97d3a2b0ff58 | 18 | ssWiSocket* socket_servo; |
mariob | 0:97d3a2b0ff58 | 19 | ssWiSocket* socket_camera_x; |
mariob | 0:97d3a2b0ff58 | 20 | ssWiSocket* socket_camera_y; |
mariob | 0:97d3a2b0ff58 | 21 | |
mariob | 0:97d3a2b0ff58 | 22 | Car car(p23, p24, p25, p26); |
mariob | 0:97d3a2b0ff58 | 23 | |
mariob | 0:97d3a2b0ff58 | 24 | |
mariob | 0:97d3a2b0ff58 | 25 | void udateFunction (const void* arg); |
mariob | 0:97d3a2b0ff58 | 26 | |
mariob | 0:97d3a2b0ff58 | 27 | |
mariob | 0:97d3a2b0ff58 | 28 | int main() |
mariob | 0:97d3a2b0ff58 | 29 | { |
mariob | 0:97d3a2b0ff58 | 30 | //Communication link connection |
mariob | 0:97d3a2b0ff58 | 31 | XBeeModule xbee(p9, p10, 102, 14); |
mariob | 0:97d3a2b0ff58 | 32 | xbee.setDstAddress(XBeeBroadcastAddress()); |
mariob | 0:97d3a2b0ff58 | 33 | xbee.init(-1, 5); |
mariob | 0:97d3a2b0ff58 | 34 | |
mariob | 0:97d3a2b0ff58 | 35 | //Socket creation |
mariob | 0:97d3a2b0ff58 | 36 | socket_motor = ssWiSocket::createSocket(PORT_MOTOR); |
mariob | 0:97d3a2b0ff58 | 37 | socket_servo = ssWiSocket::createSocket(PORT_SERVO); |
mariob | 0:97d3a2b0ff58 | 38 | socket_camera_x = ssWiSocket::createSocket(PORT_SERVO_CAMERA_X); |
mariob | 0:97d3a2b0ff58 | 39 | socket_camera_y = ssWiSocket::createSocket(PORT_SERVO_CAMERA_Y); |
mariob | 0:97d3a2b0ff58 | 40 | if (socket_motor==NULL || socket_servo==NULL || |
mariob | 0:97d3a2b0ff58 | 41 | socket_camera_x==NULL || socket_camera_y==NULL) |
mariob | 0:97d3a2b0ff58 | 42 | printf("Error: sockets\n\r"); |
mariob | 0:97d3a2b0ff58 | 43 | |
mariob | 0:97d3a2b0ff58 | 44 | //Timer setting |
mariob | 0:97d3a2b0ff58 | 45 | RtosTimer timer(udateFunction, osTimerPeriodic, NULL); |
mariob | 0:97d3a2b0ff58 | 46 | timer.start(200); |
mariob | 0:97d3a2b0ff58 | 47 | |
mariob | 0:97d3a2b0ff58 | 48 | //Infinite wait |
mariob | 0:97d3a2b0ff58 | 49 | Thread::wait(osWaitForever); |
mariob | 0:97d3a2b0ff58 | 50 | } |
mariob | 0:97d3a2b0ff58 | 51 | |
mariob | 0:97d3a2b0ff58 | 52 | |
mariob | 0:97d3a2b0ff58 | 53 | void udateFunction (const void* arg) |
mariob | 0:97d3a2b0ff58 | 54 | { |
mariob | 0:97d3a2b0ff58 | 55 | static DigitalOut led(LED1); |
mariob | 0:97d3a2b0ff58 | 56 | static int var = 0; |
mariob | 0:97d3a2b0ff58 | 57 | // while(1) { |
mariob | 0:97d3a2b0ff58 | 58 | car.setSpeed((float)(socket_motor->read())/1000.0); |
mariob | 0:97d3a2b0ff58 | 59 | car.setSteering((float)(socket_servo->read())/1000.0); |
mariob | 0:97d3a2b0ff58 | 60 | float x = (float)socket_camera_x->read()/1000.0; |
mariob | 0:97d3a2b0ff58 | 61 | float y = (float)socket_camera_y->read()/1000.0; |
mariob | 0:97d3a2b0ff58 | 62 | car.setCamera(x, y); |
mariob | 0:97d3a2b0ff58 | 63 | led = var>=10?1:0; |
mariob | 0:97d3a2b0ff58 | 64 | var = var>=20?0:var+1; |
mariob | 0:97d3a2b0ff58 | 65 | // Thread::wait(UPDATING_FUNCTION_MS); |
mariob | 0:97d3a2b0ff58 | 66 | // } |
mariob | 0:97d3a2b0ff58 | 67 | } |