From fa6c6440266670ea11fda3d8bb5a9d48553e00d2 Mon Sep 17 00:00:00 2001 From: daniel watson Date: Thu, 7 Nov 2013 14:22:39 -0800 Subject: [PATCH] put sketches and 3d printables into sub-dirs --- .../caster-standoff.scad | 0 .../motor-mount-drill-jig.scad | 0 .../mounting-bracket.scad | 0 .../schematic-3d-printable.scad | 0 .../schematic.scad | 0 .../sonar-table-top-holder.scad | 0 wheel.scad => 3d-printables/wheel.scad | 0 {motor => arduino-sketches/motor}/README | 0 {motor => arduino-sketches/motor}/motor.ino | 0 {phase0 => arduino-sketches/phase0}/README.md | 0 .../phase0}/phase0.ino | 0 {phase1 => arduino-sketches/phase1}/README.md | 0 .../phase1}/phase1.ino | 0 {phase2 => arduino-sketches/phase2}/README.md | 0 .../phase2}/phase2.ino | 0 .../phase3}/phase3.ino | 0 .../pushbutton}/README | 0 .../pushbutton}/pushbutton.ino | 0 {serial => arduino-sketches/serial}/README | 0 .../serial}/serial.ino | 0 .../stay_on_table/stay_on_table.ino | 166 ++++++++++++++++++ bill-of-materials | 14 -- 22 files changed, 166 insertions(+), 14 deletions(-) rename caster-standoff.scad => 3d-printables/caster-standoff.scad (100%) rename motor-mount-drill-jig.scad => 3d-printables/motor-mount-drill-jig.scad (100%) rename mounting-bracket.scad => 3d-printables/mounting-bracket.scad (100%) rename schematic-3d-printable.scad => 3d-printables/schematic-3d-printable.scad (100%) rename schematic.scad => 3d-printables/schematic.scad (100%) rename sonar-table-top-holder.scad => 3d-printables/sonar-table-top-holder.scad (100%) rename wheel.scad => 3d-printables/wheel.scad (100%) rename {motor => arduino-sketches/motor}/README (100%) rename {motor => arduino-sketches/motor}/motor.ino (100%) rename {phase0 => arduino-sketches/phase0}/README.md (100%) rename {phase0 => arduino-sketches/phase0}/phase0.ino (100%) rename {phase1 => arduino-sketches/phase1}/README.md (100%) rename {phase1 => arduino-sketches/phase1}/phase1.ino (100%) rename {phase2 => arduino-sketches/phase2}/README.md (100%) rename {phase2 => arduino-sketches/phase2}/phase2.ino (100%) rename {phase3 => arduino-sketches/phase3}/phase3.ino (100%) rename {pushbutton => arduino-sketches/pushbutton}/README (100%) rename {pushbutton => arduino-sketches/pushbutton}/pushbutton.ino (100%) rename {serial => arduino-sketches/serial}/README (100%) rename {serial => arduino-sketches/serial}/serial.ino (100%) create mode 100644 arduino-sketches/stay_on_table/stay_on_table.ino delete mode 100644 bill-of-materials diff --git a/caster-standoff.scad b/3d-printables/caster-standoff.scad similarity index 100% rename from caster-standoff.scad rename to 3d-printables/caster-standoff.scad diff --git a/motor-mount-drill-jig.scad b/3d-printables/motor-mount-drill-jig.scad similarity index 100% rename from motor-mount-drill-jig.scad rename to 3d-printables/motor-mount-drill-jig.scad diff --git a/mounting-bracket.scad b/3d-printables/mounting-bracket.scad similarity index 100% rename from mounting-bracket.scad rename to 3d-printables/mounting-bracket.scad diff --git a/schematic-3d-printable.scad b/3d-printables/schematic-3d-printable.scad similarity index 100% rename from schematic-3d-printable.scad rename to 3d-printables/schematic-3d-printable.scad diff --git a/schematic.scad b/3d-printables/schematic.scad similarity index 100% rename from schematic.scad rename to 3d-printables/schematic.scad diff --git a/sonar-table-top-holder.scad b/3d-printables/sonar-table-top-holder.scad similarity index 100% rename from sonar-table-top-holder.scad rename to 3d-printables/sonar-table-top-holder.scad diff --git a/wheel.scad b/3d-printables/wheel.scad similarity index 100% rename from wheel.scad rename to 3d-printables/wheel.scad diff --git a/motor/README b/arduino-sketches/motor/README similarity index 100% rename from motor/README rename to arduino-sketches/motor/README diff --git a/motor/motor.ino b/arduino-sketches/motor/motor.ino similarity index 100% rename from motor/motor.ino rename to arduino-sketches/motor/motor.ino diff --git a/phase0/README.md b/arduino-sketches/phase0/README.md similarity index 100% rename from phase0/README.md rename to arduino-sketches/phase0/README.md diff --git a/phase0/phase0.ino b/arduino-sketches/phase0/phase0.ino similarity index 100% rename from phase0/phase0.ino rename to arduino-sketches/phase0/phase0.ino diff --git a/phase1/README.md b/arduino-sketches/phase1/README.md similarity index 100% rename from phase1/README.md rename to arduino-sketches/phase1/README.md diff --git a/phase1/phase1.ino b/arduino-sketches/phase1/phase1.ino similarity index 100% rename from phase1/phase1.ino rename to arduino-sketches/phase1/phase1.ino diff --git a/phase2/README.md b/arduino-sketches/phase2/README.md similarity index 100% rename from phase2/README.md rename to arduino-sketches/phase2/README.md diff --git a/phase2/phase2.ino b/arduino-sketches/phase2/phase2.ino similarity index 100% rename from phase2/phase2.ino rename to arduino-sketches/phase2/phase2.ino diff --git a/phase3/phase3.ino b/arduino-sketches/phase3/phase3.ino similarity index 100% rename from phase3/phase3.ino rename to arduino-sketches/phase3/phase3.ino diff --git a/pushbutton/README b/arduino-sketches/pushbutton/README similarity index 100% rename from pushbutton/README rename to arduino-sketches/pushbutton/README diff --git a/pushbutton/pushbutton.ino b/arduino-sketches/pushbutton/pushbutton.ino similarity index 100% rename from pushbutton/pushbutton.ino rename to arduino-sketches/pushbutton/pushbutton.ino diff --git a/serial/README b/arduino-sketches/serial/README similarity index 100% rename from serial/README rename to arduino-sketches/serial/README diff --git a/serial/serial.ino b/arduino-sketches/serial/serial.ino similarity index 100% rename from serial/serial.ino rename to arduino-sketches/serial/serial.ino diff --git a/arduino-sketches/stay_on_table/stay_on_table.ino b/arduino-sketches/stay_on_table/stay_on_table.ino new file mode 100644 index 0000000..73f9e9b --- /dev/null +++ b/arduino-sketches/stay_on_table/stay_on_table.ino @@ -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 . + */ + +// 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/bill-of-materials b/bill-of-materials deleted file mode 100644 index cca9f23..0000000 --- a/bill-of-materials +++ /dev/null @@ -1,14 +0,0 @@ -Bill of Materials: - -* 1 Arduino(tm) board + USB Cable (SainSmart: 20-011-110: ~$14/10) -* 1 Mini BreadBoard (Ebay: ~$3/10) -* 1 Breadboard cables (Ebay: ~$4/10) -* 1 4in x 5in peg board to mount arduino + miniboard -* 4 small squares of double sided tape -* 3 #4-40 Phillips 1/2" flat-head screws -* 6 #4-40 hex nuts -* 3 #4 lock washers -* 2 Red LED's -* 2 Yellow LED's -* 2 Green LED's -* 6 330 Ohm Resistors -- 2.30.2