Practical Robotics Modular Robot Library
robot.h@2:bf34b86aa0f3, 2016-11-26 (annotated)
- Committer:
- jah128
- Date:
- Sat Nov 26 21:50:10 2016 +0000
- Revision:
- 2:bf34b86aa0f3
- Parent:
- 1:a6728adaf7e7
- Child:
- 3:8762f6b2ea8d
Added extra leds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:8a2dd255c508 | 1 | |
jah128 | 0:8a2dd255c508 | 2 | |
jah128 | 0:8a2dd255c508 | 3 | #ifndef ROBOT_H |
jah128 | 0:8a2dd255c508 | 4 | #define ROBOT_H |
jah128 | 0:8a2dd255c508 | 5 | |
jah128 | 0:8a2dd255c508 | 6 | #include "mbed.h" |
jah128 | 0:8a2dd255c508 | 7 | #include "led.h" |
jah128 | 0:8a2dd255c508 | 8 | #include "sensors.h" |
jah128 | 0:8a2dd255c508 | 9 | #include "motors.h" |
jah128 | 0:8a2dd255c508 | 10 | #include "calibration.h" |
jah128 | 0:8a2dd255c508 | 11 | |
jah128 | 0:8a2dd255c508 | 12 | #define LED_ADDRESS 0xC0 |
jah128 | 0:8a2dd255c508 | 13 | #define ADC_ADDRESS 0x90 |
jah128 | 0:8a2dd255c508 | 14 | |
jah128 | 1:a6728adaf7e7 | 15 | // SERIAL INTERFACES SETTINGS |
jah128 | 1:a6728adaf7e7 | 16 | |
jah128 | 1:a6728adaf7e7 | 17 | /* ENABLE_BLUETOOTH [1=on, 0=off]: Enable if the BlueSmirf module is being used */ |
jah128 | 1:a6728adaf7e7 | 18 | /** @brief Enable if the BlueSmirf module is being used. 0=off 1=on*/ |
jah128 | 1:a6728adaf7e7 | 19 | #define ENABLE_BLUETOOTH 1 |
jah128 | 1:a6728adaf7e7 | 20 | |
jah128 | 1:a6728adaf7e7 | 21 | /* ENABLE_PC_SERIAL [1=on, 0=off]: Enable if the PC(RPi) USB serial module is being used */ |
jah128 | 1:a6728adaf7e7 | 22 | #define ENABLE_PC_SERIAL 1 |
jah128 | 1:a6728adaf7e7 | 23 | |
jah128 | 1:a6728adaf7e7 | 24 | /* BLUETOOTH_BAUD [recommended=115200]: Baud rate for the BlueSMIRF module */ |
jah128 | 1:a6728adaf7e7 | 25 | #define BLUETOOTH_BAUD 115200 |
jah128 | 1:a6728adaf7e7 | 26 | |
jah128 | 1:a6728adaf7e7 | 27 | /* PC_BAUD [recommended=460800 for optimal performance, 115200 for compatability]: Baud rate for the PC USB serial module */ |
jah128 | 1:a6728adaf7e7 | 28 | //#define PC_BAUD 460800 |
jah128 | 1:a6728adaf7e7 | 29 | #define PC_BAUD 115200 |
jah128 | 1:a6728adaf7e7 | 30 | |
jah128 | 1:a6728adaf7e7 | 31 | /* DEBUG_MODE [1=on, 0=off]: Enable to allow debug messages to be sent of one of the serial interfaces */ |
jah128 | 1:a6728adaf7e7 | 32 | #define DEBUG_MODE 1 |
jah128 | 1:a6728adaf7e7 | 33 | |
jah128 | 1:a6728adaf7e7 | 34 | /* DEBUG_OUTPUT_STREAM [1=PC\USB 2=BlueSmirf 4=Display]: Specify which output stream(s) should be used by default for debug messages, if enabled*/ |
jah128 | 1:a6728adaf7e7 | 35 | #define DEBUG_OUTPUT_STREAM 1 |
jah128 | 1:a6728adaf7e7 | 36 | |
jah128 | 0:8a2dd255c508 | 37 | // To update sensors 10 times a second (8 x 0.0125 = 0.1) |
jah128 | 0:8a2dd255c508 | 38 | #define SENSOR_TICKER_PERIOD 0.0125 |
jah128 | 0:8a2dd255c508 | 39 | |
jah128 | 0:8a2dd255c508 | 40 | // H-Bridge should work at upto 100kHz (10uS) but note it seems to behave unusually at frequencies close to but above this |
jah128 | 0:8a2dd255c508 | 41 | // Slower speeds work a bit faster but noisier |
jah128 | 0:8a2dd255c508 | 42 | #define MOTOR_PWM_PERIOD_US 400 |
jah128 | 0:8a2dd255c508 | 43 | |
jah128 | 0:8a2dd255c508 | 44 | #define USE_STALL_OFFSET 1 |
jah128 | 0:8a2dd255c508 | 45 | #define STALL_OFFSET 0.22 |
jah128 | 0:8a2dd255c508 | 46 | |
jah128 | 0:8a2dd255c508 | 47 | extern I2C primary_i2c; |
jah128 | 2:bf34b86aa0f3 | 48 | extern DigitalOut case_led; |
jah128 | 2:bf34b86aa0f3 | 49 | extern DigitalOut mbed_led1; |
jah128 | 2:bf34b86aa0f3 | 50 | extern DigitalOut mbed_led2; |
jah128 | 2:bf34b86aa0f3 | 51 | extern DigitalOut mbed_led3; |
jah128 | 2:bf34b86aa0f3 | 52 | extern DigitalOut mbed_led4; |
jah128 | 0:8a2dd255c508 | 53 | extern AnalogIn vin_battery; |
jah128 | 0:8a2dd255c508 | 54 | extern Serial pc; |
jah128 | 0:8a2dd255c508 | 55 | extern Led led; |
jah128 | 0:8a2dd255c508 | 56 | extern Sensors sensors; |
jah128 | 0:8a2dd255c508 | 57 | extern Motors motors; |
jah128 | 0:8a2dd255c508 | 58 | extern volatile char i2c_lock; |
jah128 | 0:8a2dd255c508 | 59 | |
jah128 | 1:a6728adaf7e7 | 60 | /** |
jah128 | 1:a6728adaf7e7 | 61 | * The Robot class contains the core functions for the robot |
jah128 | 1:a6728adaf7e7 | 62 | */ |
jah128 | 0:8a2dd255c508 | 63 | class Robot |
jah128 | 0:8a2dd255c508 | 64 | { |
jah128 | 0:8a2dd255c508 | 65 | public: |
jah128 | 0:8a2dd255c508 | 66 | |
jah128 | 0:8a2dd255c508 | 67 | /** |
jah128 | 0:8a2dd255c508 | 68 | * Main initialisation routine: setup the robot, the I2C interfaces, start system timers etc. |
jah128 | 0:8a2dd255c508 | 69 | * |
jah128 | 0:8a2dd255c508 | 70 | */ |
jah128 | 0:8a2dd255c508 | 71 | void init(void); |
jah128 | 0:8a2dd255c508 | 72 | |
jah128 | 0:8a2dd255c508 | 73 | /** |
jah128 | 0:8a2dd255c508 | 74 | * Get the uptime for the MBED |
jah128 | 0:8a2dd255c508 | 75 | * |
jah128 | 0:8a2dd255c508 | 76 | * @return The amount of time in seconds that the MBED has been active since last reset |
jah128 | 0:8a2dd255c508 | 77 | */ |
jah128 | 0:8a2dd255c508 | 78 | float get_uptime(void); |
jah128 | 0:8a2dd255c508 | 79 | |
jah128 | 0:8a2dd255c508 | 80 | /** |
jah128 | 0:8a2dd255c508 | 81 | * Get the battery voltage |
jah128 | 0:8a2dd255c508 | 82 | * |
jah128 | 0:8a2dd255c508 | 83 | * The battery voltage is passed through a 7.5V Zener diode, then into a 1:1 potential divider. This |
jah128 | 0:8a2dd255c508 | 84 | * allows a voltage in the approximate range 7.5 to 13.8V to be measured. |
jah128 | 0:8a2dd255c508 | 85 | * |
jah128 | 0:8a2dd255c508 | 86 | * @return The current voltage reading for the battery |
jah128 | 0:8a2dd255c508 | 87 | */ |
jah128 | 0:8a2dd255c508 | 88 | float get_battery_voltage(void); |
jah128 | 0:8a2dd255c508 | 89 | |
jah128 | 1:a6728adaf7e7 | 90 | /** |
jah128 | 1:a6728adaf7e7 | 91 | * Display a string message (printf) on the selected debug output stream [eg pc, bt or both] |
jah128 | 1:a6728adaf7e7 | 92 | */ |
jah128 | 1:a6728adaf7e7 | 93 | void debug(const char* format, ...); |
jah128 | 1:a6728adaf7e7 | 94 | |
jah128 | 1:a6728adaf7e7 | 95 | /** |
jah128 | 1:a6728adaf7e7 | 96 | * Setup the serial interfaces (pc, bt) at the correct baud rate and attach listeners |
jah128 | 1:a6728adaf7e7 | 97 | */ |
jah128 | 1:a6728adaf7e7 | 98 | void setup_serial_interfaces(void); |
jah128 | 1:a6728adaf7e7 | 99 | |
jah128 | 0:8a2dd255c508 | 100 | private: |
jah128 | 0:8a2dd255c508 | 101 | void _update_minutes(void); |
jah128 | 1:a6728adaf7e7 | 102 | void _bt_rx_callback(void); |
jah128 | 1:a6728adaf7e7 | 103 | void _pc_rx_callback(void); |
jah128 | 0:8a2dd255c508 | 104 | }; |
jah128 | 0:8a2dd255c508 | 105 | |
jah128 | 0:8a2dd255c508 | 106 | |
jah128 | 0:8a2dd255c508 | 107 | #endif |