Skip to content

Commit

Permalink
[plotting] add more examples, add docstrings to client.py, omit retur…
Browse files Browse the repository at this point in the history
…n vals from client.py
  • Loading branch information
madratman committed Nov 11, 2019
1 parent cbc3727 commit e0df750
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 31 deletions.
67 changes: 59 additions & 8 deletions PythonClient/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,79 @@ def simGetLidarSegmentation(self, lidar_name = '', vehicle_name = ''):

# Plotting APIs
def simPlotPoints(self, points, color_rgba=[1.0, 0.0, 0.0, 0.4], size = 10, duration = -1.0, is_persistent = False):
return self.client.call('simPlotPoints', points, color_rgba, size, duration, is_persistent)
"""
Plot a list of 3D points in World NED frame
Args:
points (list[Vector3r]): List of Vector3r objects
color_rgba (list, optional): desired RGBA values from 0.0 to 1.0
size (int, optional): Size of plotted point
duration (float, optional): Duration (seconds) to plot for
is_persistent (bool, optional): If set to True, the desired object will be plotted for infinite time.
"""
self.client.call('simPlotPoints', points, color_rgba, size, duration, is_persistent)

def simPlotLineStrip(self, points, color_rgba=[1.0, 0.0, 0.0, 0.4], thickness = 5, duration = -1.0, is_persistent = False):
return self.client.call('simPlotLineStrip', points, color_rgba, thickness, duration, is_persistent)
"""
Plots a line strip in World NED frame, defined from points[0] to points[1], points[1] to points[2], ... , points[n-2] to points[n-1]
Args:
points (list[Vector3r]): List of 3D locations of line start and end points, specified as Vector3r objects
color_rgba (list, optional): desired RGBA values from 0.0 to 1.0
thickness (int, optional): Thickness of line
duration (float, optional): Duration (seconds) to plot for
is_persistent (bool, optional): If set to True, the desired object will be plotted for infinite time.
"""
self.client.call('simPlotLineStrip', points, color_rgba, thickness, duration, is_persistent)

def simPlotLineList(self, points, color_rgba=[1.0, 0.0, 0.0, 0.4], thickness = 5, duration = -1.0, is_persistent = False):
return self.client.call('simPlotLineList', points, color_rgba, thickness, duration, is_persistent)
"""
Plots a line strip in World NED frame, defined from points[0] to points[1], points[2] to points[3], ... , points[n-2] to points[n-1]
Args:
points (list[Vector3r]): List of 3D locations of line start and end points, specified as Vector3r objects. Must be even
color_rgba (list, optional): desired RGBA values from 0.0 to 1.0
thickness (int, optional): Thickness of line
duration (float, optional): Duration (seconds) to plot for
is_persistent (bool, optional): If set to True, the desired object will be plotted for infinite time.
"""
self.client.call('simPlotLineList', points, color_rgba, thickness, duration, is_persistent)

def simPlotArrowList(self, points_start, points_end, color_rgba=[1.0, 0.0, 0.0, 0.4], thickness = 5, arrow_size = 2, duration = -1.0, is_persistent = False):
return self.client.call('simPlotArrowList', points_start, points_end, color_rgba, thickness, arrow_size, duration, is_persistent)
"""
Plots a list of arrows in World NED frame, defined from points_start[0] to points_end[0], points_start[1] to points_end[1], ... , points_start[n-1] to points_end[n-1]
Args:
points_start (list[Vector3r]): List of 3D start positions of arrow start positions, specified as Vector3r objects
points_end (list[Vector3r]): List of 3D end positions of arrow start positions, specified as Vector3r objects
color_rgba (list, optional): desired RGBA values from 0.0 to 1.0
thickness (int, optional): Thickness of line
arrow_size (int, optional): Size of arrow head
duration (float, optional): Duration (seconds) to plot for
is_persistent (bool, optional): If set to True, the desired object will be plotted for infinite time.
"""
self.client.call('simPlotArrowList', points_start, points_end, color_rgba, thickness, arrow_size, duration, is_persistent)

def simPlotTransform(self, poses, scale = 5, thickness = 5, duration = -1.0, is_persistent = False):
return self.client.call('simPlotTransform', poses, scale, thickness, duration, is_persistent)
"""Summary
Args:
poses (list[Pose]): List of Pose objects representing the transforms to plot
scale (int, optional): Length of transform axes
thickness (int, optional): Thickness of lines
duration (float, optional): Duration (seconds) to plot for
is_persistent (bool, optional): If set to True, the desired object will be plotted for infinite time.
"""
self.client.call('simPlotTransform', poses, scale, thickness, duration, is_persistent)

# def simPlotTransformAndNames(self, poses, names, tf_scale = 5, text_scale = 10, text_color = [1.0, 0.0, 0.0, 0.4], thickness = 5, duration = -1.0, is_persistent = False):
# return self.client.call('simPlotTransformAndNames', poses, names, tf_scale, text_scale, duration, is_persistent)
# self.client.call('simPlotTransformAndNames', poses, names, tf_scale, text_scale, duration, is_persistent)

def simPlotStrings(self, positions, strings = ["Microsoft", "AirSim"], scale = 5, color_rgba=[1.0, 0.0, 0.0, 0.4], duration = -1.0, is_persistent = False):
return self.client.call('simPlotStrings', positions, strings, scale, color_rgba, duration, is_persistent)
self.client.call('simPlotStrings', positions, strings, scale, color_rgba, duration, is_persistent)

# def simPlotStringOnActor(self, positions, strings = ["Microsoft", "AirSim"], actor_name = "", scale = 5, color_rgba=[1.0, 0.0, 0.0, 0.4], duration = -1.0, is_persistent = False):
# return self.client.call('simPlotStringOnActor', positions, strings, scale, actor_name, color_rgba, duration, is_persistent)
# self.client.call('simPlotStringOnActor', positions, strings, scale, actor_name, color_rgba, duration, is_persistent)

#----------- APIs to control ACharacter in scene ----------/
def simCharSetFaceExpression(self, expression_name, value, character_name = ""):
Expand Down
58 changes: 35 additions & 23 deletions PythonClient/computer_vision/plot_markers.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
import setup_path
import airsim
from airsim import Vector3r
from airsim import Vector3r, Quaternionr, Pose
from airsim.utils import to_quaternion
import numpy as np
import time

client = airsim.VehicleClient()
client.confirmConnection()

# plot 2 red arrows for 3 seconds
arrow_1_start, arrow_2_start = Vector3r(0,0,-1), Vector3r(0,0,-3)
arrow_1_end, arrow_2_end = Vector3r(1,1,-1), Vector3r(2,2,-3)
client.simPlotArrowList(points_start = [arrow_1_start, arrow_2_start], points_end = [arrow_1_end, arrow_2_end],
color_rgba = [1.0, 0.0, 1.0, 1.0], duration = 3.0, arrow_size = 20, thickness = 4)
# plot red arrows for 30 seconds
client.simPlotArrowList(points_start = [Vector3r(x,y,0) for x, y in zip(np.linspace(0,10,20), np.linspace(0,0,20))],
points_end = [Vector3r(x,y,0) for x, y in zip(np.linspace(0,10,20), np.linspace(10,10,20))],
color_rgba = [1.0, 0.0, 1.0, 1.0], duration = 30.0, arrow_size = 10, thickness = 1)

# plot 2 yellow arrows for 4 seconds
arrow_1_start, arrow_2_start = Vector3r(0,1,-1), Vector3r(0,1,-3)
arrow_1_end, arrow_2_end = Vector3r(4,5,-1), Vector3r(2,3,-3)
client.simPlotArrowList(points_start = [arrow_1_start, arrow_2_start], points_end = [arrow_1_end, arrow_2_end],
color_rgba = [1.0, 1.0, 0.0, 1.0], duration = 4.0, arrow_size = 20, thickness = 3)
# plot magenta arrows for 15 seconds
client.simPlotArrowList(points_start = [Vector3r(x,y,-3) for x, y in zip(np.linspace(0,10,20), np.linspace(0,0,20))],
points_end = [Vector3r(x,y,-5) for x, y in zip(np.linspace(0,10,20), np.linspace(10,20,20))],
color_rgba = [1.0, 1.0, 0.0, 1.0], duration = 15.0, arrow_size = 20, thickness = 3)

# plot 2 red arrows for 5 seconds
arrow_1_start, arrow_2_start = Vector3r(1,1,-2), Vector3r(1,1,-4)
arrow_1_end, arrow_2_end = Vector3r(-4,-4,-2), Vector3r(-2,-2,-4)
client.simPlotArrowList(points_start = [arrow_1_start, arrow_2_start], points_end = [arrow_1_end, arrow_2_end],
color_rgba = [1.0, 0.0, 0.0, 1.0], duration = 5.0, arrow_size = 20, thickness = 2)
# plot red arrows for 10 seconds
client.simPlotArrowList(points_start = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(0,0,20), np.linspace(-3,-10, 20))],
points_end = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(10,20,20), np.linspace(-5,-8, 20))],
color_rgba = [1.0, 0.0, 0.0, 1.0], duration = 10.0, arrow_size = 100, thickness = 5)

# plot 2 white arrows which are persistent
arrow_1_start, arrow_2_start = Vector3r(2,2,-2), Vector3r(0,1,-4)
arrow_1_end, arrow_2_end = Vector3r(2,3,-2), Vector3r(2,4,-4)
client.simPlotArrowList(points_start = [arrow_1_start, arrow_2_start], points_end = [arrow_1_end, arrow_2_end],
color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 5.0, arrow_size = 20, thickness = 10, is_persistent = True)
client.simPlotArrowList(points_start = [Vector3r(x,y,-2) for x, y in zip(np.linspace(0,10,20), np.linspace(0,20,20))],
points_end = [Vector3r(x,y,-5) for x, y in zip(np.linspace(3,17,20), np.linspace(5,28,20))],
color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 5.0, arrow_size = 100, thickness = 1, is_persistent = True)

# plot points
client.simPlotPoints(points = [Vector3r(x,y,-2) for x, y in zip(np.linspace(0,10,20), np.linspace(0,20,20))], color_rgba=[1.0, 0.0, 0.0, 1.0], size = 20, duration = 20.0, is_persistent = False)
client.simPlotPoints(points = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,-10,20), np.linspace(0,-20,20), np.linspace(0,-5,20))], color_rgba=[0.0, 0.0, 1.0, 1.0], size = 10, duration = 20.0, is_persistent = False)
client.simPlotPoints(points = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(0,-20,20), np.linspace(0,-7,20))], color_rgba=[1.0, 0.0, 1.0, 1.0], size = 15, duration = 20.0, is_persistent = False)
client.simPlotPoints(points = [Vector3r(x,y,-5) for x, y in zip(np.linspace(0,-10,20), np.linspace(0,-20,20))], color_rgba=[1.0, 0.0, 0.0, 1.0], size = 25, duration = 20.0, is_persistent = False)
client.simPlotPoints(points = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,-10,20), np.linspace(0,-20,20), np.linspace(0,-5,20))], color_rgba=[0.0, 0.0, 1.0, 1.0], size = 10, duration = 20.0, is_persistent = False)
client.simPlotPoints(points = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(0,-20,20), np.linspace(0,-7,20))], color_rgba=[1.0, 0.0, 1.0, 1.0], size = 15, duration = 20.0, is_persistent = False)

# plot line strip. 0-1, 1-2, 2-3
client.simPlotLineStrip(points = [Vector3r(x,y,-5) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))], color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5, duration = 30.0, is_persistent = False)

# plot line list. 0-1, 2-3, 4-5. Must be even.
client.simPlotLineList(points = [Vector3r(x,y,-7) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))], color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5, duration = 30.0, is_persistent = False)

# plot transforms
client.simPlotTransform(poses = [Pose(position_val=Vector3r(x,y,-7), orientation_val=to_quaternion(pitch=0.0, roll=0.0, yaw=np.pi/2)) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))],
scale = 35, thickness = 5, duration = 10.0, is_persistent = False)

client.simPlotTransform(poses = [Pose(position_val=Vector3r(x,y,-5), orientation_val=to_quaternion(pitch=0.0, roll=0.0, yaw=0.0)) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))],
scale = 35, thickness = 5, duration = 10.0, is_persistent = False)

0 comments on commit e0df750

Please sign in to comment.