I'm using the DroneKit API in Python for controlling a drone using a companion computer. I'm trying to create a class, Vehicle, which inherits from the Vehicle class in DroneKit. The purpose of this class is for me to override some methods present in DroneKit that don't work with PX4 as well as adding a few methods of my own, whilst still having access to all of the methods available by default.
The issue is that you don't create a Vehicle object directly using Dronekit – you call the connect() function which return a Vehicle object.
My question is, how do I create an instance of my class?
The accepted method seems to be to call the parent init(), like so:
class Vehicle(dronekit_Vehicle):
def __init__(self, stuff):
dronekit_Vehicle.__init__(stuff)
But like I said, you don't create a Vehicle object directly in Dronekit, e.g. vehicle = Vehicle(stuff), but by vehicle = connect(stuff), which eventually returns a Vehicle object but also does a bunch of other stuff.
The only way I can think of is
class Vehicle(dronekit_Vehicle):
def __init__(self, stuff):
self.vehicle = connect(stuff)
And then having to use self.vehicle.function() to access the default DroneKit commands and attributes, which is a huge pain.
How do I make this work?