_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q228800
delaunay
train
def delaunay(data, line_color=None, line_width=2, cmap=None, max_lenght=100): """ Draw a delaunay triangulation of the points :param data: data access object :param line_color: line color :param line_width: line width :param cmap: color map :param max_lenght: scaling constant for coloring t...
python
{ "resource": "" }
q228801
convexhull
train
def convexhull(data, col, fill=True, point_size=4): """ Convex hull for a set of points :param data: points :param col: color :param fill: whether to fill the convexhull polygon or not :param point_size: size of the points on the convexhull. Points are not rendered if None """ from geop...
python
{ "resource": "" }
q228802
kde
train
def kde(data, bw, cmap='hot', method='hist', scaling='sqrt', alpha=220, cut_below=None, clip_above=None, binsize=1, cmap_levels=10, show_colorbar=False): """ Kernel density estimation visualization :param data: data access object :param bw: kernel bandwidth (in screen coordinates) ...
python
{ "resource": "" }
q228803
labels
train
def labels(data, label_column, color=None, font_name=FONT_NAME, font_size=14, anchor_x='left', anchor_y='top'): """ Draw a text label for each sample :param data: data access object :param label_column: column in the data access object where the labels text is stored :param color: color...
python
{ "resource": "" }
q228804
set_map_alpha
train
def set_map_alpha(alpha): """ Alpha color of the map tiles :param alpha: int between 0 and 255. 0 is completely dark, 255 is full brightness """ if alpha < 0 or alpha > 255: raise Exception('invalid alpha ' + str(alpha)) _global_config.map_alpha = alpha
python
{ "resource": "" }
q228805
read_csv
train
def read_csv(fname): """ Read a csv file into a DataAccessObject :param fname: filename """ values = defaultdict(list) with open(fname) as f: reader = csv.DictReader(f) for row in reader: for (k,v) in row.items(): values[k].append(v) npvalues = {k...
python
{ "resource": "" }
q228806
DataAccessObject.head
train
def head(self, n): """ Return a DataAccessObject containing the first n rows :param n: number of rows :return: DataAccessObject """ return DataAccessObject({k: self.dict[k][:n] for k in self.dict})
python
{ "resource": "" }
q228807
BoundingBox.from_points
train
def from_points(lons, lats): """ Compute the BoundingBox from a set of latitudes and longitudes :param lons: longitudes :param lats: latitudes :return: BoundingBox """ north, west = max(lats), min(lons) south, east = min(lats), max(lons) return Bo...
python
{ "resource": "" }
q228808
BoundingBox.from_bboxes
train
def from_bboxes(bboxes): """ Compute a BoundingBox enclosing all specified bboxes :param bboxes: a list of BoundingBoxes :return: BoundingBox """ north = max([b.north for b in bboxes]) south = min([b.south for b in bboxes]) west = min([b.west for b in bbo...
python
{ "resource": "" }
q228809
get_pydoc_completions
train
def get_pydoc_completions(modulename): """Get possible completions for modulename for pydoc. Returns a list of possible values to be passed to pydoc. """ modulename = compat.ensure_not_unicode(modulename) modulename = modulename.rstrip(".") if modulename == "": return sorted(get_module...
python
{ "resource": "" }
q228810
get_modules
train
def get_modules(modulename=None): """Return a list of modules and packages under modulename. If modulename is not given, return a list of all top level modules and packages. """ modulename = compat.ensure_not_unicode(modulename) if not modulename: try: return ([modname for ...
python
{ "resource": "" }
q228811
JSONRPCServer.read_json
train
def read_json(self): """Read a single line and decode it as JSON. Can raise an EOFError() when the input source was closed. """ line = self.stdin.readline() if line == '': raise EOFError() return json.loads(line)
python
{ "resource": "" }
q228812
JSONRPCServer.write_json
train
def write_json(self, **kwargs): """Write an JSON object on a single line. The keyword arguments are interpreted as a single JSON object. It's not possible with this method to write non-objects. """ self.stdout.write(json.dumps(kwargs) + "\n") self.stdout.flush()
python
{ "resource": "" }
q228813
JSONRPCServer.handle_request
train
def handle_request(self): """Handle a single JSON-RPC request. Read a request, call the appropriate handler method, and return the encoded result. Errors in the handler method are caught and encoded as error objects. Errors in the decoding phase are not caught, as we can not res...
python
{ "resource": "" }
q228814
get_source
train
def get_source(fileobj): """Translate fileobj into file contents. fileobj is either a string or a dict. If it's a string, that's the file contents. If it's a string, then the filename key contains the name of the file whose contents we are to use. If the dict contains a true value for the key dele...
python
{ "resource": "" }
q228815
ElpyRPCServer._call_backend
train
def _call_backend(self, method, default, *args, **kwargs): """Call the backend method with args. If there is currently no backend, return default.""" meth = getattr(self.backend, method, None) if meth is None: return default else: return meth(*args, **kwa...
python
{ "resource": "" }
q228816
ElpyRPCServer.rpc_get_calltip
train
def rpc_get_calltip(self, filename, source, offset): """Get the calltip for the function at the offset. """ return self._call_backend("rpc_get_calltip", None, filename, get_source(source), offset)
python
{ "resource": "" }
q228817
ElpyRPCServer.rpc_get_oneline_docstring
train
def rpc_get_oneline_docstring(self, filename, source, offset): """Get a oneline docstring for the symbol at the offset. """ return self._call_backend("rpc_get_oneline_docstring", None, filename, get_source(source), offset)
python
{ "resource": "" }
q228818
ElpyRPCServer.rpc_get_completions
train
def rpc_get_completions(self, filename, source, offset): """Get a list of completion candidates for the symbol at offset. """ results = self._call_backend("rpc_get_completions", [], filename, get_source(source), offset) # Uniquify by name res...
python
{ "resource": "" }
q228819
ElpyRPCServer.rpc_get_definition
train
def rpc_get_definition(self, filename, source, offset): """Get the location of the definition for the symbol at the offset. """ return self._call_backend("rpc_get_definition", None, filename, get_source(source), offset)
python
{ "resource": "" }
q228820
ElpyRPCServer.rpc_get_assignment
train
def rpc_get_assignment(self, filename, source, offset): """Get the location of the assignment for the symbol at the offset. """ return self._call_backend("rpc_get_assignment", None, filename, get_source(source), offset)
python
{ "resource": "" }
q228821
ElpyRPCServer.rpc_get_docstring
train
def rpc_get_docstring(self, filename, source, offset): """Get the docstring for the symbol at the offset. """ return self._call_backend("rpc_get_docstring", None, filename, get_source(source), offset)
python
{ "resource": "" }
q228822
ElpyRPCServer.rpc_get_pydoc_documentation
train
def rpc_get_pydoc_documentation(self, symbol): """Get the Pydoc documentation for the given symbol. Uses pydoc and can return a string with backspace characters for bold highlighting. """ try: docstring = pydoc.render_doc(str(symbol), ...
python
{ "resource": "" }
q228823
ElpyRPCServer.rpc_get_refactor_options
train
def rpc_get_refactor_options(self, filename, start, end=None): """Return a list of possible refactoring options. This list will be filtered depending on whether it's applicable at the point START and possibly the region between START and END. """ try: from e...
python
{ "resource": "" }
q228824
ElpyRPCServer.rpc_refactor
train
def rpc_refactor(self, filename, method, args): """Return a list of changes from the refactoring action. A change is a dictionary describing the change. See elpy.refactor.translate_changes for a description. """ try: from elpy import refactor except: ...
python
{ "resource": "" }
q228825
ElpyRPCServer.rpc_get_names
train
def rpc_get_names(self, filename, source, offset): """Get all possible names """ source = get_source(source) if hasattr(self.backend, "rpc_get_names"): return self.backend.rpc_get_names(filename, source, offset) else: raise Fault("get_names not implemente...
python
{ "resource": "" }
q228826
pos_to_linecol
train
def pos_to_linecol(text, pos): """Return a tuple of line and column for offset pos in text. Lines are one-based, columns zero-based. This is how Jedi wants it. Don't ask me why. """ line_start = text.rfind("\n", 0, pos) + 1 line = text.count("\n", 0, line_start) + 1 col = pos - line_start...
python
{ "resource": "" }
q228827
linecol_to_pos
train
def linecol_to_pos(text, line, col): """Return the offset of this line and column in text. Lines are one-based, columns zero-based. This is how Jedi wants it. Don't ask me why. """ nth_newline_offset = 0 for i in range(line - 1): new_offset = text.find("\n", nth_newline_offset) ...
python
{ "resource": "" }
q228828
JediBackend.rpc_get_oneline_docstring
train
def rpc_get_oneline_docstring(self, filename, source, offset): """Return a oneline docstring for the symbol at offset""" line, column = pos_to_linecol(source, offset) definitions = run_with_debug(jedi, 'goto_definitions', source=source, line=line, column=colu...
python
{ "resource": "" }
q228829
JediBackend.rpc_get_usages
train
def rpc_get_usages(self, filename, source, offset): """Return the uses of the symbol at offset. Returns a list of occurrences of the symbol, as dicts with the fields name, filename, and offset. """ line, column = pos_to_linecol(source, offset) uses = run_with_debug(jedi...
python
{ "resource": "" }
q228830
JediBackend.rpc_get_names
train
def rpc_get_names(self, filename, source, offset): """Return the list of possible names""" names = jedi.api.names(source=source, path=filename, encoding='utf-8', all_scopes=True, definitions=True, ...
python
{ "resource": "" }
q228831
options
train
def options(description, **kwargs): """Decorator to set some options on a method.""" def set_notes(function): function.refactor_notes = {'name': function.__name__, 'category': "Miscellaneous", 'description': description, ...
python
{ "resource": "" }
q228832
translate_changes
train
def translate_changes(initial_change): """Translate rope.base.change.Change instances to dictionaries. See Refactor.get_changes for an explanation of the resulting dictionary. """ agenda = [initial_change] result = [] while agenda: change = agenda.pop(0) if isinstance(chang...
python
{ "resource": "" }
q228833
Refactor.get_refactor_options
train
def get_refactor_options(self, start, end=None): """Return a list of options for refactoring at the given position. If `end` is also given, refactoring on a region is assumed. Each option is a dictionary of key/value pairs. The value of the key 'name' is the one to be used for get_chan...
python
{ "resource": "" }
q228834
Refactor._is_on_import_statement
train
def _is_on_import_statement(self, offset): "Does this offset point to an import statement?" data = self.resource.read() bol = data.rfind("\n", 0, offset) + 1 eol = data.find("\n", 0, bol) if eol == -1: eol = len(data) line = data[bol:eol] line = line.s...
python
{ "resource": "" }
q228835
Refactor._is_on_symbol
train
def _is_on_symbol(self, offset): "Is this offset on a symbol?" if not ROPE_AVAILABLE: return False data = self.resource.read() if offset >= len(data): return False if data[offset] != '_' and not data[offset].isalnum(): return False word...
python
{ "resource": "" }
q228836
Refactor.get_changes
train
def get_changes(self, name, *args): """Return a list of changes for the named refactoring action. Changes are dictionaries describing a single action to be taken for the refactoring to be successful. A change has an action and possibly a type. In the description below, the acti...
python
{ "resource": "" }
q228837
Refactor.refactor_froms_to_imports
train
def refactor_froms_to_imports(self, offset): """Converting imports of the form "from ..." to "import ...".""" refactor = ImportOrganizer(self.project) changes = refactor.froms_to_imports(self.resource, offset) return translate_changes(changes)
python
{ "resource": "" }
q228838
Refactor.refactor_organize_imports
train
def refactor_organize_imports(self): """Clean up and organize imports.""" refactor = ImportOrganizer(self.project) changes = refactor.organize_imports(self.resource) return translate_changes(changes)
python
{ "resource": "" }
q228839
Refactor.refactor_module_to_package
train
def refactor_module_to_package(self): """Convert the current module into a package.""" refactor = ModuleToPackage(self.project, self.resource) return self._get_changes(refactor)
python
{ "resource": "" }
q228840
Refactor.refactor_rename_at_point
train
def refactor_rename_at_point(self, offset, new_name, in_hierarchy, docs): """Rename the symbol at point.""" try: refactor = Rename(self.project, self.resource, offset) except RefactoringError as e: raise Fault(str(e), code=400) return self._get_changes(refactor, n...
python
{ "resource": "" }
q228841
Refactor.refactor_rename_current_module
train
def refactor_rename_current_module(self, new_name): """Rename the current module.""" refactor = Rename(self.project, self.resource, None) return self._get_changes(refactor, new_name)
python
{ "resource": "" }
q228842
Refactor.refactor_move_module
train
def refactor_move_module(self, new_name): """Move the current module.""" refactor = create_move(self.project, self.resource) resource = path_to_resource(self.project, new_name) return self._get_changes(refactor, resource)
python
{ "resource": "" }
q228843
Refactor.refactor_create_inline
train
def refactor_create_inline(self, offset, only_this): """Inline the function call at point.""" refactor = create_inline(self.project, self.resource, offset) if only_this: return self._get_changes(refactor, remove=False, only_current=True) else: return self._get_cha...
python
{ "resource": "" }
q228844
Refactor.refactor_extract_method
train
def refactor_extract_method(self, start, end, name, make_global): """Extract region as a method.""" refactor = ExtractMethod(self.project, self.resource, start, end) return self._get_changes( refactor, name, similar=True, global_=make_global )
python
{ "resource": "" }
q228845
Refactor.refactor_use_function
train
def refactor_use_function(self, offset): """Use the function at point wherever possible.""" try: refactor = UseFunction(self.project, self.resource, offset) except RefactoringError as e: raise Fault( 'Refactoring error: {}'.format(e), code=...
python
{ "resource": "" }
q228846
XenonDevice.generate_payload
train
def generate_payload(self, command, data=None): """ Generate the payload to send. Args: command(str): The type of command. This is one of the entries from payload_dict data(dict, optional): The data to be send. This is what will be passed ...
python
{ "resource": "" }
q228847
BulbDevice.set_colour
train
def set_colour(self, r, g, b): """ Set colour of an rgb bulb. Args: r(int): Value for the colour red as int from 0-255. g(int): Value for the colour green as int from 0-255. b(int): Value for the colour blue as int from 0-255. """ if not 0 <= ...
python
{ "resource": "" }
q228848
BulbDevice.set_white
train
def set_white(self, brightness, colourtemp): """ Set white coloured theme of an rgb bulb. Args: brightness(int): Value for the brightness (25-255). colourtemp(int): Value for the colour temperature (0-255). """ if not 25 <= brightness <= 255: ...
python
{ "resource": "" }
q228849
BulbDevice.set_brightness
train
def set_brightness(self, brightness): """ Set the brightness value of an rgb bulb. Args: brightness(int): Value for the brightness (25-255). """ if not 25 <= brightness <= 255: raise ValueError("The brightness needs to be between 25 and 255.") pa...
python
{ "resource": "" }
q228850
BulbDevice.set_colourtemp
train
def set_colourtemp(self, colourtemp): """ Set the colour temperature of an rgb bulb. Args: colourtemp(int): Value for the colour temperature (0-255). """ if not 0 <= colourtemp <= 255: raise ValueError("The colour temperature needs to be between 0 and 255...
python
{ "resource": "" }
q228851
BulbDevice.colour_rgb
train
def colour_rgb(self): """Return colour as RGB value""" hexvalue = self.status()[self.DPS][self.DPS_INDEX_COLOUR] return BulbDevice._hexvalue_to_rgb(hexvalue)
python
{ "resource": "" }
q228852
BulbDevice.colour_hsv
train
def colour_hsv(self): """Return colour as HSV value""" hexvalue = self.status()[self.DPS][self.DPS_INDEX_COLOUR] return BulbDevice._hexvalue_to_hsv(hexvalue)
python
{ "resource": "" }
q228853
HighLevelCommander.set_group_mask
train
def set_group_mask(self, group_mask=ALL_GROUPS): """ Set the group mask that the Crazyflie belongs to :param group_mask: mask for which groups this CF belongs to """ self._send_packet(struct.pack('<BB', self.COMMAND_SET_GROUP_MASK, ...
python
{ "resource": "" }
q228854
HighLevelCommander.takeoff
train
def takeoff(self, absolute_height_m, duration_s, group_mask=ALL_GROUPS): """ vertical takeoff from current x-y position to given height :param absolute_height_m: absolut (m) :param duration_s: time it should take until target height is reached (s) :par...
python
{ "resource": "" }
q228855
HighLevelCommander.land
train
def land(self, absolute_height_m, duration_s, group_mask=ALL_GROUPS): """ vertical land from current x-y position to given height :param absolute_height_m: absolut (m) :param duration_s: time it should take until target height is reached (s) :param gro...
python
{ "resource": "" }
q228856
HighLevelCommander.go_to
train
def go_to(self, x, y, z, yaw, duration_s, relative=False, group_mask=ALL_GROUPS): """ Go to an absolute or relative position :param x: x (m) :param y: y (m) :param z: z (m) :param yaw: yaw (radians) :param duration_s: time it should take to reach th...
python
{ "resource": "" }
q228857
HighLevelCommander.start_trajectory
train
def start_trajectory(self, trajectory_id, time_scale=1.0, relative=False, reversed=False, group_mask=ALL_GROUPS): """ starts executing a specified trajectory :param trajectory_id: id of the trajectory (previously defined by define_trajectory) :par...
python
{ "resource": "" }
q228858
HighLevelCommander.define_trajectory
train
def define_trajectory(self, trajectory_id, offset, n_pieces): """ Define a trajectory that has previously been uploaded to memory. :param trajectory_id: The id of the trajectory :param offset: offset in uploaded memory :param n_pieces: Nr of pieces in the trajectory :ret...
python
{ "resource": "" }
q228859
choose
train
def choose(items, title_text, question_text): """ Interactively choose one of the items. """ print(title_text) for i, item in enumerate(items, start=1): print('%d) %s' % (i, item)) print('%d) Abort' % (i + 1)) selected = input(question_text) try: index = int(selected) ...
python
{ "resource": "" }
q228860
scan
train
def scan(): """ Scan for Crazyflie and return its URI. """ # Initiate the low level drivers cflib.crtp.init_drivers(enable_debug_driver=False) # Scan for Crazyflies print('Scanning interfaces for Crazyflies...') available = cflib.crtp.scan_interfaces() interfaces = [uri for uri, _ ...
python
{ "resource": "" }
q228861
Flasher.connect
train
def connect(self): """ Connect to the crazyflie. """ print('Connecting to %s' % self._link_uri) self._cf.open_link(self._link_uri)
python
{ "resource": "" }
q228862
Flasher.wait_for_connection
train
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 ...
python
{ "resource": "" }
q228863
Flasher.search_memories
train
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)
python
{ "resource": "" }
q228864
RadioBridge._stab_log_data
train
def _stab_log_data(self, timestamp, data, logconf): """Callback froma the log API when data arrives""" print('[%d][%s]: %s' % (timestamp, logconf.name, data))
python
{ "resource": "" }
q228865
PlatformService.fetch_platform_informations
train
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()
python
{ "resource": "" }
q228866
UsbDriver.receive_packet
train
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: ...
python
{ "resource": "" }
q228867
Caller.add_callback
train
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)
python
{ "resource": "" }
q228868
Bootloader.read_cf1_config
train
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)
python
{ "resource": "" }
q228869
Crazyradio.set_channel
train
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
python
{ "resource": "" }
q228870
Crazyradio.set_address
train
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...
python
{ "resource": "" }
q228871
Crazyradio.set_data_rate
train
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
python
{ "resource": "" }
q228872
Crazyradio.set_arc
train
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
python
{ "resource": "" }
q228873
Crazyradio.set_ard_time
train
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...
python
{ "resource": "" }
q228874
TocCache.fetch
train
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: ...
python
{ "resource": "" }
q228875
TocCache.insert
train
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...
python
{ "resource": "" }
q228876
TocCache._encoder
train
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, ...
python
{ "resource": "" }
q228877
TocCache._decoder
train
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']) ...
python
{ "resource": "" }
q228878
LoPoAnchor.set_mode
train
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)
python
{ "resource": "" }
q228879
Swarm.open_links
train
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...
python
{ "resource": "" }
q228880
Swarm.close_links
train
def close_links(self): """ Close all open links """ for uri, cf in self._cfs.items(): cf.close_link() self._is_open = False
python
{ "resource": "" }
q228881
Swarm.sequential
train
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...
python
{ "resource": "" }
q228882
Swarm.parallel_safe
train
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...
python
{ "resource": "" }
q228883
PositionHlCommander.take_off
train
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...
python
{ "resource": "" }
q228884
PositionHlCommander.go_to
train
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...
python
{ "resource": "" }
q228885
Param.request_update_of_all_params
train
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)
python
{ "resource": "" }
q228886
Param._check_if_all_updated
train
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]: ...
python
{ "resource": "" }
q228887
Param._param_updated
train
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: ...
python
{ "resource": "" }
q228888
Param.remove_update_callback
train
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) ...
python
{ "resource": "" }
q228889
Param.add_update_callback
train
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) ...
python
{ "resource": "" }
q228890
Param.refresh_toc
train
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, ...
python
{ "resource": "" }
q228891
Param._disconnected
train
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 = {}
python
{ "resource": "" }
q228892
Param.request_param_update
train
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))
python
{ "resource": "" }
q228893
Param.set_value
train
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...
python
{ "resource": "" }
q228894
_ParamUpdater._new_packet_cb
train
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...
python
{ "resource": "" }
q228895
_ParamUpdater.request_param_update
train
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) ...
python
{ "resource": "" }
q228896
Toc.add_element
train
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
python
{ "resource": "" }
q228897
Toc.get_element_id
train
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...
python
{ "resource": "" }
q228898
Toc.get_element_by_id
train
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...
python
{ "resource": "" }
q228899
TocFetcher.start
train
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 ...
python
{ "resource": "" }