MCPcopy Create free account
hub / github.com/bitcraze/crazyflie-lib-python / Param

Class Param

cflib/crazyflie/param.py:112–279  ·  view source on GitHub ↗

Used to read and write parameter values in the Crazyflie.

Source from the content-addressed store, hash-verified

110
111
112class Param():
113 """
114 Used to read and write parameter values in the Crazyflie.
115 """
116
117 def __init__(self, crazyflie):
118 self.toc = Toc()
119
120 self.cf = crazyflie
121 self._useV2 = False
122 self.param_update_callbacks = {}
123 self.group_update_callbacks = {}
124 self.all_update_callback = Caller()
125 self.param_updater = None
126
127 self.param_updater = _ParamUpdater(
128 self.cf, self._useV2, self._param_updated)
129 self.param_updater.start()
130
131 self.cf.disconnected.add_callback(self._disconnected)
132
133 self.all_updated = Caller()
134 self.is_updated = False
135
136 self.values = {}
137
138 def request_update_of_all_params(self):
139 """Request an update of all the parameters in the TOC"""
140 for group in self.toc.toc:
141 for name in self.toc.toc[group]:
142 complete_name = '%s.%s' % (group, name)
143 self.request_param_update(complete_name)
144
145 def _check_if_all_updated(self):
146 """Check if all parameters from the TOC has at least been fetched
147 once"""
148 for g in self.toc.toc:
149 if g not in self.values:
150 return False
151 for n in self.toc.toc[g]:
152 if n not in self.values[g]:
153 return False
154
155 return True
156
157 def _param_updated(self, pk):
158 """Callback with data for an updated parameter"""
159 if self._useV2:
160 var_id = struct.unpack('<H', pk.data[:2])[0]
161 else:
162 var_id = pk.data[0]
163 element = self.toc.get_element_by_id(var_id)
164 if element:
165 if self._useV2:
166 s = struct.unpack(element.pytype, pk.data[2:])[0]
167 else:
168 s = struct.unpack(element.pytype, pk.data[1:])[0]
169 s = s.__str__()

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected