INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Connect to the crazyflie. | def connect(self):
"""
Connect to the crazyflie.
"""
print('Connecting to %s' % self._link_uri)
self._cf.open_link(self._link_uri) |
Busy loop until connection is established.
Will abort after timeout (seconds). Return value is a boolean, whether
connection could be established. | def wait_for_connection(self, timeout=10):
"""
Busy loop until connection is established.
Will abort after timeout (seconds). Return value is a boolean, whether
connection could be established.
"""
start_time = datetime.datetime.now()
while True:
if ... |
Search and return list of 1-wire memories. | def search_memories(self):
"""
Search and return list of 1-wire memories.
"""
if not self.connected:
raise NotConnected()
return self._cf.mem.get_mems(MemoryElement.TYPE_1W) |
This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | def _connected(self, link_uri):
""" This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded."""
print('Connected to %s' % link_uri)
self._cf.packet_received.add_callback(self._got_packet) |
Callback froma the log API when data arrives | def _stab_log_data(self, timestamp, data, logconf):
"""Callback froma the log API when data arrives"""
print('[%d][%s]: %s' % (timestamp, logconf.name, data)) |
Callback when connection initial connection fails (i.e no Crazyflie
at the speficied address) | def _connection_failed(self, link_uri, msg):
"""Callback when connection initial connection fails (i.e no Crazyflie
at the speficied address)"""
print('Connection to %s failed: %s' % (link_uri, msg))
self.is_connected = False |
Fetch platform info from the firmware
Should be called at the earliest in the connection sequence | def fetch_platform_informations(self, callback):
"""
Fetch platform info from the firmware
Should be called at the earliest in the connection sequence
"""
self._protocolVersion = -1
self._callback = callback
self._request_protocol_version() |
Enable/disable the client side X-mode. When enabled this recalculates
the setpoints before sending them to the Crazyflie. | def set_continous_wave(self, enabled):
"""
Enable/disable the client side X-mode. When enabled this recalculates
the setpoints before sending them to the Crazyflie.
"""
pk = CRTPPacket()
pk.set_header(CRTPPort.PLATFORM, PLATFORM_COMMAND)
pk.data = (0, enabled)
... |
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 occ... | def connect(self, uri, link_quality_callback, link_error_callback):
"""
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 qu... |
Receive a packet though the link. This call is blocking but will
timeout and return None if a timeout is supplied. | def receive_packet(self, time=0):
"""
Receive a packet though the link. This call is blocking but will
timeout and return None if a timeout is supplied.
"""
if time == 0:
try:
return self.in_queue.get(False)
except queue.Empty:
... |
Send the packet pk though the link | def send_packet(self, pk):
""" Send the packet pk though the link """
# if self.out_queue.full():
# self.out_queue.get()
if (self.cfusb is None):
return
try:
dataOut = (pk.header,)
dataOut += pk.datat
self.cfusb.send_packet(data... |
Close the link. | def close(self):
""" Close the link. """
# Stop the comm thread
self._thread.stop()
# Close the USB dongle
try:
if self.cfusb:
self.cfusb.set_crtp_to_usb(False)
self.cfusb.close()
except Exception as e:
# If we pull... |
Scan interface for Crazyflies | def scan_interface(self, address):
""" Scan interface for Crazyflies """
if self.cfusb is None:
try:
self.cfusb = CfUsb()
except Exception as e:
logger.warn(
'Exception while scanning for Crazyflie USB: {}'.format(
... |
Run the receiver thread | def run(self):
""" Run the receiver thread """
while (True):
if (self.sp):
break
try:
# Blocking until USB data available
data = self.cfusb.receive_packet()
if len(data) > 0:
pk = CRTPPacket(data... |
This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | def _connected(self, link_uri):
""" This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded."""
print('Connected to %s' % link_uri)
mems = self._cf.mem.get_mems(MemoryElement.TYPE_1W)
self._mems_to_update = len(mems)
... |
Register cb as a new callback. Will not register duplicates. | def add_callback(self, cb):
""" Register cb as a new callback. Will not register duplicates. """
if ((cb in self.callbacks) is False):
self.callbacks.append(cb) |
This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | def _connected(self, link_uri):
""" This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded."""
print('Connected to %s' % link_uri)
self._is_link_open = True
self._connect_event.set() |
Callback when connection initial connection fails (i.e no Crazyflie
at the specified address) | def _connection_failed(self, link_uri, msg):
"""Callback when connection initial connection fails (i.e no Crazyflie
at the specified address)"""
print('Connection to %s failed: %s' % (link_uri, msg))
self._is_link_open = False
self._error_message = msg
self._connect_event... |
Read a flash page from the specified target | def read_cf1_config(self):
"""Read a flash page from the specified target"""
target = self._cload.targets[0xFF]
config_page = target.flash_pages - 1
return self._cload.read_flash(addr=0xFF, page=config_page) |
Returns a list of CrazyRadio devices currently connected to the computer | def _find_devices(serial=None):
"""
Returns a list of CrazyRadio devices currently connected to the computer
"""
ret = []
if pyusb1:
for d in usb.core.find(idVendor=0x1915, idProduct=0x7777, find_all=1,
backend=pyusb_backend):
if serial is not None... |
Set the radio channel to be used | def set_channel(self, channel):
""" Set the radio channel to be used """
if channel != self.current_channel:
_send_vendor_setup(self.handle, SET_RADIO_CHANNEL, channel, 0, ())
self.current_channel = channel |
Set the radio address to be used | def set_address(self, address):
""" Set the radio address to be used"""
if len(address) != 5:
raise Exception('Crazyradio: the radio address shall be 5'
' bytes long')
if address != self.current_address:
_send_vendor_setup(self.handle, SET_RADI... |
Set the radio datarate to be used | def set_data_rate(self, datarate):
""" Set the radio datarate to be used """
if datarate != self.current_datarate:
_send_vendor_setup(self.handle, SET_DATA_RATE, datarate, 0, ())
self.current_datarate = datarate |
Set the ACK retry count for radio communication | def set_arc(self, arc):
""" Set the ACK retry count for radio communication """
_send_vendor_setup(self.handle, SET_RADIO_ARC, arc, 0, ())
self.arc = arc |
Set the ACK retry delay for radio communication | def set_ard_time(self, us):
""" Set the ACK retry delay for radio communication """
# Auto Retransmit Delay:
# 0000 - Wait 250uS
# 0001 - Wait 500uS
# 0010 - Wait 750uS
# ........
# 1111 - Wait 4000uS
# Round down, to value representing a multiple of 250u... |
Send a packet and receive the ack from the radio dongle
The ack contains information about the packet transmition
and a data payload if the ack packet contained any | def send_packet(self, dataOut):
""" Send a packet and receive the ack from the radio dongle
The ack contains information about the packet transmition
and a data payload if the ack packet contained any """
ackIn = None
data = None
try:
if (pyusb1 is Fal... |
Callback for data received from the copter. | def incoming(self, packet):
"""
Callback for data received from the copter.
"""
# This might be done prettier ;-)
console_text = packet.data.decode('UTF-8')
self.receivedChar.call(console_text) |
Send the current Crazyflie X, Y, Z position. This is going to be
forwarded to the Crazyflie's position estimator. | def send_extpos(self, x, y, z):
"""
Send the current Crazyflie X, Y, Z position. This is going to be
forwarded to the Crazyflie's position estimator.
"""
self._cf.loc.send_extpos([x, y, z]) |
Try to get a hit in the cache, return None otherwise | def fetch(self, crc):
""" Try to get a hit in the cache, return None otherwise """
cache_data = None
pattern = '%08X.json' % crc
hit = None
for name in self._cache_files:
if (name.endswith(pattern)):
hit = name
if (hit):
try:
... |
Save a new cache to file | def insert(self, crc, toc):
""" Save a new cache to file """
if self._rw_cache:
try:
filename = '%s/%08X.json' % (self._rw_cache, crc)
cache = open(filename, 'w')
cache.write(json.dumps(toc, indent=2,
defa... |
Encode a toc element leaf-node | def _encoder(self, obj):
""" Encode a toc element leaf-node """
return {'__class__': obj.__class__.__name__,
'ident': obj.ident,
'group': obj.group,
'name': obj.name,
'ctype': obj.ctype,
'pytype': obj.pytype,
... |
Decode a toc element leaf-node | def _decoder(self, obj):
""" Decode a toc element leaf-node """
if '__class__' in obj:
elem = eval(obj['__class__'])()
elem.ident = obj['ident']
elem.group = str(obj['group'])
elem.name = str(obj['name'])
elem.ctype = str(obj['ctype'])
... |
Send a packet with a position to one anchor.
:param anchor_id: The id of the targeted anchor. This is the first byte
of the anchor address.
:param position: The position of the anchor, as an array | def set_position(self, anchor_id, position):
"""
Send a packet with a position to one anchor.
:param anchor_id: The id of the targeted anchor. This is the first byte
of the anchor address.
:param position: The position of the anchor, as an array
"""
x = position[0... |
Send a packet to set the anchor mode. If the anchor receive the packet,
it will change mode and resets. | def set_mode(self, anchor_id, mode):
"""
Send a packet to set the anchor mode. If the anchor receive the packet,
it will change mode and resets.
"""
data = struct.pack('<BB', LoPoAnchor.LPP_TYPE_MODE, mode)
self.crazyflie.loc.send_short_lpp_packet(anchor_id, data) |
Open links to all individuals in the swarm | def open_links(self):
"""
Open links to all individuals in the swarm
"""
if self._is_open:
raise Exception('Already opened')
try:
self.parallel_safe(lambda scf: scf.open_link())
self._is_open = True
except Exception as e:
s... |
Close all open links | def close_links(self):
"""
Close all open links
"""
for uri, cf in self._cfs.items():
cf.close_link()
self._is_open = False |
Execute a function for all Crazyflies in the swarm, in sequence.
The first argument of the function that is passed in will be a
SyncCrazyflie instance connected to the Crazyflie to operate on.
A list of optional parameters (per Crazyflie) may follow defined by
the args_dict. The diction... | def sequential(self, func, args_dict=None):
"""
Execute a function for all Crazyflies in the swarm, in sequence.
The first argument of the function that is passed in will be a
SyncCrazyflie instance connected to the Crazyflie to operate on.
A list of optional parameters (per Cra... |
Execute a function for all Crazyflies in the swarm, in parallel.
One thread per Crazyflie is started to execute the function. The
threads are joined at the end and if one or more of the threads raised
an exception this function will also raise an exception.
For a description of the argu... | def parallel_safe(self, func, args_dict=None):
"""
Execute a function for all Crazyflies in the swarm, in parallel.
One thread per Crazyflie is started to execute the function. The
threads are joined at the end and if one or more of the threads raised
an exception this function w... |
Takes off, that is starts the motors, goes straight up and hovers.
Do not call this function if you use the with keyword. Take off is
done automatically when the context is created.
:param height: the height (meters) to hover at. None uses the default
height set when cons... | def take_off(self, height=DEFAULT, velocity=DEFAULT):
"""
Takes off, that is starts the motors, goes straight up and hovers.
Do not call this function if you use the with keyword. Take off is
done automatically when the context is created.
:param height: the height (meters) to h... |
Go straight down and turn off the motors.
Do not call this function if you use the with keyword. Landing is
done automatically when the context goes out of scope.
:param velocity: The velocity (meters/second) when going down
:return: | def land(self, velocity=DEFAULT):
"""
Go straight down and turn off the motors.
Do not call this function if you use the with keyword. Landing is
done automatically when the context goes out of scope.
:param velocity: The velocity (meters/second) when going down
:return... |
Move in a straight line.
positive X is forward
positive Y is left
positive Z is up
:param distance_x_m: The distance to travel along the X-axis (meters)
:param distance_y_m: The distance to travel along the Y-axis (meters)
:param distance_z_m: The distance to travel alon... | def move_distance(self, distance_x_m, distance_y_m, distance_z_m,
velocity=DEFAULT):
"""
Move in a straight line.
positive X is forward
positive Y is left
positive Z is up
:param distance_x_m: The distance to travel along the X-axis (meters)
... |
Go to a position
:param x: X coordinate
:param y: Y coordinate
:param z: Z coordinate
:param velocity: the velocity (meters/second)
:return: | def go_to(self, x, y, z=DEFAULT, velocity=DEFAULT):
"""
Go to a position
:param x: X coordinate
:param y: Y coordinate
:param z: Z coordinate
:param velocity: the velocity (meters/second)
:return:
"""
z = self._height(z)
dx = x - self._x... |
Request an update of all the parameters in the TOC | def request_update_of_all_params(self):
"""Request an update of all the parameters in the TOC"""
for group in self.toc.toc:
for name in self.toc.toc[group]:
complete_name = '%s.%s' % (group, name)
self.request_param_update(complete_name) |
Check if all parameters from the TOC has at least been fetched
once | def _check_if_all_updated(self):
"""Check if all parameters from the TOC has at least been fetched
once"""
for g in self.toc.toc:
if g not in self.values:
return False
for n in self.toc.toc[g]:
if n not in self.values[g]:
... |
Callback with data for an updated parameter | def _param_updated(self, pk):
"""Callback with data for an updated parameter"""
if self._useV2:
var_id = struct.unpack('<H', pk.data[:2])[0]
else:
var_id = pk.data[0]
element = self.toc.get_element_by_id(var_id)
if element:
if self._useV2:
... |
Remove the supplied callback for a group or a group.name | def remove_update_callback(self, group, name=None, cb=None):
"""Remove the supplied callback for a group or a group.name"""
if not cb:
return
if not name:
if group in self.group_update_callbacks:
self.group_update_callbacks[group].remove_callback(cb)
... |
Add a callback for a specific parameter name. This callback will be
executed when a new value is read from the Crazyflie. | def add_update_callback(self, group=None, name=None, cb=None):
"""
Add a callback for a specific parameter name. This callback will be
executed when a new value is read from the Crazyflie.
"""
if not group and not name:
self.all_update_callback.add_callback(cb)
... |
Initiate a refresh of the parameter TOC. | def refresh_toc(self, refresh_done_callback, toc_cache):
"""
Initiate a refresh of the parameter TOC.
"""
self._useV2 = self.cf.platform.get_protocol_version() >= 4
toc_fetcher = TocFetcher(self.cf, ParamTocElement,
CRTPPort.PARAM, self.toc,
... |
Disconnected callback from Crazyflie API | def _disconnected(self, uri):
"""Disconnected callback from Crazyflie API"""
self.param_updater.close()
self.is_updated = False
# Clear all values from the previous Crazyflie
self.toc = Toc()
self.values = {} |
Request an update of the value for the supplied parameter. | def request_param_update(self, complete_name):
"""
Request an update of the value for the supplied parameter.
"""
self.param_updater.request_param_update(
self.toc.get_element_id(complete_name)) |
Set the value for the supplied parameter. | def set_value(self, complete_name, value):
"""
Set the value for the supplied parameter.
"""
element = self.toc.get_element_by_complete_name(complete_name)
if not element:
logger.warning("Cannot set value for [%s], it's not in the TOC!",
co... |
Callback for newly arrived packets | def _new_packet_cb(self, pk):
"""Callback for newly arrived packets"""
if pk.channel == READ_CHANNEL or pk.channel == WRITE_CHANNEL:
if self._useV2:
var_id = struct.unpack('<H', pk.data[:2])[0]
if pk.channel == READ_CHANNEL:
pk.data = pk.da... |
Place a param update request on the queue | def request_param_update(self, var_id):
"""Place a param update request on the queue"""
self._useV2 = self.cf.platform.get_protocol_version() >= 4
pk = CRTPPacket()
pk.set_header(CRTPPort.PARAM, READ_CHANNEL)
if self._useV2:
pk.data = struct.pack('<H', var_id)
... |
Add a new TocElement to the TOC container. | def add_element(self, element):
"""Add a new TocElement to the TOC container."""
try:
self.toc[element.group][element.name] = element
except KeyError:
self.toc[element.group] = {}
self.toc[element.group][element.name] = element |
Get the TocElement element id-number of the element with the
supplied name. | def get_element_id(self, complete_name):
"""Get the TocElement element id-number of the element with the
supplied name."""
[group, name] = complete_name.split('.')
element = self.get_element(group, name)
if element:
return element.ident
else:
logge... |
Get a TocElement element identified by index number from the
container. | def get_element_by_id(self, ident):
"""Get a TocElement element identified by index number from the
container."""
for group in list(self.toc.keys()):
for name in list(self.toc[group].keys()):
if self.toc[group][name].ident == ident:
return self.toc... |
Initiate fetching of the TOC. | def start(self):
"""Initiate fetching of the TOC."""
self._useV2 = self.cf.platform.get_protocol_version() >= 4
logger.debug('[%d]: Using V2 protocol: %d', self.port, self._useV2)
logger.debug('[%d]: Start fetching...', self.port)
# Register callback in this class for the port
... |
Callback for when the TOC fetching is finished | def _toc_fetch_finished(self):
"""Callback for when the TOC fetching is finished"""
self.cf.remove_port_callback(self.port, self._new_packet_cb)
logger.debug('[%d]: Done!', self.port)
self.finished_callback() |
Handle a newly arrived packet | def _new_packet_cb(self, packet):
"""Handle a newly arrived packet"""
chan = packet.channel
if (chan != 0):
return
payload = packet.data[1:]
if (self.state == GET_TOC_INFO):
if self._useV2:
[self.nbr_of_items, self._crc] = struct.unpack(
... |
Request information about a specific item in the TOC | def _request_toc_element(self, index):
"""Request information about a specific item in the TOC"""
logger.debug('Requesting index %d on port %d', index, self.port)
pk = CRTPPacket()
if self._useV2:
pk.set_header(self.port, TOC_CHANNEL)
pk.data = (CMD_TOC_ITEM_V2, i... |
Start the connection setup by refreshing the TOCs | def _start_connection_setup(self):
"""Start the connection setup by refreshing the TOCs"""
logger.info('We are connected[%s], request connection setup',
self.link_uri)
self.platform.fetch_platform_informations(self._platform_info_fetched) |
Called when the param TOC has been fully updated | def _param_toc_updated_cb(self):
"""Called when the param TOC has been fully updated"""
logger.info('Param TOC finished updating')
self.connected_ts = datetime.datetime.now()
self.connected.call(self.link_uri)
# Trigger the update for all the parameters
self.param.request... |
Called when the memories have been identified | def _mems_updated_cb(self):
"""Called when the memories have been identified"""
logger.info('Memories finished updating')
self.param.refresh_toc(self._param_toc_updated_cb, self._toc_cache) |
Called from the link driver when there's an error | def _link_error_cb(self, errmsg):
"""Called from the link driver when there's an error"""
logger.warning('Got link error callback [%s] in state [%s]',
errmsg, self.state)
if (self.link is not None):
self.link.close()
self.link = None
if (self.st... |
Called when first packet arrives from Crazyflie.
This is used to determine if we are connected to something that is
answering. | def _check_for_initial_packet_cb(self, data):
"""
Called when first packet arrives from Crazyflie.
This is used to determine if we are connected to something that is
answering.
"""
self.state = State.CONNECTED
self.link_established.call(self.link_uri)
sel... |
Open the communication link to a copter at the given URI and setup the
connection (download log/parameter TOC). | def open_link(self, link_uri):
"""
Open the communication link to a copter at the given URI and setup the
connection (download log/parameter TOC).
"""
self.connection_requested.call(link_uri)
self.state = State.INITIALIZED
self.link_uri = link_uri
try:
... |
Close the communication link. | def close_link(self):
"""Close the communication link."""
logger.info('Closing link')
if (self.link is not None):
self.commander.send_setpoint(0, 0, 0, 0)
if (self.link is not None):
self.link.close()
self.link = None
self._answer_patterns = {}... |
Resend packets that we have not gotten answers to | def _no_answer_do_retry(self, pk, pattern):
"""Resend packets that we have not gotten answers to"""
logger.info('Resending for pattern %s', pattern)
# Set the timer to None before trying to send again
self.send_packet(pk, expected_reply=pattern, resend=True) |
Callback called for every packet received to check if we are
waiting for an answer on this port. If so, then cancel the retry
timer. | def _check_for_answers(self, pk):
"""
Callback called for every packet received to check if we are
waiting for an answer on this port. If so, then cancel the retry
timer.
"""
longest_match = ()
if len(self._answer_patterns) > 0:
data = (pk.header,) + t... |
Send a packet through the link interface.
pk -- Packet to send
expect_answer -- True if a packet from the Crazyflie is expected to
be sent back, otherwise false | def send_packet(self, pk, expected_reply=(), resend=False, timeout=0.2):
"""
Send a packet through the link interface.
pk -- Packet to send
expect_answer -- True if a packet from the Crazyflie is expected to
be sent back, otherwise false
"""
sel... |
Add a callback for data that comes on a specific port | def add_port_callback(self, port, cb):
"""Add a callback for data that comes on a specific port"""
logger.debug('Adding callback on port [%d] to [%s]', port, cb)
self.add_header_callback(cb, port, 0, 0xff, 0x0) |
Remove a callback for data that comes on a specific port | def remove_port_callback(self, port, cb):
"""Remove a callback for data that comes on a specific port"""
logger.debug('Removing callback on port [%d] to [%s]', port, cb)
for port_callback in self.cb:
if port_callback.port == port and port_callback.callback == cb:
self... |
Add a callback for a specific port/header callback with the
possibility to add a mask for channel and port for multiple
hits for same callback. | def add_header_callback(self, cb, port, channel, port_mask=0xFF,
channel_mask=0xFF):
"""
Add a callback for a specific port/header callback with the
possibility to add a mask for channel and port for multiple
hits for same callback.
"""
self.cb... |
Add a new variable to the configuration.
name - Complete name of the variable in the form group.name
fetch_as - String representation of the type the variable should be
fetched as (i.e uint8_t, float, FP16, etc)
If no fetch_as type is supplied, then the stored as type will b... | def add_variable(self, name, fetch_as=None):
"""Add a new variable to the configuration.
name - Complete name of the variable in the form group.name
fetch_as - String representation of the type the variable should be
fetched as (i.e uint8_t, float, FP16, etc)
If no f... |
Add a raw memory position to log.
name - Arbitrary name of the variable
fetch_as - String representation of the type of the data the memory
should be fetch as (i.e uint8_t, float, FP16)
stored_as - String representation of the type the data is stored as
in... | def add_memory(self, name, fetch_as, stored_as, address):
"""Add a raw memory position to log.
name - Arbitrary name of the variable
fetch_as - String representation of the type of the data the memory
should be fetch as (i.e uint8_t, float, FP16)
stored_as - String re... |
Save the log configuration in the Crazyflie | def create(self):
"""Save the log configuration in the Crazyflie"""
pk = CRTPPacket()
pk.set_header(5, CHAN_SETTINGS)
if self.useV2:
pk.data = (CMD_CREATE_BLOCK_V2, self.id)
else:
pk.data = (CMD_CREATE_BLOCK, self.id)
for var in self.variables:
... |
Start the logging for this entry | def start(self):
"""Start the logging for this entry"""
if (self.cf.link is not None):
if (self._added is False):
self.create()
logger.debug('First time block is started, add block')
else:
logger.debug('Block already registered, sta... |
Stop the logging for this entry | def stop(self):
"""Stop the logging for this entry"""
if (self.cf.link is not None):
if (self.id is None):
logger.warning('Stopping block, but no block registered')
else:
logger.debug('Sending stop logging for block id=%d', self.id)
... |
Delete this entry in the Crazyflie | def delete(self):
"""Delete this entry in the Crazyflie"""
if (self.cf.link is not None):
if (self.id is None):
logger.warning('Delete block, but no block registered')
else:
logger.debug('LogEntry: Sending delete logging for block id=%d'
... |
Unpack received logging data so it represent real values according
to the configuration in the entry | def unpack_log_data(self, log_data, timestamp):
"""Unpack received logging data so it represent real values according
to the configuration in the entry"""
ret_data = {}
data_index = 0
for var in self.variables:
size = LogTocElement.get_size_from_id(var.fetch_as)
... |
Return variable type id given the C-storage name | def get_id_from_cstring(name):
"""Return variable type id given the C-storage name"""
for key in list(LogTocElement.types.keys()):
if (LogTocElement.types[key][0] == name):
return key
raise KeyError('Type [%s] not found in LogTocElement.types!' % name) |
Add a log configuration to the logging framework.
When doing this the contents of the log configuration will be validated
and listeners for new log configurations will be notified. When
validating the configuration the variables are checked against the TOC
to see that they actually exis... | def add_config(self, logconf):
"""Add a log configuration to the logging framework.
When doing this the contents of the log configuration will be validated
and listeners for new log configurations will be notified. When
validating the configuration the variables are checked against the ... |
Start refreshing the table of loggale variables | def refresh_toc(self, refresh_done_callback, toc_cache):
"""Start refreshing the table of loggale variables"""
self._useV2 = self.cf.platform.get_protocol_version() >= 4
self._toc_cache = toc_cache
self._refresh_callback = refresh_done_callback
self.toc = None
pk = CRT... |
Callback for newly arrived packets with TOC information | def _new_packet_cb(self, packet):
"""Callback for newly arrived packets with TOC information"""
chan = packet.channel
cmd = packet.data[0]
payload = packet.data[1:]
if (chan == CHAN_SETTINGS):
id = payload[0]
error_status = payload[1]
block = ... |
This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | def _connected(self, link_uri):
""" This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded."""
print('Connected to %s' % link_uri)
mems = self._cf.mem.get_mems(MemoryElement.TYPE_I2C)
print('Found {} EEPOM(s)'.format(... |
This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded. | def _connected(self, link_uri):
""" This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded."""
print('Connected to %s' % link_uri)
# The definition of the logconfig can be made before connecting
self._lg_stab = LogCon... |
Initialize all the drivers. | def init_drivers(enable_debug_driver=False):
"""Initialize all the drivers."""
for driver in DRIVERS:
try:
if driver != DebugDriver or enable_debug_driver:
CLASSES.append(driver)
except Exception: # pylint: disable=W0703
continue |
Scan all the interfaces for available Crazyflies | def scan_interfaces(address=None):
""" Scan all the interfaces for available Crazyflies """
available = []
found = []
for driverClass in CLASSES:
try:
logger.debug('Scanning: %s', driverClass)
instance = driverClass()
found = instance.scan_interface(address)
... |
Get the status of all the interfaces | def get_interfaces_status():
"""Get the status of all the interfaces"""
status = {}
for driverClass in CLASSES:
try:
instance = driverClass()
status[instance.get_name()] = instance.get_status()
except Exception:
raise
return status |
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. | def get_link_driver(uri, link_quality_callback=None, link_error_callback=None):
"""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."""
for driverClass in CLASSES:
try:
instance = drive... |
Callback for data received from the copter. | def _incoming(self, packet):
"""
Callback for data received from the copter.
"""
if len(packet.data) < 1:
logger.warning('Localization packet received with incorrect' +
'length (length is {})'.format(len(packet.data)))
return
pk... |
Send the current Crazyflie X, Y, Z position. This is going to be
forwarded to the Crazyflie's position estimator. | def send_extpos(self, pos):
"""
Send the current Crazyflie X, Y, Z position. This is going to be
forwarded to the Crazyflie's position estimator.
"""
pk = CRTPPacket()
pk.port = CRTPPort.LOCALIZATION
pk.channel = self.POSITION_CH
pk.data = struct.pack('<f... |
Send ultra-wide-band LPP packet to dest_id | def send_short_lpp_packet(self, dest_id, data):
"""
Send ultra-wide-band LPP packet to dest_id
"""
pk = CRTPPacket()
pk.port = CRTPPort.LOCALIZATION
pk.channel = self.GENERIC_CH
pk.data = struct.pack('<BB', self.LPS_SHORT_LPP_PACKET, dest_id) + data
self.... |
Send a new control setpoint for roll/pitch/yaw/thrust to the copter
The arguments roll/pitch/yaw/trust is the new setpoints that should
be sent to the copter | def send_setpoint(self, roll, pitch, yaw, thrust):
"""
Send a new control setpoint for roll/pitch/yaw/thrust to the copter
The arguments roll/pitch/yaw/trust is the new setpoints that should
be sent to the copter
"""
if thrust > 0xFFFF or thrust < 0:
raise Va... |
Send STOP setpoing, stopping the motors and (potentially) falling. | def send_stop_setpoint(self):
"""
Send STOP setpoing, stopping the motors and (potentially) falling.
"""
pk = CRTPPacket()
pk.port = CRTPPort.COMMANDER_GENERIC
pk.data = struct.pack('<B', TYPE_STOP)
self._cf.send_packet(pk) |
Send Velocity in the world frame of reference setpoint.
vx, vy, vz are in m/s
yawrate is in degrees/s | def send_velocity_world_setpoint(self, vx, vy, vz, yawrate):
"""
Send Velocity in the world frame of reference setpoint.
vx, vy, vz are in m/s
yawrate is in degrees/s
"""
pk = CRTPPacket()
pk.port = CRTPPort.COMMANDER_GENERIC
pk.data = struct.pack('<Bffff... |
Control mode where the height is send as an absolute setpoint (intended
to be the distance to the surface under the Crazflie).
Roll, pitch, yawrate are defined as degrees, degrees, degrees/s | def send_zdistance_setpoint(self, roll, pitch, yawrate, zdistance):
"""
Control mode where the height is send as an absolute setpoint (intended
to be the distance to the surface under the Crazflie).
Roll, pitch, yawrate are defined as degrees, degrees, degrees/s
"""
pk =... |
Control mode where the height is send as an absolute setpoint (intended
to be the distance to the surface under the Crazflie).
vx and vy are in m/s
yawrate is in degrees/s | def send_hover_setpoint(self, vx, vy, yawrate, zdistance):
"""
Control mode where the height is send as an absolute setpoint (intended
to be the distance to the surface under the Crazflie).
vx and vy are in m/s
yawrate is in degrees/s
"""
pk = CRTPPacket()
... |
Control mode where the position is sent as absolute x,y,z coordinate in
meter and the yaw is the absolute orientation.
x and y are in m
yaw is in degrees | def send_position_setpoint(self, x, y, z, yaw):
"""
Control mode where the position is sent as absolute x,y,z coordinate in
meter and the yaw is the absolute orientation.
x and y are in m
yaw is in degrees
"""
pk = CRTPPacket()
pk.port = CRTPPort.COMMANDE... |
Get string representation of memory type | def type_to_string(t):
"""Get string representation of memory type"""
if t == MemoryElement.TYPE_I2C:
return 'I2C'
if t == MemoryElement.TYPE_1W:
return '1-wire'
if t == MemoryElement.TYPE_DRIVER_LED:
return 'LED driver'
if t == MemoryElement.T... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.