C++ Library for the PsiSwarm Robot - Version 0.8

Dependents:   PsiSwarm_V8_Blank_CPP Autonomia_RndmWlk

Fork of PsiSwarmV7_CPP by Psi Swarm Robot

Committer:
jah128
Date:
Sun Oct 16 16:00:20 2016 +0000
Revision:
10:e58323951c08
Parent:
9:dde9e21030eb
Child:
11:312663037b8c
Added Sensors class

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 8:6c92789d5f87 80 extern Serial pc;
jah128 8:6c92789d5f87 81 extern Serial bt;
jah128 8:6c92789d5f87 82 extern Display display;
jah128 8:6c92789d5f87 83 extern Motors motors;
jah128 8:6c92789d5f87 84 extern Eprom eprom;
jah128 9:dde9e21030eb 85 extern Led led;
jah128 10:e58323951c08 86 extern Sensors sensors;
jah128 8:6c92789d5f87 87
jah128 0:d6269d17c8cf 88 void init(void);
jah128 0:d6269d17c8cf 89 float get_uptime(void);
jah128 0:d6269d17c8cf 90 void pause_user_code(float period);
jah128 0:d6269d17c8cf 91 void reset_encoders(void);
jah128 0:d6269d17c8cf 92 void debug(const char* format, ...) ;
jah128 0:d6269d17c8cf 93
jah128 0:d6269d17c8cf 94 void IF_end_pause_user_code(void);
jah128 0:d6269d17c8cf 95 void IF_handle_events(void);
jah128 0:d6269d17c8cf 96 void IF_update_encoders(void);
jah128 0:d6269d17c8cf 97 void IF_update_user_id(void);
jah128 0:d6269d17c8cf 98 void IF_update_switch(void);
jah128 0:d6269d17c8cf 99 void IF_update_minutes(void);
jah128 1:060690a934a9 100 void IF_get_hardware_description(void);
jah128 0:d6269d17c8cf 101
jah128 0:d6269d17c8cf 102 extern char * program_name;
jah128 0:d6269d17c8cf 103 extern char * author_name;
jah128 0:d6269d17c8cf 104 extern char * version_name;
jah128 0:d6269d17c8cf 105
jah128 0:d6269d17c8cf 106 extern I2C primary_i2c;
jah128 0:d6269d17c8cf 107 extern InterruptIn gpio_interrupt;
jah128 0:d6269d17c8cf 108
jah128 0:d6269d17c8cf 109 extern AnalogIn vin_current;
jah128 0:d6269d17c8cf 110 extern AnalogIn vin_battery;
jah128 0:d6269d17c8cf 111 extern AnalogIn vin_dc;
jah128 0:d6269d17c8cf 112
jah128 0:d6269d17c8cf 113 extern DigitalOut mbed_led1;
jah128 0:d6269d17c8cf 114 extern DigitalOut mbed_led2;
jah128 0:d6269d17c8cf 115 extern DigitalOut mbed_led3;
jah128 0:d6269d17c8cf 116 extern DigitalOut mbed_led4;
jah128 0:d6269d17c8cf 117 extern PwmOut center_led_red;
jah128 0:d6269d17c8cf 118 extern PwmOut center_led_green;
jah128 0:d6269d17c8cf 119 extern PwmOut motor_left_f;
jah128 0:d6269d17c8cf 120 extern PwmOut motor_left_r;
jah128 0:d6269d17c8cf 121 extern PwmOut motor_right_f;
jah128 0:d6269d17c8cf 122 extern PwmOut motor_right_r;
jah128 0:d6269d17c8cf 123
jah128 0:d6269d17c8cf 124 extern char time_based_motor_action;
jah128 0:d6269d17c8cf 125
jah128 0:d6269d17c8cf 126 extern int base_colour_sensor_raw_values [];
jah128 0:d6269d17c8cf 127 extern int top_colour_sensor_raw_values [];
jah128 0:d6269d17c8cf 128
jah128 0:d6269d17c8cf 129 extern char waiting_for_ultrasonic;
jah128 0:d6269d17c8cf 130 extern int ultrasonic_distance;
jah128 0:d6269d17c8cf 131 extern char ultrasonic_distance_updated;
jah128 0:d6269d17c8cf 132 extern Timeout ultrasonic_timeout;
jah128 0:d6269d17c8cf 133 extern Ticker ultrasonic_ticker;
jah128 0:d6269d17c8cf 134
jah128 0:d6269d17c8cf 135 extern unsigned short background_ir_values [];
jah128 0:d6269d17c8cf 136 extern unsigned short illuminated_ir_values [];
jah128 0:d6269d17c8cf 137 extern float reflected_ir_distances [];
jah128 0:d6269d17c8cf 138 extern char ir_values_stored;
jah128 0:d6269d17c8cf 139
jah128 0:d6269d17c8cf 140 extern char firmware_bytes[];
jah128 0:d6269d17c8cf 141
jah128 0:d6269d17c8cf 142 extern char testing_voltage_regulators_flag;
jah128 0:d6269d17c8cf 143 extern char power_good_motor_left;
jah128 0:d6269d17c8cf 144 extern char power_good_motor_right;
jah128 0:d6269d17c8cf 145 extern char power_good_infrared;
jah128 0:d6269d17c8cf 146 extern char status_dc_in;
jah128 0:d6269d17c8cf 147 extern char status_charging;
jah128 0:d6269d17c8cf 148
jah128 0:d6269d17c8cf 149 extern unsigned short background_base_ir_values [];
jah128 0:d6269d17c8cf 150 extern unsigned short illuminated_base_ir_values [];
jah128 0:d6269d17c8cf 151 extern char base_ir_values_stored;
jah128 0:d6269d17c8cf 152 extern float line_position;
jah128 0:d6269d17c8cf 153 extern char line_found;
jah128 0:d6269d17c8cf 154
jah128 0:d6269d17c8cf 155 extern float motor_left_speed;
jah128 0:d6269d17c8cf 156 extern float motor_right_speed;
jah128 0:d6269d17c8cf 157 extern char motor_left_brake;
jah128 0:d6269d17c8cf 158 extern char motor_right_brake;
jah128 0:d6269d17c8cf 159
jah128 0:d6269d17c8cf 160 extern float center_led_brightness;
jah128 0:d6269d17c8cf 161 extern float backlight_brightness;
jah128 0:d6269d17c8cf 162
jah128 4:1c621cb8cf0d 163 extern char use_motor_calibration;
jah128 4:1c621cb8cf0d 164 extern char motor_calibration_set;
jah128 4:1c621cb8cf0d 165 extern float left_motor_calibration_value;
jah128 4:1c621cb8cf0d 166 extern float right_motor_calibration_value;
jah128 4:1c621cb8cf0d 167
jah128 0:d6269d17c8cf 168 extern float firmware_version;
jah128 1:060690a934a9 169 extern float pcb_version;
jah128 1:060690a934a9 170 extern float serial_number;
jah128 1:060690a934a9 171
jah128 1:060690a934a9 172 extern char has_compass;
jah128 1:060690a934a9 173 extern char has_side_ir;
jah128 1:060690a934a9 174 extern char has_base_ir;
jah128 1:060690a934a9 175 extern char has_base_colour_sensor;
jah128 1:060690a934a9 176 extern char has_top_colour_sensor;
jah128 1:060690a934a9 177 extern char has_wheel_encoders;
jah128 1:060690a934a9 178 extern char has_audio_pic;
jah128 1:060690a934a9 179 extern char has_ultrasonic_sensor;
jah128 1:060690a934a9 180 extern char has_temperature_sensor;
jah128 1:060690a934a9 181 extern char has_recharging_circuit;
jah128 1:060690a934a9 182 extern char has_433_radio;
jah128 0:d6269d17c8cf 183
jah128 0:d6269d17c8cf 184 extern int ir_pulse_delay;
jah128 0:d6269d17c8cf 185 extern int base_ir_pulse_delay;
jah128 0:d6269d17c8cf 186
jah128 0:d6269d17c8cf 187 extern char robot_id;
jah128 0:d6269d17c8cf 188 extern char previous_robot_id;
jah128 0:d6269d17c8cf 189
jah128 0:d6269d17c8cf 190 extern char wheel_encoder_byte;
jah128 0:d6269d17c8cf 191 extern char previous_wheel_encoder_byte;
jah128 0:d6269d17c8cf 192 extern signed int left_encoder;
jah128 0:d6269d17c8cf 193 extern signed int right_encoder;
jah128 0:d6269d17c8cf 194
jah128 0:d6269d17c8cf 195 extern char switch_byte;
jah128 0:d6269d17c8cf 196 extern char previous_switch_byte;
jah128 0:d6269d17c8cf 197
jah128 0:d6269d17c8cf 198 extern char user_code_running;
jah128 0:d6269d17c8cf 199 extern char user_code_restore_mode;
jah128 0:d6269d17c8cf 200 extern char demo_on;
jah128 0:d6269d17c8cf 201 extern char event;
jah128 0:d6269d17c8cf 202 extern char change_id_event;
jah128 0:d6269d17c8cf 203 extern char encoder_event;
jah128 0:d6269d17c8cf 204 extern char switch_event;
jah128 0:d6269d17c8cf 205 extern char system_warnings;
jah128 0:d6269d17c8cf 206
jah128 0:d6269d17c8cf 207 extern char debug_mode;
jah128 0:d6269d17c8cf 208 extern char debug_output;
jah128 0:d6269d17c8cf 209
jah128 0:d6269d17c8cf 210 extern vector<string> basic_filenames;
jah128 0:d6269d17c8cf 211 extern char psi_basic_file_count;
jah128 0:d6269d17c8cf 212 extern char use_flash_basic;
jah128 0:d6269d17c8cf 213 extern char file_transfer_mode;
jah128 0:d6269d17c8cf 214 #endif