提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
为实现四旋翼在AirSim仿真环境中的自主飞行,需要掌握通过程序API控制四旋翼执行前进、升降、转向等基本动作的方法。本文即为探索该方法的过程总结。一、AirSim提供了哪些和移动有关的API?
通过查看源代码client.py
,发现提供了大量的API用于四旋翼的控制,如图:
但是,源代码中既没有函数的实现,也没有给出相对详细的注释。因此,现在的问题转化为:明确这些APIs的原理,学会使用这些APIs。
其中,moveByVelocity()
有一些简短的参数说明,如下:
def moveByVelocityAsync(self, vx, vy, vz, duration, drivetrain = DrivetrainType.MaxDegreeOfFreedom, yaw_mode = YawMode(), vehicle_name = ''):
"""
Args: 参数:
vx (float): desired velocity in world (NED) X axis 世界坐标系下x轴方向,期望的速度
vy (float): desired velocity in world (NED) Y axis 世界坐标系下y轴方向,期望的速度
vz (float): desired velocity in world (NED) Z axis 世界坐标系下z轴方向,期望的速度
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('moveByVelocity', vx, vy, vz, duration, drivetrain, yaw_mode, vehicle_name)
很正常地,就会有个疑问,moveByVelocityZ()
和moveByVelocity()
有什么区别呢?
在Issue #880
中,找到了答案,二者的主要区别在于:moveByVelocityZ()
将海拔保持在固定的Z
坐标上,即具有高度保持的能力。
PS. takeoff()
的注释:
def takeoffAsync(self, timeout_sec = 20, vehicle_name = ''):
"""
Takeoff vehicle to 3m above ground. Vehicle should not be moving when this API is used 四旋翼飞到距离地面3m的高度。当该API使用的时候,四旋翼不应该移动。
Args:
timeout_sec (int, optional): Timeout for the vehicle to reach desired altitude
vehicle_name (str, optional): Name of the vehicle 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('takeoff', timeout_sec, vehicle_name)
在issue中搜索moveByVelocityZ
:
controlling via Roll, pitch, yaw, throttle inputs
How to control the drone accurately?
write a function that will move the drone w.r.t its own referential?
Yaw and move continuously
二、用好moveByVelocityZ()
例子:
start = client.getMultirotorState().kinematics_estimated.position
vx = 3; vy = 3; z = start.z_val; duration = 6 # start.z_val
client.moveByVelocityZAsync(vx, vy, z, duration,airsim.DrivetrainType.ForwardOnly,airsim.YawMode(False,0.0)).join() # 2020-12-02 如何保持固定高度飞行?UE4中的世界坐标系是怎样的?
首先获取四旋翼的当前位置(用来设置z
值),然后定义vx
、vy
、z
和duration
,最后调用函数。其中,默认参数使用了ForwardOnly
和YawMode(False,0.0)
总结
目前实现的四旋翼的移动控制还非常简单,只做简单的了解,后续结合具体路径进一步探讨移动控制。(20201205)