Unfinished v0.7, added bearing detection

Fork of Pi_Swarm_Library_v06_alpha by piswarm

Committer:
jah128
Date:
Fri Jan 31 22:59:25 2014 +0000
Revision:
0:9ffe8ebd1c40
Child:
1:b067a08ff54e
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:9ffe8ebd1c40 1 /* University of York Robot Lab Pi Swarm Robot Library
jah128 0:9ffe8ebd1c40 2 *
jah128 0:9ffe8ebd1c40 3 * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York
jah128 0:9ffe8ebd1c40 4 *
jah128 0:9ffe8ebd1c40 5 * Version 0.4 January 2014
jah128 0:9ffe8ebd1c40 6 *
jah128 0:9ffe8ebd1c40 7 * Designed for use with the Pi Swarm Board (enhanced MBED sensor board) v1.2
jah128 0:9ffe8ebd1c40 8 *
jah128 0:9ffe8ebd1c40 9 * Based on the original m3pi library, Copyright (c) 2007-2010 cstyles (see copyright notice at end of file)
jah128 0:9ffe8ebd1c40 10 */
jah128 0:9ffe8ebd1c40 11
jah128 0:9ffe8ebd1c40 12 #ifndef PISWARM_H
jah128 0:9ffe8ebd1c40 13 #define PISWARM_H
jah128 0:9ffe8ebd1c40 14
jah128 0:9ffe8ebd1c40 15 #include "mbed.h"
jah128 0:9ffe8ebd1c40 16 #include "platform.h"
jah128 0:9ffe8ebd1c40 17 #include "alpha433.h"
jah128 0:9ffe8ebd1c40 18 #include "main.h"
jah128 0:9ffe8ebd1c40 19
jah128 0:9ffe8ebd1c40 20
jah128 0:9ffe8ebd1c40 21 #ifdef MBED_RPC
jah128 0:9ffe8ebd1c40 22 #include "rpc.h"
jah128 0:9ffe8ebd1c40 23 #endif
jah128 0:9ffe8ebd1c40 24
jah128 0:9ffe8ebd1c40 25 #define SEND_SIGNATURE 0x81
jah128 0:9ffe8ebd1c40 26 #define SEND_RAW_SENSOR_VALUES 0x86
jah128 0:9ffe8ebd1c40 27 #define SEND_TRIMPOT 0xB0
jah128 0:9ffe8ebd1c40 28 #define SEND_BATTERY_MILLIVOLTS 0xB1
jah128 0:9ffe8ebd1c40 29 #define DO_PLAY 0xB3
jah128 0:9ffe8ebd1c40 30 #define PI_CALIBRATE 0xB4
jah128 0:9ffe8ebd1c40 31 #define DO_CLEAR 0xB7
jah128 0:9ffe8ebd1c40 32 #define DO_PRINT 0xB8
jah128 0:9ffe8ebd1c40 33 #define DO_LCD_GOTO_XY 0xB9
jah128 0:9ffe8ebd1c40 34 #define LINE_SENSORS_RESET_CALIBRATION 0xB5
jah128 0:9ffe8ebd1c40 35 #define SEND_LINE_POSITION 0xB6
jah128 0:9ffe8ebd1c40 36 #define AUTO_CALIBRATE 0xBA
jah128 0:9ffe8ebd1c40 37 #define SET_PID 0xBB
jah128 0:9ffe8ebd1c40 38 #define STOP_PID 0xBC
jah128 0:9ffe8ebd1c40 39 #define M1_FORWARD 0xC1
jah128 0:9ffe8ebd1c40 40 #define M1_BACKWARD 0xC2
jah128 0:9ffe8ebd1c40 41 #define M2_FORWARD 0xC5
jah128 0:9ffe8ebd1c40 42 #define M2_BACKWARD 0xC6
jah128 0:9ffe8ebd1c40 43 #define EXPANSION_IC_ADDRESS 0x40
jah128 0:9ffe8ebd1c40 44 #define MAGNETOMETER_ADDRESS 0x1C
jah128 0:9ffe8ebd1c40 45 #define ADC_ADDRESS 0x46
jah128 0:9ffe8ebd1c40 46 #define EEPROM_ADDRESS 0XA0
jah128 0:9ffe8ebd1c40 47
jah128 0:9ffe8ebd1c40 48 class PiSwarm : public Stream {
jah128 0:9ffe8ebd1c40 49
jah128 0:9ffe8ebd1c40 50 // Public functions
jah128 0:9ffe8ebd1c40 51 public:
jah128 0:9ffe8ebd1c40 52
jah128 0:9ffe8ebd1c40 53 /** Create the m3pi object connected to the default pins
jah128 0:9ffe8ebd1c40 54 * Pin 05 : Alpha Transceiver SDI
jah128 0:9ffe8ebd1c40 55 * Pin 06 : Alpha Transceiver SDO
jah128 0:9ffe8ebd1c40 56 * Pin 07 : Alpha Transceiver CLK
jah128 0:9ffe8ebd1c40 57 * Pin 08 : Alpha Transceiver FSS
jah128 0:9ffe8ebd1c40 58 * Pin 09 : Serial (3pi) transmit
jah128 0:9ffe8ebd1c40 59 * Pin 10 : Serial (3pi) receive
jah128 0:9ffe8ebd1c40 60 * Pin 11 : Alpha Transceiver NIRQ
jah128 0:9ffe8ebd1c40 61 * Pin 12 : IR Pulse Output for IR1,2,7,8
jah128 0:9ffe8ebd1c40 62 * Pin 13 : IR Pulse Output for IR3,4,5,6
jah128 0:9ffe8ebd1c40 63 * Pin 14 : Echo Pin for Sonar
jah128 0:9ffe8ebd1c40 64 * Pin 15 : Light Sensor Analogue Input
jah128 0:9ffe8ebd1c40 65 * Pin 16 : Gyrometer Analogue Input
jah128 0:9ffe8ebd1c40 66 * Pin 17 : Accelerometer Z Analogue Input
jah128 0:9ffe8ebd1c40 67 * Pin 18 : Accelerometer Y Analogue Input
jah128 0:9ffe8ebd1c40 68 * Pin 19 : Accelerometer X Analogue Input
jah128 0:9ffe8ebd1c40 69 * Pin 20 : Temperature Sensor Analogue Input
jah128 0:9ffe8ebd1c40 70 * Pin 21 : Center LED Blue PWM Output
jah128 0:9ffe8ebd1c40 71 * Pin 22 : Center LED Green PWM Output
jah128 0:9ffe8ebd1c40 72 * Pin 23 : Center LED Red PWM Output
jah128 0:9ffe8ebd1c40 73 * Pin 24 : Outer LED Blue PWM Output
jah128 0:9ffe8ebd1c40 74 * Pin 25 : Outer LED Green PWM Output
jah128 0:9ffe8ebd1c40 75 * Pin 26 : Outer LED Red PWM Output
jah128 0:9ffe8ebd1c40 76 * Pin 27 : I2C SCL
jah128 0:9ffe8ebd1c40 77 * Pin 28 : I2C SDA
jah128 0:9ffe8ebd1c40 78 * Pin 29 : GPIO Expander Interrupt
jah128 0:9ffe8ebd1c40 79 * Pin 30 : Trigger Pin for Sonar
jah128 0:9ffe8ebd1c40 80 * Pin 31 : USB D+ Connector
jah128 0:9ffe8ebd1c40 81 * Pin 32 : USB D- Connector
jah128 0:9ffe8ebd1c40 82 */
jah128 0:9ffe8ebd1c40 83 PiSwarm();
jah128 0:9ffe8ebd1c40 84
jah128 0:9ffe8ebd1c40 85 // Returns the RGB Colour of the Outer LED as an int (r<<16 g<<8 b)
jah128 0:9ffe8ebd1c40 86 int get_oled_colour(void);
jah128 0:9ffe8ebd1c40 87
jah128 0:9ffe8ebd1c40 88 // Returns the RGB Colour of the Center LED as an int (r<<16 g<<8 b)
jah128 0:9ffe8ebd1c40 89 int get_cled_colour(void);
jah128 0:9ffe8ebd1c40 90
jah128 0:9ffe8ebd1c40 91 // Toggle the state of a single outer LED without affected the others
jah128 0:9ffe8ebd1c40 92 void set_oled(char oled, char value);
jah128 0:9ffe8ebd1c40 93
jah128 0:9ffe8ebd1c40 94 void test_oled(void);
jah128 0:9ffe8ebd1c40 95 void turn_off_all_oleds(void);
jah128 0:9ffe8ebd1c40 96
jah128 0:9ffe8ebd1c40 97 // Toggle the states of all 10 outer LEDs
jah128 0:9ffe8ebd1c40 98 void set_oleds(char oled_0, char oled_1, char oled_2, char oled_3, char oled_4, char oled_5, char oled_6, char oled_7, char oled_8, char oled_9);
jah128 0:9ffe8ebd1c40 99
jah128 0:9ffe8ebd1c40 100 void activate_oleds(void);
jah128 0:9ffe8ebd1c40 101
jah128 0:9ffe8ebd1c40 102 // The default setup routine: called when s3pi is created
jah128 0:9ffe8ebd1c40 103 void setup ( void );
jah128 0:9ffe8ebd1c40 104
jah128 0:9ffe8ebd1c40 105 // Send a message of given length over the RF interface
jah128 0:9ffe8ebd1c40 106 void send_rf_message(char* message, char length);
jah128 0:9ffe8ebd1c40 107
jah128 0:9ffe8ebd1c40 108 // Sets up the IO expansion IC using I2C commands; returns a zero if successful
jah128 0:9ffe8ebd1c40 109 int setup_expansion_ic ( void );
jah128 0:9ffe8ebd1c40 110
jah128 0:9ffe8ebd1c40 111 // Turns on or off the LDO outputs based on the current enable variables (enable_ir_ldo and enable_led_ldo)
jah128 0:9ffe8ebd1c40 112 void enable_ldo_outputs ( void );
jah128 0:9ffe8ebd1c40 113
jah128 0:9ffe8ebd1c40 114 // Called after a delay from the IO expansion interrupt; delay helps debounce switches
jah128 0:9ffe8ebd1c40 115 void interrupt_timeout_event ( void );
jah128 0:9ffe8ebd1c40 116
jah128 0:9ffe8ebd1c40 117 // The interrupt handler for the IO expansion IC; calls the timeout event to debounce switches
jah128 0:9ffe8ebd1c40 118 void expansion_interrupt_handler ( void );
jah128 0:9ffe8ebd1c40 119
jah128 0:9ffe8ebd1c40 120 // Turns off interrupt LED after a delay to indicate switch has been pressed
jah128 0:9ffe8ebd1c40 121 void led_timeout_event ( void );
jah128 0:9ffe8ebd1c40 122
jah128 0:9ffe8ebd1c40 123 // Set colour of outer LEDs
jah128 0:9ffe8ebd1c40 124 void set_oled_colour ( char red, char green, char blue );
jah128 0:9ffe8ebd1c40 125
jah128 0:9ffe8ebd1c40 126 // Set colour of central LED
jah128 0:9ffe8ebd1c40 127 void set_cled_colour ( char red, char green, char blue );
jah128 0:9ffe8ebd1c40 128
jah128 0:9ffe8ebd1c40 129 // Set brightness of outer LEDs (works by increasing total period for PWM)
jah128 0:9ffe8ebd1c40 130 void set_oled_brightness ( char brightness );
jah128 0:9ffe8ebd1c40 131
jah128 0:9ffe8ebd1c40 132 // Set brightness of central LED (works by increasing total period for PWM)
jah128 0:9ffe8ebd1c40 133 void set_cled_brightness ( char brightness );
jah128 0:9ffe8ebd1c40 134
jah128 0:9ffe8ebd1c40 135 // Read temperature from the temperature IC; return is temperature in degrees Celsius
jah128 0:9ffe8ebd1c40 136 float read_temperature ( void );
jah128 0:9ffe8ebd1c40 137
jah128 0:9ffe8ebd1c40 138 // Routine to calibrate gyro; by default run in setup, robot should be stationary to avoid errors
jah128 0:9ffe8ebd1c40 139 // Returns 1 if successful, 0 if failed
jah128 0:9ffe8ebd1c40 140 char calibrate_gyro ( void );
jah128 0:9ffe8ebd1c40 141
jah128 0:9ffe8ebd1c40 142 // Routine to calibrate accelerometer, by default run after successful gyro calibration, robot should be flat and stationary to avoid errors
jah128 0:9ffe8ebd1c40 143 // Returns 1 if successful, 0 if failed
jah128 0:9ffe8ebd1c40 144 char calibrate_accelerometer ( void );
jah128 0:9ffe8ebd1c40 145
jah128 0:9ffe8ebd1c40 146 // Routine to calibrate magnetometer
jah128 0:9ffe8ebd1c40 147 // Returns 1 if successful, 0 if failed
jah128 0:9ffe8ebd1c40 148 char calibrate_magnetometer ( void );
jah128 0:9ffe8ebd1c40 149
jah128 0:9ffe8ebd1c40 150 char setup_adc( void );
jah128 0:9ffe8ebd1c40 151
jah128 0:9ffe8ebd1c40 152 // Routine to initialise radio
jah128 0:9ffe8ebd1c40 153 void setup_radio( void );
jah128 0:9ffe8ebd1c40 154
jah128 0:9ffe8ebd1c40 155 // Routines returns an approximate distance of any reflected obstacle in front of the given IR sensor (in millimeters)
jah128 0:9ffe8ebd1c40 156 // Returns a value of 100 if nothing is detected
jah128 0:9ffe8ebd1c40 157 // True distance depends on a number of factors (reflectiveness of surface being one of the key ones)
jah128 0:9ffe8ebd1c40 158 // Minimum value is around 5
jah128 0:9ffe8ebd1c40 159 float read_reflected_ir_distance ( char index );
jah128 0:9ffe8ebd1c40 160
jah128 0:9ffe8ebd1c40 161 // Returns the raw ADC value for a given IR sensor
jah128 0:9ffe8ebd1c40 162 unsigned short read_adc_value( char index );
jah128 0:9ffe8ebd1c40 163
jah128 0:9ffe8ebd1c40 164 // Read the I2C magnetometer and store values locally: use before get_magnetometer_x etc...
jah128 0:9ffe8ebd1c40 165 char read_magnetometer ( void );
jah128 0:9ffe8ebd1c40 166
jah128 0:9ffe8ebd1c40 167 // Return the magnetometer x value stored on last call of read_magnetometer()
jah128 0:9ffe8ebd1c40 168 signed short get_magnetometer_x ( void );
jah128 0:9ffe8ebd1c40 169
jah128 0:9ffe8ebd1c40 170 // Return the magnetometer y value stored on last call of read_magnetometer()
jah128 0:9ffe8ebd1c40 171 signed short get_magnetometer_y ( void );
jah128 0:9ffe8ebd1c40 172
jah128 0:9ffe8ebd1c40 173 // Return the magnetometer z value stored on last call of read_magnetometer()
jah128 0:9ffe8ebd1c40 174 signed short get_magnetometer_z ( void );
jah128 0:9ffe8ebd1c40 175
jah128 0:9ffe8ebd1c40 176 // Blinks the calibration LED during calibration (turns off if calibration successful)
jah128 0:9ffe8ebd1c40 177 void calibrate_ticker_routine ( void );
jah128 0:9ffe8ebd1c40 178
jah128 0:9ffe8ebd1c40 179 // Read the gyroscope yaw value. Return value is degrees per second clockwise.
jah128 0:9ffe8ebd1c40 180 float read_gyro ( void );
jah128 0:9ffe8ebd1c40 181
jah128 0:9ffe8ebd1c40 182 // Read the X value from the accelerometer. Return value is mps2.
jah128 0:9ffe8ebd1c40 183 float read_accelerometer_x ( void );
jah128 0:9ffe8ebd1c40 184
jah128 0:9ffe8ebd1c40 185 // Read the Y value from the accelerometer. Return value is mps2.
jah128 0:9ffe8ebd1c40 186 float read_accelerometer_y ( void );
jah128 0:9ffe8ebd1c40 187
jah128 0:9ffe8ebd1c40 188 // Read the Z value from the accelerometer. Return value is mps2. Generally this will have g against it.
jah128 0:9ffe8ebd1c40 189 float read_accelerometer_z ( void );
jah128 0:9ffe8ebd1c40 190
jah128 0:9ffe8ebd1c40 191 // Read the value from the light sensor. This will return a value ranging from 0 to a peak of around 100 in direct, bright light.
jah128 0:9ffe8ebd1c40 192 float read_light_sensor ( void );
jah128 0:9ffe8ebd1c40 193
jah128 0:9ffe8ebd1c40 194 // Read the robot ID set using the DIP switches (these are read during setup and not updated).
jah128 0:9ffe8ebd1c40 195 char get_id ( void );
jah128 0:9ffe8ebd1c40 196
jah128 0:9ffe8ebd1c40 197 // Read the switches value from the last call of the ISR
jah128 0:9ffe8ebd1c40 198 char get_switches ( void );
jah128 0:9ffe8ebd1c40 199
jah128 0:9ffe8ebd1c40 200 // Enable or disable the center LED
jah128 0:9ffe8ebd1c40 201 void enable_cled ( char enable );
jah128 0:9ffe8ebd1c40 202
jah128 0:9ffe8ebd1c40 203 // Write single byte to EEPROM
jah128 0:9ffe8ebd1c40 204 void write_eeprom_byte ( int address, char data );
jah128 0:9ffe8ebd1c40 205
jah128 0:9ffe8ebd1c40 206 // Write (length) bytes to EEPROM
jah128 0:9ffe8ebd1c40 207 void write_eeprom_block ( int address, char length, char * data);
jah128 0:9ffe8ebd1c40 208
jah128 0:9ffe8ebd1c40 209 // Read single byte from EEPROM
jah128 0:9ffe8ebd1c40 210 char read_eeprom_byte ( int address );
jah128 0:9ffe8ebd1c40 211
jah128 0:9ffe8ebd1c40 212 // Read next byte from EEPROM at current address
jah128 0:9ffe8ebd1c40 213 char read_next_eeprom_byte ( void );
jah128 0:9ffe8ebd1c40 214
jah128 0:9ffe8ebd1c40 215 // Read (length) from EEPROM
jah128 0:9ffe8ebd1c40 216 char read_eeprom_block ( int address, char length );
jah128 0:9ffe8ebd1c40 217
jah128 0:9ffe8ebd1c40 218 // The following functions are (generally) those which are part of the original M3Pi library and interact with the 3Pi robot
jah128 0:9ffe8ebd1c40 219
jah128 0:9ffe8ebd1c40 220 /** Read the raw line sensors into a 5-int array
jah128 0:9ffe8ebd1c40 221 * @ param raw_ls_array Pointer to 5-int array for raw values (range 0-2000)
jah128 0:9ffe8ebd1c40 222 */
jah128 0:9ffe8ebd1c40 223 void read_raw_sensors ( int * raw_ls_array );
jah128 0:9ffe8ebd1c40 224
jah128 0:9ffe8ebd1c40 225
jah128 0:9ffe8ebd1c40 226 /** Play a tune on the 3pi buzzer
jah128 0:9ffe8ebd1c40 227 * @ param tune Pointer to a character sequence of the tune
jah128 0:9ffe8ebd1c40 228 * @ param length Length of characters in sequence
jah128 0:9ffe8ebd1c40 229 * ‘A’ – ‘G’: used to specify the notes that will be played
jah128 0:9ffe8ebd1c40 230 * ‘R’: used to specify a rest (no sound for the duration of the note)
jah128 0:9ffe8ebd1c40 231 * ‘<’ ‘>’ plays the next note one octave lower or higher
jah128 0:9ffe8ebd1c40 232 * ‘+’ or ‘#’ after a note raises any note one half-step, ‘-’ after a note lowers any note one half-step
jah128 0:9ffe8ebd1c40 233 * ‘.’ after a note “dots” it, increasing the length by 50%. Each additional dot adds half as much as the previous dot, so that “A..” is 1.75 times the length of “A”.
jah128 0:9ffe8ebd1c40 234 * ‘O’ followed by a number sets the octave (default: O4).
jah128 0:9ffe8ebd1c40 235 * ‘T’ followed by a number sets the tempo in beats/min (default: T120).
jah128 0:9ffe8ebd1c40 236 * ‘L’ followed by a number sets the default note duration to the type specified by the number: 4 for quarter notes, 8 for eighth notes, 16 for sixteenth notes, etc. (default: L4).
jah128 0:9ffe8ebd1c40 237 * ‘V’ followed by a number from 0-15 sets the music volume (default: V15).
jah128 0:9ffe8ebd1c40 238 * ‘MS’ sets all subsequent notes to play play staccato – each note is played for 1/2 of its allotted time, followed by an equal period of silence.
jah128 0:9ffe8ebd1c40 239 * ‘ML’ sets all subsequent notes to play legato – each note is played for full length. This is the default setting.
jah128 0:9ffe8ebd1c40 240 * ‘!’ resets the octave, tempo, duration, volume, and staccato setting to their default values. These settings persist from one play() to the next, which allows you to more conveniently break up your music into reusable sections.
jah128 0:9ffe8ebd1c40 241 * 1-2000: when immediately following a note, a number determines the duration of the note. For example, C16 specifies C played as a sixteenth note (1/16th the length of a whole note).
jah128 0:9ffe8ebd1c40 242 * EG Blue Danube Waltz (badly): s3pi.play_tune("MSCEGGR>F>FR>D>DRCCEGGR>G>GR>E>ER<B<BDAAR>A>AR>F>F",51);
jah128 0:9ffe8ebd1c40 243 */
jah128 0:9ffe8ebd1c40 244 void play_tune (char * tune, int length);
jah128 0:9ffe8ebd1c40 245
jah128 0:9ffe8ebd1c40 246 /** Force a hardware reset of the 3pi
jah128 0:9ffe8ebd1c40 247 */
jah128 0:9ffe8ebd1c40 248 void reset (void);
jah128 0:9ffe8ebd1c40 249
jah128 0:9ffe8ebd1c40 250 float get_left_motor (void);
jah128 0:9ffe8ebd1c40 251 float get_right_motor (void);
jah128 0:9ffe8ebd1c40 252
jah128 0:9ffe8ebd1c40 253 /** Directly control the speed and direction of the left motor
jah128 0:9ffe8ebd1c40 254 *
jah128 0:9ffe8ebd1c40 255 * @param speed A normalised number -1.0 - 1.0 represents the full range.
jah128 0:9ffe8ebd1c40 256 */
jah128 0:9ffe8ebd1c40 257 void left_motor (float speed);
jah128 0:9ffe8ebd1c40 258
jah128 0:9ffe8ebd1c40 259 /** Directly control the speed and direction of the right motor
jah128 0:9ffe8ebd1c40 260 *
jah128 0:9ffe8ebd1c40 261 * @param speed A normalised number -1.0 - 1.0 represents the full range.
jah128 0:9ffe8ebd1c40 262 */
jah128 0:9ffe8ebd1c40 263 void right_motor (float speed);
jah128 0:9ffe8ebd1c40 264
jah128 0:9ffe8ebd1c40 265 /** Drive both motors forward as the same speed
jah128 0:9ffe8ebd1c40 266 *
jah128 0:9ffe8ebd1c40 267 * @param speed A normalised number 0 - 1.0 represents the full range.
jah128 0:9ffe8ebd1c40 268 */
jah128 0:9ffe8ebd1c40 269 void forward (float speed);
jah128 0:9ffe8ebd1c40 270
jah128 0:9ffe8ebd1c40 271 /** Drive both motors backward as the same speed
jah128 0:9ffe8ebd1c40 272 *
jah128 0:9ffe8ebd1c40 273 * @param speed A normalised number 0 - 1.0 represents the full range.
jah128 0:9ffe8ebd1c40 274 */
jah128 0:9ffe8ebd1c40 275 void backward (float speed);
jah128 0:9ffe8ebd1c40 276
jah128 0:9ffe8ebd1c40 277 /** Drive left motor backwards and right motor forwards at the same speed to turn on the spot
jah128 0:9ffe8ebd1c40 278 *
jah128 0:9ffe8ebd1c40 279 * @param speed A normalised number 0 - 1.0 represents the full range.
jah128 0:9ffe8ebd1c40 280 */
jah128 0:9ffe8ebd1c40 281 void left (float speed);
jah128 0:9ffe8ebd1c40 282
jah128 0:9ffe8ebd1c40 283 /** Drive left motor forward and right motor backwards at the same speed to turn on the spot
jah128 0:9ffe8ebd1c40 284 * @param speed A normalised number 0 - 1.0 represents the full range.
jah128 0:9ffe8ebd1c40 285 */
jah128 0:9ffe8ebd1c40 286 void right (float speed);
jah128 0:9ffe8ebd1c40 287
jah128 0:9ffe8ebd1c40 288 /** Stop both motors
jah128 0:9ffe8ebd1c40 289 *
jah128 0:9ffe8ebd1c40 290 */
jah128 0:9ffe8ebd1c40 291 void stop (void);
jah128 0:9ffe8ebd1c40 292
jah128 0:9ffe8ebd1c40 293 /** Read the voltage of the potentiometer on the 3pi
jah128 0:9ffe8ebd1c40 294 * @returns voltage as a float
jah128 0:9ffe8ebd1c40 295 *
jah128 0:9ffe8ebd1c40 296 */
jah128 0:9ffe8ebd1c40 297 float pot_voltage(void);
jah128 0:9ffe8ebd1c40 298
jah128 0:9ffe8ebd1c40 299 /** Read the battery voltage on the 3pi
jah128 0:9ffe8ebd1c40 300 * @returns battery voltage as a float
jah128 0:9ffe8ebd1c40 301 */
jah128 0:9ffe8ebd1c40 302 float battery(void);
jah128 0:9ffe8ebd1c40 303
jah128 0:9ffe8ebd1c40 304 /** Read the position of the detected line
jah128 0:9ffe8ebd1c40 305 * @returns position as A normalised number -1.0 - 1.0 represents the full range.
jah128 0:9ffe8ebd1c40 306 * -1.0 means line is on the left, or the line has been lost
jah128 0:9ffe8ebd1c40 307 * 0.0 means the line is in the middle
jah128 0:9ffe8ebd1c40 308 * 1.0 means the line is on the right
jah128 0:9ffe8ebd1c40 309 */
jah128 0:9ffe8ebd1c40 310 float line_position (void);
jah128 0:9ffe8ebd1c40 311
jah128 0:9ffe8ebd1c40 312
jah128 0:9ffe8ebd1c40 313 /** Calibrate the sensors. This turns the robot left then right, looking for a line
jah128 0:9ffe8ebd1c40 314 *
jah128 0:9ffe8ebd1c40 315 */
jah128 0:9ffe8ebd1c40 316 char sensor_auto_calibrate (void);
jah128 0:9ffe8ebd1c40 317
jah128 0:9ffe8ebd1c40 318 /** Set calibration manually to the current settings.
jah128 0:9ffe8ebd1c40 319 *
jah128 0:9ffe8ebd1c40 320 */
jah128 0:9ffe8ebd1c40 321 void calibrate(void);
jah128 0:9ffe8ebd1c40 322
jah128 0:9ffe8ebd1c40 323 /** Clear the current calibration settings
jah128 0:9ffe8ebd1c40 324 *
jah128 0:9ffe8ebd1c40 325 */
jah128 0:9ffe8ebd1c40 326 void reset_calibration (void);
jah128 0:9ffe8ebd1c40 327
jah128 0:9ffe8ebd1c40 328 void PID_start(int max_speed, int a, int b, int c, int d);
jah128 0:9ffe8ebd1c40 329
jah128 0:9ffe8ebd1c40 330 void PID_stop();
jah128 0:9ffe8ebd1c40 331
jah128 0:9ffe8ebd1c40 332 /** Locate the cursor on the 8x2 LCD
jah128 0:9ffe8ebd1c40 333 *
jah128 0:9ffe8ebd1c40 334 * @param x The horizontal position, from 0 to 7
jah128 0:9ffe8ebd1c40 335 * @param y The vertical position, from 0 to 1
jah128 0:9ffe8ebd1c40 336 */
jah128 0:9ffe8ebd1c40 337 void locate(int x, int y);
jah128 0:9ffe8ebd1c40 338
jah128 0:9ffe8ebd1c40 339 /** Clear the LCD
jah128 0:9ffe8ebd1c40 340 *
jah128 0:9ffe8ebd1c40 341 */
jah128 0:9ffe8ebd1c40 342 void cls(void);
jah128 0:9ffe8ebd1c40 343
jah128 0:9ffe8ebd1c40 344 /** Send a character directly to the 3pi serial interface
jah128 0:9ffe8ebd1c40 345 * @param c The character to send to the 3pi
jah128 0:9ffe8ebd1c40 346 */
jah128 0:9ffe8ebd1c40 347 int putc(int c);
jah128 0:9ffe8ebd1c40 348
jah128 0:9ffe8ebd1c40 349 /** Receive a character directly to the 3pi serial interface
jah128 0:9ffe8ebd1c40 350 * @returns c The character received from the 3pi
jah128 0:9ffe8ebd1c40 351 */
jah128 0:9ffe8ebd1c40 352 int getc();
jah128 0:9ffe8ebd1c40 353
jah128 0:9ffe8ebd1c40 354 /** Send a string buffer to the 3pi serial interface
jah128 0:9ffe8ebd1c40 355 * @param text A pointer to a char array
jah128 0:9ffe8ebd1c40 356 * @param int The character to send to the 3pi
jah128 0:9ffe8ebd1c40 357 */
jah128 0:9ffe8ebd1c40 358 int print(char* text, int length);
jah128 0:9ffe8ebd1c40 359
jah128 0:9ffe8ebd1c40 360
jah128 0:9ffe8ebd1c40 361 void start_system_timer(void);
jah128 0:9ffe8ebd1c40 362
jah128 0:9ffe8ebd1c40 363 float get_uptime (void);
jah128 0:9ffe8ebd1c40 364
jah128 0:9ffe8ebd1c40 365 #ifdef MBED_RPC
jah128 0:9ffe8ebd1c40 366 virtual const struct rpc_method *get_rpc_methods();
jah128 0:9ffe8ebd1c40 367 #endif
jah128 0:9ffe8ebd1c40 368
jah128 0:9ffe8ebd1c40 369 private :
jah128 0:9ffe8ebd1c40 370
jah128 0:9ffe8ebd1c40 371 Serial _ser;
jah128 0:9ffe8ebd1c40 372 PwmOut _oled_r, _oled_g, _oled_b, _cled_r, _cled_g, _cled_b;
jah128 0:9ffe8ebd1c40 373 AnalogIn _gyro, _accel_x, _accel_y, _accel_z, _temperature, _light;
jah128 0:9ffe8ebd1c40 374 DigitalOut _irpulse_1, _irpulse_2;
jah128 0:9ffe8ebd1c40 375 I2C _i2c;
jah128 0:9ffe8ebd1c40 376 Alpha433 _rf;
jah128 0:9ffe8ebd1c40 377 Timer _system_timer;
jah128 0:9ffe8ebd1c40 378
jah128 0:9ffe8ebd1c40 379 void motor (int motor, float speed);
jah128 0:9ffe8ebd1c40 380 virtual int _putc(int c);
jah128 0:9ffe8ebd1c40 381 virtual int _getc();
jah128 0:9ffe8ebd1c40 382
jah128 0:9ffe8ebd1c40 383 };
jah128 0:9ffe8ebd1c40 384
jah128 0:9ffe8ebd1c40 385 void display_system_time(void);
jah128 0:9ffe8ebd1c40 386 void init(void);
jah128 0:9ffe8ebd1c40 387 extern Serial pc;
jah128 0:9ffe8ebd1c40 388 extern PiSwarm piswarm;
jah128 0:9ffe8ebd1c40 389
jah128 0:9ffe8ebd1c40 390 #endif
jah128 0:9ffe8ebd1c40 391
jah128 0:9ffe8ebd1c40 392
jah128 0:9ffe8ebd1c40 393 /********************************************************************************
jah128 0:9ffe8ebd1c40 394 * COPYRIGHT NOTICE *
jah128 0:9ffe8ebd1c40 395 * *
jah128 0:9ffe8ebd1c40 396 * Permission is hereby granted, free of charge, to any person obtaining a copy *
jah128 0:9ffe8ebd1c40 397 * of this software and associated documentation files (the "Software"), to deal*
jah128 0:9ffe8ebd1c40 398 * in the Software without restriction, including without limitation the rights *
jah128 0:9ffe8ebd1c40 399 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
jah128 0:9ffe8ebd1c40 400 * copies of the Software, and to permit persons to whom the Software is *
jah128 0:9ffe8ebd1c40 401 * furnished to do so, subject to the following conditions: *
jah128 0:9ffe8ebd1c40 402 * *
jah128 0:9ffe8ebd1c40 403 * The above copyright notice and this permission notice shall be included in *
jah128 0:9ffe8ebd1c40 404 * all copies or substantial portions of the Software. *
jah128 0:9ffe8ebd1c40 405 * *
jah128 0:9ffe8ebd1c40 406 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
jah128 0:9ffe8ebd1c40 407 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
jah128 0:9ffe8ebd1c40 408 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
jah128 0:9ffe8ebd1c40 409 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
jah128 0:9ffe8ebd1c40 410 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,*
jah128 0:9ffe8ebd1c40 411 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
jah128 0:9ffe8ebd1c40 412 * THE SOFTWARE. *
jah128 0:9ffe8ebd1c40 413 * *
jah128 0:9ffe8ebd1c40 414 *******************************************************************************/