publishing a message from the subscriber
Hello,
I created a node that has a subscriber and a publisher, the thing is that i need to deliver to the publisher the message that the subscriber is reading, when i do rosrun i obtain:
jose@ubuntu:~/prueba$ rosrun prueba segunda
segunda: /usr/include/boost/smart_ptr/shared_ptr.hpp:412: boost::shared_ptr<T>::reference boost::shared_ptr<T>::operator*() const [with T = const std_msgs::Float64_<std::allocator<void> >, boost::shared_ptr<T>::reference = const std_msgs::Float64_<std::allocator<void> >&]: Assertion `px != 0' failed.
Abortado (`core' generado)
the code of my node is the next one:
#include "ros/ros.h"
#include "std_msgs/Float64.h"
#include <sstream>
std_msgs::Float64::ConstPtr mensaje;
void indiceCallback(const std_msgs::Float64::ConstPtr& msg)
{
ROS_INFO("Valor indice: [%f]", msg->data);
mensaje=msg;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "segunda");
ros::NodeHandle n;
/////SUSCRIPTOR/////
ros::Subscriber sub = n.subscribe("indice", 50, indiceCallback);
//ros::spinOnce();
/////PUBLICADOR/////
ros::Publisher pub = n.advertise<std_msgs::Float64>("/sh_ffj3_mixed_position_velocity_controller/command", 50);
ros::Rate loop_rate(10);
ros::spinOnce();
int count = 0;
while (ros::ok())
{
//std_msgs::Float64::ConstPtr msg;
// msg = mensaje;
pub.publish(mensaje);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
add a comment