Skip to content

Commit

Permalink
update py docs and other examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Aug 29, 2017
1 parent af62c60 commit 9909c32
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 316 deletions.
24 changes: 15 additions & 9 deletions PythonClient/PythonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class Vector3r(MsgpackMixin):
y_val = np.float32(0)
z_val = np.float32(0)

def __init__(self, x_val = np.float32(0), y_val = np.float32(0), z_val = np.float32(0)):
self.x_val = x_val
self.y_val = y_val
self.z_val = z_val


class Quaternionr(MsgpackMixin):
w_val = np.float32(0)
x_val = np.float32(0)
Expand Down Expand Up @@ -232,10 +238,10 @@ def simSetPose(self, position, orientation):
# https:#en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
@staticmethod
def toEulerianAngle(q):
z = q[0]
y = q[1]
x = q[2]
w = q[3]
z = q.z_val
y = q.y_val
x = q.x_val
w = q.w_val
ysqr = y * y

# roll (x-axis rotation)
Expand All @@ -260,18 +266,18 @@ def toEulerianAngle(q):

@staticmethod
def toQuaternion(pitch, roll, yaw):
q = [0, 0, 0, 0]
t0 = math.cos(yaw * 0.5)
t1 = math.sin(yaw * 0.5)
t2 = math.cos(roll * 0.5)
t3 = math.sin(roll * 0.5)
t4 = math.cos(pitch * 0.5)
t5 = math.sin(pitch * 0.5)

q[3] = t0 * t2 * t4 + t1 * t3 * t5 #w
q[2] = t0 * t3 * t4 - t1 * t2 * t5 #x
q[1] = t0 * t2 * t5 + t1 * t3 * t4 #y
q[0] = t1 * t2 * t4 - t0 * t3 * t5 #z
q = Quaternionr()
q.w_val = t0 * t2 * t4 + t1 * t3 * t5 #w
q.x_val = t0 * t3 * t4 - t1 * t2 * t5 #x
q.y_val = t0 * t2 * t5 + t1 * t3 * t4 #y
q.z_val = t1 * t2 * t4 - t0 * t3 * t5 #z
return q

@staticmethod
Expand Down
8 changes: 1 addition & 7 deletions PythonClient/PythonClient.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>e2049e20-b6dd-474e-8bca-1c8dc54725aa</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>navigate.py</StartupFile>
<StartupFile>hello_drone.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
Expand All @@ -28,9 +28,6 @@
<Compile Include="camera.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="generate_stereo_data.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="hello_drone.py">
<SubType>Code</SubType>
</Compile>
Expand All @@ -42,9 +39,6 @@
</Compile>
<Compile Include="pfm.py" />
<Compile Include="PythonClient.py" />
<Compile Include="takeoff.py">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand Down
7 changes: 6 additions & 1 deletion PythonClient/camera.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# use open cv to show new images from AirSim

from PythonClient import *
# requires Python 3.5.3 :: Anaconda 4.4.0
# pip install opencv-python
import cv2
import time
import sys
Expand Down Expand Up @@ -29,6 +31,9 @@ def printUsage():
print (cameraTypeMap[cameraType])

client = AirSimClient('127.0.0.1')
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

help = False

Expand All @@ -49,7 +54,7 @@ def printUsage():
print("Camera is not returning image, please check airsim for error messages")
sys.exit(0)
else:
png = cv2.imdecode(rawImage, cv2.IMREAD_UNCHANGED)
png = cv2.imdecode(AirSimClient.stringToUint8Array(rawImage), cv2.IMREAD_UNCHANGED)
cv2.putText(png,'FPS ' + str(fps),textOrg, fontFace, fontScale,(255,0,255),thickness)
cv2.imshow("Depth", png)

Expand Down
160 changes: 0 additions & 160 deletions PythonClient/generate_stereo_data.py

This file was deleted.

3 changes: 3 additions & 0 deletions PythonClient/hello_drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
AirSimClient.wait_key('Press any key to takeoff')
client.takeoff()

AirSimClient.wait_key('Press any key to move vehicle to (-10, 10, -10) at 5 m/s')
client.moveToPosition(-10, 10, -10, 5)

AirSimClient.wait_key('Press any key to take images')
responses = client.simGetImages([
ImageRequest(0, AirSimImageType.DepthVis),
Expand Down
11 changes: 7 additions & 4 deletions PythonClient/navigate.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# use open cv to show new images from AirSim

from PythonClient import *
# requires Python 3.5.3 :: Anaconda 4.4.0
# pip install opencv-python
import cv2
import time
import math
import sys

client = AirSimClient('127.0.0.1')
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

# you must first press "1" in the AirSim view to turn on the depth capture

# get depth image
client.setImageTypeForCamera(0, AirSimImageType.Depth)
time.sleep(1) # give it time to render
yaw = 0
pi = 3.14159265483
vx = 0
Expand All @@ -22,7 +25,7 @@

while True:
# this will return png width= 256, height= 144
result = client.simGetImage(0, AirSimImageType.Depth)
result = client.simGetImage(0, AirSimImageType.DepthVis)
if (result == "\0"):
if (not help):
help = True
Expand Down Expand Up @@ -81,7 +84,7 @@
vy = math.sin(yaw);

print ("distance=", current)
client.moveByVelocityZ(vx, vy,-6, 1, DrivetrainType.ForwardOnly, YawMode(False, 0)).get()
client.moveByVelocityZ(vx, vy,-6, 1, DrivetrainType.ForwardOnly, YawMode(False, 0))

x = int(driving * 50)
cv2.rectangle(png, (x,0), (x+50,50), (0,255,0), 2)
Expand Down
7 changes: 6 additions & 1 deletion PythonClient/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import time

client = AirSimClient('127.0.0.1')
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

# AirSim uses NED coordinates so negative axis is up.
# z of -5 is 5 meters above the original launch point.
Expand All @@ -12,4 +15,6 @@

# this method is async and we are not waiting for the result since we are passing max_wait_seconds=0.
print("client.moveOnPath to fly fast path along the streets")
result = client.moveOnPath([(0,-253,z),(125,-253,z),(125,0,z),(0,0,z)], 15, 0, DrivetrainType.ForwardOnly, YawMode(False,0), 20, 1)
result = client.moveOnPath([Vector3r(0,-253,z),Vector3r(125,-253,z),Vector3r(125,0,z),Vector3r(0,0,z)],
15, 60,
DrivetrainType.ForwardOnly, YawMode(False,0), 20, 1)
33 changes: 0 additions & 33 deletions PythonClient/takeoff.py

This file was deleted.

Loading

0 comments on commit 9909c32

Please sign in to comment.