|
发表于 2022-1-11 16:22:23
4783 浏览 2 回复
PX4+gazebo仿真的unecpected comand176报错
我想使用PX4+gazebo跑一个起飞,悬停,降落的程序;结果遇到了图中错误; 问题表现为: - mavros_msgs::State current_state;
- void state_cb(const mavros_msgs::State::ConstPtr& msg)
- {
- current_state = *msg;
- }
- geometry_msgs::PoseStamped current_pose;
- void local_cb(const geometry_msgs::PoseStamped::ConstPtr& msg)
- {
- current_pose = *msg;
- }
- int main(int argc, char **argv)
- {
- ros::init(argc, argv, "offb_node");
- ros::NodeHandle nh;
- ros::Subscriber state_sub = nh.subscribe<mavros_msgs::State>
- ("mavros/state", 10, state_cb);
- ros::Subscriber local_pos_sub = nh.subscribe<geometry_msgs::PoseStamped>
- ("mavros/local_position/pose",10,local_cb);
- ros::Publisher local_pos_pub = nh.advertise<geometry_msgs::PoseStamped>
- ("mavros/setpoint_position/local", 10);
- ros::ServiceClient arming_client = nh.serviceClient<mavros_msgs::CommandBool>
- ("mavros/cmd/arming");
- ros::ServiceClient set_mode_client = nh.serviceClient<mavros_msgs::SetMode>
- ("mavros/set_mode");
- //the setpoint publishing rate MUST be faster than 2Hz
- ros::Rate rate(20.0);
- // wait for FCU connection
- while(ros::ok() && !current_state.connected){
- ros::spinOnce();
- rate.sleep();
- }
- geometry_msgs::PoseStamped pose;
- pose.pose.position.x = 0;
- pose.pose.position.y = 0;
- pose.pose.position.z = 2;
- //send a few setpoints before starting
- for(int i = 100; ros::ok() && i > 0; --i){
- local_pos_pub.publish(pose);
- ros::spinOnce();
- rate.sleep();
- }
- mavros_msgs::SetMode offb_set_mode;
- offb_set_mode.request.custom_mode = "OFFBOARD";
- mavros_msgs::CommandBool arm_cmd;
- arm_cmd.request.value = true;
- ros::Time last_request = ros::Time::now();
- ROS_INFO("Offboarding");
- while(ros::ok())
- {
- if( current_state.mode != "OFFBOARD" &&
- (ros::Time::now() - last_request > ros::Duration(5.0))){
- if( set_mode_client.call(offb_set_mode) &&
- offb_set_mode.response.mode_sent){
- ROS_INFO("Offboard enabled");
- }
- last_request = ros::Time::now();
- } else {
- if( !current_state.armed &&
- (ros::Time::now() - last_request > ros::Duration(5.0))){
- if( arming_client.call(arm_cmd) &&
- arm_cmd.response.success){
- ROS_INFO("Vehicle armed");
- }
- last_request = ros::Time::now();
- }
- }
- local_pos_pub.publish(pose);
- ros::spinOnce();
- geometry_msgs::Point curr,aim;
- curr = current_pose.pose.position;
- aim = pose.pose.position;
- double dist = sqrt(pow((curr.x-aim.x),2)+pow((curr.y-aim.y),2)+pow((curr.z-aim.z),2));
- if(dist < 0.08)
- {
- ROS_INFO("Reach the goal.");
- break;
- }
- rate.sleep();
- }
- for(int i = 100; ros::ok() && i > 0; --i)//悬停一会
- {
- local_pos_pub.publish(pose);
- ros::spinOnce();
- rate.sleep();
- }
- ROS_INFO("Landing");
- mavros_msgs::SetMode land_set_mode;
- land_set_mode.request.custom_mode = "AUTO.LAND";
- while (ros::ok())
- {
- if( current_state.mode != "AUTO.LAND" &&
- (ros::Time::now() - last_request > ros::Duration(5.0))){
- if( set_mode_client.call(land_set_mode) &&
- land_set_mode.response.mode_sent){
- ROS_INFO("Land enabled");
- }
- last_request = ros::Time::now();
- }
- if(!current_state.armed)
- {
- break;
- }
- // local_pos_pub.publish(pose);
- ros::spinOnce();
- rate.sleep();
- }
- return 0;
- }
复制代码 不知道是什么原因,请各位同学老师指点。
hazyparker已获得悬赏 3 阿木币最佳答案
这个程序在别的机子上能跑,而且我看能跑的也会报这个176的错,但是不影响运行;不知道是什么原因卡在了“offboard enable”出不来,导致解锁不了,没法向下进行 ...
|
扫一扫浏览分享
|
|
|
|
|
|
|
发表于 2022-1-11 16:25:51
|
|
|
|
|
|
|
楼主|
发表于 2022-1-11 16:59:20
这个程序在别的机子上能跑,而且我看能跑的也会报这个176的错,但是不影响运行;不知道是什么原因卡在了“offboard enable”出不来,导致解锁不了,没法向下进行 |
|
|
|
|
|
|
|