C++ Library for the PsiSwarm Robot - Version 0.7
Fork of PsiSwarmV7 by
psiswarm.h@2:c6986ee3c7c5, 2016-03-11 (annotated)
- Committer:
- jah128
- Date:
- Fri Mar 11 13:51:24 2016 +0000
- Revision:
- 2:c6986ee3c7c5
- Parent:
- 1:060690a934a9
- Child:
- 4:1c621cb8cf0d
Added Alex' IR functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:d6269d17c8cf | 1 | /* University of York Robotics Laboratory PsiSwarm Library: PsiSwarm Core Header File |
jah128 | 0:d6269d17c8cf | 2 | * |
jah128 | 0:d6269d17c8cf | 3 | * File: psiswarm.h |
jah128 | 0:d6269d17c8cf | 4 | * |
jah128 | 0:d6269d17c8cf | 5 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 0:d6269d17c8cf | 6 | * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis |
jah128 | 0:d6269d17c8cf | 7 | * |
jah128 | 2:c6986ee3c7c5 | 8 | * PsiSwarm Library Version: 0.41 |
jah128 | 0:d6269d17c8cf | 9 | * |
jah128 | 2:c6986ee3c7c5 | 10 | * March 2016 |
jah128 | 0:d6269d17c8cf | 11 | * |
jah128 | 0:d6269d17c8cf | 12 | * |
jah128 | 0:d6269d17c8cf | 13 | */ |
jah128 | 0:d6269d17c8cf | 14 | |
jah128 | 0:d6269d17c8cf | 15 | #ifndef PSISWARM_H |
jah128 | 0:d6269d17c8cf | 16 | #define PSISWARM_H |
jah128 | 0:d6269d17c8cf | 17 | |
jah128 | 2:c6986ee3c7c5 | 18 | #define SOFTWARE_VERSION_CODE 0.41 |
jah128 | 0:d6269d17c8cf | 19 | |
jah128 | 0:d6269d17c8cf | 20 | #define PIC_ADDRESS 0x30 |
jah128 | 0:d6269d17c8cf | 21 | #define LCD_ADDRESS 0x7C |
jah128 | 0:d6269d17c8cf | 22 | #define LED_IC_ADDRESS 0x42 |
jah128 | 0:d6269d17c8cf | 23 | #define GPIO_IC_ADDRESS 0x40 |
jah128 | 0:d6269d17c8cf | 24 | #define AUX_IC_ADDRESS 0x4E |
jah128 | 0:d6269d17c8cf | 25 | #define ADC1_ADDRESS 0x46 |
jah128 | 0:d6269d17c8cf | 26 | #define ADC2_ADDRESS 0x48 |
jah128 | 0:d6269d17c8cf | 27 | #define EEPROM_ADDRESS 0XA0 |
jah128 | 0:d6269d17c8cf | 28 | #define TEMPERATURE_ADDRESS 0X30 |
jah128 | 0:d6269d17c8cf | 29 | #define BASE_COLOUR_ADDRESS 0X52 |
jah128 | 0:d6269d17c8cf | 30 | #define TOP_COLOUR_ADDRESS 0X72 |
jah128 | 0:d6269d17c8cf | 31 | #define ULTRASONIC_ADDRESS 0XE0 |
jah128 | 0:d6269d17c8cf | 32 | #define COMMAND_MESSAGE_BYTE 0X1D |
jah128 | 0:d6269d17c8cf | 33 | #define ACKNOWLEDGE_MESSAGE_BYTE 0X1E |
jah128 | 0:d6269d17c8cf | 34 | #define RESPONSE_MESSAGE_BYTE 0X1F |
jah128 | 0:d6269d17c8cf | 35 | #define PSI_BYTE 0X1D |
jah128 | 0:d6269d17c8cf | 36 | |
jah128 | 0:d6269d17c8cf | 37 | //Set temperature sensor warnings: 60C critical, 50C high, 0C low |
jah128 | 0:d6269d17c8cf | 38 | #define TEMPERATURE_CRITICAL_HI 0X03 |
jah128 | 0:d6269d17c8cf | 39 | #define TEMPEARTURE_CRITICAL_LO 0XC0 |
jah128 | 0:d6269d17c8cf | 40 | #define TEMPERATURE_HIGH_HI 0X03 |
jah128 | 0:d6269d17c8cf | 41 | #define TEMPEARTURE_HIGH_LO 0X20 |
jah128 | 0:d6269d17c8cf | 42 | #define TEMPERATURE_LOW_HI 0X00 |
jah128 | 0:d6269d17c8cf | 43 | #define TEMPEARTURE_LOW_LO 0X00 |
jah128 | 0:d6269d17c8cf | 44 | |
jah128 | 0:d6269d17c8cf | 45 | #define DEFAULT_IR_PULSE_DELAY 400 |
jah128 | 0:d6269d17c8cf | 46 | #define DEFAULT_BASE_IR_PULSE_DELAY 50 |
jah128 | 0:d6269d17c8cf | 47 | |
jah128 | 0:d6269d17c8cf | 48 | #include <stdio.h> |
jah128 | 0:d6269d17c8cf | 49 | #include <stdarg.h> |
jah128 | 0:d6269d17c8cf | 50 | #include <string> |
jah128 | 0:d6269d17c8cf | 51 | #include <vector> |
jah128 | 0:d6269d17c8cf | 52 | |
jah128 | 0:d6269d17c8cf | 53 | #include "settings.h" |
jah128 | 0:d6269d17c8cf | 54 | #include "serial.h" |
jah128 | 0:d6269d17c8cf | 55 | #include "mbed.h" |
jah128 | 0:d6269d17c8cf | 56 | #include "display.h" |
jah128 | 0:d6269d17c8cf | 57 | #include "led.h" |
jah128 | 0:d6269d17c8cf | 58 | #include "i2c.h" |
jah128 | 0:d6269d17c8cf | 59 | #include "motors.h" |
jah128 | 0:d6269d17c8cf | 60 | #include "sensors.h" |
jah128 | 0:d6269d17c8cf | 61 | #include "eprom.h" |
jah128 | 0:d6269d17c8cf | 62 | #include "colour.h" |
jah128 | 0:d6269d17c8cf | 63 | #include "pic.h" |
jah128 | 0:d6269d17c8cf | 64 | #include "demo.h" |
jah128 | 0:d6269d17c8cf | 65 | #include "dances.h" |
jah128 | 0:d6269d17c8cf | 66 | #include "basic.h" |
jah128 | 0:d6269d17c8cf | 67 | |
jah128 | 0:d6269d17c8cf | 68 | //NB The user needs to have a main.cpp with a main() function and a handle_switch_event(char) function |
jah128 | 0:d6269d17c8cf | 69 | #include "main.h" |
jah128 | 0:d6269d17c8cf | 70 | |
jah128 | 0:d6269d17c8cf | 71 | |
jah128 | 0:d6269d17c8cf | 72 | void init(void); |
jah128 | 0:d6269d17c8cf | 73 | float get_uptime(void); |
jah128 | 0:d6269d17c8cf | 74 | void pause_user_code(float period); |
jah128 | 0:d6269d17c8cf | 75 | void reset_encoders(void); |
jah128 | 0:d6269d17c8cf | 76 | void debug(const char* format, ...) ; |
jah128 | 0:d6269d17c8cf | 77 | |
jah128 | 0:d6269d17c8cf | 78 | void IF_end_pause_user_code(void); |
jah128 | 0:d6269d17c8cf | 79 | void IF_handle_events(void); |
jah128 | 0:d6269d17c8cf | 80 | void IF_update_encoders(void); |
jah128 | 0:d6269d17c8cf | 81 | void IF_update_user_id(void); |
jah128 | 0:d6269d17c8cf | 82 | void IF_update_switch(void); |
jah128 | 0:d6269d17c8cf | 83 | void IF_update_minutes(void); |
jah128 | 1:060690a934a9 | 84 | void IF_get_hardware_description(void); |
jah128 | 0:d6269d17c8cf | 85 | |
jah128 | 0:d6269d17c8cf | 86 | extern char * program_name; |
jah128 | 0:d6269d17c8cf | 87 | extern char * author_name; |
jah128 | 0:d6269d17c8cf | 88 | extern char * version_name; |
jah128 | 0:d6269d17c8cf | 89 | |
jah128 | 0:d6269d17c8cf | 90 | extern Serial pc; |
jah128 | 0:d6269d17c8cf | 91 | extern Serial bt; |
jah128 | 0:d6269d17c8cf | 92 | extern Display display; |
jah128 | 0:d6269d17c8cf | 93 | extern I2C primary_i2c; |
jah128 | 0:d6269d17c8cf | 94 | extern InterruptIn gpio_interrupt; |
jah128 | 0:d6269d17c8cf | 95 | |
jah128 | 0:d6269d17c8cf | 96 | extern AnalogIn vin_current; |
jah128 | 0:d6269d17c8cf | 97 | extern AnalogIn vin_battery; |
jah128 | 0:d6269d17c8cf | 98 | extern AnalogIn vin_dc; |
jah128 | 0:d6269d17c8cf | 99 | |
jah128 | 0:d6269d17c8cf | 100 | extern DigitalOut mbed_led1; |
jah128 | 0:d6269d17c8cf | 101 | extern DigitalOut mbed_led2; |
jah128 | 0:d6269d17c8cf | 102 | extern DigitalOut mbed_led3; |
jah128 | 0:d6269d17c8cf | 103 | extern DigitalOut mbed_led4; |
jah128 | 0:d6269d17c8cf | 104 | extern PwmOut center_led_red; |
jah128 | 0:d6269d17c8cf | 105 | extern PwmOut center_led_green; |
jah128 | 0:d6269d17c8cf | 106 | extern PwmOut motor_left_f; |
jah128 | 0:d6269d17c8cf | 107 | extern PwmOut motor_left_r; |
jah128 | 0:d6269d17c8cf | 108 | extern PwmOut motor_right_f; |
jah128 | 0:d6269d17c8cf | 109 | extern PwmOut motor_right_r; |
jah128 | 0:d6269d17c8cf | 110 | |
jah128 | 0:d6269d17c8cf | 111 | extern char time_based_motor_action; |
jah128 | 0:d6269d17c8cf | 112 | |
jah128 | 0:d6269d17c8cf | 113 | extern int base_colour_sensor_raw_values []; |
jah128 | 0:d6269d17c8cf | 114 | extern int top_colour_sensor_raw_values []; |
jah128 | 0:d6269d17c8cf | 115 | |
jah128 | 0:d6269d17c8cf | 116 | extern char waiting_for_ultrasonic; |
jah128 | 0:d6269d17c8cf | 117 | extern int ultrasonic_distance; |
jah128 | 0:d6269d17c8cf | 118 | extern char ultrasonic_distance_updated; |
jah128 | 0:d6269d17c8cf | 119 | extern Timeout ultrasonic_timeout; |
jah128 | 0:d6269d17c8cf | 120 | extern Ticker ultrasonic_ticker; |
jah128 | 0:d6269d17c8cf | 121 | |
jah128 | 0:d6269d17c8cf | 122 | extern unsigned short background_ir_values []; |
jah128 | 0:d6269d17c8cf | 123 | extern unsigned short illuminated_ir_values []; |
jah128 | 0:d6269d17c8cf | 124 | extern float reflected_ir_distances []; |
jah128 | 0:d6269d17c8cf | 125 | extern char ir_values_stored; |
jah128 | 0:d6269d17c8cf | 126 | |
jah128 | 0:d6269d17c8cf | 127 | extern char firmware_bytes[]; |
jah128 | 0:d6269d17c8cf | 128 | |
jah128 | 0:d6269d17c8cf | 129 | extern char testing_voltage_regulators_flag; |
jah128 | 0:d6269d17c8cf | 130 | extern char power_good_motor_left; |
jah128 | 0:d6269d17c8cf | 131 | extern char power_good_motor_right; |
jah128 | 0:d6269d17c8cf | 132 | extern char power_good_infrared; |
jah128 | 0:d6269d17c8cf | 133 | extern char status_dc_in; |
jah128 | 0:d6269d17c8cf | 134 | extern char status_charging; |
jah128 | 0:d6269d17c8cf | 135 | |
jah128 | 0:d6269d17c8cf | 136 | extern unsigned short background_base_ir_values []; |
jah128 | 0:d6269d17c8cf | 137 | extern unsigned short illuminated_base_ir_values []; |
jah128 | 0:d6269d17c8cf | 138 | extern char base_ir_values_stored; |
jah128 | 0:d6269d17c8cf | 139 | extern float line_position; |
jah128 | 0:d6269d17c8cf | 140 | extern char line_found; |
jah128 | 0:d6269d17c8cf | 141 | |
jah128 | 0:d6269d17c8cf | 142 | extern float motor_left_speed; |
jah128 | 0:d6269d17c8cf | 143 | extern float motor_right_speed; |
jah128 | 0:d6269d17c8cf | 144 | extern char motor_left_brake; |
jah128 | 0:d6269d17c8cf | 145 | extern char motor_right_brake; |
jah128 | 0:d6269d17c8cf | 146 | |
jah128 | 0:d6269d17c8cf | 147 | extern float center_led_brightness; |
jah128 | 0:d6269d17c8cf | 148 | extern float backlight_brightness; |
jah128 | 0:d6269d17c8cf | 149 | |
jah128 | 0:d6269d17c8cf | 150 | extern float firmware_version; |
jah128 | 1:060690a934a9 | 151 | extern float pcb_version; |
jah128 | 1:060690a934a9 | 152 | extern float serial_number; |
jah128 | 1:060690a934a9 | 153 | |
jah128 | 1:060690a934a9 | 154 | extern char has_compass; |
jah128 | 1:060690a934a9 | 155 | extern char has_side_ir; |
jah128 | 1:060690a934a9 | 156 | extern char has_base_ir; |
jah128 | 1:060690a934a9 | 157 | extern char has_base_colour_sensor; |
jah128 | 1:060690a934a9 | 158 | extern char has_top_colour_sensor; |
jah128 | 1:060690a934a9 | 159 | extern char has_wheel_encoders; |
jah128 | 1:060690a934a9 | 160 | extern char has_audio_pic; |
jah128 | 1:060690a934a9 | 161 | extern char has_ultrasonic_sensor; |
jah128 | 1:060690a934a9 | 162 | extern char has_temperature_sensor; |
jah128 | 1:060690a934a9 | 163 | extern char has_recharging_circuit; |
jah128 | 1:060690a934a9 | 164 | extern char has_433_radio; |
jah128 | 0:d6269d17c8cf | 165 | |
jah128 | 0:d6269d17c8cf | 166 | extern int ir_pulse_delay; |
jah128 | 0:d6269d17c8cf | 167 | extern int base_ir_pulse_delay; |
jah128 | 0:d6269d17c8cf | 168 | |
jah128 | 0:d6269d17c8cf | 169 | extern char robot_id; |
jah128 | 0:d6269d17c8cf | 170 | extern char previous_robot_id; |
jah128 | 0:d6269d17c8cf | 171 | |
jah128 | 0:d6269d17c8cf | 172 | extern char wheel_encoder_byte; |
jah128 | 0:d6269d17c8cf | 173 | extern char previous_wheel_encoder_byte; |
jah128 | 0:d6269d17c8cf | 174 | extern signed int left_encoder; |
jah128 | 0:d6269d17c8cf | 175 | extern signed int right_encoder; |
jah128 | 0:d6269d17c8cf | 176 | |
jah128 | 0:d6269d17c8cf | 177 | extern char switch_byte; |
jah128 | 0:d6269d17c8cf | 178 | extern char previous_switch_byte; |
jah128 | 0:d6269d17c8cf | 179 | |
jah128 | 0:d6269d17c8cf | 180 | extern char user_code_running; |
jah128 | 0:d6269d17c8cf | 181 | extern char user_code_restore_mode; |
jah128 | 0:d6269d17c8cf | 182 | extern char demo_on; |
jah128 | 0:d6269d17c8cf | 183 | extern char event; |
jah128 | 0:d6269d17c8cf | 184 | extern char change_id_event; |
jah128 | 0:d6269d17c8cf | 185 | extern char encoder_event; |
jah128 | 0:d6269d17c8cf | 186 | extern char switch_event; |
jah128 | 0:d6269d17c8cf | 187 | extern char system_warnings; |
jah128 | 0:d6269d17c8cf | 188 | |
jah128 | 0:d6269d17c8cf | 189 | extern char debug_mode; |
jah128 | 0:d6269d17c8cf | 190 | extern char debug_output; |
jah128 | 0:d6269d17c8cf | 191 | |
jah128 | 0:d6269d17c8cf | 192 | extern vector<string> basic_filenames; |
jah128 | 0:d6269d17c8cf | 193 | extern char psi_basic_file_count; |
jah128 | 0:d6269d17c8cf | 194 | extern char use_flash_basic; |
jah128 | 0:d6269d17c8cf | 195 | extern char file_transfer_mode; |
jah128 | 0:d6269d17c8cf | 196 | #endif |