AirSim学习日志 8-画图API

之前写轨迹跟踪代码的时候用到了AirSim的绘图API,但是实际上没弄清楚几个API的功能,代码是能跑就算成功。今天专门学习整理一下绘图相关的API。

在编辑器中输入client.simplot后,检索到相关的函数如下:

image-20220708101139346

画线simPlotLineList
def simPlotLineList(self, points, color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5.0, duration = -1.0, is_persistent = False)

client.py文件中对该函数的解释是:

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]

也就是在全局坐标系(NED,北东地)下,按 P 0 − P 1 , P 2 − P 3 , ⋅ ⋅ ⋅ P0-P1,P2-P3,··· P0P1,P2P3,的顺序画线。

  • 参数points的类型为list[Vector3r],为要绘制的点,由包含三维坐标信息的airsim.Vector3r组成的列表,且必须为偶数个点。
  • 参数color_rgba的类型为list,分别为RGB通道和不透明度,值范围为0-1。
  • 参数thickness的类型为float,表示线条粗细。
  • 参数duration的类型为float,表示绘制的持续时间。
  • 参数is_persistent的类型为bool,如果为真,则将在无限时间内绘制。

前三个参数比较好理解,但是后两个参数的解释就不太清楚了。我自己去仿真环境里跑一下才知道,这两个参数说的是绘图在场景中存留的时间,如果is_persistent为真,则绘图会一直存在(除非手动设置擦除绘图);如果is_persistent为假,则要看参数duration,它的值表示绘图在场景中存留的时间长短。

image-20220708104351938

(simPlotLineList绘制,四个点画出两条线)
画线simPlotLineStrip
def simPlotLineStrip(self, points, color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5.0, duration = -1.0, is_persistent = False)

client.py文件中对该函数的解释是:

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]

与上面的simPlotLineList只有一个不同,它的画线是按 P 0 − P 1 , P 1 − P 2 , ⋅ ⋅ ⋅ P0-P1,P1-P2,··· P0P1,P1P2,的顺序,是连续的。函数参数的含义也都与simPlotLineList一致。

image-20220708104327101

(simPlotLineStrip绘制,四个点画出三条线)
画箭头simPlotArrows
def simPlotArrows(self, points_start, points_end, color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5.0, arrow_size = 2.0, duration = -1.0, is_persistent = False)

client.py文件中对该函数的解释是:

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]

给出两组三维点points_startpoints_end,绘制由points_start指向points_end的箭头。点集的定义与上面两个函数一致,其他参数的含义也一致。

image-20220708104327101

(simPlotArrows绘制,但这箭头很小还很抽象,放大到跟前才看出来)
画点simPlotPoints
def simPlotPoints(self, points, color_rgba=[1.0, 0.0, 0.0, 1.0], size = 10.0, duration = -1.0, is_persistent = False)

client.py文件中对该函数的解释是:

Plot a list of 3D points in World NED frame

意思就是画点。除了参数size外,其他参数都与之前一致,size表示点的尺寸。

image-20220708105736320

(simPlotPoints绘制,这点是方的,而且无论从哪个角度看都是正方形,没有立体感)
画字符simPlotStrings
def simPlotStrings(self, strings, positions, scale = 5, color_rgba=[1.0, 0.0, 0.0, 1.0], duration = -1.0)

client.py文件中对该函数的解释是:

Plots a list of strings at desired positions in World NED frame.

意思是画一系列string。

  • 参数strings的类型为list[String],为要绘制的字符串。
  • 参数positions的类型为list[Vector3r],字符串的位置,与上一个参数一一对应。
  • 参数scale的类型为list[float],对应字符的大小。

其他两个参数与之前一致。这里没有is_persistent这个参数,也就不能持续绘图。但是我发现如果设置duration为-1,绘图会持续存在,设置其他负数没有这个效果,前面几个函数也没有这个效果。但问题是画上去之后擦不掉了,用清空绘图的函数也不行…代码还是不能乱写。

image-20220708110940203

(simPlotStrings绘制,同时绘制了对应位置的点)
绘制变换

simPlotTransformssimPlotTransformsWithNames两个函数,官方文档和client.py中都说是Plots a list of transforms,但是这个transforms到底是指什么也不太清楚,网上也查不到相关的资料。如果以后会使用到再来看这两个函数吧。

清除所有绘图simFlushPersistentMarkers
 client.simFlushPersistentMarkers()

顾名思义,清除世界中的所有绘图。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值