YRL Maze lab made more script-y

Dependencies:   PsiSwarmLab-ScriptingBased mbed

Fork of UKESF_Lab by UKESF Headstart Summer School

Revision:
31:7fa2c47d73a2
Parent:
30:513457c1ad12
Child:
32:cdcc91651e55
--- a/main.cpp	Tue Mar 15 00:58:43 2016 +0000
+++ b/main.cpp	Mon Jun 20 13:36:30 2016 +0000
@@ -1,70 +1,87 @@
-/***********************************************************************
-**  ██████╗ ███████╗██╗███████╗██╗    ██╗ █████╗ ██████╗ ███╗   ███╗  **
-**  ██╔══██╗██╔════╝██║██╔════╝██║    ██║██╔══██╗██╔══██╗████╗ ████║  **
-**  ██████╔╝███████╗██║███████╗██║ █╗ ██║███████║██████╔╝██╔████╔██║  **
-**  ██╔═══╝ ╚════██║██║╚════██║██║███╗██║██╔══██║██╔══██╗██║╚██╔╝██║  **
-**  ██║     ███████║██║███████║╚███╔███╔╝██║  ██║██║  ██║██║ ╚═╝ ██║  **
-**  ╚═╝     ╚══════╝╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝  **
-************************************************************************
-**(C) Dr James Hilder - York Robotics Laboratory - University of York **
-***********************************************************************/
+/**********************************************************
+* UKESF Headstart Summer School - Robot Programming Lab   *
+**********************************************************/
 
-/// PsiSwarm Blank Example Code
-/// Version 0.41
-/// James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis
-/// University of York
+// Note: A line beginning with // is a 'comment' and is
+// ignored by the compiler [it is shown in green text in the IDE]
 
-/// Include main.h - this includes psiswarm.h all the other necessary core files
+// Include main.h - this contains the code needed to setup
+// the Psi-Swarm robot and its hardware
 #include "main.h"
 
-char * program_name = "Blank";
+// You can change the author name to saomething else if you want - just make sure it is no more than 16 characters long
 char * author_name  = "YRL";
-char * version_name = "0.41";
-
-void user_code_loop()
-{
-    wait(1);   
-}
-
-///Place user code here that should be run after initialisation but before the main loop
-void user_code_setup()
-{
-    wait(1);
-    display.clear_display();
-    display.set_position(0,0);
-    display.write_string("No Code");  
-    
-    //bmeme_user_code_setup(); 
-}
-
-/// Code goes here to handle what should happen when the user switch is pressed
-void handle_switch_event(char switch_state)
-{
-    /// 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
-    /// NB For maximum compatability it is recommended to minimise reliance on center button press
-
-    //bmeme_handle_switch_event(switch_state);
-}
-
-void handle_user_serial_message(char * message, char length, char interface)
-{
-    // This is where user code for handling a (non-system) serial message should go
-    //
-    // message = pointer to message char array
-    // length = length of message
-    // interface = 0 for PC serial connection, 1 for Bluetooth
-    
-    //bmeme_handle_user_serial_message(message, length, interface);
-}
 
 /// The main routine: it is recommended to leave this function alone and add user code to the above functions
 int main()
 {
-    ///init() in psiswarm.cpp sets up the robot
+    // init() in psiswarm.cpp sets up the robot - we need to run this line of code before anything else or the robot won't work.
     init();
-    user_code_setup();
-    user_code_running = 1;
-    while(1) {
-        user_code_loop();
+
+    // We shall create a for-loop to try to move the robot in a 50cm square.
+    for(int i=0; i<4; i++){
+      
+      // Move the robot forward 50cm
+      move_forward(50);
+      
+      // Wait one second
+      wait(1.0);
+      
+      // Turn the robot right 90 degrees
+      turn_right();
+      
+      // Wait for one second
+      wait(1.0);
     }
-}
\ No newline at end of file
+    
+    // When we have finished our code, we want to leave the MBED in an endless loop.
+    while(1){}
+}
+
+/**
+* void move_forward(int distance)
+* This function should move the robot forward for the distance
+* (in centimeter) specified by distance
+*/
+void move_forward(int distance)
+{
+    float left_motor_speed = 0.4;
+    float right_motor_speed = 0.4;
+    float cm_per_second = 25.0;
+    float delay = distance / cm_per_second;
+    set_motor_speed(left_motor_speed, right_motor_speed);
+    wait(delay);
+    brake();
+}
+
+/**
+* void turn_right()
+* This function should turn the robot right by 90 degrees.
+*/
+void turn_right()
+{
+    float speed = 0.2;
+    float degrees_per_second = 150.0;
+    float delay = 90 / degrees_per_second;
+    turn(speed);
+    wait(delay);
+    brake();
+}
+
+/**
+* void turn_left()
+* This function should turn the robot left by 90 degrees.  You will need to fill in the code here 
+* HINT: You can use Ctrl-C and Ctrl-V to copy\paste blocks of code!
+*/
+void turn_left()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// You can ignore the code beyond this point: we need these variables and functions to make the code
+// compile without errors, but we aren't using the functions for this lab session.
+char * program_name = "Headstart";
+char * version_name = "0.5";
+void handle_switch_event(char switch_state){}
+void handle_user_serial_message(char * message, char length, char interface){}
\ No newline at end of file