First release.
Dependencies: FXOS8700CQ SDFileSystem mbed
Final program
- Controling a robot by Bluetooth, it is capable of making 90° turns and move pre-defined distances.
Code by:
- Mayumi Hori
- Sarahí Morán
- Gerardo Carmona
main.cpp
- Committer:
- gerardo_carmona
- Date:
- 2014-10-16
- Revision:
- 1:ab09b233da7b
- Parent:
- 0:3a322aad8c88
- Child:
- 2:94059cb643be
File content as of revision 1:ab09b233da7b:
/* ================================================================================== --- TEST 1 --- OBJETIVE: Move the motor via bluetooth and program 90° turns to the right and left using the magnometer. It will report data from the encoders and limit the movement by the ultrasonic sensors COMPONENTS: * Bluetooth * Magnometer (FXOS8700CQ & magnometer.h) * Motors (motors.h) * Encoder * Ultrasonics CONTROLS: w: foward s: reverse a: left turn d: right turn o: 90° left turn p: 90° right turn Credits: * Mayumi Haro * Sarahí Morán * Gerardo Carmona VERSION: 1.1 - 10/16/14 HISTORY: 1.1 - 10/16/14 (*) Some bug fixes (*) Added encoder.h and encpoder.cpp (empty files) 1.0 - 10/14/14 (+) Initial release. ================================================================================== */ // ----- Libraries ------------------------------------------------------------------ #include "mbed.h" #include "motors.h" #include "magnometer.h" // ----- Constants ------------------------------------------------------------------ #define LED_ERROR 6 #define LED_NORMAL 5 #define LED_BUSY 3 #define BT_TIME 100 // ----- I/O Pins ------------------------------------------------------------------- Serial pc(USBTX, USBRX); Serial bt(PTC15, PTC14); //FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1) // Leds for status BusOut leds(LED_RED, LED_GREEN, LED_BLUE); // Sensors //AnalogIn current_left(A0); //AnalogIn current_left(A1); AnalogIn ultra_left(A2); AnalogIn ultra_right(A3); DigitalIn encoder_left(D3); DigitalIn encoder_right(D4); // ----- Others --------------------------------------------------------------------- //SRAWDATA accel_data; //SRAWDATA magn_data; Timer bt_timer; Timer gps_timer; // ----- Variables ------------------------------------------------------------------ char bt_data; // ----- Function prototypes -------------------------------------------------------- //double get_mag_x(); //double get_mag_y(); //double get_mag_angle(); // Read angle from the compass char read_bt(); // ----- Main program --------------------------------------------------------------- int main(){ bt.baud(9600); pc.baud(9600); //fxos.enable(); leds = LED_NORMAL; bt_timer.start(); while (true){ if (bt_timer.read_ms() >= BT_TIME){ bt_data = read_bt(); if (bt_data != ' '){ move_motors(bt_data, 100, 100); } } } } // ----- Functions ------------------------------------------------------------------ char read_bt(){ char c = ' '; if (bt.readable()){ c = bt.getc(); bt.printf("%c\n\r", c); } return c; }