0

阿木币

0

精华

2 小时

在线时间

应届白菜

Rank: 1

发表于 2024-4-25 12:15:50 224 浏览 6 回复

[飞控嵌入式] ros2启动固定翼

请问哪位大佬能用ros2的话题让固定翼起飞吗   类似于官方给的四旋翼的offboard模式   应该发布什么话题  怎么给命令呢
我知道答案 回答被采纳将会获得4 阿木币 已有6人回答

扫一扫浏览分享
回复

使用道具 举报

0

阿木币

0

精华

2 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2024-4-25 19:09:10
是仿真哈  不是实物
回复 点赞

使用道具 举报

13

阿木币

0

精华

14 小时

在线时间

管理员

Rank: 9Rank: 9Rank: 9

发表于 2024-4-26 10:13:50
你可以通过设置飞行模式为AUTO.TAKEOFF并发布到/mavros/cmd/takeoff话题,同时指定起飞高度和位置。对于进一步的飞行控制,可以使用/mavros/setpoint_velocity/cmd_vel话题来调整速度和方向。
回复 点赞

使用道具 举报

13

阿木币

0

精华

14 小时

在线时间

管理员

Rank: 9Rank: 9Rank: 9

发表于 2024-4-26 10:15:07
举个例(假设使用的是ROS2和PX4)
  1. import rclpy
  2. from rclpy.node import Node
  3. from mavros_msgs.srv import SetMode
  4. from mavros_msgs.msg import CommandBool, State

  5. class FixedWingController(Node):
  6.     def __init__(self):
  7.         super().__init__('fixed_wing_controller')
  8.         self.set_mode_client = self.create_client(SetMode, '/mavros/set_mode')
  9.         while not self.set_mode_client.wait_for_service(timeout_sec=1.0):
  10.             self.get_logger().info('service not available, waiting again...')
  11.         self.state_subscriber = self.create_subscription(State, '/mavros/state', self.state_callback, 10)

  12.     def set_auto_takeoff(self):
  13.         req = SetMode.Request()
  14.         req.custom_mode = 'AUTO.TAKEOFF'
  15.         self.set_mode_client.call_async(req)

  16.     def state_callback(self, msg):
  17.         self.get_logger().info(f"Current State: {msg.mode}")

  18. # 初始化ROS 2节点
  19. rclpy.init(args=None)
  20. node = FixedWingController()
  21. node.set_auto_takeoff()
  22. rclpy.spin(node)
  23. node.destroy_node()
  24. rclpy.shutdown()
复制代码
回复 点赞

使用道具 举报

0

阿木币

0

精华

2 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2024-4-26 17:48:15
尘埃1未定 发表于 2024-4-26 10:13
你可以通过设置飞行模式为AUTO.TAKEOFF并发布到/mavros/cmd/takeoff话题,同时指定起飞高度和位置。对于进 ...

很感谢您的回复,但是在ros2中的话题和它是不一样的 ,没有直接就takeoff就能起飞的代码操作
,比如我试了发布vehiclecommand的指令让他起飞  还是无济于事,您确定ros2也能这么简单吗
回复 点赞

使用道具 举报

13

阿木币

0

精华

14 小时

在线时间

管理员

Rank: 9Rank: 9Rank: 9

发表于 2024-4-26 18:36:29
用VehicleCommand消息来控制,参考下面这个示例看看呢
回复 点赞

使用道具 举报

13

阿木币

0

精华

14 小时

在线时间

管理员

Rank: 9Rank: 9Rank: 9

发表于 2024-4-26 18:36:39
  1. from px4_msgs.msg import VehicleCommand
  2. import rclpy
  3. from rclpy.node import Node

  4. class UAVCommander(Node):
  5.     def __init__(self):
  6.         super().__init__('uav_commander')
  7.         self.publisher_ = self.create_publisher(VehicleCommand, '/fmu/vehicle_command/out', 10)
  8.         takeoff_command = VehicleCommand()
  9.         takeoff_command.command = VehicleCommand.VEHICLE_CMD_NAV_TAKEOFF
  10.         # 设置其他必要参数
  11.         self.publisher_.publish(takeoff_command)

  12. def main(args=None):
  13.     rclpy.init(args=args)
  14.     uav_commander = UAVCommander()
  15.     rclpy.spin(uav_commander)
  16.     uav_commander.destroy_node()
  17.     rclpy.shutdown()

  18. if __name__ == '__main__':
  19.     main()
复制代码
回复 点赞

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表