< >
Home » ROS1与lighthouse定位系统教程 » lighthouse定位系统入门教程-心电图飞行

lighthouse定位系统入门教程-心电图飞行

说明

  • 介绍如何实现单台无人机的心电图飞行

  • 本文基于无人机多机套件主机测试

  • Crazyflie无人机集群套件,采购地址

仿真飞行:

  • 生成心电图轨迹的点坐标的脚本
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# Define ECG curve equation (e.g., sine wave)
t = np.linspace(0, 7*np.pi, 30)
z = 0.3 + 0.38 * np.sin(t)  # Adjust amplitude and frequency as needed
x = 0.5 * t / (2*np.pi)     # Scale y-axis to match height
y = np.zeros_like(t)        # Set z-axis to 0 (assuming flat plane)

# Create 3D plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, z)

# Save 3D coordinates to a file
data = np.column_stack((x, y, z))
np.savetxt('ecg_coordinates.csv', data, delimiter=',')

# Show plot (optional)
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("ecg_coordinates.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.startTrajectory(0, timescale=TIMESCALE, reverse=True)
        # timeHelper.sleep(traj1.duration * TIMESCALE + 2.0)

        allcfs.land(targetHeight=0.06, duration=2.0)
        timeHelper.sleep(3.0)
  • 运行脚本
python3 ecg_coordinates.py --sim
  • 启动后,无人机起飞0.5米,上下心电图飞行

真机飞行

  • 1号无人机放置在基站测试区域中心

  • 通过choose.py配置无人机,打开choose.py,勾选使用1号无人机

python3 chooser.py 

请输入图片描述

  • 终端下启动launch文件
roslaunch crazyswarm hover_swarm.launch
  • 启动后,会弹出rviz,并显示对应的位置

  • 新终端,启动脚本

python3 ecg_coordinates.py

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: none