Ask Your Question

Call to publish() on an invalid Publisher

asked 2016-04-16 10:25:52 -0600

jeping123456 gravatar image

updated 2016-04-16 12:26:14 -0600

gvdhoorn gravatar image

i rolslaunch the file of one node but got the error message as following.

[FATAL] [1460819328.350552093]: ASSERTION FAILED
    file = /opt/ros/indigo/include/ros/publisher.h
    line = 102
    cond = false
    message = 
[FATAL] [1460819328.350660121]: Call to publish() on an invalid Publisher
[FATAL] [1460819328.350700112]:

i am doubt that publisher.h has some error, but it is OK when i rolslaunch anothee file of another node.

edit retag flag offensive close merge delete


Please format console copy/pastes with the Preformatted text button (the one with 101010 on it). Otherwise the error text gets filtered, and it's not visible.

gvdhoorn gravatar image gvdhoorn  ( 2016-04-16 12:27:01 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2016-04-18 00:23:03 -0600

djsw gravatar image

Has the publisher been initialised? This is an error I recently ran into, and from memory, this error will be thrown if you try to publish on a publisher that has been declared as a class variable, but not initialised either in the constructor or in the function body. If it's initialised in the constructor and the instance of the class is in a different scope to the call to publish(), that will also cause this error (say if you construct your instance in your main loop but try to call publish from a subscriber callback).

edit flag offensive delete link more


Thanks! This helped.

ai-shwarya gravatar image ai-shwarya  ( 2016-12-05 02:29:46 -0600 )edit

answered 2016-04-18 00:44:05 -0600

dmngu9 gravatar image

I had this problem before. In my case, I call a function that has ros publisher in it before declare pub = n.advertise ... in main()

Maybe this will help you

edit flag offensive delete link more

answered 2018-12-21 03:21:09 -0600

Farid gravatar image

updated 2018-12-21 03:22:35 -0600

Publisher must be initialized. The following sample code to publish IMU message might be helpful:

void pubIMU(double tsIMU, double gyro_x, double gyro_y, double gyro_z, double acc_x, double acc_y, double acc_z)
       sensor_msgs::Imu imuMsg;

//  imuMsg.header.stamp = ros::Time::now();

    imuMsg.header.frame_id = "imu"; //

    imuMsg.angular_velocity.x = gyro_x;
    imuMsg.angular_velocity.y = gyro_y;
    imuMsg.angular_velocity.z = gyro_z;

    imuMsg.linear_acceleration.x = acc_x;
    imuMsg.linear_acceleration.y = acc_y;
    imuMsg.linear_acceleration.z = acc_z;

void readCSV(const string &strPath2Dataset)
       // some function to extract info from a sample csv file:
       // ....
       // ....
       // ....

       pubIMU(timeStampIMU[i], gyro_X[i], gyro_Y[i], gyro_Z[i], acc_X[i], acc_Y[i], acc_Z[i]);
       // ^^^^^real function I'd like to publish^^^^^, ****modify based on your own need!!!

int main(int argc, char **argv)
    ros::init(argc, argv, "imuPub");
    ros::NodeHandle nh;

    // all your publisher must be defined in the very beginning:
    pub_imu     = nh.advertise      <sensor_msgs::Imu>                  ("/imu_raw"     ,1);
    pub_cam     = nh.advertise      <geometry_msgs::PoseStamped>        ("/cam_pose"    ,1);
    pub_path    = nh.advertise      <nav_msgs::Path>                    ("/cam_path"    ,1);

    return 0;
edit flag offensive delete link more

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: 2016-04-16 10:25:52 -0600

Seen: 7,767 times

Last updated: Dec 21 '18