Exemplo n.º 1
0
 def setcolor(self, port, color):
     if self._bricks:
         try:
             port = int(port)
         except:
             pass
         if (port in NXT_SENSOR_PORTS):
             port_aux = NXT_SENSOR_PORTS[port]
             if color == WHITE:
                 color = Type.COLORFULL
             elif color == CONSTANTS['red']:
                 color = Type.COLORRED
             elif color == CONSTANTS['green']:
                 color = Type.COLORGREEN
             elif color == CONSTANTS['blue']:
                 color = Type.COLORBLUE
             else:
                 color = Type.COLORNONE
             try:
                 Color20(self._bricks[self.active_nxt], port_aux).set_light_color(color)
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_PORT_S % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 2
0
    def prim_translate(self, text):
        url = TRANSLATE_APIURL + "translate/text"

        values = {'public_key': TRANSLATE_PUBLIC,
                  'secret_key': TRANSLATE_SECRET,
                  'source_content': text,
                  'source_language': self.from_lang,
                  'target_language': self.to_lang}

        data = urllib.urlencode(values)
        headers = {'X-Mashape-Key': MASHAPE_KEY}

        error = _('error trying to translate:') + '"%s", (%s to %s)' % (
            text, self.from_lang, self.to_lang)

        try:
            request = urllib2.Request(url, data, headers)
            data = json.loads(urllib2.urlopen(request).read())
        except:
            raise logoerror(error)

        if data['status']['msg'] != 'ok' or 'error' in data:
            raise logoerror(error)
        else:
            return data['results']['TranslatedText']
Exemplo n.º 3
0
 def digitalRead(self, pin):
     self._check_init()
     try:
         pin = int(pin)
     except:
         raise logoerror(ERROR_PIN_TYPE)
     try:
         a = self._arduinos[self.active_arduino]
         mode = a.digital[pin]._get_mode()
     except:
         raise logoerror(ERROR)
     if mode != MODE[_('INPUT')]:
         raise logoerror(ERROR_PIN_CONFIGURED)
     res = -1
     try:
         a = self._arduinos[self.active_arduino]
         a.digital[pin].enable_reporting()
         a.pass_time(0.05) # wait for the iterator to start receiving data
         if a.digital[pin].read() is None:
             # if the library returns None it is actually False  not being updated
             res = False
         else:
             res = a.digital[pin].read()
         a.digital[pin].disable_reporting()
     except:
         pass
     return res
Exemplo n.º 4
0
 def setcolor(self, port, color):
     if self._bricks:
         try:
             port = int(port)
         except:
             pass
         if (port in NXT_SENSOR_PORTS):
             port_aux = NXT_SENSOR_PORTS[port]
             if color == WHITE:
                 color = Type.COLORFULL
             elif color == CONSTANTS['red']:
                 color = Type.COLORRED
             elif color == CONSTANTS['green']:
                 color = Type.COLORGREEN
             elif color == CONSTANTS['blue']:
                 color = Type.COLORBLUE
             else:
                 color = Type.COLORNONE
             try:
                 Color20(self._bricks[self.active_nxt], port_aux).set_light_color(color)
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_PORT_S % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 5
0
 def digitalRead(self, pin):
     self._check_init()
     try:
         pin = int(pin)
     except:
         raise logoerror(ERROR_PIN_TYPE)
     try:
         a = self._arduinos[self.active_arduino]
         mode = a.digital[pin]._get_mode()
     except:
         raise logoerror(ERROR)
     if mode != MODE[_('INPUT')]:
         raise logoerror(ERROR_PIN_CONFIGURED)
     res = -1
     try:
         a = self._arduinos[self.active_arduino]
         a.digital[pin].enable_reporting()
         a.pass_time(0.05) # wait for the iterator to start receiving data
         if a.digital[pin].read() is None:
             # if the library returns None it is actually False  not being updated
             res = False
         else:
             res = a.digital[pin].read()
         a.digital[pin].disable_reporting()
     except:
         pass
     return res
Exemplo n.º 6
0
 def battery(self):
     if self._bricks:
         try:
             return self._bricks[self.active_nxt].get_battery_level()
         except:
             raise logoerror(ERROR_GENERIC)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 7
0
 def playtone(self, freq, time):
     if self._bricks:
         try:
             self._bricks[self.active_nxt].play_tone(freq, time)
         except:
             raise logoerror(ERROR_GENERIC)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 8
0
 def playtone(self, freq, time):
     if self._bricks:
         try:
             self._bricks[self.active_nxt].play_tone(freq, time)
         except:
             raise logoerror(ERROR_GENERIC)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 9
0
 def battery(self):
     if self._bricks:
         try:
             return self._bricks[self.active_nxt].get_battery_level()
         except:
             raise logoerror(ERROR_GENERIC)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 10
0
 def gTemp(self, idMotor):
     idMotor = int(idMotor)
     a = self.butia.readInfo(str(idMotor),43,2)
     res = self.ajustarValor(a)
     if (res == 65279):
         raise logoerror(ERROR_NO_CONECTADO)
     else:
         if (res == 65535):
             raise logoerror(ERROR_ID_NO_VALIDO)    
         return res
Exemplo n.º 11
0
 def setMotorB(self, speed):
     try:
         speed = int(speed)
     except:
         raise logoerror(ERROR_SPEED)
     if speed > 100 or speed < -100:
         raise logoerror(ERROR_SPEED)
     if self.WeDos:
         wedo = self.WeDos[self.active_wedo]
         wedo.motor_b = speed
Exemplo n.º 12
0
 def setMotorB(self, speed):
     try:
         speed = int(speed)
     except:
         raise logoerror(ERROR_SPEED)
     if speed > 100 or speed < -100:
         raise logoerror(ERROR_SPEED)
     if self.WeDos:
         wedo = self.WeDos[self.active_wedo]
         wedo.motor_b = speed
Exemplo n.º 13
0
 def selectButia(self, i):
     try:
         i = int(i)
     except:
         raise logoerror(_('The device must be an integer'))
     i = i - 1
     if (i < self.butia_count) and (i >= 0):
         self.active_butia = i
     else:
         raise logoerror(_('Not found Butia %s') % (i + 1))
Exemplo n.º 14
0
 def gPosition(self, idMotor):
     idMotor = int(idMotor)
     a = self.butia.readInfo(str(idMotor),36,2)
     res = self.ajustarValor(a)
     res = (res * 300 / 1023)
     if (res == 19143):
         raise logoerror(ERROR_NO_CONECTADO)
     else:
         if (res == 19218):
             raise logoerror(ERROR_ID_NO_VALIDO)    
         return res
Exemplo n.º 15
0
 def _prim_arduinoname(self, i):
     n = len(self._arduinos)
     try:
         i = int(i)
     except:
         logoerror(_('The device must be an integer'))
     i = i - 1
     if (i < n) and (i >= 0):
         return self._arduinos_dev[i]
     else:
         raise logoerror(_('Not found Arduino %s') % (i + 1))
Exemplo n.º 16
0
 def _prim_arduinoselect(self, i):
     n = len(self._arduinos)
     try:
         i = int(i)
     except:
         logoerror(_('The device must be an integer'))
     i = i - 1
     if (i < n) and (i >= 0):
         self.active_arduino = i
     else:
         raise logoerror(_('Not found Arduino %s') % (i + 1))
Exemplo n.º 17
0
 def gVolt(self, idMotor):
     idMotor = int(idMotor)
     a = self.butia.readInfo(str(idMotor),42,2)
     volt = self.ajustarValor(a) 
     res = (float(volt)/1000)
     if (res == 65.279):
         raise logoerror(ERROR_NO_CONECTADO)
     else:
         if (res == 65.535):
             raise logoerror(ERROR_ID_NO_VALIDO)    
         return res
Exemplo n.º 18
0
 def select(self, i):
     # The list index begin in 0
     try:
         i = int(i)
         i = i - 1
     except:
         raise logoerror(ERROR_NO_NUMBER % str(i))
     if (i < len(self._bricks)) and (i >= 0):
         self.active_nxt = i
     else:
         raise logoerror(BRICK_INDEX_NOT_FOUND % int(i + 1))
Exemplo n.º 19
0
 def select(self, i):
     # The list index begin in 0
     try:
         i = int(i)
         i = i - 1
     except:
         raise logoerror(ERROR_NO_NUMBER % str(i))
     if (i < len(self._bricks)) and (i >= 0):
         self.active_nxt = i
     else:
         raise logoerror(BRICK_INDEX_NOT_FOUND % int(i + 1))
Exemplo n.º 20
0
 def select_Rodi(self, i):
     n = len(self._rodis)
     try:
         i = int(i)
     except:
         raise logoerror(_('The device must be an integer'))
     i = i - 1
     if (i < n) and (i >= 0):
         self.active_arduino = i
     else:
         raise logoerror(_('Not found Rodi %s') % (i + 1))
Exemplo n.º 21
0
 def getPin(self, pin):
     try:
         pin = int(pin)
     except:
         pin = ERROR
     if (pin < 1) or (pin > 8):
         raise logoerror(ERROR_PIN_NUMBER)
     else:
         if self.butia.getModeHack(pin, self.active_butia) == 0:
             raise logoerror(_('ERROR: The pin %s must be in INPUT mode.') % pin)
         else:
             return self.butia.getHack(pin, self.active_butia)
Exemplo n.º 22
0
 def name_Rodi(self, i):
     n = len(self._rodis)
     try:
         i = int(i)
     except:
         raise logoerror(_('The device must be an integer'))
     i = i - 1
     if (i < n) and (i >= 0):
         a = self._arduinos[i]
         return a.name
     else:
         raise logoerror(_('Not found Rodi %s') % (i + 1))
Exemplo n.º 23
0
 def select(self, i):
     ''' Select current device '''
     if self.count() == 0:
         raise logoerror(WEDO_NOT_FOUND)
     try:
         t = int(i)
         t = t - 1
     except:
         raise logoerror(ERROR_NO_NUMBER % i)
     if (t < self.count()) and (t >= 0):
         self.active_wedo = t
     else:
         raise logoerror(INDEX_NOT_FOUND % (t + 1))
Exemplo n.º 24
0
 def select(self, i):
     ''' Select current device '''
     if self.count() == 0:
         raise logoerror(WEDO_NOT_FOUND)
     try:
         t = int(i)
         t = t - 1
     except:
         raise logoerror(ERROR_NO_NUMBER % i)
     if (t < self.count()) and (t >= 0):
         self.active_wedo = t
     else:
         raise logoerror(INDEX_NOT_FOUND % (t + 1))
Exemplo n.º 25
0
 def pinMode(self, pin, mode):
     self._check_init()
     try:
         pin = int(pin)
     except:
         raise logoerror(_('The pin must be an integer'))
     if (mode in MODE):
         try:
             a = self._arduinos[self.active_arduino]
             a.digital[pin]._set_mode(MODE[mode])
         except:
             raise logoerror(ERROR)
     else:
         raise logoerror(ERROR_MODE)
Exemplo n.º 26
0
    def _prim_digital_read(self, pin):
        self._check_init()
        try:
            pin = int(pin)
        except:
            logoerror(ERROR_PIN_TYPE)
        res = -1
        try:
            a = self._arduinos[self.active_arduino]
            res = a.digital_read(pin)
        except:
            pass

        return res
Exemplo n.º 27
0
 def pinMode(self, pin, mode):
     self._check_init()
     try:
         pin = int(pin)
     except:
         raise logoerror(_('The pin must be an integer'))
     if (mode in MODE):
         try:
             a = self._arduinos[self.active_arduino]
             a.digital[pin]._set_mode(MODE[mode])
         except:
             raise logoerror(ERROR)
     else:
         raise logoerror(ERROR_MODE)
Exemplo n.º 28
0
 def syncmotorsforever(self, power):
     if self._bricks:
         if not((power < -127) or (power > 127)):
             try:
                 motorB = Motor(self._bricks[self.active_nxt], PORT_B)
                 motorC = Motor(self._bricks[self.active_nxt], PORT_C)
                 syncmotors = SynchronizedMotors(motorB, motorC, 0)
                 syncmotors.run(power)
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_POWER)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 29
0
 def syncmotorsforever(self, power):
     if self._bricks:
         if not((power < -127) or (power > 127)):
             try:
                 motorB = Motor(self._bricks[self.active_nxt], PORT_B)
                 motorC = Motor(self._bricks[self.active_nxt], PORT_C)
                 syncmotors = SynchronizedMotors(motorB, motorC, 0)
                 syncmotors.run(power)
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_POWER)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 30
0
 def pinMode(self, pin, mode):
     try:
         pin = int(pin)
     except:
         pin = ERROR
     if (pin < 1) or (pin > 8):
         raise logoerror(ERROR_PIN_NUMBER)
     else:
         if mode == _('INPUT'):
             self.butia.setModeHack(pin, 1, self.active_butia)
         elif mode == _('OUTPUT'):
             self.butia.setModeHack(pin, 0, self.active_butia)
         else:
             raise logoerror(ERROR_PIN_MODE)
Exemplo n.º 31
0
 def move_Rodi(self, left, right):
     try:
         left = int(left)
     except:
         left = 0
     if (left < -MAX_SPEED) or (left > MAX_SPEED):
         raise logoerror(ERROR_SPEED_ABS)
     try:
         right = int(right)
     except:
         right = 0
     if (right < -MAX_SPEED) or (right > MAX_SPEED):
         raise logoerror(ERROR_SPEED_ABS)
     self.set_vels(left, right)
Exemplo n.º 32
0
 def _prim_pin_mode(self, pin, mode):
     self._check_init()
     try:
         pin = int(pin)
     except:
         logoerror(_('The pin must be an integer'))
     if (mode in MODE):
         mode = MODE[mode]
         try:
             a = self._arduinos[self.active_arduino]
             a.pin_mode(pin, mode)
         except:
             raise logoerror(ERROR)
     else:
         raise logoerror(ERROR_MODE)
Exemplo n.º 33
0
 def brake(self, port):
     if self._bricks:
         port = str(port)
         port_up = port.upper()
         if (port_up in NXT_MOTOR_PORTS):
             port = NXT_MOTOR_PORTS[port_up]
             try:
                 m = Motor(self._bricks[self.active_nxt], port)
                 m.brake()
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_PORT_M % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 34
0
 def brake(self, port):
     if self._bricks:
         port = str(port)
         port_up = port.upper()
         if (port_up in NXT_MOTOR_PORTS):
             port = NXT_MOTOR_PORTS[port_up]
             try:
                 m = Motor(self._bricks[self.active_nxt], port)
                 m.brake()
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_PORT_M % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 35
0
 def _check_init(self):
     n = len(self._arduinos)
     if (self.active_arduino < n) and (self.active_arduino >= 0):
         a = self._arduinos[self.active_arduino]
         a.parse()
     else:
         raise logoerror(_('Not found Arduino %s') % (self.active_arduino + 1))
Exemplo n.º 36
0
 def refresh(self):
     #Close actual Arduinos
     for dev in self._arduinos:
         try:
             dev.exit()
         except:
             pass
     self._arduinos = []
     self._arduinos_it = []
     #Search for new Arduinos
     status,output_usb = commands.getstatusoutput("ls /dev/ | grep ttyUSB")
     output_usb_parsed = output_usb.split('\n')
     status,output_acm = commands.getstatusoutput("ls /dev/ | grep ttyACM")
     output_acm_parsed = output_acm.split('\n')
     output = output_usb_parsed
     output.extend(output_acm_parsed)
     for dev in output:
         if not(dev == ''):
             n = '/dev/%s' % dev
             try:
                 board = pyfirmata.Arduino(n, baudrate=self._baud)
                 it = pyfirmata.util.Iterator(board)
                 it.start()
                 self._arduinos.append(board)
                 self._arduinos_it.append(it)
             except Exception, err:
                 print err
                 raise logoerror(_('Error loading %s board') % n)
Exemplo n.º 37
0
 def get_turtle_heading(self, turtle_name):
     #print 'taturtle.py: def get_turtle_heading'
     if turtle_name not in self.dict:
         debug_output('%s not found in turtle dictionary' % (turtle_name),
                      self.turtle_window.running_sugar)
         raise logoerror("#syntaxerror")
     return self.dict[turtle_name].get_heading()
Exemplo n.º 38
0
 def refresh(self):
     #Close actual Arduinos
     for dev in self._arduinos:
         try:
             dev.exit()
         except:
             pass
     self._arduinos = []
     self._arduinos_it = []
     #Search for new Arduinos
     status, output_usb = commands.getstatusoutput("ls /dev/ | grep ttyUSB")
     output_usb_parsed = output_usb.split('\n')
     status, output_acm = commands.getstatusoutput("ls /dev/ | grep ttyACM")
     output_acm_parsed = output_acm.split('\n')
     output = output_usb_parsed
     output.extend(output_acm_parsed)
     for dev in output:
         if not (dev == ''):
             n = '/dev/%s' % dev
             try:
                 board = pyfirmata.Arduino(n, baudrate=self._baud)
                 it = pyfirmata.util.Iterator(board)
                 it.start()
                 self._arduinos.append(board)
                 self._arduinos_it.append(it)
             except Exception, err:
                 print err
                 raise logoerror(_('Error loading %s board') % n)
Exemplo n.º 39
0
    def refresh_Rodi(self):
        #Close actual Rodis
        self.closeRodis()

        #Search for new Rodis
        #status,output_usb = commands.getstatusoutput("ls /dev/ | grep ttyUSB")
        #output_usb_parsed = output_usb.split('\n')
        #status,output_acm = commands.getstatusoutput("ls /dev/ | grep ttyACM")
        #output_acm_parsed = output_acm.split('\n')

        # add rfcomm to the list of rodis
        status, output_rfc = commands.getstatusoutput("ls /dev/ | grep rfcomm")
        output_rfc_parsed = output_rfc.split('\n')

        #output = output_usb_parsed
        #output.extend(output_acm_parsed)
        output = output_rfc_parsed

        for dev in output:
            if not (dev == ''):
                n = '/dev/%s' % dev
                try:
                    r = pyfirmata.Arduino(n, baudrate=self._baud)
                    it = pyfirmata.util.Iterator(r)
                    it.start()
                    self._rodis.append(r)
                    self._rodis_it.append(it)
                except:
                    raise logoerror(_('Error loading %s board') % n)

        self.change_color_blocks()
Exemplo n.º 40
0
 def get_turtle_heading(self, turtle_name):
     #print 'taturtle.py: def get_turtle_heading'
     if turtle_name not in self.dict:
         debug_output('%s not found in turtle dictionary' % (turtle_name),
                      self.turtle_window.running_sugar)
         raise logoerror("#syntaxerror")
     return self.dict[turtle_name].get_heading()
Exemplo n.º 41
0
 def _prim_nutriant(self, x, nutriant=0):
     print x
     print type(x)
     if type(x) == Vector:
         return x.vector[nutriant]
     else:
         raise logoerror("#syntaxerror")
Exemplo n.º 42
0
 def getLightColor(self, port):
     if self._bricks:
         try:
             port = int(port)
         except:
             pass
         if (port in NXT_SENSOR_PORTS):
             try:
                 port_aux = NXT_SENSOR_PORTS[port]
                 sensor = Light(self._bricks[self.active_nxt], port_aux)
                 return sensor.get_lightness()
             except:
                 return ERROR
         else:
             raise logoerror(ERROR_PORT_S % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 43
0
 def speed(self, speed):
     try:
         speed = int(speed)
     except:
         speed = ERROR
     if (speed < 0) or (speed > MAX_SPEED):
         raise logoerror(ERROR_SPEED)
     self.actualSpeed = [speed, speed]
Exemplo n.º 44
0
 def brickname(self, i):
     # The list index begin in 0
     try:
         i = int(i)
         i = i - 1
     except:
         raise logoerror(ERROR_NO_NUMBER % str(i))
     if (i < len(self._bricks)) and (i >= 0):
         try:
             info = self._bricks[i].get_device_info()
             name = info[0]
             name = name.replace('\x00', '')
             return name
         except:
             raise logoerror(ERROR_GENERIC)
     else:
         raise logoerror(BRICK_INDEX_NOT_FOUND % int(i + 1))
Exemplo n.º 45
0
 def motorposition(self, port):
     if self._bricks:
         port = str(port)
         port_up = port.upper()
         if (port_up in NXT_MOTOR_PORTS):
             port = NXT_MOTOR_PORTS[port_up]
             try:
                 m = Motor(self._bricks[self.active_nxt], port)
                 t = m.get_tacho()
                 previous = self._motor_pos[port_up][self.active_nxt]
                 return (t.tacho_count - previous)
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_PORT_M % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 46
0
 def motorposition(self, port):
     if self._bricks:
         port = str(port)
         port_up = port.upper()
         if (port_up in NXT_MOTOR_PORTS):
             port = NXT_MOTOR_PORTS[port_up]
             try:
                 m = Motor(self._bricks[self.active_nxt], port)
                 t = m.get_tacho()
                 previous = self._motor_pos[port_up][self.active_nxt]
                 return (t.tacho_count - previous)
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_PORT_M % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 47
0
 def motorreset(self, port):
     if self._bricks:
         port = str(port)
         port_up = port.upper()
         if (port_up in NXT_MOTOR_PORTS):
             port = NXT_MOTOR_PORTS[port_up]
             try:
                 m = Motor(self._bricks[self.active_nxt], port)
                 t = m.get_tacho()
                 self._motor_pos[port_up][self.active_nxt] = t.tacho_count
                 m.idle()
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_PORT_M % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 48
0
 def getSound(self, port):
     if self._bricks:
         try:
             port = int(port)
         except:
             pass
         if (port in NXT_SENSOR_PORTS):
             try:
                 port_aux = NXT_SENSOR_PORTS[port]
                 sensor = Sound(self._bricks[self.active_nxt], port_aux)
                 return sensor.get_sample()
             except:
                 return ERROR
         else:
             raise logoerror(ERROR_PORT_S % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 49
0
 def getLightColor(self, port):
     if self._bricks:
         try:
             port = int(port)
         except:
             pass
         if (port in NXT_SENSOR_PORTS):
             try:
                 port_aux = NXT_SENSOR_PORTS[port]
                 sensor = Light(self._bricks[self.active_nxt], port_aux)
                 return sensor.get_lightness()
             except:
                 return ERROR
         else:
             raise logoerror(ERROR_PORT_S % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 50
0
 def getSound(self, port):
     if self._bricks:
         try:
             port = int(port)
         except:
             pass
         if (port in NXT_SENSOR_PORTS):
             try:
                 port_aux = NXT_SENSOR_PORTS[port]
                 sensor = Sound(self._bricks[self.active_nxt], port_aux)
                 return sensor.get_sample()
             except:
                 return ERROR
         else:
             raise logoerror(ERROR_PORT_S % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 51
0
 def getDistance(self, port):
     if self._bricks:
         try:
             port = int(port)
         except:
             pass
         if (port in NXT_SENSOR_PORTS):
             try:
                 port_aux = NXT_SENSOR_PORTS[port]
                 sensor = HTCompass(self._bricks[self.active_nxt], port_aux)
                 return sensor.get_heading()
             except:
                 return ERROR
         else:
             raise logoerror(ERROR_PORT_S % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 52
0
 def syncmotors(self, power, turns):
     if self._bricks:
         if not((power < -127) or (power > 127)):
             if turns < 0:
                 turns = abs(turns)
                 power = -1 * power
             try:
                 motorB = Motor(self._bricks[self.active_nxt], PORT_B)
                 motorC = Motor(self._bricks[self.active_nxt], PORT_C)
                 syncmotors = SynchronizedMotors(motorB, motorC, 0)
                 syncmotors.turn(power, int(turns*360))
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_POWER)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 53
0
 def brickname(self, i):
     # The list index begin in 0
     try:
         i = int(i)
         i = i - 1
     except:
         raise logoerror(ERROR_NO_NUMBER % str(i))
     if (i < len(self._bricks)) and (i >= 0):
         try:
             info = self._bricks[i].get_device_info()
             name = info[0]
             name = name.replace('\x00', '')
             return name
         except:
             raise logoerror(ERROR_GENERIC)
     else:
         raise logoerror(BRICK_INDEX_NOT_FOUND % int(i + 1))
Exemplo n.º 54
0
 def motorreset(self, port):
     if self._bricks:
         port = str(port)
         port_up = port.upper()
         if (port_up in NXT_MOTOR_PORTS):
             port = NXT_MOTOR_PORTS[port_up]
             try:
                 m = Motor(self._bricks[self.active_nxt], port)
                 t = m.get_tacho()
                 self._motor_pos[port_up][self.active_nxt] = t.tacho_count
                 m.idle()
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_PORT_M % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 55
0
 def getButton(self, port):
     if self._fischers:
         try:
             port = int(port)
         except:
             pass
         if (port in FT_SENSOR_PORTS):
             res = ERROR
             try:
                 f = self._fischers[self.active_fischer]
                 res = f.getSensor(port-1)
             except:
                 pass
             return res
         else:
             raise logoerror(ERROR_PORT_S % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 56
0
 def startmotor(self, port, power):
     if self._bricks:
         port = str(port)
         port_up = port.upper()
         if (port_up in NXT_MOTOR_PORTS):
             port = NXT_MOTOR_PORTS[port_up]
             if not((power < -127) or (power > 127)):
                 try:
                     m = Motor(self._bricks[self.active_nxt], port)
                     m.weak_turn(power, 0)
                 except:
                     raise logoerror(ERROR_GENERIC)
             else:
                 raise logoerror(ERROR_POWER)
         else:
             raise logoerror(ERROR_PORT_M % port)
     else:
         raise logoerror(ERROR_BRICK)
Exemplo n.º 57
0
 def refresh_Rodi(self):
     try:
         r = rodi.RoDI()
         self._rodis.append(r)
         if r.see() is not None:
             self.change_color_blocks()
         else:
             del self._rodis[-1]
     except:
         raise logoerror(_('Error connecting to RoDI'))