Commits

Anonymous committed f69ef2e

- added comments

  • Participants
  • Parent commits 354eb1e

Comments (0)

Files changed (1)

+/*
 
+  This is a basic robot self-navigating robot.   It's driven by two 
+  continuous rotation servos and uses a Sharp GP2Y0A02YK0F infra-red 
+  distance measuring sensor to detect obstacles.
+  
+  If the IR sensor detects something within range, it make a turn
+  by driving the motors in opposite directions.
+
+--
+Copyright (C) 2010 by Integrated Mapping Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+*/
 
 #include <Servo.h> 
 
-/*
-
-  this version drives the robot, but if it gets too close, 
-  it makes random turn
-
-*/
-
+// connect the IR sensor to analogue pin 4
 #define irPin 4
 
+// the two servo objects
 Servo servo1;
 Servo servo2;
 
+//-----------------------------------------------------
 void setup() 
 { 
   
-  // connect the servos
+  // connect to the servos.
   servo1.attach(9);
   servo2.attach(10);
   
   // set to zero speed
   drive(0.0,0.0);
   
-  // give us a chance to put the bot down before it takes of
+  // give us a chance to put the bot down before it takes off - 4 second delay
   delay(4000);
   
 } 
 
+
+//-----------------------------------------------------
 void loop() {
 
-  // read the IR sensor
+  // read the IR sensor.  a raw reading of 350 is about 350mm away
   if (analogRead(irPin) < 350) {
 
     // nothing close, so drive forward. fwd/rev depends on
-    // which side the motors are on the robot, i.e. it's all relative
+    // which side the motors are on the robot. if it goes the wrong
+    // way, swap the motors or modify the drive() function to invert the 
+    // sign of the speed values. 0 is stopped.  -1/1 are full speed
     drive(-1.0, -1.0);
 
   
     // the loop determines what happens next - more turning or fwd
     drive(1.0, -1.0);
     delay(random(300, 1500));
-    drive(0., 0.0);
+    drive(0.0, 0.0);
     
   }
   
-  delay(75);
+  delay(50);
   
 }