def play(self, module_name): try: m = importlib.import_module(module_name) reload(m) m.play(self) except: term.ppln('erreur avec le module ' + module_name)
def kill(self): self.mutex.acquire() self.ok = False self.mutex.release() while True: done = False self.mutex.acquire() if not self.alive: done = True self.mutex.release() if done: break term.ppln('- imu reader killed')
def check_distance_sensor(self, pos, verbose=False): if pos is None: log.warning('check_distance_sensor: mauvaise valeur pour pos') return False N = 10 echantillon = [] for i in range(N): echantillon.append(self.distance(pos)) time.sleep(0.05) echantillon = np.array(echantillon) stddev = np.std(echantillon) if verbose: term.ppln('check_distance_sensor. Echantillon de mesure:') term.ppln(str(echantillon)) term.ppln('std dev: ' + str(stddev)) return stddev > 0
def kill(self): self.epd.sleep() term.ppln('- display system killed')
def check(self): all_ok = True term.ppln('- initialisation procédure de test globale') term.ppln(' - check moteurs:') try: temps = self.motor_temperature() voltages = self.motor_voltage() for m in range(4): t = temps[m] v = voltages[m] v_str = "%0.2f" % v term.pp(' [' + servo_names[m] + '] \ttemp: ' + str(t) + '° ') term.pp('\tvolt: ' + v_str + 'V ') if t < 50 and v > 9.98: term.ppln(' \t[ok]', style=['green']) else: term.ppln(' \t[error]', style=['red']) all_ok = False except: term.ppln(' [erreur]', style=['red']) term.ppln(' - check capteurs:') dist_sensors = ['avant', 'droite', 'gauche'] for s in dist_sensors: term.pp(' [dist. ' + s + '] ... ') if self.check_distance_sensor(s): term.ppln('[ok]', style=['green']) else: term.ppln('[erreur]', style=['red']) all_ok = False term.pp(' [camera] ... ') if self.camera.ready: term.ppln('[ok]', style=['green']) else: term.ppln('[erreur]', style=['red']) all_ok = False if all_ok: term.pp('- procédure de test globale ... ') term.ppln('[ok]', style=['green']) else: log.warning('Erreur procédure de test') return all_ok
def __init__(self): self.ready = True try: term.pp("- connexion aux moteurs ... ") ports = pypot.dynamixel.get_available_ports() self.dxl = pypot.dynamixel.DxlIO(ports[0], baudrate=1000000) self.left_up = 1 self.left_down = 6 self.right_up = 7 self.right_down = 15 self.servos = [self.left_up, self.left_down, \ self.right_up, self.right_down] self.dxl.set_wheel_mode(self.servos) time.sleep(0.5) self.temperatures = self.motor_temperature() term.ppln("[ok]", style=['green']) self.avance(vitesse=5, duree=0.05) self.avance(vitesse=-5, duree=0.05) time.sleep(1) except: term.ppln("[error]", style=['red']) term.ppln(" *verifiez que la batterie arrière est en service*", style=['red']) term.ppln( " *l'affichage de l'état de la batterie doit être actif*", style=['red']) self.ready = False term.pp("- connexion à la caméra ... ") self.camera = camera.Camera() if self.camera.ready: term.ppln('[ok]', style=['green']) else: term.ppln("error", style=['red']) term.pp('- Initialisation de l\'affichage ... ') self.display = display.Display() if self.display.ready: term.ppln('[ok]', style=['green']) else: term.ppln("error", style=['red']) term.pp("- calibration de l'imu ") self.imu = imu_reader.ImuReader(self) self.imu.start() time.sleep(0.250) self.imu.calib(1) time.sleep(1) term.pp('.') time.sleep(1) term.pp('.') time.sleep(1) term.pp('. ') self.imu.reset_orientation() term.ppln('[ok]', style=['green']) self.check()
def photo(self, filename='image'): term.ppln('- Enregistrement de l\'image dans ' + filename + '.' + self.camera.file_format()) self.camera.take_photo(filename)
def warning(str): term.pp('[warning] ', style=['red']) term.ppln(str)