1

阿木币

0

精华

14 小时

在线时间

应届白菜

Rank: 1

发表于 2021-3-13 11:56:01 10482 浏览 9 回复

固定翼飞行到目标点仿真gazebo

目的:机载计算机用mavros控制固定翼飞机飞到某一个点。仿真gazebo中显示已经切入offboard模式了,但是飞机就是不懂,地面站也提示进入offboard
代码如下:
或者说应该怎么实现固定翼飞机没到目标点
但是飞机不飞向目标点。
  1. /**
  2. * @file offb_node.cpp
  3. * @brief Offboard control example node, written with MAVROS version 0.19.x, PX4 Pro Flight
  4. * Stack and tested in Gazebo SITL
  5. */

  6. #include <ros/ros.h>
  7. #include <geometry_msgs/PoseStamped.h>
  8. #include <mavros_msgs/CommandBool.h>
  9. #include <mavros_msgs/SetMode.h>
  10. #include <mavros_msgs/State.h>

  11. mavros_msgs::State current_state;
  12. void state_cb(const mavros_msgs::State::ConstPtr& msg){
  13.     current_state = *msg;
  14. }

  15. int main(int argc, char **argv)
  16. {
  17.     ros::init(argc, argv, "offb_node");
  18.     ros::NodeHandle nh;

  19.     ros::Subscriber state_sub = nh.subscribe<mavros_msgs::State>
  20.             ("mavros/state", 10, state_cb);
  21.     ros::Publisher local_pos_pub = nh.advertise<geometry_msgs::PoseStamped>
  22.             ("mavros/setpoint_position/local", 10);
  23.     ros::ServiceClient arming_client = nh.serviceClient<mavros_msgs::CommandBool>
  24.             ("mavros/cmd/arming");
  25.     ros::ServiceClient set_mode_client = nh.serviceClient<mavros_msgs::SetMode>
  26.             ("mavros/set_mode");

  27.     //the setpoint publishing rate MUST be faster than 2Hz
  28.     ros::Rate rate(20.0);

  29.     // wait for FCU connection
  30.     while(ros::ok() && !current_state.connected){
  31.         ros::spinOnce();
  32.         rate.sleep();
  33.     }

  34.     geometry_msgs::PoseStamped pose;
  35.     pose.pose.position.x =200;
  36.     pose.pose.position.y = 200;
  37.     pose.pose.position.z = 25;

  38.     //send a few setpoints before starting
  39.     for(int i = 5; ros::ok() && i > 0; --i){
  40.         local_pos_pub.publish(pose);
  41.         ros::spinOnce();
  42.         rate.sleep();
  43.     }

  44.     mavros_msgs::SetMode offb_set_mode;
  45.     offb_set_mode.request.custom_mode = "OFFBOARD";

  46.     mavros_msgs::CommandBool arm_cmd;
  47.     arm_cmd.request.value = true;

  48.     ros::Time last_request = ros::Time::now();

  49.     while(ros::ok()){
  50.         if( current_state.mode != "OFFBOARD" &&
  51.             (ros::Time::now() - last_request > ros::Duration(2.0))){
  52.             if( set_mode_client.call(offb_set_mode) &&
  53.                 offb_set_mode.response.mode_sent){
  54.                 ROS_INFO("Offboard enabled");
  55.             }
  56.             last_request = ros::Time::now();
  57.         } else {
  58.             if( !current_state.armed &&
  59.                 (ros::Time::now() - last_request > ros::Duration(2.0))){
  60.                 if( arming_client.call(arm_cmd) &&
  61.                     arm_cmd.response.success){
  62.                     ROS_INFO("Vehicle armed");
  63.                 }
  64.                 last_request = ros::Time::now();
  65.             }
  66.         }

  67.         local_pos_pub.publish(pose);

  68.         ros::spinOnce();
  69.         rate.sleep();
  70.     }

  71.     return 0;
  72. }
复制代码


eason已获得悬赏 1 阿木币

最佳答案

固定翼的指点飞行指的是在某个位置为中心进行盘旋.

扫一扫浏览分享
回复

使用道具 举报

149

阿木币

1

精华

443 小时

在线时间

技术大V

Rank: 4

发表于 2021-3-13 14:21:01
固定翼的指点飞行指的是在某个位置为中心进行盘旋.
回复 点赞

使用道具 举报

1

阿木币

0

精华

14 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2021-3-13 14:24:36
eason 发表于 2021-3-13 14:21
固定翼的指点飞行指的是在某个位置为中心进行盘旋.

如果是这样的话,那应该会飞到pose位置进行盘旋啊,可是切换道offboard模式以后飞不了
回复 点赞

使用道具 举报

149

阿木币

1

精华

443 小时

在线时间

技术大V

Rank: 4

发表于 2021-3-13 14:27:15
不是这么简单的。先让飞机飞起来,在空中进行盘旋,然后你在发期望位置,发完之后切换到offboard模式。
回复 点赞

使用道具 举报

149

阿木币

1

精华

443 小时

在线时间

技术大V

Rank: 4

发表于 2021-3-13 14:28:04
固定翼的起飞和旋翼不一样,有起飞服务
回复 点赞

使用道具 举报

1

阿木币

0

精华

14 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2021-3-13 14:28:23
eason 发表于 2021-3-13 14:27
不是这么简单的。先让飞机飞起来,在空中进行盘旋,然后你在发期望位置,发完之后切换到offboard模式。 ...

飞机已经在空中了,切到offboard模式发送pose完,飞机慢慢下降到地面了
回复 点赞

使用道具 举报

149

阿木币

1

精华

443 小时

在线时间

技术大V

Rank: 4

发表于 2021-3-13 14:53:46
总之off_node应该不能直接用在固定翼上面的,px4_command应该是可以。off_node只是个简单的demo,系统状态,指令发送都没有。
回复 点赞

使用道具 举报

1

阿木币

0

精华

14 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2021-3-13 16:38:12
eason 发表于 2021-3-13 14:53
总之off_node应该不能直接用在固定翼上面的,px4_command应该是可以。off_node只是个简单的demo,系统状态 ...

您好,您说的px4_command可以具体一些吗
回复 点赞

使用道具 举报

88

阿木币

0

精华

12 小时

在线时间

应届白菜

Rank: 1

发表于 2021-3-18 18:19:36
本帖最后由 qq286907986 于 2021-3-18 18:20 编辑

你要先takeoff,然后再offboard
回复 点赞

使用道具 举报

144

阿木币

0

精华

143 小时

在线时间

技术大V

Rank: 4

发表于 2021-3-19 09:14:51
kyd123456 发表于 2021-3-13 16:38
您好,您说的px4_command可以具体一些吗

px_command是阿木实验室 GitHub的一个包  你可以去GitHub搜搜看 是开源的
回复 点赞

使用道具 举报

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

本版积分规则

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