#define Laser SENSOR_1 #define Bump SENSOR_3 #define R_Motor OUT_C #define L_Motor OUT_A #define Both_Motors OUT_C+OUT_A #define Right 1 #define Left 0 task main () { SetSensor (Laser, SENSOR_LIGHT); // Laser sensor is used as a Light sensor SetSensorMode (Laser, SENSOR_MODE_BOOL); // Using Boolean mode, returns true when the sensor sees a target. SetSensor (Bump, SENSOR_TOUCH); OnFwd (L_Motor); Off(R_Motor); until (Laser); //turn right actively till we see a target while (Laser); // then turn more to go past target SetEvent (1, SENSOR_3, EVENT_TYPE_RELEASED); // set event to monitor bumper while (true) { monitor( EVENT_MASK(1)) { OnFwd (Both_Motors); // Go forward SetPower(L_Motor,0); // slowly drifting left until (Laser); // till we see target while (Laser); // and go past it SetPower(L_Motor,7); // then turn right actively OnFwd (L_Motor); Off(R_Motor); until (Laser); while (Laser); } catch // we bumped on something (target ?). { SetPower(Both_Motors,7); OnRev (Both_Motors); // back up a little Wait(50); Off (L_Motor); // turn a little Wait(20); OnFwd (L_Motor); // then look for next target Off(R_Motor); until (Laser); while (Laser); } } }