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 __init__(self, behaviors=None, active_behaviors=None, sensobs=None, motobs=Motob(), arbitrator=Arbitrator()): # Make arguments non-mutable (because PyCharm says so) if sensobs is None: sensobs = [] if active_behaviors is None: active_behaviors = [] if behaviors is None: behaviors = [] # Checks if bbcon pointer is initialized if arbitrator.bbcon is None: arbitrator.bbcon = self # Save arguments self.behaviors = behaviors self.active_behaviors = active_behaviors self.sensobs = sensobs self.motobs = motobs self.arbitrator = arbitrator # Save halt flag self.halt_request = False
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 __init__(self): # Initialize arbitrator self.arbitrator = Arbitrator() # Initialize motobs (single object for both motors on the Zumo) self.motobs.append(Motob(Motors())) # Initialize sensors self.sensors = { 'ultrasonic': Ultrasonic(0.05), 'IR': IRProximitySensor(), 'reflectance': ReflectanceSensors(False, 0, 900), 'camera': Camera(), } self.active_sensors = [self.sensors['ultrasonic'], self.sensors['IR'], self.sensors['reflectance']] # Initialize sensobs self.sensobs = { 'distance': DistanceSensob([self.sensors['ultrasonic']]), 'line_pos': LinePosSensob([self.sensors['reflectance']]), 'proximity': ProximitySensob([self.sensors['IR']]), 'red_search': RedSearchSensob([self.sensors['camera']]), } self.active_sensobs = [self.sensobs['distance'], self.sensobs['line_pos'], self.sensobs['proximity']] time.sleep(1)
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 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 __init__(self): self.behaviours = [] #list of all behavior objects (BHRs) self.active_behaviours = [] #a list of all currently-active BHRs. self.sensobs = [] #a list of all sensory objects self.motobs = [Motob()] #a list of all motor objects self.arb = Arbitrator( ) #this resolves motor requests produced by the behaviors.
def __init__(self): self.behaviors = [] self.active_behaviors = [] self.sensobs = [] self.motob = Motob() self.arbitrator = Arbitrator(self) self.setup()
def __init__(self): self.behaviors = [] self.active_behaviors = [] self.sensobs = [] self.motob = Motob() self.arbitrator = Arbitrator(self) self.picture_taken = False
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 __init__(self): self.behaviors = [] #Liste over alle behaviors, aktive og inaktive self.active_behaviors = [] # Kun aktive behaviors self.sensobs = [] # Liste over sensorer self.motobs = Motob(self) # Liste med motorobjekter self.arbitrator = Arbitrator() # Arbitrator-objektet, velger winning behavior self.num_timesteps = 0 # Hvor mange timesteps som er kjort self.can_take_photo = False
def __init__(self): self.behaviors = [] # Stores all behaviors self.active_behaviors = [] # Stores the active behaviors self.inactive_behaviors = [] # Stores the inactive behaviors self.sensobs = [] # Stores the sensobs self.motobs = [] # Stores the motob self.arbitrator = Arbitrator( self, True) # Createas and stores a deterministic arbitrator self.current_timestep = 0 # Timestep at start is 0
def __init__(self): self.running = True self.behaviours = [] self.active_behaviours = [] self.inactive_behaviours = [] self.sensobs = [] self.motob = Motob() self.arbitrator = Arbitrator(self) self.setup()
def __init__(self): cam = CamUltra() ref = ReflectanceSob() self.sensobs = [cam, ref] self.active_behaviours = [AttackRed(cam), BeScared(cam), StayInMap(ref), Wander()] self.motobs = [Motob(self)] self.arbitrator = Arbitrator(self) #self.active_behaviours = [] self.inactive_behaviours = []
def __init__(self): self.behaviors = [] self.active_behaviors = [] self.sensobs = [] self.motobs = [] self.arbitrator = Arbitrator(self) self.halt = False self.closeObject = False self.redObject = False
def __init__(self): self.behaviors = [ ] # behavior-listen, med både inaktive og aktive behaviors self.active_behaviors = [] # liste med aktive behaviors self.sensobs = [] # liste med sensor-objekter self.motobs = Motob(self) # list med motor-objekter self.arbitrator = Arbitrator( ) # arbitrator-objektet, velger winning-behavior self.num_timesteps = 0 # antall timesteps som er kjørt self.can_take_photo = False
def __init__(self): self.__behaviors = [] # List of all behaviors self.active_behaviors = [] # List of all _active_ behaviors self.__sensobs = [] # List of all sensory objects self.motob = Motob() # List of all motor objects self.__arbitrator = Arbitrator( self) # Arbitrator chooses the next behavior self.timesteps = 0 self.notifications = []
def __init__(self): self.behaviors = [ ] # a list of all the behavior objects used by the bbcon self.active_behaviors = [ ] # a list of all behaviors that are currently active. self.sensobs = [] # a list of all sensory objects used by the bbcon self.motobs = Motob() # a list of all motor objects used by the bbcon self.arbOb = Arbitrator( ) # the arbitrator object that will resolve actuator requests produced by the behaviors. self.num_timesteps = 0 # number of timesteps done
def __init__(self): self.behaviors = [ ] #En liste av alle behavior objektene som brukes av BBCON self.active_behaviors = [] #En liste med de aktive behavior objektene self.sensobs = [ ] #En liste av alle sensorobjektene som brukes av BBCON self.motobs = Motob( ) #En liste ac alle motor objektene som brukes av BBCON self.arbitrator = Arbitrator( self, False) #Arbitratoren som skal løse requests fra behaviors self.take_pic = False
def __init__(self, config_values, motob): """ Init """ self.config_values = config_values self.behaviors = [] self.active_behaviors = [] self.inactive_behaviors = [] self.sensobs = [] self.motob = motob self.arbitrator = Arbitrator(self) self.rages = 0
def __init__(self): self.arbitrator = Arbitrator(self) #Oppretter fire sensob objekter. Kamera, ir, reflectance og ultra. cam = Sensob() cam.add_sensor(Camera()) ir = Sensob() ir.add_sensor(IRProximitySensor()) reflect = Sensob() reflect.add_sensor(ReflectanceSensors()) ultra = Sensob() ultra.add_sensor(Ultrasonic()) self.sensob = [cam,ir,reflect,ultra] self.motobs = [Motob()] self.behaviors = [] self.wall_detected = False self.wall_checked = False
def rett_fram(): ir = ReflectanceSensors(True) s = Sensob(ir) ab = Avoid_borders(s, s) wr = Walk_randomly(s, s) a = Arbitrator() m = Motob() print("Motob set") ZumoButton().wait_for_press() print("Button pressed") while True: ab.update() wr.update() print("Vekt: ", ab.weight) print("Rec: ", ab.motor_recommendations) winner_rec = a.choose_action(ab, wr) print("recom: ", winner_rec) m.update(winner_rec)
def __init__(self): """ init """ self.sensobs = [] self.add_sensob(Sensob(Ultrasonic())) self.add_sensob(Sensob(ReflectanceSensors())) self.add_sensob(Sensob(Camera())) self.motob = Motob() self.behaviors = [] self.add_behavior(Behavior(self, [10000, 10000, [10000, 10000, 10000]], "drive", 1)) self.add_behavior(Behavior(self, [30, 10000, [10000, 10000, 10000]], "stop", 3)) self.add_behavior(Behavior(self, [10000, 0.3, [10000, 10000, 10000]], "turnaround", 2)) self.add_behavior(Behavior(self, [10000, 10000, [210, 10000, 10000]], "turn_left", 5)) #self.add_behavior(Behavior(self, [10000, 10000, [10000, 200, 10000]], "turn_right", 4)) self.active_behaviors = [] self.arbitrator = Arbitrator()
def __init__(self): """ Initiates the Behavior-Based Robotic Controller :param arbitrator: arbitrator, will provide behaviors? """ self.behaviors = [] self.active_behaviors = [] self.inactive_behaviors = [] self.sensobs = [] self.motobs = [] self.motobs.append(BeltsController()) self.belts = self.motobs[0] self.arbitrator = Arbitrator(self) self.current_timestep = 0 self.controlled_robot = "Zumo Robot" self.halt_request = False
def systemTest(): motor = Motors() ultra = Ultrasonic() proxim = IRProximitySensor() camera = Camera() reflectance = ReflectanceSensors() motob = Motob(motor) arbitrator = Arbitrator(motob) stuck = CheckStuck() collisionSensob = Sensob() collisionSensob.set_sensors([ultra, proxim]) lineSensob = Sensob() lineSensob.set_sensors([reflectance]) trackSensob = Sensob() trackSensob.set_sensors([ultra, camera]) b = CollisionAvoidance(1, [collisionSensob]) f = LineFollow(1, [lineSensob]) t = TrackObject(1, [trackSensob]) #print(collisionSensob.sensors) #print(lineSensob.sensors) bbcon = BBCON(arbitrator=arbitrator, motob=motob) bbcon.set_checkStucker(stuck) bbcon.add_behavior(b) bbcon.add_behavior(f) bbcon.add_behavior(t) #bbcon.activate_behavior(0) #bbcon.activate_behavior(1) #bbcon.activate_behavior(2) bbcon.add_sensob(collisionSensob) bbcon.add_sensob(lineSensob) bbcon.add_sensob(trackSensob) runTimesteps(bbcon, 100)
self.activate_behavior() self.deactivate_behavior() # Tuple of a behavior's motor recommendations and a halt_flag (boolean) # We will update all motobs which will then update the settings # for all motors. def update_all_motobs(self, tuple): print(tuple) for i in range(len(self.motob)): # Motob can also check the halt_flag self.motob[i].update(tuple) if __name__ == '__main__': bbcon = Bbcontroller() arbitrator = Arbitrator(bbcon) zumo = ZumoButton() zumo.wait_for_press() r = ReflectanceSensors() u = Ultrasonic() c = Camera() sensobs = [r, u, c] bbcon.arbitrator = arbitrator fl = FollowLine(bbcon, sensobs) ac = AvoidCollisions(bbcon, sensobs) sp = SnapPhoto(sensobs) ro = Rotate(sensobs)
if __name__ == '__main__': ZumoButton().wait_for_press() # sensobs distance_sensob = Ultrasonic_sensob() colors_sensob = Camera_color_sensob() reflectance_sensob = Reflectance_sensob() ir_sensob = IRProximity_sensob() sensobs = [distance_sensob, reflectance_sensob, colors_sensob, ir_sensob] # behaviors avoid_collisions = Avoid_collisions_behavior(distance_sensob, ir_sensob) follow_line = Follow_line_behavior(reflectance_sensob) behaviors = [avoid_collisions, follow_line] # motobs motors = [Motors()] motob = Motob(motors) motobs = [motob] # arbitrator arbitrator = Arbitrator() bbcon = BBCON(behaviors, sensobs, motobs, arbitrator) bbcon.activate_behavior(avoid_collisions) bbcon.activate_behavior(follow_line) arbitrator.bbcon = bbcon while True: bbcon.run_one_timestep()
pose_sensor, encoders, left_bumper, right_bumper, distance, imu_sensor ]) cruise_command = MotionCommand(0.2, 0.0) cruise_behaviour = Cruise(0, cruise_command) #teleop_keys_behaviour = TeleopKeys(0) bump_escape_behaviour = RomiBumpEscape(3) usonic_escape_behaviour = RomiUsonicEscape(2) imu_escape_behaviour = RomiImuEscape(1) #behaviours = [teleop_keys_behaviour, escape_behaviour] behaviours = [ cruise_behaviour, usonic_escape_behaviour, bump_escape_behaviour, imu_escape_behaviour ] arbitrator = Arbitrator(behaviours) server = Server(host='192.168.1.101', port=65432) server.start() while True: try: sensor_readings = sensors.read_sensors() server.update(sensor_readings) for sensor_reading in sensor_readings: print(sensor_reading.name + " " + str(sensor_reading.value)) command = arbitrator.arbitrate(sensor_readings) # print(arbitrator.get_winning_behaviour().name) base.do_motion_command(command) time.sleep(0.1)
def __init__(self, sensob_controller, behaviors): self.sensob_controller = sensob_controller self.behaviors = behaviors self.arbitrator = Arbitrator() self.actionobs = [actionobs.MotOb(), actionobs.CamOb(sensob_controller.sensor['camera'])]
def __init__(self): self.behaviours = [] # liste med alle oppførslene til bbcon self.active_behaviours = [] # liste med alle oppførsler som er aktive self.sensobs = [] # liste med alle sensorobejekt brukt av bbcon self.motobs = Motob() # liste med alle motorobjekt brukt av bbcon self.arbitrator = Arbitrator() # ikke laget ennå