Skip to content

Commit e0df750

Browse files
committed
[plotting] add more examples, add docstrings to client.py, omit return vals from client.py
1 parent cbc3727 commit e0df750

2 files changed

Lines changed: 94 additions & 31 deletions

File tree

PythonClient/airsim/client.py

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,79 @@ def simGetLidarSegmentation(self, lidar_name = '', vehicle_name = ''):
167167

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

172182
def simPlotLineStrip(self, points, color_rgba=[1.0, 0.0, 0.0, 0.4], thickness = 5, duration = -1.0, is_persistent = False):
173-
return self.client.call('simPlotLineStrip', points, color_rgba, thickness, duration, is_persistent)
183+
"""
184+
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]
185+
186+
Args:
187+
points (list[Vector3r]): List of 3D locations of line start and end points, specified as Vector3r objects
188+
color_rgba (list, optional): desired RGBA values from 0.0 to 1.0
189+
thickness (int, optional): Thickness of line
190+
duration (float, optional): Duration (seconds) to plot for
191+
is_persistent (bool, optional): If set to True, the desired object will be plotted for infinite time.
192+
"""
193+
self.client.call('simPlotLineStrip', points, color_rgba, thickness, duration, is_persistent)
174194

175195
def simPlotLineList(self, points, color_rgba=[1.0, 0.0, 0.0, 0.4], thickness = 5, duration = -1.0, is_persistent = False):
176-
return self.client.call('simPlotLineList', points, color_rgba, thickness, duration, is_persistent)
196+
"""
197+
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]
198+
199+
Args:
200+
points (list[Vector3r]): List of 3D locations of line start and end points, specified as Vector3r objects. Must be even
201+
color_rgba (list, optional): desired RGBA values from 0.0 to 1.0
202+
thickness (int, optional): Thickness of line
203+
duration (float, optional): Duration (seconds) to plot for
204+
is_persistent (bool, optional): If set to True, the desired object will be plotted for infinite time.
205+
"""
206+
self.client.call('simPlotLineList', points, color_rgba, thickness, duration, is_persistent)
177207

178208
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):
179-
return self.client.call('simPlotArrowList', points_start, points_end, color_rgba, thickness, arrow_size, duration, is_persistent)
209+
"""
210+
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]
211+
212+
Args:
213+
points_start (list[Vector3r]): List of 3D start positions of arrow start positions, specified as Vector3r objects
214+
points_end (list[Vector3r]): List of 3D end positions of arrow start positions, specified as Vector3r objects
215+
color_rgba (list, optional): desired RGBA values from 0.0 to 1.0
216+
thickness (int, optional): Thickness of line
217+
arrow_size (int, optional): Size of arrow head
218+
duration (float, optional): Duration (seconds) to plot for
219+
is_persistent (bool, optional): If set to True, the desired object will be plotted for infinite time.
220+
"""
221+
self.client.call('simPlotArrowList', points_start, points_end, color_rgba, thickness, arrow_size, duration, is_persistent)
180222

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

184235
# 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):
185-
# return self.client.call('simPlotTransformAndNames', poses, names, tf_scale, text_scale, duration, is_persistent)
236+
# self.client.call('simPlotTransformAndNames', poses, names, tf_scale, text_scale, duration, is_persistent)
186237

187238
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):
188-
return self.client.call('simPlotStrings', positions, strings, scale, color_rgba, duration, is_persistent)
239+
self.client.call('simPlotStrings', positions, strings, scale, color_rgba, duration, is_persistent)
189240

190241
# 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):
191-
# return self.client.call('simPlotStringOnActor', positions, strings, scale, actor_name, color_rgba, duration, is_persistent)
242+
# self.client.call('simPlotStringOnActor', positions, strings, scale, actor_name, color_rgba, duration, is_persistent)
192243

193244
#----------- APIs to control ACharacter in scene ----------/
194245
def simCharSetFaceExpression(self, expression_name, value, character_name = ""):
Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,48 @@
11
import setup_path
22
import airsim
3-
from airsim import Vector3r
3+
from airsim import Vector3r, Quaternionr, Pose
4+
from airsim.utils import to_quaternion
45
import numpy as np
6+
import time
57

68
client = airsim.VehicleClient()
79
client.confirmConnection()
810

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

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

21-
# plot 2 red arrows for 5 seconds
22-
arrow_1_start, arrow_2_start = Vector3r(1,1,-2), Vector3r(1,1,-4)
23-
arrow_1_end, arrow_2_end = Vector3r(-4,-4,-2), Vector3r(-2,-2,-4)
24-
client.simPlotArrowList(points_start = [arrow_1_start, arrow_2_start], points_end = [arrow_1_end, arrow_2_end],
25-
color_rgba = [1.0, 0.0, 0.0, 1.0], duration = 5.0, arrow_size = 20, thickness = 2)
21+
# plot red arrows for 10 seconds
22+
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))],
23+
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))],
24+
color_rgba = [1.0, 0.0, 0.0, 1.0], duration = 10.0, arrow_size = 100, thickness = 5)
2625

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

3331
# plot points
34-
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)
35-
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)
36-
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)
32+
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)
33+
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)
34+
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)
35+
36+
# plot line strip. 0-1, 1-2, 2-3
37+
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)
38+
39+
# plot line list. 0-1, 2-3, 4-5. Must be even.
40+
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)
41+
42+
# plot transforms
43+
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))],
44+
scale = 35, thickness = 5, duration = 10.0, is_persistent = False)
45+
46+
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))],
47+
scale = 35, thickness = 5, duration = 10.0, is_persistent = False)
48+

0 commit comments

Comments
 (0)