layout stages with lexicographically ordered names
authordaniel watson <ozzloy@gmail.com>
Sun, 8 Jun 2014 06:29:23 +0000 (23:29 -0700)
committerdaniel watson <ozzloy@gmail.com>
Sun, 8 Jun 2014 06:29:23 +0000 (23:29 -0700)
36 files changed:
arduino-sketches/both_motors/both-motors-mini.fzz [deleted file]
arduino-sketches/both_motors/both-motors.fzz [deleted file]
arduino-sketches/both_motors/both_motors.ino [deleted file]
arduino-sketches/both_sonars/both-sonars-mini.fzz [deleted file]
arduino-sketches/both_sonars/both-sonars.fzz [deleted file]
arduino-sketches/both_sonars/both_sonars.ino [deleted file]
arduino-sketches/follow/follow.ino [deleted file]
arduino-sketches/motor/README [deleted file]
arduino-sketches/motor/motor.ino [deleted file]
arduino-sketches/pushbutton/README [deleted file]
arduino-sketches/pushbutton/pushbutton.ino [deleted file]
arduino-sketches/right_motor/right-motor-mini.fzz [deleted file]
arduino-sketches/right_motor/right-motor.fzz [deleted file]
arduino-sketches/right_motor/right_motor.ino [deleted file]
arduino-sketches/right_sonar/right-sonar-mini.fzz [deleted file]
arduino-sketches/right_sonar/right-sonar.fzz [deleted file]
arduino-sketches/right_sonar/right_sonar.ino [deleted file]
arduino-sketches/serial/README [deleted file]
arduino-sketches/serial/serial.ino [deleted file]
arduino-sketches/stay_on_table/stay_on_table.ino [deleted file]
arduino-sketches/untethered/untethered.fzz [deleted file]
arduino-sketches/untethered/untethered.ino [deleted file]
build-stages/a_serial/README [new file with mode: 0644]
build-stages/a_serial/a_serial.ino [new file with mode: 0644]
build-stages/b_right_sonar/b_right_sonar.ino [new file with mode: 0644]
build-stages/b_right_sonar/right-sonar.fzz [new file with mode: 0644]
build-stages/c_both_sonars/both-sonars.fzz [new file with mode: 0644]
build-stages/c_both_sonars/c_both_sonars.ino [new file with mode: 0644]
build-stages/d_right_motor/d_right_motor.ino [new file with mode: 0644]
build-stages/d_right_motor/right-motor.fzz [new file with mode: 0644]
build-stages/e_both_motors/both-motors.fzz [new file with mode: 0644]
build-stages/e_both_motors/e_both_motors.ino [new file with mode: 0644]
build-stages/f_untethered/f_untethered.ino [new file with mode: 0644]
build-stages/f_untethered/untethered.fzz [new file with mode: 0644]
build-stages/g_follow/g_follow.ino [new file with mode: 0644]
build-stages/h_stay_on_table/h_stay_on_table.ino [new file with mode: 0644]

diff --git a/arduino-sketches/both_motors/both-motors-mini.fzz b/arduino-sketches/both_motors/both-motors-mini.fzz
deleted file mode 100644 (file)
index bcac2cc..0000000
Binary files a/arduino-sketches/both_motors/both-motors-mini.fzz and /dev/null differ
diff --git a/arduino-sketches/both_motors/both-motors.fzz b/arduino-sketches/both_motors/both-motors.fzz
deleted file mode 100644 (file)
index 3050bb0..0000000
Binary files a/arduino-sketches/both_motors/both-motors.fzz and /dev/null differ
diff --git a/arduino-sketches/both_motors/both_motors.ino b/arduino-sketches/both_motors/both_motors.ino
deleted file mode 100644 (file)
index b42c07c..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of the
-    License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// define which pins are connected to which components
-int right_motor_speed_pin = 3;
-int right_motor_forward_pin = 4;
-int right_motor_backward_pin = 5;
-
-int left_motor_speed_pin = 8;
-int left_motor_forward_pin = 9;
-int left_motor_backward_pin = 10;
-
-void on(int pin){
-  digitalWrite(pin, HIGH);}
-
-void off(int pin){
-  digitalWrite(pin, LOW);}
-
-void setup(){
-  // the arduino will change the voltage on these pins
-  //  therefore, these pins are OUTPUT pins
-  pinMode(right_motor_speed_pin, OUTPUT);
-  pinMode(right_motor_forward_pin, OUTPUT);
-  pinMode(right_motor_backward_pin, OUTPUT);
-
-  pinMode(left_motor_speed_pin, OUTPUT);
-  pinMode(left_motor_forward_pin, OUTPUT);
-  pinMode(left_motor_backward_pin, OUTPUT);}
-
-void loop(){
-  off(right_motor_backward_pin);
-  on(right_motor_forward_pin);
-  analogWrite(right_motor_speed_pin, 255);
-
-  off(left_motor_backward_pin);
-  on(left_motor_forward_pin);
-  analogWrite(left_motor_speed_pin, 255);}
diff --git a/arduino-sketches/both_sonars/both-sonars-mini.fzz b/arduino-sketches/both_sonars/both-sonars-mini.fzz
deleted file mode 100644 (file)
index 0d385cf..0000000
Binary files a/arduino-sketches/both_sonars/both-sonars-mini.fzz and /dev/null differ
diff --git a/arduino-sketches/both_sonars/both-sonars.fzz b/arduino-sketches/both_sonars/both-sonars.fzz
deleted file mode 100644 (file)
index 4ec2602..0000000
Binary files a/arduino-sketches/both_sonars/both-sonars.fzz and /dev/null differ
diff --git a/arduino-sketches/both_sonars/both_sonars.ino b/arduino-sketches/both_sonars/both_sonars.ino
deleted file mode 100644 (file)
index 2d850ff..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of the
-    License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-int right_echo_pin = 6;
-int right_trigger_pin = 7;
-
-int left_echo_pin = 11;
-int left_trigger_pin = 12;
-
-int right_ping_microseconds = 0;
-int left_ping_microseconds = 0;
-double sound_cm_per_microsecond_at_sea_level = 0.034029;
-int count = 0;
-
-void on(int pin){
-  digitalWrite(pin, HIGH);}
-
-void off(int pin){
-  digitalWrite(pin, LOW);}
-
-int ping(int trigger, int echo){
-  int ping_time = 0;
-  // turn off trigger
-  off(trigger);
-  delayMicroseconds(2);
-  // turn on the trigger and leave it on long enough for the
-  // sonar sensor to notice
-  on(trigger);
-  delayMicroseconds(10);
-  off(trigger);
-  ping_time = pulseIn(echo, HIGH);
-  if(ping_time <= 0){
-    ping_time = 3000;}
-  // sonar needs some time to recover before pinging again,
-  // so make sure it gets enough sleep right here.  50 milliseconds
-  delay(50);
-  return ping_time;}
-
-void setup(){
-  Serial.begin(9600);
-  pinMode(right_echo_pin, INPUT);
-  pinMode(right_trigger_pin, OUTPUT);
-  pinMode(left_echo_pin, INPUT);
-  pinMode(left_trigger_pin, OUTPUT);}
-
-void loop(){
-  right_ping_microseconds = ping(right_trigger_pin, right_echo_pin);
-  left_ping_microseconds = ping(left_trigger_pin, left_echo_pin);
-  // print out the pulse time
-  Serial.print(right_ping_microseconds);
-  Serial.print(" = right ping microseconds, ");
-  Serial.print(left_ping_microseconds);
-  Serial.print(" = left ping microseconds. #");
-  Serial.println(count++);
-
-  // wait so it's easier to read the serial monitor.
-  // change delay to 0 for fullspeed.
-  //  default is 333, which is about 1/3 of a second
-  delay(333);}
diff --git a/arduino-sketches/follow/follow.ino b/arduino-sketches/follow/follow.ino
deleted file mode 100644 (file)
index facaf06..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of the
-    License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// define which pins are connected to which components
-int right_motor_speed_pin = 3; // orange wire
-int right_motor_forward_pin = 4; // brown
-int right_motor_backward_pin = 5; // purple
-
-int right_echo_pin = 6; // white
-int right_trigger_pin = 7; // blue
-
-int left_motor_speed_pin = 8; // orange
-int left_motor_forward_pin = 9; // brown
-int left_motor_backward_pin = 10; // purple
-
-int left_echo_pin = 11; // white
-int left_trigger_pin = 12; // blue
-
-// you'll need to adjust these based on your sonar sensor's behavior
-int desired_right_ping_time = 800;
-int desired_left_ping_time = 800;
-
-void on(int pin){
-  digitalWrite(pin, HIGH);}
-
-void off(int pin){
-  digitalWrite(pin, LOW);}
-
-void set_motor(int speed_pin,
-               int forward_pin,
-               int backward_pin,
-               int speed){
-  if(speed > 0){
-    off(backward_pin);
-    on(forward_pin);}
-  else if(speed < 0){
-    off(forward_pin);
-    on(backward_pin);
-    speed = -speed;}
-  else{ // speed is 0
-    off(forward_pin);
-    off(backward_pin);}
-  // since speed has been set positive, no need to check if speed < -255.
-  if(speed > 255){
-    speed = 255;}
-  analogWrite(speed_pin, speed);}
-
-void go(int left_motor_speed, int right_motor_speed){
-  set_motor(left_motor_speed_pin,
-            left_motor_forward_pin,
-            left_motor_backward_pin,
-            left_motor_speed);
-  set_motor(right_motor_speed_pin,
-            right_motor_forward_pin,
-            right_motor_backward_pin,
-            right_motor_speed);}
-
-int ping(int trigger, int echo){
-  int ping_time = 0;
-  // turn off trigger
-  off(trigger);
-  delayMicroseconds(2);
-  // turn on the trigger and leave it on long enough for the
-  // sonar sensor to notice
-  on(trigger);
-  delayMicroseconds(10);
-  off(trigger);
-  ping_time = pulseIn(echo, HIGH);
-  if(ping_time <= 0){
-    ping_time = 3000;}
-  // sonar needs some time to recover before pinging again,
-  // so make sure it gets enough sleep right here.  50 milliseconds
-  delay(50);
-  return ping_time;}
-
-void backup(int backup_time){
-  go(-250, -250);
-  delay(backup_time);}
-
-void turn_around(int turn_around_time){
-  go(-250, 250);
-  delay(turn_around_time);}
-
-void setup(){
-  Serial.begin(9600);
-
-  pinMode(right_motor_speed_pin, OUTPUT);
-  pinMode(right_motor_forward_pin, OUTPUT);
-  pinMode(right_motor_backward_pin, OUTPUT);
-
-  pinMode(right_echo_pin, INPUT);
-  pinMode(right_trigger_pin, OUTPUT);
-
-  pinMode(left_motor_speed_pin, OUTPUT);
-  pinMode(left_motor_forward_pin, OUTPUT);
-  pinMode(left_motor_backward_pin, OUTPUT);
-
-  pinMode(left_echo_pin, INPUT);
-  pinMode(left_trigger_pin, OUTPUT);
-
-  off(left_motor_speed_pin);
-  off(left_motor_forward_pin);
-  off(left_motor_backward_pin);
-  off(left_trigger_pin);
-
-  off(right_motor_speed_pin);
-  off(right_motor_forward_pin);
-  off(right_motor_backward_pin);
-  off(right_trigger_pin);}
-
-void loop(){
-  int left_speed;
-  int right_speed;
-
-  int forward_speed = 250;
-  int stop_speed = 0;
-
-  unsigned int actual_left_ping_time = ping(left_trigger_pin, left_echo_pin);
-  unsigned int actual_right_ping_time = ping(right_trigger_pin, right_echo_pin);
-
-  left_speed = actual_left_ping_time - desired_left_ping_time;
-  right_speed = actual_right_ping_time - desired_right_ping_time;
-
-  Serial.print("left: ping = ");
-  Serial.print(actual_left_ping_time);
-  Serial.print(" speed = ");
-  Serial.print(left_speed);
-  Serial.print(" right: ping = ");
-  Serial.print(actual_right_ping_time);
-  Serial.print(" speed = ");
-  Serial.println(right_speed);
-
-  go(left_speed, right_speed);}
diff --git a/arduino-sketches/motor/README b/arduino-sketches/motor/README
deleted file mode 100644 (file)
index 7e36e44..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-(how to use this
- (connect your robot to your computer via usb cable)
- (open arduino ide)
- (in arduino ide, open motor.ino)
- (hit the upload button)
- (your robot's wheels should start moving forward slowly)
- (yaay!)
- (you can reverse the direction a motor spins by plugging it into
-  the motor controller differently.  take the wires that come out of
-  the motor and swap where they plug into the motor controller)
- (yaay!))
diff --git a/arduino-sketches/motor/motor.ino b/arduino-sketches/motor/motor.ino
deleted file mode 100644 (file)
index af9ce4b..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of the
-    License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// define which pins are connected to which components
-int right_motor_speed_pin = 3;
-int right_motor_forward_pin = 4;
-int right_motor_backward_pin = 5;
-
-int left_motor_speed_pin = 8;
-int left_motor_forward_pin = 9;
-int left_motor_backward_pin = 10;
-
-void setup(){
-  // the arduino will change the voltage on these pins
-  //  therefore, these pins are OUTPUT pins
-  pinMode(left_motor_speed_pin, OUTPUT);
-  pinMode(left_motor_forward_pin, OUTPUT);
-  pinMode(left_motor_backward_pin, OUTPUT);
-
-  pinMode(right_motor_speed_pin, OUTPUT);
-  pinMode(right_motor_forward_pin, OUTPUT);
-  pinMode(right_motor_backward_pin, OUTPUT);}
-
-void loop(){
-  digitalWrite(left_motor_backward_pin, LOW);
-  digitalWrite(left_motor_forward_pin, HIGH);
-  analogWrite(left_motor_speed_pin, 128);
-
-  digitalWrite(right_motor_backward_pin, LOW);
-  digitalWrite(right_motor_forward_pin, HIGH);
-  analogWrite(right_motor_speed_pin, 128);}
diff --git a/arduino-sketches/pushbutton/README b/arduino-sketches/pushbutton/README
deleted file mode 100644 (file)
index 3bc1279..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-(how to use this
- (connect your robot to your computer via usb cable)
- (open arduino ide)
- (in arduino ide, open pushbutton.ino)
- (hit the upload button)
- (hit control+shift+m,
-  or go to the menu item tools, and down to serial monitor)
- (in the bottom right, select "9600 baud")
- (connect the breadboard and pushbutton as shown in "pushed.jpg")
- (hit the upload button in the arduino ide)
- (press the button!)
- (the message "button state changed!" should appear,
-  and the arduino's built in LED should light up)
- (yaaay!))
diff --git a/arduino-sketches/pushbutton/pushbutton.ino b/arduino-sketches/pushbutton/pushbutton.ino
deleted file mode 100644 (file)
index 407c649..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of
-    the License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// pin 13 controls the arduino's built-in LED
-int led_pin = 13;
-// connect the button to pin 2
-int button_pin = 2;
-// initially, the button is not pressed.
-//  0 means not pressed, 1 means pressed
-int button_value = 0;
-
-void setup(){
-  Serial.begin(9600);}
-
-void loop(){
-  // see if you can figure out how this logic works
-  if(digitalRead(button_pin) != button_value){
-    Serial.println("button state changed!");}
-  // read the value of the button pin during this loop,
-  //  and save it in a box named "button_value"
-  button_value = digitalRead(button_pin);
-  // write the value to the led pin
-  digitalWrite(led_pin, button_value);}
diff --git a/arduino-sketches/right_motor/right-motor-mini.fzz b/arduino-sketches/right_motor/right-motor-mini.fzz
deleted file mode 100644 (file)
index 4d51d4f..0000000
Binary files a/arduino-sketches/right_motor/right-motor-mini.fzz and /dev/null differ
diff --git a/arduino-sketches/right_motor/right-motor.fzz b/arduino-sketches/right_motor/right-motor.fzz
deleted file mode 100644 (file)
index 41fbc98..0000000
Binary files a/arduino-sketches/right_motor/right-motor.fzz and /dev/null differ
diff --git a/arduino-sketches/right_motor/right_motor.ino b/arduino-sketches/right_motor/right_motor.ino
deleted file mode 100644 (file)
index a27b984..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of the
-    License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// define which pins are connected to which components
-int right_motor_speed_pin = 3;
-int right_motor_forward_pin = 4;
-int right_motor_backward_pin = 5;
-
-void setup(){
-  // the arduino will change the voltage on these pins
-  //  therefore, these pins are OUTPUT pins
-  pinMode(right_motor_speed_pin, OUTPUT);
-  pinMode(right_motor_forward_pin, OUTPUT);
-  pinMode(right_motor_backward_pin, OUTPUT);}
-
-void loop(){
-  digitalWrite(right_motor_backward_pin, LOW);
-  digitalWrite(right_motor_forward_pin, HIGH);
-  analogWrite(right_motor_speed_pin, 255);}
diff --git a/arduino-sketches/right_sonar/right-sonar-mini.fzz b/arduino-sketches/right_sonar/right-sonar-mini.fzz
deleted file mode 100644 (file)
index 7d6c4cc..0000000
Binary files a/arduino-sketches/right_sonar/right-sonar-mini.fzz and /dev/null differ
diff --git a/arduino-sketches/right_sonar/right-sonar.fzz b/arduino-sketches/right_sonar/right-sonar.fzz
deleted file mode 100644 (file)
index c21e3e3..0000000
Binary files a/arduino-sketches/right_sonar/right-sonar.fzz and /dev/null differ
diff --git a/arduino-sketches/right_sonar/right_sonar.ino b/arduino-sketches/right_sonar/right_sonar.ino
deleted file mode 100644 (file)
index 3d4af2e..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of the
-    License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-int right_echo_pin = 6;
-int right_trigger_pin = 7;
-
-int ping_microseconds = 0;
-double sound_cm_per_microsecond_at_sea_level = 0.034029;
-int count = 0;
-
-void setup(){
-  Serial.begin(9600);
-  pinMode(right_echo_pin, INPUT);
-  pinMode(right_trigger_pin, OUTPUT);}
-
-void loop(){
-  // make sure trigger pin is off, a.k.a. LOW
-  digitalWrite(right_trigger_pin, LOW);
-  delayMicroseconds(2);
-
-  // send a 10 microsecond HIGH pulse to the trigger pin
-  digitalWrite(right_trigger_pin, HIGH);
-  delayMicroseconds(10); // leave the pin on for 10 microseconds
-  digitalWrite(right_trigger_pin, LOW);
-
-  ping_microseconds = pulseIn(right_echo_pin, HIGH);
-
-  // wait for the sonar sensor hardware to recover from pinging
-  delayMicroseconds(50);
-
-  // print out the pulse time
-  Serial.print(ping_microseconds);
-  Serial.print(" = ping time (microseconds), ");
-  Serial.print(ping_microseconds * sound_cm_per_microsecond_at_sea_level / 2);
-  Serial.print(" = distance (cm). #");
-  Serial.println(count++);
-
-  // wait so it's easier to read the serial monitor.
-  // change delay to 0 for fullspeed.
-  //  default is 333, which is about 1/3 of a second
-  delay(333);}
diff --git a/arduino-sketches/serial/README b/arduino-sketches/serial/README
deleted file mode 100644 (file)
index 2f0c580..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-(how to use this
- (connect your robot to your computer via usb cable)
- (open arduino ide)
- (in arduino ide, open serial.ino)
- (hit the upload button)
- (hit control+shift+m,
-  or go to the menu item tools, and down to serial monitor)
- (in the bottom right, select "9600 baud")
- (hit the reset button on the arduino)
- (you should see "hello computer!" each time you hit the reset button,
-  (this means your arduino is talking to your computer when it starts))
- (yaaay!))
diff --git a/arduino-sketches/serial/serial.ino b/arduino-sketches/serial/serial.ino
deleted file mode 100644 (file)
index 420fc32..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of
-    the License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-void setup(){
-  Serial.begin(9600);
-  Serial.println("hello computer!");}
-
-void loop(){}
diff --git a/arduino-sketches/stay_on_table/stay_on_table.ino b/arduino-sketches/stay_on_table/stay_on_table.ino
deleted file mode 100644 (file)
index 73f9e9b..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of the
-    License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// define which pins are connected to which components
-int right_motor_speed_pin = 3; // orange wire
-int right_motor_forward_pin = 4; // brown
-int right_motor_backward_pin = 5; // purple
-
-int right_echo_pin = 6; // white
-int right_trigger_pin = 7; // blue
-
-int left_motor_speed_pin = 8; // orange
-int left_motor_forward_pin = 9; // brown
-int left_motor_backward_pin = 10; // purple
-
-int left_echo_pin = 11; // white
-int left_trigger_pin = 12; // blue
-
-void on(int pin){
-  digitalWrite(pin, HIGH);}
-
-void off(int pin){
-  digitalWrite(pin, LOW);}
-
-void set_motor(int speed_pin,
-               int forward_pin,
-               int backward_pin,
-               int speed){
-  if(speed > 0){
-    off(backward_pin);
-    on(forward_pin);}
-  else if(speed < 0){
-    off(forward_pin);
-    on(backward_pin);
-    speed = -speed;}
-  else{ // speed is 0
-    off(forward_pin);
-    off(backward_pin);}
-  if(speed > 255){
-    speed = 255;}
-  analogWrite(speed_pin, speed);}
-
-void go(int left_motor_speed, int right_motor_speed){
-  set_motor(left_motor_speed_pin,
-            left_motor_forward_pin,
-            left_motor_backward_pin,
-            left_motor_speed);
-  set_motor(right_motor_speed_pin,
-            right_motor_forward_pin,
-            right_motor_backward_pin,
-            right_motor_speed);}
-
-int ping(int trigger, int echo){
-  int ping_time = 0;
-  // turn off trigger
-  off(trigger);
-  delayMicroseconds(2);
-  // turn on the trigger and leave it on long enough for the
-  // sonar sensor to notice
-  on(trigger);
-  delayMicroseconds(10);
-  off(trigger);
-  ping_time = pulseIn(echo, HIGH);
-  if(ping_time <= 0){
-    ping_time = 3000;}
-  // sonar needs some time to recover before pinging again,
-  // so make sure it gets enough sleep right here.  50 milliseconds
-  delay(50);
-  return ping_time;}
-
-void backup(int backup_time){
-  go(-250, -250);
-  delay(backup_time);}
-
-void turn_around(int turn_around_time){
-  go(-250, 250);
-  delay(turn_around_time);}
-
-void setup(){
-  Serial.begin(9600);
-
-  pinMode(right_motor_speed_pin, OUTPUT);
-  pinMode(right_motor_forward_pin, OUTPUT);
-  pinMode(right_motor_backward_pin, OUTPUT);
-
-  pinMode(right_echo_pin, INPUT);
-  pinMode(right_trigger_pin, OUTPUT);
-
-  pinMode(left_motor_speed_pin, OUTPUT);
-  pinMode(left_motor_forward_pin, OUTPUT);
-  pinMode(left_motor_backward_pin, OUTPUT);
-
-  pinMode(left_echo_pin, INPUT);
-  pinMode(left_trigger_pin, OUTPUT);
-
-  off(left_motor_speed_pin);
-  off(left_motor_forward_pin);
-  off(left_motor_backward_pin);
-  off(left_trigger_pin);
-
-  off(right_motor_speed_pin);
-  off(right_motor_forward_pin);
-  off(right_motor_backward_pin);
-  off(right_trigger_pin);}
-
-void loop(){
-  int left_speed;
-  int right_speed;
-
-  int forward_speed = 250;
-  int stop_speed = 0;
-
-  // adjust this number as necessary for your robot.
-  // it represents how far the table is from your sonar sensor.
-  // larger values mean larger distance.  default is 400
-  int right_max_ping_time_over_table = 400;
-  int left_max_ping_time_over_table = 400;
-  int backup_time = 2000;
-  // the exact amount of time for turning around might need
-  // twerking for your robot.  the default value is 3200
-  int turn_around_time = 3200;
-
-  int actual_left_ping_time = ping(left_trigger_pin, left_echo_pin);
-  int actual_right_ping_time = ping(right_trigger_pin, right_echo_pin);
-
-  Serial.print("left ping = ");
-  Serial.print(actual_left_ping_time);
-  Serial.print("\tright_ping = ");
-  Serial.println(actual_right_ping_time);
-
-  // if the left sonar senses a table, keep driving left side forward,
-  // otherwise, stop left side
-  if(actual_left_ping_time < left_max_ping_time_over_table){
-    left_speed = forward_speed;}
-  else{
-    left_speed = stop_speed;}
-  // if the right sonar senses a table, keep driving right side forward,
-  // otherwise, stop right side
-  if(actual_right_ping_time < right_max_ping_time_over_table){
-    right_speed = forward_speed;}
-  else{
-    right_speed = stop_speed;}
-
-  // if both sonars detect being off the table, backup and turn around
-  // otherwise, go the correct speed for each wheel
-  if(actual_left_ping_time >= left_max_ping_time_over_table
-     && actual_right_ping_time >= right_max_ping_time_over_table){
-    Serial.println("backing up");
-    backup(backup_time);
-    Serial.println("turning around");
-    turn_around(turn_around_time);}
-  else{
-    Serial.println("going");
-    go(left_speed, right_speed);}}
diff --git a/arduino-sketches/untethered/untethered.fzz b/arduino-sketches/untethered/untethered.fzz
deleted file mode 100644 (file)
index f4ccf10..0000000
Binary files a/arduino-sketches/untethered/untethered.fzz and /dev/null differ
diff --git a/arduino-sketches/untethered/untethered.ino b/arduino-sketches/untethered/untethered.ino
deleted file mode 100644 (file)
index b42c07c..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of the
-    License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// define which pins are connected to which components
-int right_motor_speed_pin = 3;
-int right_motor_forward_pin = 4;
-int right_motor_backward_pin = 5;
-
-int left_motor_speed_pin = 8;
-int left_motor_forward_pin = 9;
-int left_motor_backward_pin = 10;
-
-void on(int pin){
-  digitalWrite(pin, HIGH);}
-
-void off(int pin){
-  digitalWrite(pin, LOW);}
-
-void setup(){
-  // the arduino will change the voltage on these pins
-  //  therefore, these pins are OUTPUT pins
-  pinMode(right_motor_speed_pin, OUTPUT);
-  pinMode(right_motor_forward_pin, OUTPUT);
-  pinMode(right_motor_backward_pin, OUTPUT);
-
-  pinMode(left_motor_speed_pin, OUTPUT);
-  pinMode(left_motor_forward_pin, OUTPUT);
-  pinMode(left_motor_backward_pin, OUTPUT);}
-
-void loop(){
-  off(right_motor_backward_pin);
-  on(right_motor_forward_pin);
-  analogWrite(right_motor_speed_pin, 255);
-
-  off(left_motor_backward_pin);
-  on(left_motor_forward_pin);
-  analogWrite(left_motor_speed_pin, 255);}
diff --git a/build-stages/a_serial/README b/build-stages/a_serial/README
new file mode 100644 (file)
index 0000000..2f0c580
--- /dev/null
@@ -0,0 +1,12 @@
+(how to use this
+ (connect your robot to your computer via usb cable)
+ (open arduino ide)
+ (in arduino ide, open serial.ino)
+ (hit the upload button)
+ (hit control+shift+m,
+  or go to the menu item tools, and down to serial monitor)
+ (in the bottom right, select "9600 baud")
+ (hit the reset button on the arduino)
+ (you should see "hello computer!" each time you hit the reset button,
+  (this means your arduino is talking to your computer when it starts))
+ (yaaay!))
diff --git a/build-stages/a_serial/a_serial.ino b/build-stages/a_serial/a_serial.ino
new file mode 100644 (file)
index 0000000..420fc32
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of
+    the License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void setup(){
+  Serial.begin(9600);
+  Serial.println("hello computer!");}
+
+void loop(){}
diff --git a/build-stages/b_right_sonar/b_right_sonar.ino b/build-stages/b_right_sonar/b_right_sonar.ino
new file mode 100644 (file)
index 0000000..3d4af2e
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+int right_echo_pin = 6;
+int right_trigger_pin = 7;
+
+int ping_microseconds = 0;
+double sound_cm_per_microsecond_at_sea_level = 0.034029;
+int count = 0;
+
+void setup(){
+  Serial.begin(9600);
+  pinMode(right_echo_pin, INPUT);
+  pinMode(right_trigger_pin, OUTPUT);}
+
+void loop(){
+  // make sure trigger pin is off, a.k.a. LOW
+  digitalWrite(right_trigger_pin, LOW);
+  delayMicroseconds(2);
+
+  // send a 10 microsecond HIGH pulse to the trigger pin
+  digitalWrite(right_trigger_pin, HIGH);
+  delayMicroseconds(10); // leave the pin on for 10 microseconds
+  digitalWrite(right_trigger_pin, LOW);
+
+  ping_microseconds = pulseIn(right_echo_pin, HIGH);
+
+  // wait for the sonar sensor hardware to recover from pinging
+  delayMicroseconds(50);
+
+  // print out the pulse time
+  Serial.print(ping_microseconds);
+  Serial.print(" = ping time (microseconds), ");
+  Serial.print(ping_microseconds * sound_cm_per_microsecond_at_sea_level / 2);
+  Serial.print(" = distance (cm). #");
+  Serial.println(count++);
+
+  // wait so it's easier to read the serial monitor.
+  // change delay to 0 for fullspeed.
+  //  default is 333, which is about 1/3 of a second
+  delay(333);}
diff --git a/build-stages/b_right_sonar/right-sonar.fzz b/build-stages/b_right_sonar/right-sonar.fzz
new file mode 100644 (file)
index 0000000..c21e3e3
Binary files /dev/null and b/build-stages/b_right_sonar/right-sonar.fzz differ
diff --git a/build-stages/c_both_sonars/both-sonars.fzz b/build-stages/c_both_sonars/both-sonars.fzz
new file mode 100644 (file)
index 0000000..4ec2602
Binary files /dev/null and b/build-stages/c_both_sonars/both-sonars.fzz differ
diff --git a/build-stages/c_both_sonars/c_both_sonars.ino b/build-stages/c_both_sonars/c_both_sonars.ino
new file mode 100644 (file)
index 0000000..2d850ff
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+int right_echo_pin = 6;
+int right_trigger_pin = 7;
+
+int left_echo_pin = 11;
+int left_trigger_pin = 12;
+
+int right_ping_microseconds = 0;
+int left_ping_microseconds = 0;
+double sound_cm_per_microsecond_at_sea_level = 0.034029;
+int count = 0;
+
+void on(int pin){
+  digitalWrite(pin, HIGH);}
+
+void off(int pin){
+  digitalWrite(pin, LOW);}
+
+int ping(int trigger, int echo){
+  int ping_time = 0;
+  // turn off trigger
+  off(trigger);
+  delayMicroseconds(2);
+  // turn on the trigger and leave it on long enough for the
+  // sonar sensor to notice
+  on(trigger);
+  delayMicroseconds(10);
+  off(trigger);
+  ping_time = pulseIn(echo, HIGH);
+  if(ping_time <= 0){
+    ping_time = 3000;}
+  // sonar needs some time to recover before pinging again,
+  // so make sure it gets enough sleep right here.  50 milliseconds
+  delay(50);
+  return ping_time;}
+
+void setup(){
+  Serial.begin(9600);
+  pinMode(right_echo_pin, INPUT);
+  pinMode(right_trigger_pin, OUTPUT);
+  pinMode(left_echo_pin, INPUT);
+  pinMode(left_trigger_pin, OUTPUT);}
+
+void loop(){
+  right_ping_microseconds = ping(right_trigger_pin, right_echo_pin);
+  left_ping_microseconds = ping(left_trigger_pin, left_echo_pin);
+  // print out the pulse time
+  Serial.print(right_ping_microseconds);
+  Serial.print(" = right ping microseconds, ");
+  Serial.print(left_ping_microseconds);
+  Serial.print(" = left ping microseconds. #");
+  Serial.println(count++);
+
+  // wait so it's easier to read the serial monitor.
+  // change delay to 0 for fullspeed.
+  //  default is 333, which is about 1/3 of a second
+  delay(333);}
diff --git a/build-stages/d_right_motor/d_right_motor.ino b/build-stages/d_right_motor/d_right_motor.ino
new file mode 100644 (file)
index 0000000..a27b984
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// define which pins are connected to which components
+int right_motor_speed_pin = 3;
+int right_motor_forward_pin = 4;
+int right_motor_backward_pin = 5;
+
+void setup(){
+  // the arduino will change the voltage on these pins
+  //  therefore, these pins are OUTPUT pins
+  pinMode(right_motor_speed_pin, OUTPUT);
+  pinMode(right_motor_forward_pin, OUTPUT);
+  pinMode(right_motor_backward_pin, OUTPUT);}
+
+void loop(){
+  digitalWrite(right_motor_backward_pin, LOW);
+  digitalWrite(right_motor_forward_pin, HIGH);
+  analogWrite(right_motor_speed_pin, 255);}
diff --git a/build-stages/d_right_motor/right-motor.fzz b/build-stages/d_right_motor/right-motor.fzz
new file mode 100644 (file)
index 0000000..41fbc98
Binary files /dev/null and b/build-stages/d_right_motor/right-motor.fzz differ
diff --git a/build-stages/e_both_motors/both-motors.fzz b/build-stages/e_both_motors/both-motors.fzz
new file mode 100644 (file)
index 0000000..3050bb0
Binary files /dev/null and b/build-stages/e_both_motors/both-motors.fzz differ
diff --git a/build-stages/e_both_motors/e_both_motors.ino b/build-stages/e_both_motors/e_both_motors.ino
new file mode 100644 (file)
index 0000000..b42c07c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// define which pins are connected to which components
+int right_motor_speed_pin = 3;
+int right_motor_forward_pin = 4;
+int right_motor_backward_pin = 5;
+
+int left_motor_speed_pin = 8;
+int left_motor_forward_pin = 9;
+int left_motor_backward_pin = 10;
+
+void on(int pin){
+  digitalWrite(pin, HIGH);}
+
+void off(int pin){
+  digitalWrite(pin, LOW);}
+
+void setup(){
+  // the arduino will change the voltage on these pins
+  //  therefore, these pins are OUTPUT pins
+  pinMode(right_motor_speed_pin, OUTPUT);
+  pinMode(right_motor_forward_pin, OUTPUT);
+  pinMode(right_motor_backward_pin, OUTPUT);
+
+  pinMode(left_motor_speed_pin, OUTPUT);
+  pinMode(left_motor_forward_pin, OUTPUT);
+  pinMode(left_motor_backward_pin, OUTPUT);}
+
+void loop(){
+  off(right_motor_backward_pin);
+  on(right_motor_forward_pin);
+  analogWrite(right_motor_speed_pin, 255);
+
+  off(left_motor_backward_pin);
+  on(left_motor_forward_pin);
+  analogWrite(left_motor_speed_pin, 255);}
diff --git a/build-stages/f_untethered/f_untethered.ino b/build-stages/f_untethered/f_untethered.ino
new file mode 100644 (file)
index 0000000..b42c07c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// define which pins are connected to which components
+int right_motor_speed_pin = 3;
+int right_motor_forward_pin = 4;
+int right_motor_backward_pin = 5;
+
+int left_motor_speed_pin = 8;
+int left_motor_forward_pin = 9;
+int left_motor_backward_pin = 10;
+
+void on(int pin){
+  digitalWrite(pin, HIGH);}
+
+void off(int pin){
+  digitalWrite(pin, LOW);}
+
+void setup(){
+  // the arduino will change the voltage on these pins
+  //  therefore, these pins are OUTPUT pins
+  pinMode(right_motor_speed_pin, OUTPUT);
+  pinMode(right_motor_forward_pin, OUTPUT);
+  pinMode(right_motor_backward_pin, OUTPUT);
+
+  pinMode(left_motor_speed_pin, OUTPUT);
+  pinMode(left_motor_forward_pin, OUTPUT);
+  pinMode(left_motor_backward_pin, OUTPUT);}
+
+void loop(){
+  off(right_motor_backward_pin);
+  on(right_motor_forward_pin);
+  analogWrite(right_motor_speed_pin, 255);
+
+  off(left_motor_backward_pin);
+  on(left_motor_forward_pin);
+  analogWrite(left_motor_speed_pin, 255);}
diff --git a/build-stages/f_untethered/untethered.fzz b/build-stages/f_untethered/untethered.fzz
new file mode 100644 (file)
index 0000000..f4ccf10
Binary files /dev/null and b/build-stages/f_untethered/untethered.fzz differ
diff --git a/build-stages/g_follow/g_follow.ino b/build-stages/g_follow/g_follow.ino
new file mode 100644 (file)
index 0000000..facaf06
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// define which pins are connected to which components
+int right_motor_speed_pin = 3; // orange wire
+int right_motor_forward_pin = 4; // brown
+int right_motor_backward_pin = 5; // purple
+
+int right_echo_pin = 6; // white
+int right_trigger_pin = 7; // blue
+
+int left_motor_speed_pin = 8; // orange
+int left_motor_forward_pin = 9; // brown
+int left_motor_backward_pin = 10; // purple
+
+int left_echo_pin = 11; // white
+int left_trigger_pin = 12; // blue
+
+// you'll need to adjust these based on your sonar sensor's behavior
+int desired_right_ping_time = 800;
+int desired_left_ping_time = 800;
+
+void on(int pin){
+  digitalWrite(pin, HIGH);}
+
+void off(int pin){
+  digitalWrite(pin, LOW);}
+
+void set_motor(int speed_pin,
+               int forward_pin,
+               int backward_pin,
+               int speed){
+  if(speed > 0){
+    off(backward_pin);
+    on(forward_pin);}
+  else if(speed < 0){
+    off(forward_pin);
+    on(backward_pin);
+    speed = -speed;}
+  else{ // speed is 0
+    off(forward_pin);
+    off(backward_pin);}
+  // since speed has been set positive, no need to check if speed < -255.
+  if(speed > 255){
+    speed = 255;}
+  analogWrite(speed_pin, speed);}
+
+void go(int left_motor_speed, int right_motor_speed){
+  set_motor(left_motor_speed_pin,
+            left_motor_forward_pin,
+            left_motor_backward_pin,
+            left_motor_speed);
+  set_motor(right_motor_speed_pin,
+            right_motor_forward_pin,
+            right_motor_backward_pin,
+            right_motor_speed);}
+
+int ping(int trigger, int echo){
+  int ping_time = 0;
+  // turn off trigger
+  off(trigger);
+  delayMicroseconds(2);
+  // turn on the trigger and leave it on long enough for the
+  // sonar sensor to notice
+  on(trigger);
+  delayMicroseconds(10);
+  off(trigger);
+  ping_time = pulseIn(echo, HIGH);
+  if(ping_time <= 0){
+    ping_time = 3000;}
+  // sonar needs some time to recover before pinging again,
+  // so make sure it gets enough sleep right here.  50 milliseconds
+  delay(50);
+  return ping_time;}
+
+void backup(int backup_time){
+  go(-250, -250);
+  delay(backup_time);}
+
+void turn_around(int turn_around_time){
+  go(-250, 250);
+  delay(turn_around_time);}
+
+void setup(){
+  Serial.begin(9600);
+
+  pinMode(right_motor_speed_pin, OUTPUT);
+  pinMode(right_motor_forward_pin, OUTPUT);
+  pinMode(right_motor_backward_pin, OUTPUT);
+
+  pinMode(right_echo_pin, INPUT);
+  pinMode(right_trigger_pin, OUTPUT);
+
+  pinMode(left_motor_speed_pin, OUTPUT);
+  pinMode(left_motor_forward_pin, OUTPUT);
+  pinMode(left_motor_backward_pin, OUTPUT);
+
+  pinMode(left_echo_pin, INPUT);
+  pinMode(left_trigger_pin, OUTPUT);
+
+  off(left_motor_speed_pin);
+  off(left_motor_forward_pin);
+  off(left_motor_backward_pin);
+  off(left_trigger_pin);
+
+  off(right_motor_speed_pin);
+  off(right_motor_forward_pin);
+  off(right_motor_backward_pin);
+  off(right_trigger_pin);}
+
+void loop(){
+  int left_speed;
+  int right_speed;
+
+  int forward_speed = 250;
+  int stop_speed = 0;
+
+  unsigned int actual_left_ping_time = ping(left_trigger_pin, left_echo_pin);
+  unsigned int actual_right_ping_time = ping(right_trigger_pin, right_echo_pin);
+
+  left_speed = actual_left_ping_time - desired_left_ping_time;
+  right_speed = actual_right_ping_time - desired_right_ping_time;
+
+  Serial.print("left: ping = ");
+  Serial.print(actual_left_ping_time);
+  Serial.print(" speed = ");
+  Serial.print(left_speed);
+  Serial.print(" right: ping = ");
+  Serial.print(actual_right_ping_time);
+  Serial.print(" speed = ");
+  Serial.println(right_speed);
+
+  go(left_speed, right_speed);}
diff --git a/build-stages/h_stay_on_table/h_stay_on_table.ino b/build-stages/h_stay_on_table/h_stay_on_table.ino
new file mode 100644 (file)
index 0000000..73f9e9b
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// define which pins are connected to which components
+int right_motor_speed_pin = 3; // orange wire
+int right_motor_forward_pin = 4; // brown
+int right_motor_backward_pin = 5; // purple
+
+int right_echo_pin = 6; // white
+int right_trigger_pin = 7; // blue
+
+int left_motor_speed_pin = 8; // orange
+int left_motor_forward_pin = 9; // brown
+int left_motor_backward_pin = 10; // purple
+
+int left_echo_pin = 11; // white
+int left_trigger_pin = 12; // blue
+
+void on(int pin){
+  digitalWrite(pin, HIGH);}
+
+void off(int pin){
+  digitalWrite(pin, LOW);}
+
+void set_motor(int speed_pin,
+               int forward_pin,
+               int backward_pin,
+               int speed){
+  if(speed > 0){
+    off(backward_pin);
+    on(forward_pin);}
+  else if(speed < 0){
+    off(forward_pin);
+    on(backward_pin);
+    speed = -speed;}
+  else{ // speed is 0
+    off(forward_pin);
+    off(backward_pin);}
+  if(speed > 255){
+    speed = 255;}
+  analogWrite(speed_pin, speed);}
+
+void go(int left_motor_speed, int right_motor_speed){
+  set_motor(left_motor_speed_pin,
+            left_motor_forward_pin,
+            left_motor_backward_pin,
+            left_motor_speed);
+  set_motor(right_motor_speed_pin,
+            right_motor_forward_pin,
+            right_motor_backward_pin,
+            right_motor_speed);}
+
+int ping(int trigger, int echo){
+  int ping_time = 0;
+  // turn off trigger
+  off(trigger);
+  delayMicroseconds(2);
+  // turn on the trigger and leave it on long enough for the
+  // sonar sensor to notice
+  on(trigger);
+  delayMicroseconds(10);
+  off(trigger);
+  ping_time = pulseIn(echo, HIGH);
+  if(ping_time <= 0){
+    ping_time = 3000;}
+  // sonar needs some time to recover before pinging again,
+  // so make sure it gets enough sleep right here.  50 milliseconds
+  delay(50);
+  return ping_time;}
+
+void backup(int backup_time){
+  go(-250, -250);
+  delay(backup_time);}
+
+void turn_around(int turn_around_time){
+  go(-250, 250);
+  delay(turn_around_time);}
+
+void setup(){
+  Serial.begin(9600);
+
+  pinMode(right_motor_speed_pin, OUTPUT);
+  pinMode(right_motor_forward_pin, OUTPUT);
+  pinMode(right_motor_backward_pin, OUTPUT);
+
+  pinMode(right_echo_pin, INPUT);
+  pinMode(right_trigger_pin, OUTPUT);
+
+  pinMode(left_motor_speed_pin, OUTPUT);
+  pinMode(left_motor_forward_pin, OUTPUT);
+  pinMode(left_motor_backward_pin, OUTPUT);
+
+  pinMode(left_echo_pin, INPUT);
+  pinMode(left_trigger_pin, OUTPUT);
+
+  off(left_motor_speed_pin);
+  off(left_motor_forward_pin);
+  off(left_motor_backward_pin);
+  off(left_trigger_pin);
+
+  off(right_motor_speed_pin);
+  off(right_motor_forward_pin);
+  off(right_motor_backward_pin);
+  off(right_trigger_pin);}
+
+void loop(){
+  int left_speed;
+  int right_speed;
+
+  int forward_speed = 250;
+  int stop_speed = 0;
+
+  // adjust this number as necessary for your robot.
+  // it represents how far the table is from your sonar sensor.
+  // larger values mean larger distance.  default is 400
+  int right_max_ping_time_over_table = 400;
+  int left_max_ping_time_over_table = 400;
+  int backup_time = 2000;
+  // the exact amount of time for turning around might need
+  // twerking for your robot.  the default value is 3200
+  int turn_around_time = 3200;
+
+  int actual_left_ping_time = ping(left_trigger_pin, left_echo_pin);
+  int actual_right_ping_time = ping(right_trigger_pin, right_echo_pin);
+
+  Serial.print("left ping = ");
+  Serial.print(actual_left_ping_time);
+  Serial.print("\tright_ping = ");
+  Serial.println(actual_right_ping_time);
+
+  // if the left sonar senses a table, keep driving left side forward,
+  // otherwise, stop left side
+  if(actual_left_ping_time < left_max_ping_time_over_table){
+    left_speed = forward_speed;}
+  else{
+    left_speed = stop_speed;}
+  // if the right sonar senses a table, keep driving right side forward,
+  // otherwise, stop right side
+  if(actual_right_ping_time < right_max_ping_time_over_table){
+    right_speed = forward_speed;}
+  else{
+    right_speed = stop_speed;}
+
+  // if both sonars detect being off the table, backup and turn around
+  // otherwise, go the correct speed for each wheel
+  if(actual_left_ping_time >= left_max_ping_time_over_table
+     && actual_right_ping_time >= right_max_ping_time_over_table){
+    Serial.println("backing up");
+    backup(backup_time);
+    Serial.println("turning around");
+    turn_around(turn_around_time);}
+  else{
+    Serial.println("going");
+    go(left_speed, right_speed);}}