YRL Maze lab made more script-y

Dependencies:   PsiSwarmLab-ScriptingBased mbed

Fork of UKESF_Lab by UKESF Headstart Summer School

Committer:
jah128
Date:
Sat Oct 03 22:48:50 2015 +0000
Revision:
0:8a5497a2e366
Child:
1:f6356cf1cefc
Initial commit of PsiSwarm API and example code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:8a5497a2e366 1 /***********************************************************************
jah128 0:8a5497a2e366 2 ** ██████╗ ███████╗██╗███████╗██╗ ██╗ █████╗ ██████╗ ███╗ ███╗ **
jah128 0:8a5497a2e366 3 ** ██╔══██╗██╔════╝██║██╔════╝██║ ██║██╔══██╗██╔══██╗████╗ ████║ **
jah128 0:8a5497a2e366 4 ** ██████╔╝███████╗██║███████╗██║ █╗ ██║███████║██████╔╝██╔████╔██║ **
jah128 0:8a5497a2e366 5 ** ██╔═══╝ ╚════██║██║╚════██║██║███╗██║██╔══██║██╔══██╗██║╚██╔╝██║ **
jah128 0:8a5497a2e366 6 ** ██║ ███████║██║███████║╚███╔███╔╝██║ ██║██║ ██║██║ ╚═╝ ██║ **
jah128 0:8a5497a2e366 7 ** ╚═╝ ╚══════╝╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ **
jah128 0:8a5497a2e366 8 ************************************************************************
jah128 0:8a5497a2e366 9 **(C) Dr James Hilder - York Robotics Laboratory - University of York **
jah128 0:8a5497a2e366 10 ***********************************************************************/
jah128 0:8a5497a2e366 11
jah128 0:8a5497a2e366 12 // PsiSwarm Example Main File
jah128 0:8a5497a2e366 13
jah128 0:8a5497a2e366 14 // Include psiswarm.h - this includes all the other necessary core files
jah128 0:8a5497a2e366 15 #include "psiswarm.h"
jah128 0:8a5497a2e366 16
jah128 0:8a5497a2e366 17 // Use these variables to store the name for the program and the author
jah128 0:8a5497a2e366 18 // NB: Keep the strings as short as possible (ie 12 chars or less) to ensure reliable comms
jah128 0:8a5497a2e366 19 char * program_name = "Example";
jah128 0:8a5497a2e366 20 char * author_name = "JAH-YRL";
jah128 0:8a5497a2e366 21
jah128 0:8a5497a2e366 22 // Place user variables here
jah128 0:8a5497a2e366 23
jah128 0:8a5497a2e366 24 char green = 3;
jah128 0:8a5497a2e366 25 char red = 48;
jah128 0:8a5497a2e366 26 int re =0 ;
jah128 0:8a5497a2e366 27 int le =0;
jah128 0:8a5497a2e366 28
jah128 0:8a5497a2e366 29 //Place user code here that should be run after initialisation but before the main loop
jah128 0:8a5497a2e366 30 void user_code_setup(){
jah128 0:8a5497a2e366 31
jah128 0:8a5497a2e366 32 /*
jah128 0:8a5497a2e366 33 wait(2);
jah128 0:8a5497a2e366 34 calibrate_base_ir_sensors();
jah128 0:8a5497a2e366 35 wait(2);
jah128 0:8a5497a2e366 36 */
jah128 0:8a5497a2e366 37 }
jah128 0:8a5497a2e366 38
jah128 0:8a5497a2e366 39 //This function is the loop where user code should be placed
jah128 0:8a5497a2e366 40 void user_code_loop(){
jah128 0:8a5497a2e366 41
jah128 0:8a5497a2e366 42
jah128 0:8a5497a2e366 43 //Do not place code within a loop, but consider this function to be a loop that is always run
jah128 0:8a5497a2e366 44 //unless the user code is externally paused (such as by debug or recharging system)
jah128 0:8a5497a2e366 45
jah128 0:8a5497a2e366 46
jah128 0:8a5497a2e366 47
jah128 0:8a5497a2e366 48
jah128 0:8a5497a2e366 49 /*
jah128 0:8a5497a2e366 50 store_base_ir_values();
jah128 0:8a5497a2e366 51 bt.printf("OFF: %d %d %d %d %d\n ON: %d %d %d %d %d\n\n",
jah128 0:8a5497a2e366 52 get_background_base_ir_value(0),
jah128 0:8a5497a2e366 53 get_background_base_ir_value(1),
jah128 0:8a5497a2e366 54 get_background_base_ir_value(2),
jah128 0:8a5497a2e366 55 get_background_base_ir_value(3),
jah128 0:8a5497a2e366 56 get_background_base_ir_value(4),
jah128 0:8a5497a2e366 57 get_illuminated_base_ir_value(0),
jah128 0:8a5497a2e366 58 get_illuminated_base_ir_value(1),
jah128 0:8a5497a2e366 59 get_illuminated_base_ir_value(2),
jah128 0:8a5497a2e366 60 get_illuminated_base_ir_value(3),
jah128 0:8a5497a2e366 61 get_illuminated_base_ir_value(4));
jah128 0:8a5497a2e366 62 set_leds(green,red);
jah128 0:8a5497a2e366 63 switch(green){
jah128 0:8a5497a2e366 64 case 192: green = 129; break;
jah128 0:8a5497a2e366 65 case 129: green = 3; break;
jah128 0:8a5497a2e366 66 default: green = green << 1; break;
jah128 0:8a5497a2e366 67 }
jah128 0:8a5497a2e366 68 switch(red){
jah128 0:8a5497a2e366 69 case 192: red = 129; break;
jah128 0:8a5497a2e366 70 case 129: red = 3; break;
jah128 0:8a5497a2e366 71 default: red = red << 1; break;
jah128 0:8a5497a2e366 72 }
jah128 0:8a5497a2e366 73
jah128 0:8a5497a2e366 74
jah128 0:8a5497a2e366 75 if(re != right_encoder){
jah128 0:8a5497a2e366 76 re = right_encoder;
jah128 0:8a5497a2e366 77 pc.printf("Right:%d\n",re);
jah128 0:8a5497a2e366 78 }
jah128 0:8a5497a2e366 79 if(le != left_encoder){
jah128 0:8a5497a2e366 80 le = left_encoder;
jah128 0:8a5497a2e366 81 pc.printf("Left:%d\n",le);
jah128 0:8a5497a2e366 82 }
jah128 0:8a5497a2e366 83 wait(0.3);
jah128 0:8a5497a2e366 84 */
jah128 0:8a5497a2e366 85 }
jah128 0:8a5497a2e366 86
jah128 0:8a5497a2e366 87
jah128 0:8a5497a2e366 88 // Code goes here to handle what should happen when the user switch is pressed
jah128 0:8a5497a2e366 89 void handle_switch_event(char switch_state)
jah128 0:8a5497a2e366 90 {
jah128 0:8a5497a2e366 91 // Switch_state = 1 if up is pressed, 2 if down is pressed, 4 if left is pressed, 8 if right is pressed and 16 if the center button is pressed
jah128 0:8a5497a2e366 92 }
jah128 0:8a5497a2e366 93
jah128 0:8a5497a2e366 94 // The main routine: it is recommended to leave this function alone and add user code to the above functions
jah128 0:8a5497a2e366 95 int main() {
jah128 0:8a5497a2e366 96 //init() in psiswarm.cpp sets up the robot
jah128 0:8a5497a2e366 97 init();
jah128 0:8a5497a2e366 98 user_code_setup();
jah128 0:8a5497a2e366 99 user_code_running = 1;
jah128 0:8a5497a2e366 100 while(1) {
jah128 0:8a5497a2e366 101 if(user_code_running)user_code_loop();
jah128 0:8a5497a2e366 102 if(demo_on) demo_mode();
jah128 0:8a5497a2e366 103 wait_us(250);
jah128 0:8a5497a2e366 104 }
jah128 0:8a5497a2e366 105 }