ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

I wantna publish a initialpose to AMCL, but error~

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

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);
while(nh_.ok()) 
{
    //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";
    //position
    initPose_.pose.pose.position.x = 0.f;
    initPose_.pose.pose.position.y = 0.f;
    //angle
    initPose_.pose.pose.orientation.z = 0.f;
    //publish msg
    initPosePub_.publish(initPose_);
    //sleep
    rate.sleep();
}
return 0;
}

I don't know why.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

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

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: http://wiki.ros.org/Tutorials/Quatern...

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;

or

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

or

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

Comments

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

wings0728 gravatar image wings0728  ( 2017-11-07 21:09:15 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 1,074 times

Last updated: Nov 07 '17