Stuff

Dependencies:   mbed

Fork of PsiSwarm-flockingAddedBluetooth by James Wilson

Files at this revision

API Documentation at this revision

Comitter:
JamesSW
Date:
Wed Mar 01 15:23:47 2017 +0000
Parent:
18:3fa5cd53ed45
Commit message:
untidy code for bluetooth;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
programs.cpp Show annotated file Show diff for this revision Revisions of this file
programs.h Show annotated file Show diff for this revision Revisions of this file
diff -r 3fa5cd53ed45 -r b5788427db67 main.cpp
--- a/main.cpp	Thu Feb 23 09:51:40 2017 +0000
+++ b/main.cpp	Wed Mar 01 15:23:47 2017 +0000
@@ -61,6 +61,7 @@
 
 Ticker main_loop_ticker;
 
+
 ///This is the main loop for the Beautiful Meme code.  The code block is run once every 250mS* [with 4Hz beacon] once all the IR samples have been collected.
 void main_loop()
 {
@@ -76,6 +77,8 @@
     if(use_recharging_program == 1)recharging_program();
     update_display();
     if(recharging_state == 0) {
+        // remove after testing
+        main_program_state = 8;
         switch(main_program_state) {
             case 0: //Case 0 is the initial program: turn to face beacon
                 if(step_cycle == 0) {
@@ -111,6 +114,12 @@
             case 7:
                 tag_game_program();
                 break;
+            case 8:
+                mockFlocking();
+                break;
+            case 254:
+                init();
+                break;
             case 255:
                 stop_program();
                 break;
@@ -252,9 +261,7 @@
         }
     else
     {
-/*        display.clear_display();
-        display.set_position(0,0);
-        display.write_string("NOOO!");*/
+
         }
 }
 /// The main routine: it is recommended to leave this function alone and add user code to the above functions
diff -r 3fa5cd53ed45 -r b5788427db67 programs.cpp
--- a/programs.cpp	Thu Feb 23 09:51:40 2017 +0000
+++ b/programs.cpp	Wed Mar 01 15:23:47 2017 +0000
@@ -725,6 +725,59 @@
 }
 
 
+// mock flocking program
+
+void mockFlocking()
+{
+    float left_motor_speed = 0.5;
+    float right_motor_speed = 0.5;
+    char buffer[255];
+    
+        
+    if (reflected_sensor_data[0] > 300){
+        left_motor_speed = -0.5;
+        set_left_motor_speed(left_motor_speed);
+        set_right_motor_speed(right_motor_speed);      
+    }
+    else if (reflected_sensor_data[7] > 300){
+        right_motor_speed = -0.5;
+        set_left_motor_speed(left_motor_speed);
+        set_right_motor_speed(right_motor_speed);      
+    }
+    else if (robot_id == 1) {
+        display.clear_display();
+        display.set_position(0,0);
+        display.write_string("my Id is 1!");
+        float left_motor_speed = 0.3;
+        float right_motor_speed = 0.3;
+        int turnChance = rand() %100;
+        if (turnChance < 20) {
+            left_motor_speed = 0;
+        } else if (turnChance > 80) {
+            right_motor_speed = 0;
+        }
+        
+        set_left_motor_speed(left_motor_speed);
+        set_right_motor_speed(right_motor_speed);
+    }
+    else {
+        
+        if (abs(robots_heading[1]) > 40 && robots_found[1] == 1) {
+            time_based_turn_degrees(1, robots_heading[1], 1);
+            sprintf(buffer,"%d > 40", robots_heading[1]);
+            display.clear_display();
+            display.set_position(0,0);
+            display.write_string(buffer);
+        } 
+        else {
+            //used for time based turn instead of location based
+            set_left_motor_speed(left_motor_speed);
+            set_right_motor_speed(right_motor_speed);
+        }  
+    }
+
+}
+
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /// generic_program - Framework for building typical programs
 
diff -r 3fa5cd53ed45 -r b5788427db67 programs.h
--- a/programs.h	Thu Feb 23 09:51:40 2017 +0000
+++ b/programs.h	Wed Mar 01 15:23:47 2017 +0000
@@ -17,5 +17,6 @@
 void stop_program(void);
 void role_reset(void);
 void tag_game_program(void);
+void mockFlocking(void);
 
 #endif
\ No newline at end of file