Bumpbot Basic Bumpbot 1 // bumpbot1.nqc - a simple bumper // sensors #define BUMP SENSOR_1 (this sets the touch sensor to the 1 input) // motors #define LEFT OUT_A (this sets output A as the left motor) #define RIGHT OUT_C (this sets output C as the right motor) // constants #define REV_TIME 50 (this sets the reverse time for .5 sec) #define SPIN_TIME 70 (this sets the spin time for .7 sec) task main() { // configure the sensor SetSensor(BUMP, SENSOR_TOUCH); (tells the program the sensor is touch and sets its name as BUMP) // start going forward On(LEFT+RIGHT); // do this forever while(true) (this turns the bot on and moves it forward forever until the bot runs into something directly that can trigger the touch sensor) { // wait for bumper to hit something until(BUMP==1); (this says the program will run until the touch sensor is triggered) // back up Rev(LEFT+RIGHT); Wait(REV_TIME); (once the sensor is triggered the bot will reverse for the designated time of the reverse time which is set at 50) // spin around Fwd(LEFT); Wait(SPIN_TIME); (once the reverse time is reached the bot will then turn on the left motor and spin for the designated spin time which is 70 and then continue on forward until it hits something else) // resume Fwd(RIGHT); } } Bumpbot 2 : A Better Bumpbot // bumpbot2.nqc - improved sensor design // sensors #define BUMP SENSOR_1 // motors #define LEFT OUT_A #define RIGHT OUT_C // constants #define REV_TIME 50 #define SPIN_MIN 70 #define SPIN_RANDOM 50 task main() { // configure the sensor SetSensor(BUMP, SENSOR_TOUCH); // start going forward On(LEFT+RIGHT); // do this forever while(true) { // wait for bumper to hit something until(BUMP==0); // back up Rev(LEFT+RIGHT); Wait(REV_TIME); // spin around Fwd(LEFT); Wait(SPIN_MIN + Random(SPIN_RANDOM)); // resume Fwd(RIGHT); } } (this program runs exactly the same as the first with the addition of the spin random command. This command when added changes the value of the spin time to choose a time between its least value, 70, plus the value of the random,50. What this means is that the bot will spin for a random amount of time between 70120 and then continue on forward until the touch sensor is triggered again) Design evaluation: The design of the second is better for multiple reason. The first of which is that it allows the bots sensor to be triggered not only by head on contact but also by angular contact. The second advantage is that the bumper sensors objects at a lower level. these added ranges of contact allow the bot to perform more effectively in a larger variety of terrain. Program Evaluation: The program runs the same the only variation is that for the random command. This just allows the bot to move freely in a larger variety of directions after the bumper has come into contact with an object. Changing the set times for reverse, spin, and random, just allows for a larger range in directions as well.