lighthouse定位系统入门教程-圆形飞行
说明
介绍如何实现单台无人机的圆形飞行
本文基于无人机多机套件主机测试
Crazyflie无人机集群套件,采购地址
仿真飞行:
- 生成圆形轨迹的点坐标的脚本
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 参数设置
r = 0.2 # 圆的半径
num_points = 30 # 点的数量
# 生成圆的坐标
theta = np.linspace(0, 2 * np.pi, num_points)
x = r * np.cos(theta)
y = r * np.sin(theta)
z = np.zeros(num_points) # 圆在平面上,z坐标为0
# 将坐标点输出到文件
with open('circle_coordinates.csv', 'w') as f:
for i in range(num_points):
f.write(f"{x[i]}, {y[i]}, {z[i]}\n")
# 绘制圆形图像
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, z, label='circle')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.legend()
plt.show()
生成轨迹,参考
进入脚本目录
roscd crazyswarm/scripts/
- 脚本代码
#!/usr/bin/env python
import numpy as np
from pycrazyswarm import *
import uav_trajectory
if __name__ == "__main__":
swarm = Crazyswarm()
timeHelper = swarm.timeHelper
allcfs = swarm.allcfs
traj1 = uav_trajectory.Trajectory()
traj1.loadcsv("circle0.csv")
TRIALS = 1
TIMESCALE = 1.0
for i in range(TRIALS):
for cf in allcfs.crazyflies:
cf.uploadTrajectory(0, 0, traj1)
allcfs.takeoff(targetHeight=0.5, duration=2.0)
timeHelper.sleep(2.5)
for cf in allcfs.crazyflies:
pos = np.array(cf.initialPosition) + np.array([0, 0, 0.5])
cf.goTo(pos, 0, 2.0)
timeHelper.sleep(2.5)
allcfs.startTrajectory(0, timescale=TIMESCALE)
timeHelper.sleep(traj1.duration * TIMESCALE + 2.0)
allcfs.land(targetHeight=0.06, duration=2.0)
timeHelper.sleep(3.0)
- 运行脚本
python3 cricle0.py --sim
- 启动后,无人机起飞0.5米,圆形飞行
真机飞行
1号无人机放置在基站测试区域中心
通过choose.py配置无人机,打开choose.py,勾选使用1号无人机
python3 chooser.py
- 终端下启动launch文件
roslaunch crazyswarm hover_swarm.launch
启动后,会弹出rviz,并显示对应的位置
新终端,启动脚本
python3 cricle0.py
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号