Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
📦 Update AirSim
Browse files Browse the repository at this point in the history
* Update to AirSim version including my contribution (microsoft/AirSim#3475)
* Update controllers according to new version of AirSim
  • Loading branch information
meurissemax committed Mar 25, 2021
1 parent ba03fd7 commit 436577f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
17 changes: 17 additions & 0 deletions python/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,23 @@ def moveByVelocityBodyFrameAsync(self, vx, vy, vz, duration, drivetrain = Drivet
"""
return self.client.call_async('moveByVelocityBodyFrame', vx, vy, vz, duration, drivetrain, yaw_mode, vehicle_name)

def moveByVelocityZBodyFrameAsync(self, vx, vy, z, duration, drivetrain = DrivetrainType.MaxDegreeOfFreedom, yaw_mode = YawMode(), vehicle_name = ''):
"""
Args:
vx (float): desired velocity in the X axis of the vehicle's local NED frame
vy (float): desired velocity in the Y axis of the vehicle's local NED frame
z (float): desired Z value (in local NED frame of the vehicle)
duration (float): Desired amount of time (seconds), to send this command for
drivetrain (DrivetrainType, optional):
yaw_mode (YawMode, optional):
vehicle_name (str, optional): Name of the multirotor to send this command to
Returns:
msgpackrpc.future.Future: future. call .join() to wait for method to finish. Example: client.METHOD().join()
"""

return self.client.call_async('moveByVelocityZBodyFrame', vx, vy, z, duration, drivetrain, yaw_mode, vehicle_name)

def moveByAngleZAsync(self, pitch, roll, z, yaw, duration, vehicle_name = ''):
return self.client.call_async('moveByAngleZ', pitch, roll, z, yaw, duration, vehicle_name)

Expand Down
29 changes: 28 additions & 1 deletion python/airsim/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,41 @@ def from_msgpack(cls, encoded):

class ImageType:
Scene = 0
DepthPlanner = 1
DepthPlanar = 1
DepthPerspective = 2
DepthVis = 3
DisparityNormalized = 4
Segmentation = 5
SurfaceNormals = 6
Infrared = 7

class _ImageType(type):
@property
def Scene(cls):
return 0
def DepthPlanar(cls):
return 1
def DepthPerspective(cls):
return 2
def DepthVis(cls):
return 3
def DisparityNormalized(cls):
return 4
def Segmentation(cls):
return 5
def SurfaceNormals(cls):
return 6
def Infrared(cls):
return 7

def __getattr__(self, key):
if key == 'DepthPlanner':
print('\033[31m'+"DepthPlanner has been (correctly) renamed to DepthPlanar. Please use ImageType.DepthPlanar instead."+'\033[0m')
raise AttributeError

class ImageType(metaclass=_ImageType):
pass

class DrivetrainType:
MaxDegreeOfFreedom = 0
ForwardOnly = 1
Expand Down
28 changes: 8 additions & 20 deletions python/uav/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def takeoff(self):

if landed == airsim.LandedState.Landed:
self.client.takeoffAsync().join()
self.move('down', 80, 50)
self.move('down', 50, 50)

def land(self):
landed = self.state().landed_state
Expand All @@ -153,13 +153,15 @@ def move(self, direction, distance, speed=50.):
speed /= 100
duration = (distance / 100) / speed

z = self.state().kinematics_estimated.position.z_val

directions = {
'up': [0, 0, -speed, duration],
'down': [0, 0, speed, duration],
'left': [0, -speed, 0, duration],
'right': [0, speed, 0, duration],
'forward': [speed, 0, 0, duration],
'back': [-speed, 0, 0, duration]
'left': [0, -speed, z, duration],
'right': [0, speed, z, duration],
'forward': [speed, 0, z, duration],
'back': [-speed, 0, z, duration]
}

factors = directions.get(direction)
Expand All @@ -173,21 +175,7 @@ def move(self, direction, distance, speed=50.):
if direction in ['up', 'down']:
self.client.moveByVelocityBodyFrameAsync(*factors).join()
else:
kinematics = self.state().kinematics_estimated

z = kinematics.position.z_val
q = kinematics.orientation

_, _, yaw = airsim.to_eularian_angles(q)

vx, vy = factors[0], factors[1]

vx_new = vx * np.cos(yaw) - vy * np.sin(yaw)
vy_new = vx * np.sin(yaw) + vy * np.cos(yaw)

factors = [vx_new, vy_new, z, duration]

self.client.moveByVelocityZAsync(*factors).join()
self.client.moveByVelocityZBodyFrameAsync(*factors).join()

def rotate(self, direction, angle):
error = False
Expand Down

0 comments on commit 436577f

Please sign in to comment.