Handheld controller (RF) for Pi Swarm system
Fork of Pi_Swarm_Handheld_Controller by
communications.h@0:d63a63feb104, 2014-06-10 (annotated)
- Committer:
- jah128
- Date:
- Tue Jun 10 11:05:23 2014 +0000
- Revision:
- 0:d63a63feb104
Handheld controller for Pi Swarm (old code)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:d63a63feb104 | 1 | /******************************************************************************************* |
jah128 | 0:d63a63feb104 | 2 | * |
jah128 | 0:d63a63feb104 | 3 | * University of York Robot Lab Pi Swarm Library: Swarm Communications Handler |
jah128 | 0:d63a63feb104 | 4 | * |
jah128 | 0:d63a63feb104 | 5 | * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York |
jah128 | 0:d63a63feb104 | 6 | * |
jah128 | 0:d63a63feb104 | 7 | * Version 0.5 February 2014 |
jah128 | 0:d63a63feb104 | 8 | * |
jah128 | 0:d63a63feb104 | 9 | * Designed for use with the Pi Swarm Board (enhanced MBED sensor board) v1.2 |
jah128 | 0:d63a63feb104 | 10 | * |
jah128 | 0:d63a63feb104 | 11 | ******************************************************************************************/ |
jah128 | 0:d63a63feb104 | 12 | |
jah128 | 0:d63a63feb104 | 13 | #ifndef COMMUNICATIONS_H |
jah128 | 0:d63a63feb104 | 14 | #define COMMUNICATIONS_H |
jah128 | 0:d63a63feb104 | 15 | |
jah128 | 0:d63a63feb104 | 16 | // The swarm_member struct is used by the communication stack to store the status and results for RF commands and requests |
jah128 | 0:d63a63feb104 | 17 | // that have been sent. An array of [SWARM_SIZE] swarm_members is created. This contains a status flag for all of the |
jah128 | 0:d63a63feb104 | 18 | // standard requests and commands and a set of variables for data which can be collected. |
jah128 | 0:d63a63feb104 | 19 | // |
jah128 | 0:d63a63feb104 | 20 | // The status flags are set to the following values: |
jah128 | 0:d63a63feb104 | 21 | // 0 : "unused" - before any requests are sent |
jah128 | 0:d63a63feb104 | 22 | // 1 : "waiting" - a request or command has been sent and the result is not yet known |
jah128 | 0:d63a63feb104 | 23 | // 2 : "received" - a valid response to a request or command has been received |
jah128 | 0:d63a63feb104 | 24 | // 3 : "invalid" - an invalid response to a request or command has been received |
jah128 | 0:d63a63feb104 | 25 | struct swarm_member { |
jah128 | 0:d63a63feb104 | 26 | char status_rf_request_null; |
jah128 | 0:d63a63feb104 | 27 | char status_rf_request_left_motor_speed; |
jah128 | 0:d63a63feb104 | 28 | char status_rf_request_right_motor_speed; |
jah128 | 0:d63a63feb104 | 29 | char status_rf_request_button_state; |
jah128 | 0:d63a63feb104 | 30 | char status_rf_request_led_colour; |
jah128 | 0:d63a63feb104 | 31 | char status_rf_request_led_states; |
jah128 | 0:d63a63feb104 | 32 | char status_rf_request_battery; |
jah128 | 0:d63a63feb104 | 33 | char status_rf_request_light_sensor; |
jah128 | 0:d63a63feb104 | 34 | char status_rf_request_accelerometer; |
jah128 | 0:d63a63feb104 | 35 | char status_rf_request_gyroscope; |
jah128 | 0:d63a63feb104 | 36 | char status_rf_request_background_ir; |
jah128 | 0:d63a63feb104 | 37 | char status_rf_request_reflected_ir; |
jah128 | 0:d63a63feb104 | 38 | char status_rf_request_distance_ir; |
jah128 | 0:d63a63feb104 | 39 | char status_rf_request_line_following_ir; |
jah128 | 0:d63a63feb104 | 40 | char status_rf_request_uptime; |
jah128 | 0:d63a63feb104 | 41 | char status_rf_command_stop; |
jah128 | 0:d63a63feb104 | 42 | char status_rf_command_forward; |
jah128 | 0:d63a63feb104 | 43 | char status_rf_command_backward; |
jah128 | 0:d63a63feb104 | 44 | char status_rf_command_left; |
jah128 | 0:d63a63feb104 | 45 | char status_rf_command_right; |
jah128 | 0:d63a63feb104 | 46 | char status_rf_command_left_motor; |
jah128 | 0:d63a63feb104 | 47 | char status_rf_command_right_motor; |
jah128 | 0:d63a63feb104 | 48 | char status_rf_command_oled_colour; |
jah128 | 0:d63a63feb104 | 49 | char status_rf_command_cled_colour; |
jah128 | 0:d63a63feb104 | 50 | char status_rf_command_oled_state; |
jah128 | 0:d63a63feb104 | 51 | char status_rf_command_cled_state; |
jah128 | 0:d63a63feb104 | 52 | char status_rf_command_set_oled; |
jah128 | 0:d63a63feb104 | 53 | char status_rf_command_play_tune; |
jah128 | 0:d63a63feb104 | 54 | char status_rf_command_sync_time; |
jah128 | 0:d63a63feb104 | 55 | float left_motor_speed; |
jah128 | 0:d63a63feb104 | 56 | float right_motor_speed; |
jah128 | 0:d63a63feb104 | 57 | char button_state; |
jah128 | 0:d63a63feb104 | 58 | char outer_led_colour [3]; |
jah128 | 0:d63a63feb104 | 59 | char center_led_colour [3]; |
jah128 | 0:d63a63feb104 | 60 | char led_states[2]; |
jah128 | 0:d63a63feb104 | 61 | float battery; |
jah128 | 0:d63a63feb104 | 62 | float light_sensor; |
jah128 | 0:d63a63feb104 | 63 | float accelerometer[3]; |
jah128 | 0:d63a63feb104 | 64 | float gyro; |
jah128 | 0:d63a63feb104 | 65 | unsigned short background_ir[8]; |
jah128 | 0:d63a63feb104 | 66 | unsigned short reflected_ir[8]; |
jah128 | 0:d63a63feb104 | 67 | float distance_ir[8]; |
jah128 | 0:d63a63feb104 | 68 | }; |
jah128 | 0:d63a63feb104 | 69 | |
jah128 | 0:d63a63feb104 | 70 | void send_rf_message(char target, char command, char * data, char length); |
jah128 | 0:d63a63feb104 | 71 | void setup_communications(void); |
jah128 | 0:d63a63feb104 | 72 | void decodeMessage(char sender, char target, char id, char command, char * data, char length); |
jah128 | 0:d63a63feb104 | 73 | void send_response(char target, char is_broadcast, char success, char id, char is_command, char function, char * data, char length); |
jah128 | 0:d63a63feb104 | 74 | void tdma_response(); |
jah128 | 0:d63a63feb104 | 75 | void handle_command(char sender, char is_broadcast, char request_response, char id, char function, char * data, char length); |
jah128 | 0:d63a63feb104 | 76 | void handle_request(char sender, char is_broadcast, char request_response, char id, char function); |
jah128 | 0:d63a63feb104 | 77 | void processRadioData(char * data, char length); |
jah128 | 0:d63a63feb104 | 78 | void errormessage(int index); |
jah128 | 0:d63a63feb104 | 79 | void handle_response(char sender, char is_broadcast, char success, char id, char is_command, char function, char * data, char length); |
jah128 | 0:d63a63feb104 | 80 | |
jah128 | 0:d63a63feb104 | 81 | void send_rf_request_null ( char target ); |
jah128 | 0:d63a63feb104 | 82 | void send_rf_request_left_motor_speed ( char target ); |
jah128 | 0:d63a63feb104 | 83 | void send_rf_request_right_motor_speed ( char target ); |
jah128 | 0:d63a63feb104 | 84 | void send_rf_request_button_state ( char target ); |
jah128 | 0:d63a63feb104 | 85 | void send_rf_request_led_colour ( char target ); |
jah128 | 0:d63a63feb104 | 86 | void send_rf_request_led_states ( char target ); |
jah128 | 0:d63a63feb104 | 87 | void send_rf_request_battery ( char target ); |
jah128 | 0:d63a63feb104 | 88 | void send_rf_request_light_sensor ( char target ); |
jah128 | 0:d63a63feb104 | 89 | void send_rf_request_accelerometer ( char target ); |
jah128 | 0:d63a63feb104 | 90 | void send_rf_request_gyroscope ( char target ); |
jah128 | 0:d63a63feb104 | 91 | void send_rf_request_background_ir ( char target ); |
jah128 | 0:d63a63feb104 | 92 | void send_rf_request_reflected_ir ( char target ); |
jah128 | 0:d63a63feb104 | 93 | void send_rf_request_distance_ir ( char target ); |
jah128 | 0:d63a63feb104 | 94 | void send_rf_request_line_following_ir ( char target ); |
jah128 | 0:d63a63feb104 | 95 | void send_rf_request_uptime ( char target ); |
jah128 | 0:d63a63feb104 | 96 | void send_rf_command_stop ( char target, char request_response ); |
jah128 | 0:d63a63feb104 | 97 | void send_rf_command_forward ( char target, char request_response, float speed ); |
jah128 | 0:d63a63feb104 | 98 | void send_rf_command_backward ( char target, char request_response, float speed ); |
jah128 | 0:d63a63feb104 | 99 | void send_rf_command_left ( char target, char request_response, float speed ); |
jah128 | 0:d63a63feb104 | 100 | void send_rf_command_right ( char target, char request_response, float speed ); |
jah128 | 0:d63a63feb104 | 101 | void send_rf_command_left_motor ( char target, char request_response, float speed ); |
jah128 | 0:d63a63feb104 | 102 | void send_rf_command_right_motor ( char target, char request_response, float speed ); |
jah128 | 0:d63a63feb104 | 103 | void send_rf_command_oled_colour ( char target, char request_response, char red, char green, char blue ); |
jah128 | 0:d63a63feb104 | 104 | void send_rf_command_cled_colour ( char target, char request_response, char red, char green, char blue ); |
jah128 | 0:d63a63feb104 | 105 | void send_rf_command_oled_state ( char target, char request_response, char led0, char led1, char led2, char led3, char led4, char led5, char led6, char led7, char led8, char led9 ); |
jah128 | 0:d63a63feb104 | 106 | void send_rf_command_cled_state ( char target, char request_response, char enable ); |
jah128 | 0:d63a63feb104 | 107 | void send_rf_command_set_oled ( char target, char request_response, char oled, char enable ); |
jah128 | 0:d63a63feb104 | 108 | void send_rf_command_play_tune ( char target, char request_response, char * data, char length ); |
jah128 | 0:d63a63feb104 | 109 | void send_rf_command_sync_time ( char target, char request_response ); |
jah128 | 0:d63a63feb104 | 110 | |
jah128 | 0:d63a63feb104 | 111 | |
jah128 | 0:d63a63feb104 | 112 | const char * const requests_array[] = { "Req.Ack", "Req.LM", "Req.RM", "Req.But","Req.LEDCol","Req.LED","Req.Lgt","Req.Acc","Req.Gyro","Req.BIR","Req.RIR","Req.DIR","Req.LFS","Req.UpT","Req.???","Req.???"}; |
jah128 | 0:d63a63feb104 | 113 | const char * const commands_array[] = { "Cm.Stop","Cm.Fward","Cm.Bward","Cm.Left","Cm.Right","Cm.LMot","Cm.RMot","Cm.OLEDC","Cm.CLEDC","Cm.OLEDS","Cm.CLEDS","Cm.SetLED","Cm.Play","Cm.Sync","Cm.???","Cm.???"}; |
jah128 | 0:d63a63feb104 | 114 | |
jah128 | 0:d63a63feb104 | 115 | #endif //COMMUNICATIONS_H |