def main(): wp.wiringPiSetupGpio() ZumoButton().wait_for_press() global bbcon bbcon = BBCON() signal.signal(signal.SIGINT, signal_handler) run_forward = RunForward(bbcon, 2, []) bbcon.add_behavior(run_forward) bbcon.activate_behavior(run_forward) #stand_still = StandStill(bbcon, 1, []) #bbcon.add_behavior(stand_still) #bbcon.activate_behavior(stand_still) line_follower = LineFollower(bbcon, 5, [bbcon.sensobs['line_pos']]) bbcon.add_behavior(line_follower) bbcon.activate_behavior(line_follower) find_red = FindRed( bbcon, 3, [bbcon.sensobs['red_search'], bbcon.sensobs['distance']]) bbcon.add_behavior(find_red) avoid_walls = AvoidWalls( bbcon, 10, [bbcon.sensobs['distance'], bbcon.sensobs['proximity']]) bbcon.add_behavior(avoid_walls) bbcon.activate_behavior(avoid_walls) while True: bbcon.run_one_timestep()
def lineCollision(): reflect = ReflectanceSensors() ZumoButton().wait_for_press() motor = Motors() stuck = CheckStuck() ultra = Ultrasonic() proxim = IRProximitySensor() sensobCol = Sensob() sensobCol.set_sensors([ultra, proxim]) motob = Motob(motor=motor) sensobLine = Sensob() sensobLine.set_sensors([reflect]) arb = Arbitrator(motob=motob) bbcon = BBCON(arbitrator=arb, motob=motob) bbcon.set_checkStucker(stuck) line = LineFollow(1, [sensobLine]) col = CollisionAvoidance(1, [sensobCol]) bbcon.add_behavior(line) bbcon.add_behavior(col) bbcon.add_sensob(sensobCol) bbcon.add_sensob(sensobLine) count = 0 while count < 20: bbcon.run_one_timestep() count += 1
def trackTest(): ZumoButton().wait_for_press() motor = Motors() ultra = Ultrasonic() camera = Camera() stuck = CheckStuck() motob = Motob(motor) arbitrator = Arbitrator(motob=motob) sensob = Sensob() sensob.set_sensors([ultra, camera]) bbcon = BBCON(arbitrator=arbitrator, motob=motob) b = TrackObject(priority=1, sensobs=[sensob]) bbcon.set_checkStucker(stuck) bbcon.add_behavior(b) bbcon.activate_behavior(0) bbcon.add_sensob(sensob) timesteps = 0 while timesteps < 25: bbcon.run_one_timestep() timesteps += 1
def lineTest(): reflect = ReflectanceSensors() ZumoButton().wait_for_press() motor = Motors() stuck = CheckStuck() camera = Camera() motob = Motob(motor) arbitrator = Arbitrator(motob=motob) sensob = Sensob() sensob.set_sensors([reflect]) bbcon = BBCON(arbitrator=arbitrator, motob=motob) bbcon.add_sensob(sensob) bbcon.set_checkStucker(stuck) b = LineFollow(1, [sensob]) bbcon.add_behavior(b) timesteps = 0 while timesteps < 30: bbcon.run_one_timestep() timesteps += 1
def main(): sensobs = { 'ultrasonic': SensobUltrasonic(), 'irproximity': SensobIrproximity(), 'greencamera': ColorSensob((60, 150, 0), 0.3), 'redcamera': ColorSensob((150, 50, 50), 0.2), } behaviours = [ FleeBehaviour(sensobs, 8), AttackBehaviour(sensobs, 10), ExploreBehaviour(sensobs, 1), InvestigateSidesBehaviour(sensobs, 2), InvestigateForwardBehaviour(sensobs, 3), ] motobs = [ MainMotob(), ] bbcon = BBCON(behaviours, sensobs, motobs) try: while True: bbcon.run_one_timestep() except KeyboardInterrupt: motobs[0].update([("s", -1, 0, -1)])
def start(): bbcon = BBCON() arb = Arbitrator(bbcon) motor = Motors() reflect_sens = ReflectanceSensors(False) cam = Camera() ir = IR() ultra = Ultrasonic() bbcon.add_motobs(motor) bbcon.set_arb(arb) bbcon.add_behaviour(AvoidObj(bbcon, ultra, ir)) bbcon.add_behaviour(Behaviour_line_follower(bbcon, reflect_sens)) bbcon.add_behaviour(fub(bb=bbcon)) #behaviour avoid blue, has to be added last, do not change this, will screw up bbcon code bbcon.add_behaviour(Behaviour_avoid_blue(bb=bbcon, cam=cam, ultra=ultra)) bbcon.add_sensob(reflect_sens) bbcon.add_sensob(ir) bbcon.add_sensob(ultra) #cam has to be added last, will screw up bbcon code if not bbcon.add_sensob(cam) butt = ZumoButton() butt.wait_for_press() print("Start zumo") while True: bbcon.run_one_timestep()
def run_robot(): ZumoButton().wait_for_press() bbcon = BBCON() init_bbcon(bbcon) i = 0 while True: bbcon.run_one_timestep() print(i) i += 1
def main(): bbcon = BBCON() follow_line = FollowLine(bbcon) obstruction = Obstruction(bbcon) bbcon.add_behaviour(follow_line) bbcon.add_behaviour(obstruction) print("before button") ZumoButton().wait_for_press() print("after button") while True: bbcon.run_one_timestep()
def main(): zumo_button = ZumoButton() # Sets up pins and Zumobutton zumo_button.wait_for_press() bbcon1 = BBCON() # Create BBCON #Motors motor1 = Motors() # Create a Motor motob1 = Motob(motor1) # Create a motob bbcon1.motobs = [motob1] # Give Motor to BBCON # Collision avoidance ultra_sensor = ObstacleDetectionSensob() # Create obstacle sensob avoid_object = AvoidObstacleBehavior(bbcon1, 1.5) # Create obstacle Behavior ultra_sensor.add_behavior(avoid_object) # Give sensob the behavior bbcon1.add_behavior(avoid_object) # Give BBCON the behavior bbcon1.add_sensob(ultra_sensor) # Give BBCON the sensor # Line follow line_sensor = IRSensob() # Create IR sensob line_follow = FollowLineBehavior(bbcon1, 0.5) # Create linefollow behavior line_follow.add_sensob(line_sensor) # Give linefollow sin sensob bbcon1.add_behavior(line_follow) # Give BBCON the linefollow bbcon1.add_sensob(line_sensor) # Give BBCON the IR sensob # Add setup for camera, and add it to BBCON when we want to test everything together camera_sensor = FindRedSensob() # Create obstacle sensob find_and_follow_behavior = FindAndFollowRedBallBehavior(bbcon1, 1) # Create obstacle Behavior camera_sensor.add_behavior(find_and_follow_behavior) # Give sensob the behavior bbcon1.add_behavior(find_and_follow_behavior) # Give BBCON the behavior bbcon1.add_sensob(camera_sensor) motor1.stop() # Stop all motors print("\nAll creation is done, entering main loop\n") q = input("Press 'q' to quit: ") while q is not 'q': #Runs 100 timesteps. Stops if q is pressed. for i in range(0, 100): print("\nIteration " + str(i)) if bbcon1.run_one_timestep(): motor1.stop() exit() motor1.stop() q = input("Press 'q' to quit: ")
def main(): bbcon1 = BBCON() # Create BBCON # Motors motor1 = Motors() # Create a Motor motob1 = Motob(motor1) # Create a motob bbcon1.motobs = [motob1] # Give Motor to BBCON zumo_button = ZumoButton() # Sets up pins and Zumobutton # Add setup for camera, and add it to BBCON when we want to test everything together camera_sensor = FindRedSensob() # Create obstacle sensob find_and_follow_behavior = FindAndFollowRedBallBehavior( bbcon1, 3) # Create obstacle Behavior camera_sensor.add_behavior( find_and_follow_behavior) # Give sensob the behavior bbcon1.add_behavior(find_and_follow_behavior) # Give BBCON the behavior bbcon1.add_sensob(camera_sensor) motor1.stop() # Stop all motors print("\nAll creation is done, entering main loop\n") q = "" while q is not 'q': zumo_button.wait_for_press() for i in range(0, 10): print("Iteration " + str(i)) if bbcon1.run_one_timestep(): motor1.stop() exit() motor1.stop() q = input("Press 'q' to quit: ") exit()
else: ZumoButton().wait_for_press() motors = Motors() motob = Motob(motors, commands) prios = {"carry_on": .1, "avoid_lines": 1, "obstacle": 3, "picture": 1} bbcon = BBCON(config_values, motob) behaviors = { "carry_on": CarryOn(bbcon, True, prios["carry_on"], [sensobs["distnc"]]), "avoid_lines": AvoidLines(bbcon, True, prios["avoid_lines"], line_sensobs), "picture": Picture(bbcon, False, prios["picture"], [sensobs["rgbsns"]]) } bbcon.add_behavior(behaviors["carry_on"]) bbcon.add_behavior(behaviors["avoid_lines"]) bbcon.add_behavior(behaviors["picture"]) for sensob in sensobs.values(): bbcon.add_sensob(sensob) while True: if bbcon.run_one_timestep(): break print("ferdig.")