/mavros/setpoint_velocity/cmd_vel 不起飞
时间: 2023-06-15 17:05:58 浏览: 380
/mavros/setpoint_velocity/cmd_vel 是一个 ROS 话题,用于发送无人机的速度控制指令,但是它仅仅是一个话题,不会直接导致无人机起飞。
要让无人机起飞,需要提供一系列的指令,例如设置起飞模式、解锁无人机、设置目标高度和姿态等等。具体实现方式取决于你使用的飞控和控制方式。
在使用/mavros/setpoint_velocity/cmd_vel前,你需要确保你的无人机处于解锁状态,并且你已经正确地设置了起飞模式和控制方式。同时,你需要发送合适的速度指令,才能让无人机实现起飞。
如果你遇到了无法起飞的问题,你可以检查是否满足上述要求,并且查看控制台输出和日志文件,以便找到问题所在。
相关问题
kcf无人机跟踪小车ros代码,要求订阅/iris/usb_cam/image_raw话题,发布mavros/setpoint_position/local和/mavros/setpoint_velocity/cmd_vel_unstamped
以下是一个简单的ROS节点示例,用于使用KCF算法跟踪小车并发布位置和速度指令到MAVROS。
```python
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import cv2
import numpy as np
from pyimagesearch.centroidtracker import CentroidTracker
from pyimagesearch.trackableobject import TrackableObject
from geometry_msgs.msg import PoseStamped, Twist
class KCFTrackerNode:
def __init__(self):
rospy.init_node('kcf_tracker_node', anonymous=True)
self.bridge = CvBridge()
self.ct = CentroidTracker()
self.trackers = []
self.trackable_objects = {}
self.image_sub = rospy.Subscriber('/iris/usb_cam/image_raw', Image, self.image_callback)
self.position_pub = rospy.Publisher('/mavros/setpoint_position/local', PoseStamped, queue_size=1)
self.velocity_pub = rospy.Publisher('/mavros/setpoint_velocity/cmd_vel_unstamped', Twist, queue_size=1)
self.image_width = 640
self.image_height = 480
self.focal_length = 600
self.real_width = 0.5
self.target_width = 0.1
def image_callback(self, data):
cv_image = self.bridge.imgmsg_to_cv2(data, 'bgr8')
if len(self.trackers) == 0:
# initialize trackers
objects = self.ct.update([(0, 0, self.image_width, self.image_height)])
for (object_id, centroid) in objects.items():
tracker = cv2.TrackerKCF_create()
tracker.init(cv_image, (centroid[0], centroid[1], self.target_width * self.focal_length, self.target_width * self.focal_length))
self.trackers.append(tracker)
self.trackable_objects[object_id] = TrackableObject(object_id, centroid)
else:
# update trackers
for tracker in self.trackers:
success, box = tracker.update(cv_image)
if success:
(x, y, w, h) = [int(v) for v in box]
centroid = (x + w / 2, y + h / 2)
object_id = self.ct.register(centroid)
to = self.trackable_objects.get(object_id, None)
if to is None:
to = TrackableObject(object_id, centroid)
self.trackable_objects[object_id] = to
else:
to.centroids.append(centroid)
# filter out small objects
self.trackable_objects = {k: v for k, v in self.trackable_objects.items() if len(v.centroids) > 5 and v.width() > self.image_width * 0.1}
# update position and velocity commands
for object_id, to in self.trackable_objects.items():
x = (to.centroids[-1][0] - self.image_width / 2) * self.real_width / self.focal_length
y = (to.centroids[-1][1] - self.image_height / 2) * self.real_width / self.focal_length
z = 2.0
pose_msg = PoseStamped()
pose_msg.header.stamp = rospy.Time.now()
pose_msg.pose.position.x = x
pose_msg.pose.position.y = y
pose_msg.pose.position.z = z
self.position_pub.publish(pose_msg)
vx = (to.centroids[-1][0] - to.centroids[-2][0]) * self.real_width / self.focal_length
vy = (to.centroids[-1][1] - to.centroids[-2][1]) * self.real_width / self.focal_length
vz = 0.0
vel_msg = Twist()
vel_msg.linear.x = vx
vel_msg.linear.y = vy
vel_msg.linear.z = vz
self.velocity_pub.publish(vel_msg)
if __name__ == '__main__':
try:
node = KCFTrackerNode()
rospy.spin()
except rospy.ROSInterruptException:
pass
```
请注意,此节点使用了pyimagesearch库中的CentroidTracker和TrackableObject类,您需要先安装此库:
```bash
pip install imutils
```
此外,这里的代码将图像中间作为目标点,将图像宽度的10%用作最小目标宽度,将真实世界中的实际宽度设置为0.5米。您可能需要根据您的具体应用程序进行一些修改。
ros::Publisher vel_pub = nh->advertise<geometry_msgs::TwistStamped>("/iris_0/mavros/setpoint_velocity/cmd_vel", 10);
这段代码是用于在ROS系统中创建一个Publisher对象,用于发布飞行器速度控制指令。其中,"/iris_0/mavros/setpoint_velocity/cmd_vel"是话题的名称,10是发布队列的大小,geometry_msgs::TwistStamped是消息类型,表示一个带有时间戳的Twist消息,包含线速度和角速度的信息。在发布速度控制指令时,需要将速度信息填充到TwistStamped消息中,并调用Publisher对象的publish方法来发布消息。
阅读全文