Closed YCH188 closed 5 years ago
You should set new header.stamp
for each new message.
@vooon Thanks, I know! Another problem is the /mavros/local_position/pose Z coordination is approximately 1m, but I just put the UAV on the ground? Why does it is not 0? This is the flight log: https://logs.px4.io/plot_app?log=30d4800b-b799-4343-b245-d5f5777588fb I use the code in px4 tutorial for offborad control test.
/**
* @file offb_node.cpp
* @brief offboard example node, written with mavros version 0.14.2, px4 flight
* stack and tested in Gazebo SITL
*/
#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 = 1;
//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;
}
@vooon I have solved this problem. Because my baud rate is too low. I changed it from default 57600 to 921600 and it flies successfully.
You should set new
header.stamp
for each new message.
I opened the issue https://github.com/mavlink/mavros/issues/1491 here. Is it enough to set new header stamp each time? It was working fine in SITL without any stamp.
geometry_msgs::PoseStamped pointToGo;
pointToGo.pose.position.x = targetX;
pointToGo.pose.position.y = targetY;
pointToGo.pose.position.z = targetZ;
pointToGo.header.stamp = ros::Time::now();
pointToGo.header.seq = seqCount;
pointToGo.header.frame_id = 1;
seqCount++;
Issue details
Hello, I want to use /mavros/setpoint_position/pose to control the pixhawk FCU for OFFBOARD control, but when I listen to /mavros/local_position/pose it is not right for Z coordinate and is higher than what I have set in /mavros/setpoint_position/pose(I put it on the groud). But the motor of UAV ran fast which means it will still fly higher. So I cannot fly and I am confused why the /mavros/local_position/pose is not right for z coordinate, is it a software or hardware problem? Could anyone help to solve the problem? Thanks in advance!
MAVROS version and platform
Mavros: 0.18.4 ROS: Kinetic Ubuntu: 16.04
Autopilot type and version
[ ] ArduPilot [ ] PX4
Version: 3.7.1
Node logs
Diagnostics
Topic detials
/mavros/local_position/pose
/mavros/setpoint_position/pose