Waits for specified attributes to be populated from the vehicle (values are initially ``None``). This is typically called "behind the scenes" to ensure that :py:func:`connect` does not return until attributes have populated (via the ``wait_ready`` parameter). You can also u
(self, *types, **kwargs)
| 2147 | vehicle.send_mavlink(capability_msg) |
| 2148 | |
| 2149 | def wait_ready(self, *types, **kwargs): |
| 2150 | """ |
| 2151 | Waits for specified attributes to be populated from the vehicle (values are initially ``None``). |
| 2152 | |
| 2153 | This is typically called "behind the scenes" to ensure that :py:func:`connect` does not return until |
| 2154 | attributes have populated (via the ``wait_ready`` parameter). You can also use it after connecting to |
| 2155 | wait on a specific value(s). |
| 2156 | |
| 2157 | There are two ways to call the method: |
| 2158 | |
| 2159 | .. code-block:: python |
| 2160 | |
| 2161 | #Wait on default attributes to populate |
| 2162 | vehicle.wait_ready(True) |
| 2163 | |
| 2164 | #Wait on specified attributes (or array of attributes) to populate |
| 2165 | vehicle.wait_ready('mode','airspeed') |
| 2166 | |
| 2167 | Using the ``wait_ready(True)`` waits on :py:attr:`parameters`, :py:attr:`gps_0`, |
| 2168 | :py:attr:`armed`, :py:attr:`mode`, and :py:attr:`attitude`. In practice this usually |
| 2169 | means that all supported attributes will be populated. |
| 2170 | |
| 2171 | By default, the method will timeout after 30 seconds and raise an exception if the |
| 2172 | attributes were not populated. |
| 2173 | |
| 2174 | :param types: ``True`` to wait on the default set of attributes, or a |
| 2175 | comma-separated list of the specific attributes to wait on. |
| 2176 | :param int timeout: Timeout in seconds after which the method will raise an exception |
| 2177 | (the default) or return ``False``. The default timeout is 30 seconds. |
| 2178 | :param Boolean raise_exception: If ``True`` the method will raise an exception on timeout, |
| 2179 | otherwise the method will return ``False``. The default is ``True`` (raise exception). |
| 2180 | """ |
| 2181 | timeout = kwargs.get('timeout', 30) |
| 2182 | raise_exception = kwargs.get('raise_exception', True) |
| 2183 | |
| 2184 | # Vehicle defaults for wait_ready(True) or wait_ready() |
| 2185 | if list(types) == [True] or list(types) == []: |
| 2186 | types = self._default_ready_attrs |
| 2187 | |
| 2188 | if not all(isinstance(item, basestring) for item in types): |
| 2189 | raise APIException('wait_ready expects one or more string arguments.') |
| 2190 | |
| 2191 | # Wait for these attributes to have been set. |
| 2192 | await = set(types) |
| 2193 | start = monotonic.monotonic() |
| 2194 | while not await.issubset(self._ready_attrs): |
| 2195 | time.sleep(0.1) |
| 2196 | if monotonic.monotonic() - start > timeout: |
| 2197 | if raise_exception: |
| 2198 | raise APIException('wait_ready experienced a timeout after %s seconds.' % |
| 2199 | timeout) |
| 2200 | else: |
| 2201 | return False |
| 2202 | |
| 2203 | return True |
| 2204 | |
| 2205 | |
| 2206 | class Gimbal(object): |