Practical Robotics Modular Robot Library

Dependents:   ModularRobot

Committer:
jah128
Date:
Sat Nov 26 21:43:52 2016 +0000
Revision:
1:a6728adaf7e7
Parent:
0:8a2dd255c508
Child:
2:bf34b86aa0f3
Added docs, debug

Who changed what in which revision?

UserRevisionLine numberNew 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 0:8a2dd255c508 48 extern AnalogIn vin_battery;
jah128 0:8a2dd255c508 49 extern Serial pc;
jah128 0:8a2dd255c508 50 extern Led led;
jah128 0:8a2dd255c508 51 extern Sensors sensors;
jah128 0:8a2dd255c508 52 extern Motors motors;
jah128 0:8a2dd255c508 53 extern volatile char i2c_lock;
jah128 0:8a2dd255c508 54
jah128 1:a6728adaf7e7 55 /**
jah128 1:a6728adaf7e7 56 * The Robot class contains the core functions for the robot
jah128 1:a6728adaf7e7 57 */
jah128 0:8a2dd255c508 58 class Robot
jah128 0:8a2dd255c508 59 {
jah128 0:8a2dd255c508 60 public:
jah128 0:8a2dd255c508 61
jah128 0:8a2dd255c508 62 /**
jah128 0:8a2dd255c508 63 * Main initialisation routine: setup the robot, the I2C interfaces, start system timers etc.
jah128 0:8a2dd255c508 64 *
jah128 0:8a2dd255c508 65 */
jah128 0:8a2dd255c508 66 void init(void);
jah128 0:8a2dd255c508 67
jah128 0:8a2dd255c508 68 /**
jah128 0:8a2dd255c508 69 * Get the uptime for the MBED
jah128 0:8a2dd255c508 70 *
jah128 0:8a2dd255c508 71 * @return The amount of time in seconds that the MBED has been active since last reset
jah128 0:8a2dd255c508 72 */
jah128 0:8a2dd255c508 73 float get_uptime(void);
jah128 0:8a2dd255c508 74
jah128 0:8a2dd255c508 75 /**
jah128 0:8a2dd255c508 76 * Get the battery voltage
jah128 0:8a2dd255c508 77 *
jah128 0:8a2dd255c508 78 * The battery voltage is passed through a 7.5V Zener diode, then into a 1:1 potential divider. This
jah128 0:8a2dd255c508 79 * allows a voltage in the approximate range 7.5 to 13.8V to be measured.
jah128 0:8a2dd255c508 80 *
jah128 0:8a2dd255c508 81 * @return The current voltage reading for the battery
jah128 0:8a2dd255c508 82 */
jah128 0:8a2dd255c508 83 float get_battery_voltage(void);
jah128 0:8a2dd255c508 84
jah128 1:a6728adaf7e7 85 /**
jah128 1:a6728adaf7e7 86 * Display a string message (printf) on the selected debug output stream [eg pc, bt or both]
jah128 1:a6728adaf7e7 87 */
jah128 1:a6728adaf7e7 88 void debug(const char* format, ...);
jah128 1:a6728adaf7e7 89
jah128 1:a6728adaf7e7 90 /**
jah128 1:a6728adaf7e7 91 * Setup the serial interfaces (pc, bt) at the correct baud rate and attach listeners
jah128 1:a6728adaf7e7 92 */
jah128 1:a6728adaf7e7 93 void setup_serial_interfaces(void);
jah128 1:a6728adaf7e7 94
jah128 0:8a2dd255c508 95 private:
jah128 0:8a2dd255c508 96 void _update_minutes(void);
jah128 1:a6728adaf7e7 97 void _bt_rx_callback(void);
jah128 1:a6728adaf7e7 98 void _pc_rx_callback(void);
jah128 0:8a2dd255c508 99 };
jah128 0:8a2dd255c508 100
jah128 0:8a2dd255c508 101
jah128 0:8a2dd255c508 102 #endif