Practical Robotics Modular Robot Library

Dependents:   ModularRobot

Committer:
jah128
Date:
Fri Jan 13 23:16:23 2017 +0000
Revision:
6:732aa91eb555
Parent:
5:6da8daaeb9f7
Updated;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:8a2dd255c508 1 #ifndef ROBOT_H
jah128 0:8a2dd255c508 2 #define ROBOT_H
jah128 0:8a2dd255c508 3
jah128 0:8a2dd255c508 4 #include "mbed.h"
jah128 0:8a2dd255c508 5 #include "led.h"
jah128 0:8a2dd255c508 6 #include "sensors.h"
jah128 0:8a2dd255c508 7 #include "motors.h"
jah128 0:8a2dd255c508 8 #include "calibration.h"
jah128 4:c2e933d53bea 9 #include "serialcomms.h"
jah128 0:8a2dd255c508 10
jah128 0:8a2dd255c508 11 #define LED_ADDRESS 0xC0
jah128 0:8a2dd255c508 12 #define ADC_ADDRESS 0x90
jah128 4:c2e933d53bea 13 #define COMMAND_MESSAGE_BYTE 0x1D
jah128 4:c2e933d53bea 14 #define ACKNOWLEDGE_MESSAGE_BYTE 0x1E
jah128 4:c2e933d53bea 15 #define RESPONSE_MESSAGE_BYTE 0x1F
jah128 4:c2e933d53bea 16 #define STATUS_MESSAGE_BYTE 0x1C
jah128 4:c2e933d53bea 17 #define IR_MESSAGE_BYTE 0x1B
jah128 4:c2e933d53bea 18 #define SOFTWARE_VERSION_CODE 0.10
jah128 0:8a2dd255c508 19
jah128 1:a6728adaf7e7 20 // SERIAL INTERFACES SETTINGS
jah128 1:a6728adaf7e7 21
jah128 1:a6728adaf7e7 22 /* ENABLE_BLUETOOTH [1=on, 0=off]: Enable if the BlueSmirf module is being used */
jah128 1:a6728adaf7e7 23 /** @brief Enable if the BlueSmirf module is being used. 0=off 1=on*/
jah128 1:a6728adaf7e7 24 #define ENABLE_BLUETOOTH 1
jah128 1:a6728adaf7e7 25
jah128 1:a6728adaf7e7 26 /* ENABLE_PC_SERIAL [1=on, 0=off]: Enable if the PC(RPi) USB serial module is being used */
jah128 1:a6728adaf7e7 27 #define ENABLE_PC_SERIAL 1
jah128 1:a6728adaf7e7 28
jah128 1:a6728adaf7e7 29 /* BLUETOOTH_BAUD [recommended=115200]: Baud rate for the BlueSMIRF module */
jah128 1:a6728adaf7e7 30 #define BLUETOOTH_BAUD 115200
jah128 1:a6728adaf7e7 31
jah128 4:c2e933d53bea 32 /* PC_BAUD [recommended=460800 for optimal performance with RPi, 115200 for compatability]: Baud rate for the RPi USB serial module */
jah128 4:c2e933d53bea 33 //#define PC_BAUD 115200
jah128 4:c2e933d53bea 34 #define PC_BAUD 460800
jah128 1:a6728adaf7e7 35
jah128 1:a6728adaf7e7 36 /* DEBUG_MODE [1=on, 0=off]: Enable to allow debug messages to be sent of one of the serial interfaces */
jah128 1:a6728adaf7e7 37 #define DEBUG_MODE 1
jah128 1:a6728adaf7e7 38
jah128 4:c2e933d53bea 39 /* 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. Recommended to use BT for debug messages.*/
jah128 4:c2e933d53bea 40 #define DEBUG_OUTPUT_STREAM 2
jah128 1:a6728adaf7e7 41
jah128 0:8a2dd255c508 42 // To update sensors 10 times a second (8 x 0.0125 = 0.1)
jah128 0:8a2dd255c508 43 #define SENSOR_TICKER_PERIOD 0.0125
jah128 0:8a2dd255c508 44
jah128 0:8a2dd255c508 45 // 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 46 // Slower speeds work a bit faster but noisier
jah128 5:6da8daaeb9f7 47 #define MOTOR_PWM_PERIOD_US 10
jah128 0:8a2dd255c508 48
jah128 0:8a2dd255c508 49 #define USE_STALL_OFFSET 1
jah128 0:8a2dd255c508 50 #define STALL_OFFSET 0.22
jah128 0:8a2dd255c508 51
jah128 0:8a2dd255c508 52 extern I2C primary_i2c;
jah128 3:8762f6b2ea8d 53 extern DigitalIn rpi1;
jah128 2:bf34b86aa0f3 54 extern DigitalOut case_led;
jah128 2:bf34b86aa0f3 55 extern DigitalOut mbed_led1;
jah128 2:bf34b86aa0f3 56 extern DigitalOut mbed_led2;
jah128 2:bf34b86aa0f3 57 extern DigitalOut mbed_led3;
jah128 2:bf34b86aa0f3 58 extern DigitalOut mbed_led4;
jah128 4:c2e933d53bea 59 extern DigitalOut case_led;
jah128 0:8a2dd255c508 60 extern AnalogIn vin_battery;
jah128 0:8a2dd255c508 61 extern Serial pc;
jah128 4:c2e933d53bea 62 extern Serial bt;
jah128 4:c2e933d53bea 63 extern SerialComms serial;
jah128 0:8a2dd255c508 64 extern Led led;
jah128 0:8a2dd255c508 65 extern Sensors sensors;
jah128 0:8a2dd255c508 66 extern Motors motors;
jah128 0:8a2dd255c508 67 extern volatile char i2c_lock;
jah128 4:c2e933d53bea 68 extern char debug_mode;
jah128 4:c2e933d53bea 69 extern char debug_output;
jah128 4:c2e933d53bea 70 extern char status_message [];
jah128 0:8a2dd255c508 71
jah128 1:a6728adaf7e7 72 /**
jah128 1:a6728adaf7e7 73 * The Robot class contains the core functions for the robot
jah128 1:a6728adaf7e7 74 */
jah128 0:8a2dd255c508 75 class Robot
jah128 0:8a2dd255c508 76 {
jah128 0:8a2dd255c508 77 public:
jah128 0:8a2dd255c508 78
jah128 0:8a2dd255c508 79 /**
jah128 0:8a2dd255c508 80 * Main initialisation routine: setup the robot, the I2C interfaces, start system timers etc.
jah128 0:8a2dd255c508 81 *
jah128 0:8a2dd255c508 82 */
jah128 0:8a2dd255c508 83 void init(void);
jah128 0:8a2dd255c508 84
jah128 0:8a2dd255c508 85 /**
jah128 0:8a2dd255c508 86 * Get the uptime for the MBED
jah128 0:8a2dd255c508 87 *
jah128 0:8a2dd255c508 88 * @return The amount of time in seconds that the MBED has been active since last reset
jah128 0:8a2dd255c508 89 */
jah128 0:8a2dd255c508 90 float get_uptime(void);
jah128 0:8a2dd255c508 91
jah128 0:8a2dd255c508 92 /**
jah128 0:8a2dd255c508 93 * Get the battery voltage
jah128 0:8a2dd255c508 94 *
jah128 0:8a2dd255c508 95 * The battery voltage is passed through a 7.5V Zener diode, then into a 1:1 potential divider. This
jah128 0:8a2dd255c508 96 * allows a voltage in the approximate range 7.5 to 13.8V to be measured.
jah128 0:8a2dd255c508 97 *
jah128 0:8a2dd255c508 98 * @return The current voltage reading for the battery
jah128 0:8a2dd255c508 99 */
jah128 0:8a2dd255c508 100 float get_battery_voltage(void);
jah128 0:8a2dd255c508 101
jah128 1:a6728adaf7e7 102 /**
jah128 1:a6728adaf7e7 103 * Display a string message (printf) on the selected debug output stream [eg pc, bt or both]
jah128 1:a6728adaf7e7 104 */
jah128 1:a6728adaf7e7 105 void debug(const char* format, ...);
jah128 1:a6728adaf7e7 106
jah128 1:a6728adaf7e7 107
jah128 3:8762f6b2ea8d 108 /**
jah128 4:c2e933d53bea 109 * Toggles the current state of the MBED case led (use with a ticker to blink LED etc)
jah128 3:8762f6b2ea8d 110 */
jah128 4:c2e933d53bea 111 void case_led_toggle(void);
jah128 4:c2e933d53bea 112
jah128 4:c2e933d53bea 113
jah128 4:c2e933d53bea 114 /**
jah128 4:c2e933d53bea 115 * Update the global 8-character status message
jah128 4:c2e933d53bea 116 */
jah128 3:8762f6b2ea8d 117 void update_status_message(void);
jah128 3:8762f6b2ea8d 118
jah128 0:8a2dd255c508 119 private:
jah128 0:8a2dd255c508 120 void _update_minutes(void);
jah128 0:8a2dd255c508 121 };
jah128 0:8a2dd255c508 122
jah128 0:8a2dd255c508 123
jah128 4:c2e933d53bea 124 extern Robot robot;
jah128 0:8a2dd255c508 125 #endif