signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
---|---|---|---|
def _stab_log_data(self, timestamp, data, logconf): | print('<STR_LIT>' % (timestamp, logconf.name, data))<EOL> | Callback froma the log API when data arrives | f1041:c0:m5 |
def _connection_failed(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL>self.is_connected = False<EOL> | Callback when connection initial connection fails (i.e no Crazyflie
at the speficied address) | f1041:c0:m6 |
def _connection_lost(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL> | Callback when disconnected after a connection has been made (i.e
Crazyflie moves out of range) | f1041:c0:m7 |
def _disconnected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>self.is_connected = False<EOL> | Callback when the Crazyflie is disconnected (called in all cases) | f1041:c0:m8 |
def __init__(self, link_uri): | <EOL>self._cf = Crazyflie()<EOL>self._cf.connected.add_callback(self._connected)<EOL>self._cf.disconnected.add_callback(self._disconnected)<EOL>self._cf.connection_failed.add_callback(self._connection_failed)<EOL>self._cf.connection_lost.add_callback(self._connection_lost)<EOL>print('<STR_LIT>' % link_uri)<EOL>self._cf.open_link(link_uri)<EOL>self.is_connected = True<EOL> | Initialize and run the example with the specified link_uri | f1043:c0:m0 |
def _connected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>mems = self._cf.mem.get_mems(MemoryElement.TYPE_1W)<EOL>print('<STR_LIT>'.format(len(mems)))<EOL>if len(mems) > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>'.format(mems[<NUM_LIT:0>].id))<EOL>mems[<NUM_LIT:0>].erase(self._data_written)<EOL><DEDENT> | This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | f1043:c0:m1 |
def _stab_log_error(self, logconf, msg): | print('<STR_LIT>' % (logconf.name, msg))<EOL> | Callback from the log API when an error occurs | f1043:c0:m4 |
def _stab_log_data(self, timestamp, data, logconf): | print('<STR_LIT>' % (timestamp, logconf.name, data))<EOL> | Callback froma the log API when data arrives | f1043:c0:m5 |
def _connection_failed(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL>self.is_connected = False<EOL> | Callback when connection initial connection fails (i.e no Crazyflie
at the speficied address) | f1043:c0:m6 |
def _connection_lost(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL> | Callback when disconnected after a connection has been made (i.e
Crazyflie moves out of range) | f1043:c0:m7 |
def _disconnected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>self.is_connected = False<EOL> | Callback when the Crazyflie is disconnected (called in all cases) | f1043:c0:m8 |
def __init__(self, link_uri): | <EOL>self._cf = Crazyflie()<EOL>self._cf.connected.add_callback(self._connected)<EOL>self._cf.disconnected.add_callback(self._disconnected)<EOL>self._cf.connection_failed.add_callback(self._connection_failed)<EOL>self._cf.connection_lost.add_callback(self._connection_lost)<EOL>print('<STR_LIT>' % link_uri)<EOL>self._cf.open_link(link_uri)<EOL>self.is_connected = True<EOL> | Initialize and run the example with the specified link_uri | f1051:c0:m0 |
def _connected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>mems = self._cf.mem.get_mems(MemoryElement.TYPE_I2C)<EOL>print('<STR_LIT>'.format(len(mems)))<EOL>self._mems_to_update = len(mems)<EOL>for m in mems:<EOL><INDENT>print('<STR_LIT>'.format(m.id))<EOL>m.update(self._data_updated)<EOL><DEDENT> | This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | f1051:c0:m1 |
def _stab_log_error(self, logconf, msg): | print('<STR_LIT>' % (logconf.name, msg))<EOL> | Callback from the log API when an error occurs | f1051:c0:m3 |
def _stab_log_data(self, timestamp, data, logconf): | print('<STR_LIT>' % (timestamp, logconf.name, data))<EOL> | Callback froma the log API when data arrives | f1051:c0:m4 |
def _connection_failed(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL>self.is_connected = False<EOL> | Callback when connection initial connection fails (i.e no Crazyflie
at the speficied address) | f1051:c0:m5 |
def _connection_lost(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL> | Callback when disconnected after a connection has been made (i.e
Crazyflie moves out of range) | f1051:c0:m6 |
def _disconnected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>self.is_connected = False<EOL> | Callback when the Crazyflie is disconnected (called in all cases) | f1051:c0:m7 |
def __init__(self, link_uri): | <EOL>self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)<EOL>self._sock.bind(('<STR_LIT:127.0.0.1>', <NUM_LIT>))<EOL>self._cf = Crazyflie()<EOL>self._cf.connected.add_callback(self._connected)<EOL>self._cf.disconnected.add_callback(self._disconnected)<EOL>self._cf.connection_failed.add_callback(self._connection_failed)<EOL>self._cf.connection_lost.add_callback(self._connection_lost)<EOL>print('<STR_LIT>' % link_uri)<EOL>self._cf.open_link(link_uri)<EOL>self.is_connected = True<EOL>threading.Thread(target=self._server).start()<EOL> | Initialize and run the example with the specified link_uri | f1053:c0:m0 |
def _connected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>self._cf.packet_received.add_callback(self._got_packet)<EOL> | This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | f1053:c0:m1 |
def _stab_log_error(self, logconf, msg): | print('<STR_LIT>' % (logconf.name, msg))<EOL> | Callback from the log API when an error occurs | f1053:c0:m5 |
def _stab_log_data(self, timestamp, data, logconf): | print('<STR_LIT>' % (timestamp, logconf.name, data))<EOL> | Callback froma the log API when data arrives | f1053:c0:m6 |
def _connection_failed(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL>self.is_connected = False<EOL> | Callback when connection initial connection fails (i.e no Crazyflie
at the speficied address) | f1053:c0:m7 |
def _connection_lost(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL> | Callback when disconnected after a connection has been made (i.e
Crazyflie moves out of range) | f1053:c0:m8 |
def _disconnected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>self.is_connected = False<EOL> | Callback when the Crazyflie is disconnected (called in all cases) | f1053:c0:m9 |
def __init__(self, link_uri): | self._cf = Crazyflie(rw_cache='<STR_LIT>')<EOL>self._cf.connected.add_callback(self._connected)<EOL>self._cf.disconnected.add_callback(self._disconnected)<EOL>self._cf.connection_failed.add_callback(self._connection_failed)<EOL>self._cf.connection_lost.add_callback(self._connection_lost)<EOL>print('<STR_LIT>' % link_uri)<EOL>self._cf.open_link(link_uri)<EOL>self.is_connected = True<EOL>self._param_check_list = []<EOL>self._param_groups = []<EOL>random.seed()<EOL> | Initialize and run the example with the specified link_uri | f1054:c0:m0 |
def _connected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>p_toc = self._cf.param.toc.toc<EOL>for group in sorted(p_toc.keys()):<EOL><INDENT>print('<STR_LIT:{}>'.format(group))<EOL>for param in sorted(p_toc[group].keys()):<EOL><INDENT>print('<STR_LIT>'.format(param))<EOL>self._param_check_list.append('<STR_LIT>'.format(group, param))<EOL><DEDENT>self._param_groups.append('<STR_LIT:{}>'.format(group))<EOL>self._cf.param.add_update_callback(group=group, name=None,<EOL>cb=self._param_callback)<EOL><DEDENT>self._cf.param.add_update_callback(group='<STR_LIT>', name='<STR_LIT>',<EOL>cb=self._cpu_flash_callback)<EOL>print('<STR_LIT>')<EOL> | This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | f1054:c0:m1 |
def _cpu_flash_callback(self, name, value): | print('<STR_LIT>'.format(value))<EOL> | Specific callback for the cpu.flash parameter | f1054:c0:m2 |
def _param_callback(self, name, value): | print('<STR_LIT>'.format(name, value))<EOL>self._param_check_list.remove(name)<EOL>if len(self._param_check_list) == <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>')<EOL>for g in self._param_groups:<EOL><INDENT>self._cf.param.remove_update_callback(group=g,<EOL>cb=self._param_callback)<EOL><DEDENT>pkd = random.random()<EOL>print('<STR_LIT>')<EOL>print('<STR_LIT>'.format(pkd))<EOL>self._cf.param.add_update_callback(group='<STR_LIT>',<EOL>name='<STR_LIT>',<EOL>cb=self._a_pitch_kd_callback)<EOL>self._cf.param.set_value('<STR_LIT>',<EOL>'<STR_LIT>'.format(pkd))<EOL><DEDENT> | Generic callback registered for all the groups | f1054:c0:m3 |
def _a_pitch_kd_callback(self, name, value): | print('<STR_LIT>'.format(name, value))<EOL>self._cf.close_link()<EOL> | Callback for pid_attitude.pitch_kd | f1054:c0:m4 |
def _connection_failed(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL>self.is_connected = False<EOL> | Callback when connection initial connection fails (i.e no Crazyflie
at the specified address) | f1054:c0:m5 |
def _connection_lost(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL> | Callback when disconnected after a connection has been made (i.e
Crazyflie moves out of range) | f1054:c0:m6 |
def _disconnected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>self.is_connected = False<EOL> | Callback when the Crazyflie is disconnected (called in all cases) | f1054:c0:m7 |
def __init__(self, link_uri): | self._cf = Crazyflie(rw_cache='<STR_LIT>')<EOL>self._cf.connected.add_callback(self._connected)<EOL>self._cf.disconnected.add_callback(self._disconnected)<EOL>self._cf.connection_failed.add_callback(self._connection_failed)<EOL>self._cf.connection_lost.add_callback(self._connection_lost)<EOL>self._cf.open_link(link_uri)<EOL>self.connected = True<EOL>print('<STR_LIT>' % link_uri)<EOL> | Initialize and run the example with the specified link_uri | f1056:c0:m0 |
def _connected(self, link_uri): | <EOL>Thread(target=self._ramp_motors).start()<EOL> | This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | f1056:c0:m1 |
def _connection_failed(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL>self.connected = False<EOL> | Callback when connection initial connection fails (i.e no Crazyflie
at the specified address) | f1056:c0:m2 |
def _connection_lost(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL>self.connected = False<EOL> | Callback when disconnected after a connection has been made (i.e
Crazyflie moves out of range) | f1056:c0:m3 |
def _disconnected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>self.connected = False<EOL> | Callback when the Crazyflie is disconnected (called in all cases) | f1056:c0:m4 |
def __init__(self, link_uri): | <EOL>self._cf = Crazyflie()<EOL>self._cf.connected.add_callback(self._connected)<EOL>self._cf.disconnected.add_callback(self._disconnected)<EOL>self._cf.connection_failed.add_callback(self._connection_failed)<EOL>self._cf.connection_lost.add_callback(self._connection_lost)<EOL>print('<STR_LIT>' % link_uri)<EOL>self._cf.open_link(link_uri)<EOL>self.is_connected = True<EOL>self._mems_to_update = <NUM_LIT:0><EOL> | Initialize and run the example with the specified link_uri | f1058:c0:m0 |
def _connected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>mems = self._cf.mem.get_mems(MemoryElement.TYPE_1W)<EOL>self._mems_to_update = len(mems)<EOL>print('<STR_LIT>'.format(len(mems)))<EOL>for m in mems:<EOL><INDENT>print('<STR_LIT>'.format(m.id))<EOL>m.update(self._data_updated)<EOL><DEDENT> | This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | f1058:c0:m1 |
def _stab_log_error(self, logconf, msg): | print('<STR_LIT>' % (logconf.name, msg))<EOL> | Callback from the log API when an error occurs | f1058:c0:m3 |
def _stab_log_data(self, timestamp, data, logconf): | print('<STR_LIT>' % (timestamp, logconf.name, data))<EOL> | Callback froma the log API when data arrives | f1058:c0:m4 |
def _connection_failed(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL>self.is_connected = False<EOL> | Callback when connection initial connection fails (i.e no Crazyflie
at the speficied address) | f1058:c0:m5 |
def _connection_lost(self, link_uri, msg): | print('<STR_LIT>' % (link_uri, msg))<EOL> | Callback when disconnected after a connection has been made (i.e
Crazyflie moves out of range) | f1058:c0:m6 |
def _disconnected(self, link_uri): | print('<STR_LIT>' % link_uri)<EOL>self.is_connected = False<EOL> | Callback when the Crazyflie is disconnected (called in all cases) | f1058:c0:m7 |
def __init__(self): | CRTPDriver.__init__(self)<EOL>self.cfusb = None<EOL>self.uri = '<STR_LIT>'<EOL>self.link_error_callback = None<EOL>self.link_quality_callback = None<EOL>self.in_queue = None<EOL>self.out_queue = None<EOL>self._thread = None<EOL>self.needs_resending = False<EOL> | Create the link driver | f1063:c0:m0 |
def connect(self, uri, link_quality_callback, link_error_callback): | <EOL>if not re.search('<STR_LIT>', uri):<EOL><INDENT>raise WrongUriType('<STR_LIT>')<EOL><DEDENT>if not re.search('<STR_LIT>',<EOL>uri):<EOL><INDENT>raise WrongUriType('<STR_LIT>')<EOL><DEDENT>uri_data = re.search('<STR_LIT>',<EOL>uri)<EOL>self.uri = uri<EOL>if self.cfusb is None:<EOL><INDENT>self.cfusb = CfUsb(devid=int(uri_data.group(<NUM_LIT:1>)))<EOL>if self.cfusb.dev:<EOL><INDENT>self.cfusb.set_crtp_to_usb(True)<EOL><DEDENT>else:<EOL><INDENT>self.cfusb = None<EOL>raise Exception('<STR_LIT>'.format(self.uri))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>self.in_queue = queue.Queue()<EOL>self.out_queue = queue.Queue(<NUM_LIT:50>)<EOL>self._thread = _UsbReceiveThread(self.cfusb, self.in_queue,<EOL>link_quality_callback,<EOL>link_error_callback)<EOL>self._thread.start()<EOL>self.link_error_callback = link_error_callback<EOL> | Connect the link driver to a specified URI of the format:
radio://<dongle nbr>/<radio channel>/[250K,1M,2M]
The callback for linkQuality can be called at any moment from the
driver to report back the link quality in percentage. The
callback from linkError will be called when a error occues with
an error message. | f1063:c0:m1 |
def receive_packet(self, time=<NUM_LIT:0>): | if time == <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>return self.in_queue.get(False)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>elif time < <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>return self.in_queue.get(True)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>return self.in_queue.get(True, time)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>return None<EOL><DEDENT><DEDENT> | Receive a packet though the link. This call is blocking but will
timeout and return None if a timeout is supplied. | f1063:c0:m2 |
def send_packet(self, pk): | <EOL>if (self.cfusb is None):<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>dataOut = (pk.header,)<EOL>dataOut += pk.datat<EOL>self.cfusb.send_packet(dataOut)<EOL><DEDENT>except queue.Full:<EOL><INDENT>if self.link_error_callback:<EOL><INDENT>self.link_error_callback(<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT> | Send the packet pk though the link | f1063:c0:m3 |
def close(self): | <EOL>self._thread.stop()<EOL>try:<EOL><INDENT>if self.cfusb:<EOL><INDENT>self.cfusb.set_crtp_to_usb(False)<EOL>self.cfusb.close()<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>logger.info('<STR_LIT>'.format(e))<EOL>pass<EOL><DEDENT>self.cfusb = None<EOL> | Close the link. | f1063:c0:m6 |
def scan_interface(self, address): | if self.cfusb is None:<EOL><INDENT>try:<EOL><INDENT>self.cfusb = CfUsb()<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.warn(<EOL>'<STR_LIT>'.format(<EOL>str(e)))<EOL>return []<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>found = self.cfusb.scan()<EOL>self.cfusb.close()<EOL>self.cfusb = None<EOL>return found<EOL> | Scan interface for Crazyflies | f1063:c0:m7 |
def __init__(self, cfusb, inQueue, link_quality_callback,<EOL>link_error_callback): | threading.Thread.__init__(self)<EOL>self.cfusb = cfusb<EOL>self.in_queue = inQueue<EOL>self.sp = False<EOL>self.link_error_callback = link_error_callback<EOL>self.link_quality_callback = link_quality_callback<EOL> | Create the object | f1063:c1:m0 |
def stop(self): | self.sp = True<EOL>try:<EOL><INDENT>self.join()<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT> | Stop the thread | f1063:c1:m1 |
def run(self): | while (True):<EOL><INDENT>if (self.sp):<EOL><INDENT>break<EOL><DEDENT>try:<EOL><INDENT>data = self.cfusb.receive_packet()<EOL>if len(data) > <NUM_LIT:0>:<EOL><INDENT>pk = CRTPPacket(data[<NUM_LIT:0>], list(data[<NUM_LIT:1>:]))<EOL>self.in_queue.put(pk)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>import traceback<EOL>self.link_error_callback(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (e,<EOL>traceback.format_exc()))<EOL><DEDENT><DEDENT> | Run the receiver thread | f1063:c1:m2 |
def init_drivers(enable_debug_driver=False): | for driver in DRIVERS:<EOL><INDENT>try:<EOL><INDENT>if driver != DebugDriver or enable_debug_driver:<EOL><INDENT>CLASSES.append(driver)<EOL><DEDENT><DEDENT>except Exception: <EOL><INDENT>continue<EOL><DEDENT><DEDENT> | Initialize all the drivers. | f1064:m0 |
def scan_interfaces(address=None): | available = []<EOL>found = []<EOL>for driverClass in CLASSES:<EOL><INDENT>try:<EOL><INDENT>logger.debug('<STR_LIT>', driverClass)<EOL>instance = driverClass()<EOL>found = instance.scan_interface(address)<EOL>available += found<EOL><DEDENT>except Exception:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>return available<EOL> | Scan all the interfaces for available Crazyflies | f1064:m1 |
def get_interfaces_status(): | status = {}<EOL>for driverClass in CLASSES:<EOL><INDENT>try:<EOL><INDENT>instance = driverClass()<EOL>status[instance.get_name()] = instance.get_status()<EOL><DEDENT>except Exception:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>return status<EOL> | Get the status of all the interfaces | f1064:m2 |
def get_link_driver(uri, link_quality_callback=None, link_error_callback=None): | for driverClass in CLASSES:<EOL><INDENT>try:<EOL><INDENT>instance = driverClass()<EOL>instance.connect(uri, link_quality_callback, link_error_callback)<EOL>return instance<EOL><DEDENT>except WrongUriType:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>return None<EOL> | Return the link driver for the given URI. Returns None if no driver
was found for the URI or the URI was not well formatted for the matching
driver. | f1064:m3 |
def __init__(self): | CRTPDriver.__init__(self)<EOL>self._radio_manager = None<EOL>self.uri = '<STR_LIT>'<EOL>self.link_error_callback = None<EOL>self.link_quality_callback = None<EOL>self.in_queue = None<EOL>self.out_queue = None<EOL>self._thread = None<EOL>self.needs_resending = True<EOL> | Create the link driver | f1065:c2:m0 |
def connect(self, uri, link_quality_callback, link_error_callback): | <EOL>if not re.search('<STR_LIT>', uri):<EOL><INDENT>raise WrongUriType('<STR_LIT>')<EOL><DEDENT>if not re.search('<STR_LIT>'<EOL>'<STR_LIT>', uri):<EOL><INDENT>raise WrongUriType('<STR_LIT>')<EOL><DEDENT>uri_data = re.search('<STR_LIT>'<EOL>'<STR_LIT>', uri)<EOL>self.uri = uri<EOL>if len(uri_data.group(<NUM_LIT:1>)) < <NUM_LIT:10> and uri_data.group(<NUM_LIT:1>).isdigit():<EOL><INDENT>devid = int(uri_data.group(<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>devid = crazyradio.get_serials().index(<EOL>uri_data.group(<NUM_LIT:1>).upper())<EOL><DEDENT>except ValueError:<EOL><INDENT>raise Exception('<STR_LIT>'.format(<EOL>uri_data.group(<NUM_LIT:1>)))<EOL><DEDENT><DEDENT>channel = <NUM_LIT:2><EOL>if uri_data.group(<NUM_LIT:4>):<EOL><INDENT>channel = int(uri_data.group(<NUM_LIT:4>))<EOL><DEDENT>datarate = Crazyradio.DR_2MPS<EOL>if uri_data.group(<NUM_LIT:7>) == '<STR_LIT>':<EOL><INDENT>datarate = Crazyradio.DR_250KPS<EOL><DEDENT>if uri_data.group(<NUM_LIT:7>) == '<STR_LIT>':<EOL><INDENT>datarate = Crazyradio.DR_1MPS<EOL><DEDENT>if uri_data.group(<NUM_LIT:7>) == '<STR_LIT>':<EOL><INDENT>datarate = Crazyradio.DR_2MPS<EOL><DEDENT>address = DEFAULT_ADDR_A<EOL>if uri_data.group(<NUM_LIT:9>):<EOL><INDENT>addr = str(uri_data.group(<NUM_LIT:9>))<EOL>new_addr = struct.unpack('<STR_LIT>', binascii.unhexlify(addr))<EOL>address = new_addr<EOL><DEDENT>if self._radio_manager is None:<EOL><INDENT>self._radio_manager = _RadioManager(devid,<EOL>channel,<EOL>datarate,<EOL>address)<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>with self._radio_manager as cradio:<EOL><INDENT>if cradio.version >= <NUM_LIT>:<EOL><INDENT>cradio.set_arc(_nr_of_arc_retries)<EOL><DEDENT>else:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL><DEDENT><DEDENT>self.in_queue = queue.Queue()<EOL>self.out_queue = queue.Queue(<NUM_LIT:1>)<EOL>self._thread = _RadioDriverThread(self._radio_manager,<EOL>self.in_queue,<EOL>self.out_queue,<EOL>link_quality_callback,<EOL>link_error_callback,<EOL>self)<EOL>self._thread.start()<EOL>self.link_error_callback = link_error_callback<EOL> | Connect the link driver to a specified URI of the format:
radio://<dongle nbr>/<radio channel>/[250K,1M,2M]
The callback for linkQuality can be called at any moment from the
driver to report back the link quality in percentage. The
callback from linkError will be called when a error occurs with
an error message. | f1065:c2:m1 |
def receive_packet(self, time=<NUM_LIT:0>): | if time == <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>return self.in_queue.get(False)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>elif time < <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>return self.in_queue.get(True)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>return self.in_queue.get(True, time)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>return None<EOL><DEDENT><DEDENT> | Receive a packet though the link. This call is blocking but will
timeout and return None if a timeout is supplied. | f1065:c2:m2 |
def send_packet(self, pk): | try:<EOL><INDENT>self.out_queue.put(pk, True, <NUM_LIT:2>)<EOL><DEDENT>except queue.Full:<EOL><INDENT>if self.link_error_callback:<EOL><INDENT>self.link_error_callback('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT> | Send the packet pk though the link | f1065:c2:m3 |
def close(self): | <EOL>self._thread.stop()<EOL>if self._radio_manager:<EOL><INDENT>self._radio_manager.close()<EOL><DEDENT>self._radio_manager = None<EOL>while not self.out_queue.empty():<EOL><INDENT>self.out_queue.get()<EOL><DEDENT>self.link_error_callback = None<EOL>self.link_quality_callback = None<EOL> | Close the link. | f1065:c2:m6 |
def _scan_radio_channels(self, cradio, start=<NUM_LIT:0>, stop=<NUM_LIT>): | return list(cradio.scan_channels(start, stop, (<NUM_LIT>,)))<EOL> | Scan for Crazyflies between the supplied channels. | f1065:c2:m7 |
def scan_interface(self, address): | if self._radio_manager is None:<EOL><INDENT>try:<EOL><INDENT>self._radio_manager = _RadioManager(<NUM_LIT:0>)<EOL><DEDENT>except Exception:<EOL><INDENT>return []<EOL><DEDENT><DEDENT>with self._radio_manager as cradio:<EOL><INDENT>serial = '<STR_LIT>'<EOL>logger.info('<STR_LIT>', cradio.version,<EOL>serial)<EOL>found = []<EOL>if address is not None:<EOL><INDENT>addr = '<STR_LIT>'.format(address)<EOL>new_addr = struct.unpack('<STR_LIT>', binascii.unhexlify(addr))<EOL>cradio.set_address(new_addr)<EOL><DEDENT>cradio.set_arc(<NUM_LIT:1>)<EOL>cradio.set_data_rate(cradio.DR_250KPS)<EOL>if address is None or address == DEFAULT_ADDR:<EOL><INDENT>found += [['<STR_LIT>'.format(c), '<STR_LIT>']<EOL>for c in self._scan_radio_channels(cradio)]<EOL>cradio.set_data_rate(cradio.DR_1MPS)<EOL>found += [['<STR_LIT>'.format(c), '<STR_LIT>']<EOL>for c in self._scan_radio_channels(cradio)]<EOL>cradio.set_data_rate(cradio.DR_2MPS)<EOL>found += [['<STR_LIT>'.format(c), '<STR_LIT>']<EOL>for c in self._scan_radio_channels(cradio)]<EOL><DEDENT>else:<EOL><INDENT>found += [['<STR_LIT>'.format(c, address), '<STR_LIT>']<EOL>for c in self._scan_radio_channels(cradio)]<EOL>cradio.set_data_rate(cradio.DR_1MPS)<EOL>found += [['<STR_LIT>'.format(c, address), '<STR_LIT>']<EOL>for c in self._scan_radio_channels(cradio)]<EOL>cradio.set_data_rate(cradio.DR_2MPS)<EOL>found += [['<STR_LIT>'.format(c, address), '<STR_LIT>']<EOL>for c in self._scan_radio_channels(cradio)]<EOL><DEDENT><DEDENT>self._radio_manager.close()<EOL>self._radio_manager = None<EOL>return found<EOL> | Scan interface for Crazyflies | f1065:c2:m9 |
def __init__(self, radio_manager, inQueue, outQueue,<EOL>link_quality_callback, link_error_callback, link): | threading.Thread.__init__(self)<EOL>self._radio_manager = radio_manager<EOL>self._in_queue = inQueue<EOL>self._out_queue = outQueue<EOL>self._sp = False<EOL>self._link_error_callback = link_error_callback<EOL>self._link_quality_callback = link_quality_callback<EOL>self._retry_before_disconnect = _nr_of_retries<EOL>self._retries = collections.deque()<EOL>self._retry_sum = <NUM_LIT:0><EOL>self._curr_up = <NUM_LIT:0><EOL>self._curr_down = <NUM_LIT:1><EOL>self._has_safelink = False<EOL>self._link = link<EOL> | Create the object | f1065:c3:m0 |
def stop(self): | self._sp = True<EOL>try:<EOL><INDENT>self.join()<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT> | Stop the thread | f1065:c3:m1 |
def _send_packet_safe(self, cr, packet): | <EOL>packet[<NUM_LIT:0>] &= <NUM_LIT><EOL>packet[<NUM_LIT:0>] |= self._curr_up << <NUM_LIT:3> | self._curr_down << <NUM_LIT:2><EOL>resp = cr.send_packet(packet)<EOL>if resp and resp.ack and len(resp.data) and(resp.data[<NUM_LIT:0>] & <NUM_LIT>) == (self._curr_down << <NUM_LIT:2>):<EOL><INDENT>self._curr_down = <NUM_LIT:1> - self._curr_down<EOL><DEDENT>if resp and resp.ack:<EOL><INDENT>self._curr_up = <NUM_LIT:1> - self._curr_up<EOL><DEDENT>return resp<EOL> | Adds 1bit counter to CRTP header to guarantee that no ack (downlink)
payload are lost and no uplink packet are duplicated.
The caller should resend packet if not acked (ie. same as with a
direct call to crazyradio.send_packet) | f1065:c3:m2 |
def run(self): | dataOut = array.array('<STR_LIT:B>', [<NUM_LIT>])<EOL>waitTime = <NUM_LIT:0><EOL>emptyCtr = <NUM_LIT:0><EOL>with self._radio_manager as cradio:<EOL><INDENT>for _ in range(<NUM_LIT:10>):<EOL><INDENT>resp = cradio.send_packet((<NUM_LIT>, <NUM_LIT>, <NUM_LIT>))<EOL>if resp and resp.data and tuple(resp.data) == (<EOL><NUM_LIT>, <NUM_LIT>, <NUM_LIT>):<EOL><INDENT>self._has_safelink = True<EOL>self._curr_up = <NUM_LIT:0><EOL>self._curr_down = <NUM_LIT:0><EOL>break<EOL><DEDENT><DEDENT><DEDENT>self._link.needs_resending = not self._has_safelink<EOL>while (True):<EOL><INDENT>if (self._sp):<EOL><INDENT>break<EOL><DEDENT>with self._radio_manager as cradio:<EOL><INDENT>try:<EOL><INDENT>if self._has_safelink:<EOL><INDENT>ackStatus = self._send_packet_safe(cradio, dataOut)<EOL><DEDENT>else:<EOL><INDENT>ackStatus = cradio.send_packet(dataOut)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>import traceback<EOL>self._link_error_callback(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (<EOL>e, traceback.format_exc()))<EOL><DEDENT><DEDENT>if ackStatus is None:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>continue<EOL><DEDENT>if (self._link_quality_callback is not None):<EOL><INDENT>retry = <NUM_LIT:10> - ackStatus.retry<EOL>self._retries.append(retry)<EOL>self._retry_sum += retry<EOL>if len(self._retries) > <NUM_LIT:100>:<EOL><INDENT>self._retry_sum -= self._retries.popleft()<EOL><DEDENT>link_quality = float(self._retry_sum) / len(self._retries) * <NUM_LIT:10><EOL>self._link_quality_callback(link_quality)<EOL><DEDENT>if ackStatus.ack is False:<EOL><INDENT>self._retry_before_disconnect =self._retry_before_disconnect - <NUM_LIT:1><EOL>if (self._retry_before_disconnect == <NUM_LIT:0> and<EOL>self._link_error_callback is not None):<EOL><INDENT>self._link_error_callback('<STR_LIT>')<EOL><DEDENT>continue<EOL><DEDENT>self._retry_before_disconnect = _nr_of_retries<EOL>data = ackStatus.data<EOL>if (len(data) > <NUM_LIT:0>):<EOL><INDENT>inPacket = CRTPPacket(data[<NUM_LIT:0>], list(data[<NUM_LIT:1>:]))<EOL>self._in_queue.put(inPacket)<EOL>waitTime = <NUM_LIT:0><EOL>emptyCtr = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>emptyCtr += <NUM_LIT:1><EOL>if (emptyCtr > <NUM_LIT:10>):<EOL><INDENT>emptyCtr = <NUM_LIT:10><EOL>waitTime = <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>waitTime = <NUM_LIT:0><EOL><DEDENT><DEDENT>outPacket = None<EOL>try:<EOL><INDENT>outPacket = self._out_queue.get(True, waitTime)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>outPacket = None<EOL><DEDENT>dataOut = array.array('<STR_LIT:B>')<EOL>if outPacket:<EOL><INDENT>dataOut.append(outPacket.header)<EOL>for X in outPacket.data:<EOL><INDENT>if type(X) == int:<EOL><INDENT>dataOut.append(X)<EOL><DEDENT>else:<EOL><INDENT>dataOut.append(ord(X))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>dataOut.append(<NUM_LIT>)<EOL><DEDENT><DEDENT> | Run the receiver thread | f1065:c3:m3 |
def __init__(self): | self.needs_resending = True<EOL> | Driver constructor. Throw an exception if the driver is unable to
open the URI | f1068:c0:m0 |
def connect(self, uri, link_quality_callback, link_error_callback): | Connect the driver to a specified URI
@param uri Uri of the link to open
@param link_quality_callback Callback to report link quality in percent
@param link_error_callback Callback to report errors (will result in
disconnection) | f1068:c0:m1 |
|
def send_packet(self, pk): | Send a CRTP packet | f1068:c0:m2 |
|
def receive_packet(self, wait=<NUM_LIT:0>): | Receive a CRTP packet.
@param wait The time to wait for a packet in second. -1 means forever
@return One CRTP packet or None if no packet has been received. | f1068:c0:m3 |
|
def get_status(self): | Return a status string from the interface. | f1068:c0:m4 |
|
def get_name(self): | Return a human readable name of the interface. | f1068:c0:m5 |
|
def scan_interface(self, address=None): | Scan interface for available Crazyflie quadcopters and return a list
with them. | f1068:c0:m6 |
|
def enum(self): | Enumerate, and return a list, of the available link URI on this
system | f1068:c0:m7 |
|
def get_help(self): | return the help message on how to form the URI for this driver
None means no help | f1068:c0:m8 |
|
def close(self): | Close the link | f1068:c0:m9 |
|
def __init__(self, header=<NUM_LIT:0>, data=None): | self.size = <NUM_LIT:0><EOL>self._data = bytearray()<EOL>self.header = header | <NUM_LIT> << <NUM_LIT:2><EOL>self._port = (header & <NUM_LIT>) >> <NUM_LIT:4><EOL>self._channel = header & <NUM_LIT><EOL>if data:<EOL><INDENT>self._set_data(data)<EOL><DEDENT> | Create an empty packet with default values. | f1069:c1:m0 |
def _get_channel(self): | return self._channel<EOL> | Get the packet channel | f1069:c1:m1 |
def _set_channel(self, channel): | self._channel = channel<EOL>self._update_header()<EOL> | Set the packet channel | f1069:c1:m2 |
def _get_port(self): | return self._port<EOL> | Get the packet port | f1069:c1:m3 |
def _set_port(self, port): | self._port = port<EOL>self._update_header()<EOL> | Set the packet port | f1069:c1:m4 |
def get_header(self): | self._update_header()<EOL>return self.header<EOL> | Get the header | f1069:c1:m5 |
def set_header(self, port, channel): | self._port = port<EOL>self.channel = channel<EOL>self._update_header()<EOL> | Set the port and channel for this packet. | f1069:c1:m6 |
def _update_header(self): | <EOL>self.header = ((self._port & <NUM_LIT>) << <NUM_LIT:4> | <NUM_LIT:3> << <NUM_LIT:2> |<EOL>(self.channel & <NUM_LIT>))<EOL> | Update the header with the port/channel values | f1069:c1:m7 |
def _get_data(self): | return self._data<EOL> | Get the packet data | f1069:c1:m8 |
def _set_data(self, data): | if type(data) == bytearray:<EOL><INDENT>self._data = data<EOL><DEDENT>elif type(data) == str:<EOL><INDENT>if sys.version_info < (<NUM_LIT:3>,):<EOL><INDENT>self._data = bytearray(data)<EOL><DEDENT>else:<EOL><INDENT>self._data = bytearray(data.encode('<STR_LIT>'))<EOL><DEDENT><DEDENT>elif type(data) == list or type(data) == tuple:<EOL><INDENT>self._data = bytearray(data)<EOL><DEDENT>elif sys.version_info >= (<NUM_LIT:3>,) and type(data) == bytes:<EOL><INDENT>self._data = bytearray(data)<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>'<EOL>'<STR_LIT>'.format(type(data)))<EOL><DEDENT> | Set the packet data | f1069:c1:m9 |
def _get_data_l(self): | return list(self._get_data_t())<EOL> | Get the data in the packet as a list | f1069:c1:m10 |
def _get_data_t(self): | return tuple(self._data)<EOL> | Get the data in the packet as a tuple | f1069:c1:m11 |
def __str__(self): | return '<STR_LIT>'.format(self._port, self.channel, self.datat)<EOL> | Get a string representation of the packet | f1069:c1:m12 |
def __init__(self, id, type, size, mem_handler): | self.id = id<EOL>self.type = type<EOL>self.size = size<EOL>self.mem_handler = mem_handler<EOL> | Initialize the element with default values | f1070:c0:m0 |
@staticmethod<EOL><INDENT>def type_to_string(t):<DEDENT> | if t == MemoryElement.TYPE_I2C:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>if t == MemoryElement.TYPE_1W:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>if t == MemoryElement.TYPE_DRIVER_LED:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>if t == MemoryElement.TYPE_LOCO:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>if t == MemoryElement.TYPE_TRAJ:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>if t == MemoryElement.TYPE_LOCO2:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return '<STR_LIT>'<EOL> | Get string representation of memory type | f1070:c0:m1 |
def __str__(self): | return ('<STR_LIT>'.format(<EOL>self.id, MemoryElement.type_to_string(self.type), self.size))<EOL> | Generate debug string for memory | f1070:c0:m3 |
def __init__(self): | self.r = <NUM_LIT:0><EOL>self.g = <NUM_LIT:0><EOL>self.b = <NUM_LIT:0><EOL>self.intensity = <NUM_LIT:100><EOL> | Initialize to off | f1070:c1:m0 |
def set(self, r, g, b, intensity=None): | self.r = r<EOL>self.g = g<EOL>self.b = b<EOL>if intensity:<EOL><INDENT>self.intensity = intensity<EOL><DEDENT> | Set the R/G/B and optionally intensity in one call | f1070:c1:m1 |
def __init__(self, id, type, size, mem_handler): | super(LEDDriverMemory, self).__init__(id=id, type=type, size=size,<EOL>mem_handler=mem_handler)<EOL>self._update_finished_cb = None<EOL>self._write_finished_cb = None<EOL>self.leds = []<EOL>for i in range(<NUM_LIT:12>):<EOL><INDENT>self.leds.append(LED())<EOL><DEDENT> | Initialize with 12 LEDs | f1070:c2:m0 |
def new_data(self, mem, addr, data): | if mem.id == self.id:<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>")<EOL><DEDENT> | Callback for when new memory data has been fetched | f1070:c2:m1 |
def write_data(self, write_finished_cb): | self._write_finished_cb = write_finished_cb<EOL>data = bytearray()<EOL>for led in self.leds:<EOL><INDENT>R5 = ((int)((((int(led.r) & <NUM_LIT>) * <NUM_LIT> + <NUM_LIT>) >> <NUM_LIT:11>) & <NUM_LIT>) *<EOL>led.intensity / <NUM_LIT:100>)<EOL>G6 = ((int)((((int(led.g) & <NUM_LIT>) * <NUM_LIT> + <NUM_LIT>) >> <NUM_LIT:10>) & <NUM_LIT>) *<EOL>led.intensity / <NUM_LIT:100>)<EOL>B5 = ((int)((((int(led.b) & <NUM_LIT>) * <NUM_LIT> + <NUM_LIT>) >> <NUM_LIT:11>) & <NUM_LIT>) *<EOL>led.intensity / <NUM_LIT:100>)<EOL>tmp = (int(R5) << <NUM_LIT:11>) | (int(G6) << <NUM_LIT:5>) | (int(B5) << <NUM_LIT:0>)<EOL>data += bytearray((tmp >> <NUM_LIT:8>, tmp & <NUM_LIT>))<EOL><DEDENT>self.mem_handler.write(self, <NUM_LIT>, data, flush_queue=True)<EOL> | Write the saved LED-ring data to the Crazyflie | f1070:c2:m2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.