|
发表于 2020-11-17 17:09:43
47519 浏览 22 回复
mavros offboard模式控制无人机无法起飞
本帖最后由 Lqcx 于 2020-11-18 16:05 编辑
我在用offboard模式控制无人机时无人机可以解锁但是却无法起飞,不知道为啥,运行的节点是官方的起飞定高节点,如下:
#include <ros/ros.h>
#include <geometry_msgs/PoseStamped.h>
#include <mavros_msgs/CommandBool.h>
#include <mavros_msgs/SetMode.h>
#include <mavros_msgs/State.h>
mavros_msgs::State current_state;
void state_cb(const mavros_msgs::State::ConstPtr& msg){
current_state = *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::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();
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();
rate.sleep();
}
return 0;
}
eason已获得悬赏 10 阿木币最佳答案
可以解决
|
-
这是几个窗口,分别是offboard节点, /mavros/setpoint_position/local和rostopic echo /mavros/local_posi ...
 扫一扫浏览分享
|
|
|
|
|
|
|
发表于 2020-11-19 09:47:16
[img][/img] [img][/img]接口说明你可以参考一下,已上传附件。从你的截图来看,你打印的 mavros/local_position/pose只有z的高度数据,没有xy数据,你可能是在室内飞行,定位数据来源选择了vio,但是并没有启动vio。总的来说,mavros/local_position/pose看出来你的飞机本身都没有xy数据,那你给他发布了(0,0,5),他怎么能够响应呢?而且在室内你发布(0,0,5)是5米高,应该来说室内没有那么高吧,你这样很危险
|
|
|
|
|
|
|
|
发表于 2020-11-18 09:53:02
打印 rostopic echo /mavros/setpoint_position/local 看看你有没有发本地的坐标(0,0,2),然后再看看 rostopic echo /mavros/local_position/pose 飞机当前的位置信息。 |
|
|
|
|
|
|
|
楼主|
发表于 2020-11-18 14:15:02
我这里rostopic echo /mavros/setpoint_position/local和rostopic echo /mavros/local_position/pose都能显示飞机的位置信息但是解锁后不能飞行。 |
|
|
|
|
|
|
|
发表于 2020-11-18 14:25:40
你发有啥提示信息出来么 地面站显示已解锁了么 是不是无人机的硬件问题呢 |
|
|
|
|
|
|
|
楼主|
发表于 2020-11-18 14:34:50
本帖最后由 Lqcx 于 2020-11-18 15:02 编辑
解锁了,无人机电机开始旋转,但是不能起飞,过会儿之后又自动锁上了,手动飞行是可以正常飞起来的 |
|
|
|
|
|
|
|
发表于 2020-11-18 15:06:50
这个,就没有一点提示信息吗?地面站,或者mavros终端,否则就有点不科学了.... |
|
|
|
|
|
|
|
发表于 2020-11-18 15:15:59
|
|
|
|
|
|
|
发表于 2020-11-18 15:30:08
你应该是offboard后 没有持续的给出期望的速度或者加速度信息 |
|
|
|
|
|
|
|
发表于 2020-11-18 15:30:58
无人机它不知道往哪边飞,就会出现这种能解锁,但一会儿又自动锁上的情况。 |
|
|
|
|
|
|
|
楼主|
发表于 2020-11-18 16:03:22
|
|
|
|
|
|
|