Ask Your Question

I wantna publish a initialpose to AMCL, but error~

asked 2017-11-07 19:58:46 -0600

wings0728 gravatar image

I try to write a node for publish a msg to initialpose topic, but error

Error:   TF_NAN_INPUT: Ignoring transform for child_frame_id "odom" from authority "unknown_publisher" because of a nan value in the transform (-nan -nan -nan) (-nan -nan -nan -nan)
         at line 244 in /tmp/binarydeb/ros-kinetic-tf2-0.5.16/src/buffer_core.cpp
Error:   TF_DENORMALIZED_QUATERNION: Ignoring transform for child_frame_id "odom" from authority "unknown_publisher" because of an invalid quaternion in the transform (-nan -nan -nan -nan)
         at line 257 in /tmp/binarydeb/ros-kinetic-tf2-0.5.16/src/buffer_core.cpp

my code:

#include <ros/ros.h>
#include <geometry_msgs/PoseWithCovarianceStamped.h>

int main (int argc, char** argv) 
    ros::init(argc, argv, "initialpose_pub");
    ros::NodeHandle nh_;
    ros::Publisher initPosePub_ = nh_.advertise<geometry_msgs::PoseWithCovarianceStamped>("initialpose", 2, true);
ros::Rate rate(1.0);
    //get time
    ros::Time scanTime_ = ros::Time::now();     
    //create msg
    geometry_msgs::PoseWithCovarianceStamped initPose_;
    //create the time & frame
    initPose_.header.stamp = scanTime_;
    initPose_.header.frame_id = "map";
    initPose_.pose.pose.position.x = 0.f;
    initPose_.pose.pose.position.y = 0.f;
    initPose_.pose.pose.orientation.z = 0.f;
    //publish msg
return 0;

I don't know why.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-11-07 20:47:41 -0600

ahendrix gravatar image

The orientation that your node is publishing isn't a valid quaternion.

The details of quaternions are too complex to explain here, but there's a nice tutorial on them:

The short version is that you should initialize the w part of your quaternion to 1.0 or use a function to create your quaterninon instead of just setting the z value:

initPose_.pose.pose.orientation.w = 1.0;


initPose_.pose.pose.orientation = tf::createQuaternionFromRPY(0.0, 0.0, 0.0);


initPose_.pose.pose.orientation = tf::createQuaternionFromYaw(0.0);

Note that if you want to use the tf convenience functions for creating quaternions, you'll want to include the appropriate tf header and add a dependency on tf to your CMakeLists.txt

edit flag offensive delete link more


thank you!!!!!!!!!! it's working!!!!

wings0728 gravatar imagewings0728 ( 2017-11-07 21:09:15 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-11-07 19:58:46 -0600

Seen: 476 times

Last updated: Nov 07 '17