def isRunning(self): """ Check if is running :return: check if roboter is running :rType: Integer [0,1] """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' order = [self._robot.getRNumber(), 3, 209] response = self._communication.send_receive(order) i = 0 while response == 'fail': response = self._communication.send_receive(order) if i > 4: logging.warn('NRF-transmission failed') return 'fail' i = i + 1 while int(response[0]) != self._robot.getRNumber(): response = self._communication.receive()() if int(response[0]) == self._robot.getRNumber(): if response[2] != '110': data_response = lMisc.fail(response[2]) else: data_response = lMisc.to_bin(response[3], 1) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def getValues(self): """ Getter floor sensor :return: floor sensor values :rType: tuple 000 """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' _rNumber = self._robot.getRNumber() order = [_rNumber, 4, 3, 2] response = self._communication.send_receive(order) i = 0 while response == 'fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 if int(response[0]) != _rNumber: response = self._communication.receive(order) if int(response[0]) == _rNumber: if response[2] != '101': print response data_response = lMisc.fail(response[2]) else: data_response = lMisc.to_bin(response[3], 3) else: data_response = lMisc.fail(55) logging.debug(str(data_response)) return data_response
def getValues(self): """ Getter proximity sensor :return: proximity sensor values :rType: tuple [0, 0, 0, 0, 0, 0, 0, 0] all values in {0,1} """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' _rNumber = self._robot.getRNumber() order = [_rNumber, 4, 3, 1] response = self._communication.send_receive(order) i = 0 while response == 'fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != _rNumber: response = self._communication.receive(order) if int(response[0]) == _rNumber: if response[2] != '102': data_response = lMisc.fail(response[2]) else: data_response = lMisc.to_bin(response[3], 8) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def getValues(self): """ Getter battery :return: battery status :rType: Integer [0,1] """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' _rNumber = self._robot.getRNumber() order = [_rNumber, 3, 204] response = self._communication.send_receive(order) i = 0 while response == 'fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != _rNumber: response = self._communication.receive() if int(response[0]) == _rNumber: if response[2] != '105': data_response = lMisc.fail(response[2]) else: data_response = lMisc.to_bin(response[3], 1) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def getSensitivity(self): # Get the threshold value for the distance sensors """ Getter proximity sensor sensitivity :return: sensitivity :rType: Integer [0,1023] """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' _rNumber = self._robot.getRNumber() order = [_rNumber, 3, 207] response = self._communication.send_receive(order) i = 0 while response == 'fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != _rNumber: response = self._communication.receive(order) if int(response[0]) == _rNumber: if response[2] != '108': data_response = lMisc.fail(response[2]) else: data_response = (int(response[4]) << 8) + int(response[3]) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def getdestroy(self): # Check on what sensors a 'High' is simulated (ground and distance sensors) """ Getter destroy :return: response :rType: """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' _rNumber = self._robot.getRNumber() order = [_rNumber, 3, 208] response = self._communication.send_receive(order) i = 0 while response == 'fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != _rNumber: response = self._communication.receive(order) if int(response[0]) == _rNumber: data_response = [] if response[2] != '109': data_response = lMisc.fail(response[2]) else: data_response.append(lMisc.to_bin(response[3], 8)) data_response.append(lMisc.to_bin(response[4], 3)) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def getRobotID(self): # has to be set previously """ Getter robotID :return: robotID :rType: Integer """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' _rNumber = self._robot.getRNumber() order = [_rNumber, 3, 4] response = self._communication.send_receive(order) i = 0 while response == 'fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != _rNumber: response = self._communication.receive(order) if int(response[0]) == _rNumber: if response[2] != '103': data_response = lMisc.fail(response[2]) else: data_response = response[3] else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def getID(self, robotNr): # Get the current infrared ID from robot """ Getter infrared id :parameter: robotNr :pType: Integer :return: infrared id :rType: Integer [0,7] """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' order = [robotNr, 3, 9] response = self._communication.send_receive(order) i = 0 while response == 'misc.fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while (int(response[0]) != robotNr): response = self._communication.receive() if int(response[0]) == robotNr: if response[2] != '47': data_response = lMisc.fail(response[2]) else: data_response = response[3] else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def analogreadbattery(self): # Get the current battery status as an analog value """ Getter analog battery :return: response :rType: Integer [volt with value/1000] """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' _rNumber = self._robot.getRNumber() order = [_rNumber, 3, 205] response = self._communication.send_receive(order) i = 0 while response == 'fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != _rNumber: response = self._communication.receive(order) if int(response[0]) == _rNumber: if response[2] != '106': data_response = lMisc.fail(response[2]) else: data_response = (int(response[4]) << 8) + int(response[3]) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def setSensitivity(self, robotNr, sens): # Set the threshold value for the distance sensors """ Setter infrared sensitivity :parameter: robotNr :pType: Integer :parameter: sens :pType: Integer [0,1023] """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' if not 0 <= sens < 1023: raise ValueError('ERROR: Invalid parameter for "sens"! (0 - 1023 expected)') sens_tmp = struct.unpack('BB', struct.pack('H', sens)) sens_int1 = sens_tmp[0] sens_int2 = sens_tmp[1] order = [robotNr, 5, 13, sens_int1, sens_int2] logging.debug(order) response = self._communication.send(order) i = 0 while response == 'misc.fail': response = self._communication.send(order) if i > 4: return lMisc.fail(20) i = i + 1
def setdestroy(self, d1=0, d2=0, d3=0, d4=0, d5=0, d6=0, d7=0, d8=0, g1=0, g2=0, g3=0): """ Setter destroy :parameter: d1 (default=0), d2 (default=0), d3 (default=0), d4 (default=0), d5 (default=0), d6 (default=0), d7 (default=0), d8 (default=0), g1 (default=0), g2 (default=0), g3 (default=0), :pType: Integer """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' # Set certain sensors simulating a 'High' signal (ground and distance sensors) data_to_send1 = d8 data_to_send1 = (int(data_to_send1) << 1) + int(d7) data_to_send1 = (int(data_to_send1) << 1) + int(d6) data_to_send1 = (int(data_to_send1) << 1) + int(d5) data_to_send1 = (int(data_to_send1) << 1) + int(d4) data_to_send1 = (int(data_to_send1) << 1) + int(d3) data_to_send1 = (int(data_to_send1) << 1) + int(d2) data_to_send1 = (int(data_to_send1) << 1) + int(d1) data_to_send2 = g3 data_to_send2 = (int(data_to_send2) << 1) + int(g2) data_to_send2 = (int(data_to_send2) << 1) + int(g1) order = [self._robot.getRNumber(), 5, 202, data_to_send1, data_to_send2] logging.debug(order) i = 0 while self._communication.send(order) == 'fail': if i > 4: return lMisc.fail(20) i = i + 1
def send(self, sender_rbn, receiver_id, data_byte): # Send IR package """ send infrared :parameter: sender_rbn :pType: Integer :paramter: receiver_id :pType: Integer [0,7] :paramter: data_byte :pType: Integer [0,255] """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' if (receiver_id < 0) or (receiver_id > 7): raise ValueError('ERROR: Invalid parameter for "receiver_id"! (0-7 expected)') if (data_byte < 0) or (data_byte > 255): raise ValueError('ERROR: Invalid parameter for "data_byte"! (0-255 expected)') order = [sender_rbn, 5, 7, receiver_id, data_byte] data_response = [] response = self._communication.send_receive(order) i = 0 while response == 'misc.fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != sender_rbn: response = self._communication.receive(order) if int(response[0]) == sender_rbn: if response[2] != '45': data_response = lMisc.fail(response[2]) else: data_response.append(int(response[3])) data_response.append(int(response[4])) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def getSensorWord(self, robotNr, sensor): # Debug """ Getter sensor word :parameter: sensor :pType: Integer :return: sensor word :rType: tuple """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' if (sensor - 1 < 0) or (sensor - 1 > 7): raise ValueError('ERROR: Invalid parameter for "sensor"! (1-8 expected)') order = [robotNr, 4, 14, sensor] data_response = [] response = self._communication.send_receive(order) i = 0 while response == 'misc.fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != robotNr: response = self._communication.receive() if int(response[0]) == robotNr: if response[2] != '60': data_response = lMisc.fail(response[2]) else: data_response.append(int(response[3])) data_response.append(int(response[4])) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def getLastValues(self, robotNr): # Get last IR values of robot """ Getter infrared values :parameter: robotNr :pType: Integer :return: infrared values :rType: tuple """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' order = [robotNr, 3, 11] data_response = [] response = self._communication.send_receive(order) i = 0 while response == 'misc.fail': response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != robotNr: response = self._communication.receive() if int(response[0]) == robotNr: if response[2] != '49': data_response = lMisc.fail(response[2]) else: data_response.append(int(response[3])) data_response.append(int(response[4])) data_response.append(int(response[5])) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def analogread(self, sensor): # Get the analog value of a specific sensor """ Analog read :parameter: sensor :pType: Integer :return: response :rType: """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' _rNumber = self._robot.getRNumber() if (sensor <= 0) or (sensor >= 12): raise ValueError('ERROR: Invalid parameter for "sensor"! (1-11 expected)') order = [_rNumber, 4, 5, sensor] response = self._communication.send_receive(order) i = 0 while (response == 'fail'): response = self._communication.send_receive(order) if i > 4: return lMisc.fail(20) i = i + 1 while int(response[0]) != _rNumber: response = self._communication.receive(order) if int(response[0]) == _rNumber: if response[2] != '100': data_response = lMisc.fail(response[2]) else: data_response = (int(response[4]) << 8) + int(response[3]) else: data_response = lMisc.fail(55) logging.debug(data_response) return data_response
def setRobotID(self, r_type): """ Setter robotID :parameter: r_type :pType: Integer """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' order = [self._robot.getRNumber(), 5, 203, r_type] logging.debug(order) i = 0 while self._communication.send(order) == 'fail': if i > 4: return lMisc.fail(20) i = i + 1
def setID(self, robotNr, infra_id): # Set infrared ID of the robot """ Setter infrared id :parameter: robotNr :pType: Integer :parameter: infra_id :pType: Integer [0,7] """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' if (infra_id < 0) or (infra_id > 7): raise ValueError('ERROR: Invalid parameter for "receiver_id"! (0-7 expected)') order = [robotNr, 4, 10, infra_id] logging.debug(order) response = self._communication.send(order) i = 0 while response == 'misc.fail': response = self._communication.send(order) if i > 4: return lMisc.fail(20) i = i + 1
def setSensitivity(self, sens): # Set the threshold value for the ground sensors """ Setter floor sensor sensitivity :parameter: sensitivity :pType: Integer [0, 1023] """ if not self._robot.getConnectionStatus(): logging.exception('No connection available') raise Exception, 'No connection available' if not 0 <= sens < 1024: logging.error('ERROR: Invalid parameter for "sens"! (0 - 1023 expected)') raise ValueError('ERROR: Invalid parameter for "sens"! (0 - 1023 expected)') sens_tmp = struct.unpack('BB', struct.pack('H', sens)) sens_int1 = sens_tmp[0] sens_int2 = sens_tmp[1] order = [self._robot.getRNumber(), 5, 200, sens_int1, sens_int2] logging.debug(order) i = 0 while self._communication.send(order) == 'fail': if i > 4: return lMisc.fail(20) i = i + 1