Library for the PsiSwarm Robot - Version 0.7

Dependents:   PsiSwarm_V7_Blank

Fork of PsiSwarmLibrary by James Hilder

Committer:
jah128
Date:
Sat Oct 15 13:51:39 2016 +0000
Revision:
6:b340a527add9
Parent:
5:3cdd1a37cdd7
Added Apache license to files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:d6269d17c8cf 1 /* University of York Robotics Laboratory PsiSwarm Library: PsiSwarm Core Header File
jah128 0:d6269d17c8cf 2 *
jah128 6:b340a527add9 3 * Copyright 2016 University of York
jah128 6:b340a527add9 4 *
jah128 6:b340a527add9 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 6:b340a527add9 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 5:3cdd1a37cdd7 16 * PsiSwarm Library Version: 0.7
jah128 0:d6269d17c8cf 17 *
jah128 5:3cdd1a37cdd7 18 * October 2016
jah128 0:d6269d17c8cf 19 *
jah128 0:d6269d17c8cf 20 *
jah128 0:d6269d17c8cf 21 */
jah128 0:d6269d17c8cf 22
jah128 0:d6269d17c8cf 23 #ifndef PSISWARM_H
jah128 0:d6269d17c8cf 24 #define PSISWARM_H
jah128 0:d6269d17c8cf 25
jah128 5:3cdd1a37cdd7 26 #define SOFTWARE_VERSION_CODE 0.70
jah128 0:d6269d17c8cf 27
jah128 0:d6269d17c8cf 28 #define PIC_ADDRESS 0x30
jah128 0:d6269d17c8cf 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 0:d6269d17c8cf 66 #include "i2c.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 0:d6269d17c8cf 71 #include "pic.h"
jah128 0:d6269d17c8cf 72 #include "demo.h"
jah128 0:d6269d17c8cf 73 #include "dances.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 0:d6269d17c8cf 79
jah128 0:d6269d17c8cf 80 void init(void);
jah128 0:d6269d17c8cf 81 float get_uptime(void);
jah128 0:d6269d17c8cf 82 void pause_user_code(float period);
jah128 0:d6269d17c8cf 83 void reset_encoders(void);
jah128 0:d6269d17c8cf 84 void debug(const char* format, ...) ;
jah128 0:d6269d17c8cf 85
jah128 0:d6269d17c8cf 86 void IF_end_pause_user_code(void);
jah128 0:d6269d17c8cf 87 void IF_handle_events(void);
jah128 0:d6269d17c8cf 88 void IF_update_encoders(void);
jah128 0:d6269d17c8cf 89 void IF_update_user_id(void);
jah128 0:d6269d17c8cf 90 void IF_update_switch(void);
jah128 0:d6269d17c8cf 91 void IF_update_minutes(void);
jah128 1:060690a934a9 92 void IF_get_hardware_description(void);
jah128 0:d6269d17c8cf 93
jah128 0:d6269d17c8cf 94 extern char * program_name;
jah128 0:d6269d17c8cf 95 extern char * author_name;
jah128 0:d6269d17c8cf 96 extern char * version_name;
jah128 0:d6269d17c8cf 97
jah128 0:d6269d17c8cf 98 extern Serial pc;
jah128 0:d6269d17c8cf 99 extern Serial bt;
jah128 0:d6269d17c8cf 100 extern Display display;
jah128 0:d6269d17c8cf 101 extern I2C primary_i2c;
jah128 0:d6269d17c8cf 102 extern InterruptIn gpio_interrupt;
jah128 0:d6269d17c8cf 103
jah128 0:d6269d17c8cf 104 extern AnalogIn vin_current;
jah128 0:d6269d17c8cf 105 extern AnalogIn vin_battery;
jah128 0:d6269d17c8cf 106 extern AnalogIn vin_dc;
jah128 0:d6269d17c8cf 107
jah128 0:d6269d17c8cf 108 extern DigitalOut mbed_led1;
jah128 0:d6269d17c8cf 109 extern DigitalOut mbed_led2;
jah128 0:d6269d17c8cf 110 extern DigitalOut mbed_led3;
jah128 0:d6269d17c8cf 111 extern DigitalOut mbed_led4;
jah128 0:d6269d17c8cf 112 extern PwmOut center_led_red;
jah128 0:d6269d17c8cf 113 extern PwmOut center_led_green;
jah128 0:d6269d17c8cf 114 extern PwmOut motor_left_f;
jah128 0:d6269d17c8cf 115 extern PwmOut motor_left_r;
jah128 0:d6269d17c8cf 116 extern PwmOut motor_right_f;
jah128 0:d6269d17c8cf 117 extern PwmOut motor_right_r;
jah128 0:d6269d17c8cf 118
jah128 0:d6269d17c8cf 119 extern char time_based_motor_action;
jah128 0:d6269d17c8cf 120
jah128 0:d6269d17c8cf 121 extern int base_colour_sensor_raw_values [];
jah128 0:d6269d17c8cf 122 extern int top_colour_sensor_raw_values [];
jah128 0:d6269d17c8cf 123
jah128 0:d6269d17c8cf 124 extern char waiting_for_ultrasonic;
jah128 0:d6269d17c8cf 125 extern int ultrasonic_distance;
jah128 0:d6269d17c8cf 126 extern char ultrasonic_distance_updated;
jah128 0:d6269d17c8cf 127 extern Timeout ultrasonic_timeout;
jah128 0:d6269d17c8cf 128 extern Ticker ultrasonic_ticker;
jah128 0:d6269d17c8cf 129
jah128 0:d6269d17c8cf 130 extern unsigned short background_ir_values [];
jah128 0:d6269d17c8cf 131 extern unsigned short illuminated_ir_values [];
jah128 0:d6269d17c8cf 132 extern float reflected_ir_distances [];
jah128 0:d6269d17c8cf 133 extern char ir_values_stored;
jah128 0:d6269d17c8cf 134
jah128 0:d6269d17c8cf 135 extern char firmware_bytes[];
jah128 0:d6269d17c8cf 136
jah128 0:d6269d17c8cf 137 extern char testing_voltage_regulators_flag;
jah128 0:d6269d17c8cf 138 extern char power_good_motor_left;
jah128 0:d6269d17c8cf 139 extern char power_good_motor_right;
jah128 0:d6269d17c8cf 140 extern char power_good_infrared;
jah128 0:d6269d17c8cf 141 extern char status_dc_in;
jah128 0:d6269d17c8cf 142 extern char status_charging;
jah128 0:d6269d17c8cf 143
jah128 0:d6269d17c8cf 144 extern unsigned short background_base_ir_values [];
jah128 0:d6269d17c8cf 145 extern unsigned short illuminated_base_ir_values [];
jah128 0:d6269d17c8cf 146 extern char base_ir_values_stored;
jah128 0:d6269d17c8cf 147 extern float line_position;
jah128 0:d6269d17c8cf 148 extern char line_found;
jah128 0:d6269d17c8cf 149
jah128 0:d6269d17c8cf 150 extern float motor_left_speed;
jah128 0:d6269d17c8cf 151 extern float motor_right_speed;
jah128 0:d6269d17c8cf 152 extern char motor_left_brake;
jah128 0:d6269d17c8cf 153 extern char motor_right_brake;
jah128 0:d6269d17c8cf 154
jah128 0:d6269d17c8cf 155 extern float center_led_brightness;
jah128 0:d6269d17c8cf 156 extern float backlight_brightness;
jah128 0:d6269d17c8cf 157
jah128 4:1c621cb8cf0d 158 extern char use_motor_calibration;
jah128 4:1c621cb8cf0d 159 extern char motor_calibration_set;
jah128 4:1c621cb8cf0d 160 extern float left_motor_calibration_value;
jah128 4:1c621cb8cf0d 161 extern float right_motor_calibration_value;
jah128 4:1c621cb8cf0d 162
jah128 0:d6269d17c8cf 163 extern float firmware_version;
jah128 1:060690a934a9 164 extern float pcb_version;
jah128 1:060690a934a9 165 extern float serial_number;
jah128 1:060690a934a9 166
jah128 1:060690a934a9 167 extern char has_compass;
jah128 1:060690a934a9 168 extern char has_side_ir;
jah128 1:060690a934a9 169 extern char has_base_ir;
jah128 1:060690a934a9 170 extern char has_base_colour_sensor;
jah128 1:060690a934a9 171 extern char has_top_colour_sensor;
jah128 1:060690a934a9 172 extern char has_wheel_encoders;
jah128 1:060690a934a9 173 extern char has_audio_pic;
jah128 1:060690a934a9 174 extern char has_ultrasonic_sensor;
jah128 1:060690a934a9 175 extern char has_temperature_sensor;
jah128 1:060690a934a9 176 extern char has_recharging_circuit;
jah128 1:060690a934a9 177 extern char has_433_radio;
jah128 0:d6269d17c8cf 178
jah128 0:d6269d17c8cf 179 extern int ir_pulse_delay;
jah128 0:d6269d17c8cf 180 extern int base_ir_pulse_delay;
jah128 0:d6269d17c8cf 181
jah128 0:d6269d17c8cf 182 extern char robot_id;
jah128 0:d6269d17c8cf 183 extern char previous_robot_id;
jah128 0:d6269d17c8cf 184
jah128 0:d6269d17c8cf 185 extern char wheel_encoder_byte;
jah128 0:d6269d17c8cf 186 extern char previous_wheel_encoder_byte;
jah128 0:d6269d17c8cf 187 extern signed int left_encoder;
jah128 0:d6269d17c8cf 188 extern signed int right_encoder;
jah128 0:d6269d17c8cf 189
jah128 0:d6269d17c8cf 190 extern char switch_byte;
jah128 0:d6269d17c8cf 191 extern char previous_switch_byte;
jah128 0:d6269d17c8cf 192
jah128 0:d6269d17c8cf 193 extern char user_code_running;
jah128 0:d6269d17c8cf 194 extern char user_code_restore_mode;
jah128 0:d6269d17c8cf 195 extern char demo_on;
jah128 0:d6269d17c8cf 196 extern char event;
jah128 0:d6269d17c8cf 197 extern char change_id_event;
jah128 0:d6269d17c8cf 198 extern char encoder_event;
jah128 0:d6269d17c8cf 199 extern char switch_event;
jah128 0:d6269d17c8cf 200 extern char system_warnings;
jah128 0:d6269d17c8cf 201
jah128 0:d6269d17c8cf 202 extern char debug_mode;
jah128 0:d6269d17c8cf 203 extern char debug_output;
jah128 0:d6269d17c8cf 204
jah128 0:d6269d17c8cf 205 extern vector<string> basic_filenames;
jah128 0:d6269d17c8cf 206 extern char psi_basic_file_count;
jah128 0:d6269d17c8cf 207 extern char use_flash_basic;
jah128 0:d6269d17c8cf 208 extern char file_transfer_mode;
jah128 0:d6269d17c8cf 209 #endif