Repository navigation
Closed
Description
Bikeshedding time~~~!
I feel like we want a method .await([types], defaults=True) that does the following:
- Waits for system_status to enter an initialized state. This is equivalent to a
.notify_changeevent on"initialized". (included by default when defaults=True) - Waits for parameters to be loaded. This is equivalent to a
.notify_changeevent on"parameters". (included by default when defaults=True) - Waits for what other defaults? (Armed? Mode? etc.)
- Waits for an arbitrary list of
.notify_changeevents. This encompasses attributes.
So an example vehicle state example may be:
vehicle = connect('127.0.0.1:14550')
vehicle.await(['location', 'attitude', 'velocity', 'gps_0', 'groundspeed',
'airspeed', 'mount_status', 'battery', 'rangefinder', 'mode', 'armed'])
print " Location: %s" % vehicle.location
print " Attitude: %s" % vehicle.attitude
print " Velocity: %s" % vehicle.velocity
print " GPS: %s" % vehicle.gps_0
print " Groundspeed: %s" % vehicle.groundspeed
print " Airspeed: %s" % vehicle.airspeed
print " Mount status: %s" % vehicle.mount_status
print " Battery: %s" % vehicle.battery
print " Rangefinder: %s" % vehicle.rangefinder
print " Rangefinder distance: %s" % vehicle.rangefinder.distance
print " Rangefinder voltage: %s" % vehicle.rangefinder.voltage
print " Mode: %s" % vehicle.mode.name # settable
print " Armed: %s" % vehicle.armed # settableWow, what a verbose function! But does it make sense? We want to ensure these values are populated. But this example then doesn't scale if we are always waiting for a rangefinder event that doesn't happen. Maybe we want to await a selection of always-on parameters, then time-await a selection of properties that may be optional?
vehicle = connect('127.0.0.1:14550')
vehicle.await(['location', 'attitude', 'velocity', 'gps_0', 'groundspeed',
'airspeed', 'mode', 'armed'])
print " Location: %s" % vehicle.location
print " Attitude: %s" % vehicle.attitude
print " Velocity: %s" % vehicle.velocity
print " GPS: %s" % vehicle.gps_0
print " Groundspeed: %s" % vehicle.groundspeed
print " Airspeed: %s" % vehicle.airspeed
print " Mode: %s" % vehicle.mode.name # settable
print " Armed: %s" % vehicle.armed # settable
# optional params
time.sleep(3)
print " Mount status: %s" % vehicle.mount_status
print " Battery: %s" % vehicle.battery
print " Rangefinder: %s" % vehicle.rangefinder
print " Rangefinder distance: %s" % vehicle.rangefinder.distance
print " Rangefinder voltage: %s" % vehicle.rangefinder.voltageWe can also consider the .await() method to be aliased in the connect function as so:
vehicle = connect('127.0.0.1:14550', await=['location', 'attitude', 'velocity'])(In this case, how do you disable defaults?)
Activity
mrpollo commentedon Oct 14, 2015
I like this approach, we should also consider adding a timeout to await so it's useful on other "optional" params
BTW the
raise_exceptionportion is not mandatory, just trying to figure out how to fail if timeout time exceededhamishwillee commentedon Oct 14, 2015
My two bits:
Thoughts/concerns
tcr3dr commentedon Nov 3, 2015
The PR #401 implements a method
vehicle.wait_ready(attr1, attr2, ..., timeout=30, raise_exception=True)From the initialization of the vehicle, we keep an ongoing list of what attributes have been emitted via the notification listener. wait_ready sees if those have been triggered, and if not, waits for them (up to a timeout, which can be None). For example:
await_parambehavior is now expressed in terms ofwait_ready('gps_0', 'parameters').wait_ready('parameters')would return instantly.etc. Note that certain attributes can become un-ready, or expire, such as "commands" and e.g. "link_alive" (if it were implemented). These are removed for the attribute record and we wait for the notification to be sent again in the loop. This seemed like the most intuitive behavior for invalidation.
We can also expose it as a parameter in connect(), if we want. I think the duplication is worth it.
Idiomatically, we should also define what
connect(wait_ready=True)does in terms of "default" values. My reasoning: we can standardize on.commands.download(wait_ready=True)to reduce the number of duplicate calls to download + wait_ready on the commands object. The semantics for the keyword argument would then be the same across objects and the whole codebase.hamishwillee commentedon Nov 3, 2015
That meets all the points I had.
With respect to mirroring in
connect()and standardized idioms good idea. Not sure what the default set should be but minimally mode, armed, attitude. Possibly gps. This is the set that comes first (doesn't have to wait on anything like takeoff), and I am fairly sure will be output for every device.The good news is, if the defaults are wrong, we will easily be able to tune this by doing
wait_readyafterwards on just a couple of vehicle-specific things.tcr3dr commentedon Nov 7, 2015
Going to close this tracking issue as support has been landed (>= rc7).