def __init__(self, bee_name): self.__bee = bee.Bee(name=bee_name) self.name = bee_name self.__thread = threading.Thread(target=self.climb) self.__thread.daemon = True self.__thread.start() self.max_turn = 2.0 self.max_grad = 0.5
def __init__(self, bee_name, logfile, pub_addr, sub_addr, conf_file=None, verb=False): # process the input arguments and config file. self.bee_name = bee_name if conf_file is not None and conf_file != 'null' and conf_file != 'None': with open(conf_file, 'r') as f: conf = yaml.safe_load(f) else: conf = {} self.override_fwd_clr = conf.get('override_fwd_clr', False) self._fwd_clr = conf.get('fwd_clr', (0.3, 0.3, 0.3)) self.max_turn = 2.0 # TODO: from cfg file? self.max_grad = 0.5 # TODO: from cfg file? self.verb = verb if self.verb: print "attempting to connect to bee with name %s" % bee_name print "\tpub_addr:{}".format(pub_addr) print "\tsub_addr:{}".format(sub_addr) ''' instantiates a assisipy.bee object but not derived from bee (At present) default settings are 2nd argument, if not set by config file ''' self.__bee = bee.Bee(name=self.bee_name, pub_addr=pub_addr, sub_addr=sub_addr) # easiest way to show something about the bee state is through colour self.CLR_FWD = (0.93, 0.79, 0) self.CLR_COLL_OBJ = (0, 0, 1) self.CLR_COLL_BEE = (0, 1, 0) self.CLR_WAIT = (0.93, 0.0, 0) if self.override_fwd_clr: # special color for this bee from config file c = [float(n) for n in self._fwd_clr.strip('()').split(',')] self.CLR_FWD = c self.__bee.set_color(*self.CLR_FWD) self.last_turn_time = time.time() self.last_report = time.time()
def go_straight(bee): vel = 0.5 bee.set_vel(vel, vel) def turn_random(bee): vel = 0.2 direction = random.choice([-1, 1]) bee.set_vel(direction * vel, -direction * vel) sleep(random.uniform(1, 5)) if __name__ == '__main__': mybee = bee.Bee(name=sys.argv[1]) random.seed() count = 0 # Naive wander control loop while True: while mybee.get_range(bee.OBJECT_FRONT) < 2: turn_random(mybee) go_straight(mybee) count += 1 if count % 10 == 0: print("I'm feeling {0} degrees.".format(mybee.get_temp())) sleep(0.1)
def __init__(self, bee_name): self.__bee = bee.Bee(name=bee_name) self.__thread = threading.Thread(target=self.wander) self.__thread.daemon = True self._rotate_sz = 1.25 self.__thread.start()
#!/usr/bin/env python # -*- coding: utf-8 -*- # A simple demo of bee-casu interaction # Taken from assisi-python/casu_proxy_led example. from assisipy import bee if __name__ == '__main__': # Connect to the bee walker = bee.Bee(name='Bee-001') # Let the bee run in circles walker.set_vel(0.975, 1.2)