C++ Library for the PsiSwarm Robot - Version 0.8
Dependents: PsiSwarm_V8_Blank_CPP Autonomia_RndmWlk
Fork of PsiSwarmV7_CPP by
psiswarm.h@15:be92991621b4, 2017-07-14 (annotated)
- Committer:
- JessicaGao
- Date:
- Fri Jul 14 12:34:22 2017 +0000
- Revision:
- 15:be92991621b4
- Parent:
- 14:d32d948f7a76
detect beacon;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 12:878c6e9d9e60 | 1 | /* University of York Robotics Laboratory PsiSwarm Library: PsiSwarm C++ Core Header File |
jah128 | 12:878c6e9d9e60 | 2 | * |
jah128 | 6:b340a527add9 | 3 | * Copyright 2016 University of York |
jah128 | 6:b340a527add9 | 4 | * |
jah128 | 12:878c6e9d9e60 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. |
jah128 | 6:b340a527add9 | 6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
jah128 | 6:b340a527add9 | 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS |
jah128 | 12:878c6e9d9e60 | 8 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jah128 | 6:b340a527add9 | 9 | * See the License for the specific language governing permissions and limitations under the License. |
jah128 | 6:b340a527add9 | 10 | * |
jah128 | 0:d6269d17c8cf | 11 | * File: psiswarm.h |
jah128 | 0:d6269d17c8cf | 12 | * |
jah128 | 0:d6269d17c8cf | 13 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 0:d6269d17c8cf | 14 | * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis |
jah128 | 0:d6269d17c8cf | 15 | * |
jah128 | 11:312663037b8c | 16 | * PsiSwarm Library Version: 0.8 |
jah128 | 0:d6269d17c8cf | 17 | * |
jah128 | 5:3cdd1a37cdd7 | 18 | * October 2016 |
jah128 | 0:d6269d17c8cf | 19 | * |
jah128 | 0:d6269d17c8cf | 20 | * |
jah128 | 12:878c6e9d9e60 | 21 | */ |
jah128 | 0:d6269d17c8cf | 22 | |
jah128 | 0:d6269d17c8cf | 23 | #ifndef PSISWARM_H |
jah128 | 0:d6269d17c8cf | 24 | #define PSISWARM_H |
jah128 | 12:878c6e9d9e60 | 25 | |
jah128 | 11:312663037b8c | 26 | #define SOFTWARE_VERSION_CODE 0.80 |
jah128 | 0:d6269d17c8cf | 27 | |
jah128 | 0:d6269d17c8cf | 28 | #define PIC_ADDRESS 0x30 |
jah128 | 12:878c6e9d9e60 | 29 | #define LCD_ADDRESS 0x7C |
jah128 | 0:d6269d17c8cf | 30 | #define LED_IC_ADDRESS 0x42 |
jah128 | 0:d6269d17c8cf | 31 | #define GPIO_IC_ADDRESS 0x40 |
jah128 | 0:d6269d17c8cf | 32 | #define AUX_IC_ADDRESS 0x4E |
jah128 | 0:d6269d17c8cf | 33 | #define ADC1_ADDRESS 0x46 |
jah128 | 0:d6269d17c8cf | 34 | #define ADC2_ADDRESS 0x48 |
jah128 | 0:d6269d17c8cf | 35 | #define EEPROM_ADDRESS 0XA0 |
jah128 | 0:d6269d17c8cf | 36 | #define TEMPERATURE_ADDRESS 0X30 |
jah128 | 0:d6269d17c8cf | 37 | #define BASE_COLOUR_ADDRESS 0X52 |
jah128 | 0:d6269d17c8cf | 38 | #define TOP_COLOUR_ADDRESS 0X72 |
jah128 | 0:d6269d17c8cf | 39 | #define ULTRASONIC_ADDRESS 0XE0 |
jah128 | 0:d6269d17c8cf | 40 | #define COMMAND_MESSAGE_BYTE 0X1D |
jah128 | 0:d6269d17c8cf | 41 | #define ACKNOWLEDGE_MESSAGE_BYTE 0X1E |
jah128 | 0:d6269d17c8cf | 42 | #define RESPONSE_MESSAGE_BYTE 0X1F |
jah128 | 0:d6269d17c8cf | 43 | #define PSI_BYTE 0X1D |
jah128 | 0:d6269d17c8cf | 44 | |
jah128 | 0:d6269d17c8cf | 45 | //Set temperature sensor warnings: 60C critical, 50C high, 0C low |
jah128 | 0:d6269d17c8cf | 46 | #define TEMPERATURE_CRITICAL_HI 0X03 |
jah128 | 0:d6269d17c8cf | 47 | #define TEMPEARTURE_CRITICAL_LO 0XC0 |
jah128 | 0:d6269d17c8cf | 48 | #define TEMPERATURE_HIGH_HI 0X03 |
jah128 | 0:d6269d17c8cf | 49 | #define TEMPEARTURE_HIGH_LO 0X20 |
jah128 | 0:d6269d17c8cf | 50 | #define TEMPERATURE_LOW_HI 0X00 |
jah128 | 0:d6269d17c8cf | 51 | #define TEMPEARTURE_LOW_LO 0X00 |
jah128 | 0:d6269d17c8cf | 52 | |
jah128 | 0:d6269d17c8cf | 53 | #define DEFAULT_IR_PULSE_DELAY 400 |
jah128 | 0:d6269d17c8cf | 54 | #define DEFAULT_BASE_IR_PULSE_DELAY 50 |
jah128 | 0:d6269d17c8cf | 55 | |
jah128 | 0:d6269d17c8cf | 56 | #include <stdio.h> |
jah128 | 0:d6269d17c8cf | 57 | #include <stdarg.h> |
jah128 | 0:d6269d17c8cf | 58 | #include <string> |
jah128 | 0:d6269d17c8cf | 59 | #include <vector> |
jah128 | 0:d6269d17c8cf | 60 | |
jah128 | 0:d6269d17c8cf | 61 | #include "settings.h" |
jah128 | 0:d6269d17c8cf | 62 | #include "serial.h" |
jah128 | 0:d6269d17c8cf | 63 | #include "mbed.h" |
jah128 | 0:d6269d17c8cf | 64 | #include "display.h" |
jah128 | 0:d6269d17c8cf | 65 | #include "led.h" |
jah128 | 11:312663037b8c | 66 | #include "i2c_setup.h" |
jah128 | 0:d6269d17c8cf | 67 | #include "motors.h" |
jah128 | 0:d6269d17c8cf | 68 | #include "sensors.h" |
jah128 | 0:d6269d17c8cf | 69 | #include "eprom.h" |
jah128 | 0:d6269d17c8cf | 70 | #include "colour.h" |
jah128 | 11:312663037b8c | 71 | #include "sound.h" |
jah128 | 0:d6269d17c8cf | 72 | #include "demo.h" |
jah128 | 12:878c6e9d9e60 | 73 | #include "animations.h" |
jah128 | 0:d6269d17c8cf | 74 | #include "basic.h" |
jah128 | 0:d6269d17c8cf | 75 | |
jah128 | 0:d6269d17c8cf | 76 | //NB The user needs to have a main.cpp with a main() function and a handle_switch_event(char) function |
jah128 | 0:d6269d17c8cf | 77 | #include "main.h" |
jah128 | 0:d6269d17c8cf | 78 | |
jah128 | 12:878c6e9d9e60 | 79 | /** Psiswarm Class |
jah128 | 12:878c6e9d9e60 | 80 | * The main class to define a robot |
jah128 | 12:878c6e9d9e60 | 81 | * |
jah128 | 12:878c6e9d9e60 | 82 | * Example code for main.cpp: |
jah128 | 12:878c6e9d9e60 | 83 | * @code |
jah128 | 12:878c6e9d9e60 | 84 | * #include "psiswarm.h" |
jah128 | 12:878c6e9d9e60 | 85 | * Psiswarm psi; |
jah128 | 12:878c6e9d9e60 | 86 | * char * program_name = "Example"; |
jah128 | 12:878c6e9d9e60 | 87 | * char * author_name = "Name"; |
jah128 | 12:878c6e9d9e60 | 88 | * char * version_name = "0.8"; |
jah128 | 12:878c6e9d9e60 | 89 | * void handle_switch_event(char switch_state){} |
jah128 | 12:878c6e9d9e60 | 90 | * void handle_user_serial_message(char * message, char length, char interface) {} |
jah128 | 12:878c6e9d9e60 | 91 | * int main(){ |
jah128 | 12:878c6e9d9e60 | 92 | * psi.init(); |
jah128 | 12:878c6e9d9e60 | 93 | * while(1) { //Do something! |
jah128 | 12:878c6e9d9e60 | 94 | * } |
jah128 | 12:878c6e9d9e60 | 95 | * } |
jah128 | 12:878c6e9d9e60 | 96 | * @endcode |
jah128 | 12:878c6e9d9e60 | 97 | */ |
jah128 | 12:878c6e9d9e60 | 98 | class Psiswarm |
jah128 | 12:878c6e9d9e60 | 99 | { |
jah128 | 12:878c6e9d9e60 | 100 | public: |
jah128 | 12:878c6e9d9e60 | 101 | /** |
jah128 | 12:878c6e9d9e60 | 102 | * Main initialisation routine for the PsiSwarm robot |
jah128 | 12:878c6e9d9e60 | 103 | * |
jah128 | 12:878c6e9d9e60 | 104 | * Set up the GPIO expansion ICs, launch demo mode if button is held |
jah128 | 12:878c6e9d9e60 | 105 | */ |
jah128 | 12:878c6e9d9e60 | 106 | void init(void); |
jah128 | 12:878c6e9d9e60 | 107 | |
jah128 | 12:878c6e9d9e60 | 108 | /** |
jah128 | 12:878c6e9d9e60 | 109 | * Get the uptime for the robot |
jah128 | 12:878c6e9d9e60 | 110 | * |
jah128 | 12:878c6e9d9e60 | 111 | * @return The amount of time in seconds that the MBED has been active since last reset |
jah128 | 12:878c6e9d9e60 | 112 | */ |
jah128 | 12:878c6e9d9e60 | 113 | float get_uptime(void); |
jah128 | 12:878c6e9d9e60 | 114 | |
jah128 | 12:878c6e9d9e60 | 115 | /** |
jah128 | 12:878c6e9d9e60 | 116 | * Pause the user code for a defined amount of time |
jah128 | 12:878c6e9d9e60 | 117 | * |
jah128 | 12:878c6e9d9e60 | 118 | * @param The amount of time in seconds to pause user code |
jah128 | 12:878c6e9d9e60 | 119 | */ |
jah128 | 12:878c6e9d9e60 | 120 | void pause_user_code(float period); |
jah128 | 12:878c6e9d9e60 | 121 | |
jah128 | 12:878c6e9d9e60 | 122 | /** |
jah128 | 12:878c6e9d9e60 | 123 | * Reset the wheel encoder counters |
jah128 | 12:878c6e9d9e60 | 124 | */ |
jah128 | 12:878c6e9d9e60 | 125 | void reset_encoders(void); |
jah128 | 12:878c6e9d9e60 | 126 | |
jah128 | 12:878c6e9d9e60 | 127 | /** |
jah128 | 12:878c6e9d9e60 | 128 | * Send a string (in printf format) to the preferred debug stream, specified in settings.h [of overridden programmatically] |
jah128 | 12:878c6e9d9e60 | 129 | * |
jah128 | 12:878c6e9d9e60 | 130 | * @param The string to send to output stream |
jah128 | 12:878c6e9d9e60 | 131 | */ |
jah128 | 12:878c6e9d9e60 | 132 | void debug(const char* format, ...) ; |
jah128 | 12:878c6e9d9e60 | 133 | private: |
jah128 | 12:878c6e9d9e60 | 134 | void IF_end_pause_user_code(void); |
jah128 | 12:878c6e9d9e60 | 135 | void IF_handle_events(void); |
jah128 | 12:878c6e9d9e60 | 136 | void IF_update_encoders(void); |
jah128 | 12:878c6e9d9e60 | 137 | void IF_update_user_id(void); |
jah128 | 12:878c6e9d9e60 | 138 | void IF_update_switch(void); |
jah128 | 12:878c6e9d9e60 | 139 | void IF_update_minutes(void); |
jah128 | 12:878c6e9d9e60 | 140 | void IF_get_hardware_description(void); |
jah128 | 12:878c6e9d9e60 | 141 | }; |
jah128 | 0:d6269d17c8cf | 142 | |
jah128 | 12:878c6e9d9e60 | 143 | extern Psiswarm psi; |
jah128 | 8:6c92789d5f87 | 144 | extern Serial pc; |
jah128 | 8:6c92789d5f87 | 145 | extern Serial bt; |
jah128 | 8:6c92789d5f87 | 146 | extern Display display; |
jah128 | 8:6c92789d5f87 | 147 | extern Motors motors; |
jah128 | 8:6c92789d5f87 | 148 | extern Eprom eprom; |
jah128 | 9:dde9e21030eb | 149 | extern Led led; |
jah128 | 10:e58323951c08 | 150 | extern Sensors sensors; |
jah128 | 11:312663037b8c | 151 | extern SerialControl serial; |
jah128 | 11:312663037b8c | 152 | extern Sound sound; |
jah128 | 11:312663037b8c | 153 | extern Setup i2c_setup; |
jah128 | 11:312663037b8c | 154 | extern Demo demo; |
jah128 | 12:878c6e9d9e60 | 155 | extern Animations animations; |
jah128 | 12:878c6e9d9e60 | 156 | extern Basic basic; |
jah128 | 0:d6269d17c8cf | 157 | extern char * program_name; |
jah128 | 0:d6269d17c8cf | 158 | extern char * author_name; |
jah128 | 0:d6269d17c8cf | 159 | extern char * version_name; |
jah128 | 0:d6269d17c8cf | 160 | |
jah128 | 0:d6269d17c8cf | 161 | extern I2C primary_i2c; |
jah128 | 0:d6269d17c8cf | 162 | extern InterruptIn gpio_interrupt; |
jah128 | 0:d6269d17c8cf | 163 | |
jah128 | 0:d6269d17c8cf | 164 | extern AnalogIn vin_current; |
jah128 | 0:d6269d17c8cf | 165 | extern AnalogIn vin_battery; |
jah128 | 0:d6269d17c8cf | 166 | extern AnalogIn vin_dc; |
jah128 | 0:d6269d17c8cf | 167 | |
jah128 | 0:d6269d17c8cf | 168 | extern DigitalOut mbed_led1; |
jah128 | 0:d6269d17c8cf | 169 | extern DigitalOut mbed_led2; |
jah128 | 0:d6269d17c8cf | 170 | extern DigitalOut mbed_led3; |
jah128 | 0:d6269d17c8cf | 171 | extern DigitalOut mbed_led4; |
jah128 | 0:d6269d17c8cf | 172 | extern PwmOut center_led_red; |
jah128 | 0:d6269d17c8cf | 173 | extern PwmOut center_led_green; |
jah128 | 0:d6269d17c8cf | 174 | extern PwmOut motor_left_f; |
jah128 | 0:d6269d17c8cf | 175 | extern PwmOut motor_left_r; |
jah128 | 0:d6269d17c8cf | 176 | extern PwmOut motor_right_f; |
jah128 | 0:d6269d17c8cf | 177 | extern PwmOut motor_right_r; |
jah128 | 0:d6269d17c8cf | 178 | |
jah128 | 0:d6269d17c8cf | 179 | extern char time_based_motor_action; |
jah128 | 0:d6269d17c8cf | 180 | |
jah128 | 0:d6269d17c8cf | 181 | extern int base_colour_sensor_raw_values []; |
jah128 | 0:d6269d17c8cf | 182 | extern int top_colour_sensor_raw_values []; |
jah128 | 0:d6269d17c8cf | 183 | |
jah128 | 0:d6269d17c8cf | 184 | extern char waiting_for_ultrasonic; |
jah128 | 0:d6269d17c8cf | 185 | extern int ultrasonic_distance; |
jah128 | 0:d6269d17c8cf | 186 | extern char ultrasonic_distance_updated; |
jah128 | 0:d6269d17c8cf | 187 | extern Timeout ultrasonic_timeout; |
jah128 | 0:d6269d17c8cf | 188 | extern Ticker ultrasonic_ticker; |
jah128 | 0:d6269d17c8cf | 189 | |
JessicaGao | 15:be92991621b4 | 190 | extern char background_ir_values []; |
jah128 | 0:d6269d17c8cf | 191 | extern unsigned short illuminated_ir_values []; |
jah128 | 0:d6269d17c8cf | 192 | extern float reflected_ir_distances []; |
jah128 | 0:d6269d17c8cf | 193 | extern char ir_values_stored; |
jah128 | 0:d6269d17c8cf | 194 | |
jah128 | 0:d6269d17c8cf | 195 | extern char firmware_bytes[]; |
jah128 | 0:d6269d17c8cf | 196 | |
jah128 | 0:d6269d17c8cf | 197 | extern char testing_voltage_regulators_flag; |
jah128 | 0:d6269d17c8cf | 198 | extern char power_good_motor_left; |
jah128 | 0:d6269d17c8cf | 199 | extern char power_good_motor_right; |
jah128 | 0:d6269d17c8cf | 200 | extern char power_good_infrared; |
jah128 | 0:d6269d17c8cf | 201 | extern char status_dc_in; |
jah128 | 0:d6269d17c8cf | 202 | extern char status_charging; |
jah128 | 0:d6269d17c8cf | 203 | |
jah128 | 0:d6269d17c8cf | 204 | extern unsigned short background_base_ir_values []; |
jah128 | 0:d6269d17c8cf | 205 | extern unsigned short illuminated_base_ir_values []; |
jah128 | 0:d6269d17c8cf | 206 | extern char base_ir_values_stored; |
jah128 | 0:d6269d17c8cf | 207 | extern float line_position; |
jah128 | 0:d6269d17c8cf | 208 | extern char line_found; |
jah128 | 0:d6269d17c8cf | 209 | |
jah128 | 0:d6269d17c8cf | 210 | extern float motor_left_speed; |
jah128 | 0:d6269d17c8cf | 211 | extern float motor_right_speed; |
jah128 | 0:d6269d17c8cf | 212 | extern char motor_left_brake; |
jah128 | 0:d6269d17c8cf | 213 | extern char motor_right_brake; |
jah128 | 0:d6269d17c8cf | 214 | |
jah128 | 0:d6269d17c8cf | 215 | extern float center_led_brightness; |
jah128 | 0:d6269d17c8cf | 216 | extern float backlight_brightness; |
jah128 | 0:d6269d17c8cf | 217 | |
jah128 | 4:1c621cb8cf0d | 218 | extern char use_motor_calibration; |
jah128 | 4:1c621cb8cf0d | 219 | extern char motor_calibration_set; |
jah128 | 4:1c621cb8cf0d | 220 | extern float left_motor_calibration_value; |
jah128 | 4:1c621cb8cf0d | 221 | extern float right_motor_calibration_value; |
jah128 | 4:1c621cb8cf0d | 222 | |
jah128 | 0:d6269d17c8cf | 223 | extern float firmware_version; |
jah128 | 1:060690a934a9 | 224 | extern float pcb_version; |
jah128 | 1:060690a934a9 | 225 | extern float serial_number; |
jah128 | 1:060690a934a9 | 226 | |
jah128 | 1:060690a934a9 | 227 | extern char has_compass; |
jah128 | 1:060690a934a9 | 228 | extern char has_side_ir; |
jah128 | 1:060690a934a9 | 229 | extern char has_base_ir; |
jah128 | 1:060690a934a9 | 230 | extern char has_base_colour_sensor; |
jah128 | 1:060690a934a9 | 231 | extern char has_top_colour_sensor; |
jah128 | 1:060690a934a9 | 232 | extern char has_wheel_encoders; |
jah128 | 1:060690a934a9 | 233 | extern char has_audio_pic; |
jah128 | 1:060690a934a9 | 234 | extern char has_ultrasonic_sensor; |
jah128 | 1:060690a934a9 | 235 | extern char has_temperature_sensor; |
jah128 | 1:060690a934a9 | 236 | extern char has_recharging_circuit; |
jah128 | 1:060690a934a9 | 237 | extern char has_433_radio; |
jah128 | 0:d6269d17c8cf | 238 | |
jah128 | 0:d6269d17c8cf | 239 | extern int ir_pulse_delay; |
jah128 | 0:d6269d17c8cf | 240 | extern int base_ir_pulse_delay; |
jah128 | 0:d6269d17c8cf | 241 | |
jah128 | 0:d6269d17c8cf | 242 | extern char robot_id; |
jah128 | 0:d6269d17c8cf | 243 | extern char previous_robot_id; |
jah128 | 0:d6269d17c8cf | 244 | |
jah128 | 0:d6269d17c8cf | 245 | extern char wheel_encoder_byte; |
jah128 | 0:d6269d17c8cf | 246 | extern char previous_wheel_encoder_byte; |
jah128 | 0:d6269d17c8cf | 247 | extern signed int left_encoder; |
jah128 | 0:d6269d17c8cf | 248 | extern signed int right_encoder; |
jah128 | 0:d6269d17c8cf | 249 | |
jah128 | 0:d6269d17c8cf | 250 | extern char switch_byte; |
jah128 | 0:d6269d17c8cf | 251 | extern char previous_switch_byte; |
jah128 | 0:d6269d17c8cf | 252 | |
jah128 | 0:d6269d17c8cf | 253 | extern char user_code_running; |
jah128 | 0:d6269d17c8cf | 254 | extern char user_code_restore_mode; |
jah128 | 0:d6269d17c8cf | 255 | extern char demo_on; |
jah128 | 0:d6269d17c8cf | 256 | extern char event; |
jah128 | 0:d6269d17c8cf | 257 | extern char change_id_event; |
jah128 | 0:d6269d17c8cf | 258 | extern char encoder_event; |
jah128 | 0:d6269d17c8cf | 259 | extern char switch_event; |
jah128 | 0:d6269d17c8cf | 260 | extern char system_warnings; |
jah128 | 0:d6269d17c8cf | 261 | |
jah128 | 0:d6269d17c8cf | 262 | extern char debug_mode; |
jah128 | 0:d6269d17c8cf | 263 | extern char debug_output; |
jah128 | 0:d6269d17c8cf | 264 | |
jah128 | 12:878c6e9d9e60 | 265 | extern vector<string> basic_filenames; |
jah128 | 0:d6269d17c8cf | 266 | extern char psi_basic_file_count; |
jah128 | 0:d6269d17c8cf | 267 | extern char use_flash_basic; |
jah128 | 0:d6269d17c8cf | 268 | extern char file_transfer_mode; |
jah128 | 12:878c6e9d9e60 | 269 | |
JessicaGao | 14:d32d948f7a76 | 270 | extern char beacon_data_needing; |
jah128 | 0:d6269d17c8cf | 271 | #endif |