Skip to content

DPKY2.0 Race condition in Vehicle.battery #298

@hamishwillee

Description

@hamishwillee

The vehicle_state.py example fails with

Traceback (most recent call last):
  File "D:\github\dronekit-python\examples\vehicle_state\vehicle_state.py", line 23, in <module>
    print " Battery: %s" % vehicle.battery
  File "build\bdist.win-amd64\egg\droneapi\module\api.py", line 182, in battery
  File "build\bdist.win-amd64\egg\droneapi\lib\__init__.py", line 181, in __init__
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

I think this is is due to a race condition. We are getting the Battery object before it is initialised with a real value. The result is a divide by None error because the default value is set to None in the interface. You can reproduce this using code like below ... and if you uncomment the timer before the print for a few seconds the error does not occur.

from droneapi import connect
from droneapi.lib import VehicleMode
from pymavlink import mavutil
import time

api = connect('127.0.0.1:14550')
vehicle = api.get_vehicles()[0]
#time.sleep(1)
print " Battery: %s" % vehicle.battery
time.sleep(3)
print 'exit'

Note also that on startup all the values are None because they haven't had a chance to initialise with values. I kind of feel we shouldn't return from the vehicle call until we have got some vehicle information ....

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions