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

Revision history [back]

click to hide/show revision 1
initial version

This is a C++ problem.

You have:

#include "ros/ros.h"
...

ros::Publisher pub;

...

int main(int argc, char **argv)
{
  ...
  ros::Publisher pub = n.advertise<geometry_msgs::PointStamped>("pressure_height", 100);
  ...
}

The pub outside your main(..) (ie: in the global scope) is not the same ros::Publisher as the one you create and initialise inside main(..). The latter is a new variable, which happens to have the same name (it shadows the pub in the global scope).

In your pressureCallback(..) you then try to use the pub in the global scope, which hasn't been initialised yet. This is an error, as you can't use a ros::Publisher which hasn't been initialised, hence the fatal error message .

You should be able to do this:

int main(int argc, char **argv)
{
  ...
  pub = n.advertise<geometry_msgs::PointStamped>("pressure_height", 100);
  ...
}

This is a C++ problem.

You have:

#include "ros/ros.h"
...

ros::Publisher pub;

...

int main(int argc, char **argv)
{
  ...
  ros::Publisher pub = n.advertise<geometry_msgs::PointStamped>("pressure_height", 100);
  ...
}

The pub outside your main(..) (ie: in the global scope) is not the same ros::Publisher as the one you create and initialise inside main(..). The latter is a new variable, which happens to have the same name (it shadows the pub in the global scope).

In your pressureCallback(..) you then try to use the pub in the global scope, which hasn't been initialised yet. This is an error, as you can't use a ros::Publisher which hasn't been initialised, hence the fatal error message .

You should be able to do this:

int main(int argc, char **argv)
{
  ...
  pub = n.advertise<geometry_msgs::PointStamped>("pressure_height", 100);
  ...
}

Having written that, the following might be easier, and still results in the conversion being performed:

rosrun topic_tools transform /rexrov2/pressure /pressure_height geometry_msgs/PointStamped \
  'geometry_msgs.msg.PointStamped( \
    header=m.header, \
    point=geometry_msgs.msg.Point( \
      x=0.0, \
      y=0.0, \
      z=(m.fluid_pressure / (997.04 * 9.8)) \
    )' \
   --import geometry_msgs

This uses topic_tools/transform, which avoids the need to write your own node entirely.

Note: I haven't tested this, so there may be a syntax error hidden there.

This is a C++ problem.

You have:

#include "ros/ros.h"
...

ros::Publisher pub;

...

int main(int argc, char **argv)
{
  ...
  ros::Publisher pub = n.advertise<geometry_msgs::PointStamped>("pressure_height", 100);
  ...
}

The pub outside your main(..) (ie: in the global scope) is not the same ros::Publisher as the one you create and initialise inside main(..). The latter is a new variable, which happens to have the same name (it shadows the pub in the global scope).

In your pressureCallback(..) you then try to use the pub in the global scope, which hasn't been initialised yet. This is an error, as you can't use a ros::Publisher which hasn't been initialised, hence the fatal error message .

You should be able to do this:

int main(int argc, char **argv)
{
  ...
  pub = n.advertise<geometry_msgs::PointStamped>("pressure_height", 100);
  ...
}

Having written that, the following might be easier, and still results in the conversion being performed:

rosrun topic_tools transform /rexrov2/pressure /pressure_height geometry_msgs/PointStamped \
  'geometry_msgs.msg.PointStamped( \
    header=m.header, \
    point=geometry_msgs.msg.Point( \
      x=0.0, \
      y=0.0, \
      z=(m.fluid_pressure / (997.04 * 9.8)) \
    )' \
   --import geometry_msgs

This uses topic_tools/transform, which avoids the need to write your own node entirely.

Note: Note 1: this ignores the variance in the FluidPressure message.

Note 2: I haven't tested this, so there may be a syntax error hidden there.