def main(): print("Press the button") Led().light_on() ZumoButton().wait_for_press() Led().light_off() print("Button pressed") # Sensors camera_sensor = Camera(img_width=200, img_height=25) reflectance_sensor = ReflectanceSensors() ultrasonic_sensor = Ultrasonic() # Other led = Led() led.light_off() # Sensobs camera_sensob = CameraSensob(camera_sensor) reflectance_sensob = ReflectanceSensob(reflectance_sensor) ultrasonic_sensob = Sensob(ultrasonic_sensor) # Motobs motob = Motob() # Controller bbcon = Bbcon() # Behaviors moveForward_behavior = MoveForward(None, 1, bbcon) avoidCollision_behavior = AvoidCollision(ultrasonic_sensob, 4, bbcon) followColor_behavior = FollowColor(camera_sensob, 6, bbcon) pauseAtLines_behavior = PauseAtLines(reflectance_sensob, 8, bbcon) stopCloseColor_behavior = StopCloseColor(camera_sensob, 10, bbcon) # Add all sensobs to controller bbcon.add_sensob(camera_sensob) bbcon.add_sensob(reflectance_sensob) bbcon.add_sensob(ultrasonic_sensob) # Add all Behaviors to controller bbcon.add_behavior(avoidCollision_behavior) bbcon.add_behavior(moveForward_behavior) bbcon.add_behavior(followColor_behavior) bbcon.add_behavior(pauseAtLines_behavior) bbcon.add_behavior(stopCloseColor_behavior) bbcon.activate_all_behaviors() # Add all motobs to controller bbcon.add_motob(motob) print("starting") try: while bbcon.active: bbcon.run_one_timestep() except: print("Failed") motob.stop() print(sys.exc_info()[0])
def main(): motob = Motob() bbcon = Bbcon(motob) arbitrator = Arbitrator(bbcon) bbcon.set_arbitrator(arbitrator) # sensorer og sensob ult_sensor = Ultrasonic() ref_sensor = ReflectanceSensors(auto_calibrate=False) reflectance_sensob = ReflectanceSensob(ref_sensor) ultrasonic_sensob = UltrasonicSensob(ult_sensor) camera_sensob = CameraSensob(None, color=0) #behaviors dont_crash = DontCrash(bbcon, ultrasonic_sensob) follow_line = FollowLine(bbcon, reflectance_sensob) find_object = FindColoredObject(bbcon, camera_sensob) bbcon.add_behavior(dont_crash) bbcon.add_behavior(follow_line) bbcon.add_behavior(find_object) try: ZumoButton().wait_for_press() while not bbcon.object_found: # Kjører helt til vi finner objektet bbcon.run_one_timestep() except KeyboardInterrupt: motob.motor.stop() finally: GPIO.cleanup()
def main(): bbcon = Bbcon() lineRider = FollowLine(bbcon) obstruction = Obstruction(bbcon) photo = Photo(bbcon) bbcon.add_behavior(lineRider) bbcon.add_behavior(obstruction) bbcon.add_behavior(photo) ZumoButton().wait_for_press() while True: bbcon.run_one_timestep()
def main(): """ Runs the program """ bbcon = Bbcon() #drive_forward = DriveForward(bbcon) follow_line = FollowLine(bbcon) obstruction = Obstruction(bbcon) # Legger til behavior #bbcon.add_behavior(drive_forward) bbcon.add_behavior(follow_line) bbcon.add_behavior(obstruction) ZumoButton().wait_for_press() while True: bbcon.run_one_timestep()
follow_red_behaviour = FollowRedBehaviour(bb, follow_red_sensob) bb.sensors.insert(0, camera_sensor) bb.add_sensory_object(follow_red_sensob) bb.add_behaviour(follow_red_behaviour) bb.activate_behaviour(follow_red_behaviour) # Collision avoidance ultra_sonic_sensor = Ultrasonic() collision_sensob = UltraSensob(ultra_sonic_sensor) collision_behaviour = AvoidCollisionBehaviour(bb, collision_sensob) bb.add_sensor(ultra_sonic_sensor) bb.add_sensory_object(collision_sensob) bb.add_behaviour(collision_behaviour) bb.activate_behaviour(collision_behaviour) try: while bb.run_one_timestep(): print("Pi keeps on running.") except Exception as e: # stop motor etc print("Stopping motor") motors.stop() if isinstance(e, KeyboardInterrupt): raise e # found no good way to print stacktrace, raising instead. -kriss raise e print("Pi halted.")