in resources/drone_orbit.py [0:0]
def __init__(self, photo_prefix="photo_", radius=2, altitude=10, speed=2, iterations=1, center=[1, 0], snapshots=None, image_dir="./images/"):
self.radius = radius
self.altitude = altitude
self.speed = speed
self.iterations = iterations
self.snapshots = snapshots
self.snapshot_delta = None
self.next_snapshot = None
self.image_dir = image_dir
self.z = None
self.snapshot_index = 0
self.photo_prefix = photo_prefix
self.takeoff = True # whether we did a take off
if self.snapshots is not None and self.snapshots > 0:
self.snapshot_delta = 360 / self.snapshots
if self.iterations <= 0:
self.iterations = 1
if len(center) != 2:
raise Exception(
"Expecting '[x,y]' for the center direction vector")
# center is just a direction vector, so normalize it to compute the actual cx,cy locations.
cx = float(center[0])
cy = float(center[1])
length = math.sqrt((cx*cx)+(cy*cy))
cx /= length
cy /= length
cx *= self.radius
cy *= self.radius
self.client = airsim.MultirotorClient()
self.client.confirmConnection()
self.client.enableApiControl(True)
self.home = self.client.getMultirotorState().kinematics_estimated.position
# check that our home position is stable
start = time.time()
count = 0
while count < 100:
pos = self.home
if abs(pos.z_val - self.home.z_val) > 1:
count = 0
self.home = pos
if time.time() - start > 10:
print(
"Drone position is drifting, we are waiting for it to settle down...")
start = time
else:
count += 1
self.center = self.client.getMultirotorState().kinematics_estimated.position
self.center.x_val += cx
self.center.y_val += cy