Published topic name is different than specified by `advertise`
Hello everyone
I am writing a simple package which contains two executable nodes. One of the two nodes acgen_node_test
should publish a message to the topic acgen/des_currents_reg
and the other node acgen_node
should receive said message.
Now in my sender node acgen_node_test
I advertise using
currents_pub = nh.advertise<acgen::DesCurrentsReg>("acgen/des_currents_reg", 256);
but for some reason, it seems like these messages get published under the topic /acgen_node/acgen/des_currents_reg
instead of just acgen/des_currents_reg
(at least that's what rostopic list
shows). I try subscribing in my receiver node using:
des_currents_res_subs=nh.subscribe("acgen/des_currents_reg",64,msg_des_currents_reg_cb);
I'm not sure how I can resolve this issue?
Full Code of sender node acgen_node_test
:
#include <ros/ros.h>
#include <ros/console.h>
#include "acgen/DesCurrentsReg.h"
#import <math.h>
ros::Publisher currents_pub;
const double delta_T=20e-3; //publishing time interval
const double i_amp=1.0; //amplitude of desirec currents [A]
const double omega=2*M_PI*5; //frequency of reference waveform
void acgen_timer_cb(const ros::TimerEvent&){
double current=i_amp*sin(omega*delta_T);
std::vector<double> currents={1.0,0,0,0,0,0};
currents_pub.publish(currents);
}
//main
int main(int argc,char** argv){
ros::init(argc, argv, "acgen_node_test",ros::init_options::NoSigintHandler);
ROS_INFO("staring up acgen test node");
ros::NodeHandle nh("~");
currents_pub = nh.advertise<acgen::DesCurrentsReg>("acgen/des_currents_reg", 256);
//main timer shows callback function send the driver messages
ros::Timer timer = nh.createTimer(ros::Duration(delta_T), acgen_timer_cb);
ROS_INFO("Start spinning");
ros::spin();
}
Main Routine of receiver node acgen_node
:
int main(int argc,char** argv){
ros::init(argc, argv, "acgen_node",ros::init_options::NoSigintHandler);
ROS_INFO("startup");
signal(SIGINT, mySigintHandler);
ros::NodeHandle nh("~");
//init tcp connection
bool comm_est_succeeded=init_comm();
if(!comm_est_succeeded){
if(errno==ETIMEDOUT)
ROS_ERROR("Could not establish TCP connection to ControlCard: Timeout");
else
ROS_ERROR("Could not establish TCP connection to ControlCard: %s",strerror(errno));
ros::shutdown();
return EXIT_FAILURE;
}
ROS_INFO("Established Connection");
//main timer showse callback function send the driver messages
ros::Timer timer = nh.createTimer(ros::Duration(20e-3), acgen_timer_cb);
ROS_INFO("Sending data packets at an interval of %f ms",send_interval*1e3);
//register services
srv_enable_acgen=nh.advertiseService("acgen/enable",srv_enable_acgen_cb);
srv_stop_acgen=nh.advertiseService("acgen/stop",srv_stop_acgen_cb);
srv_run_regular=nh.advertiseService("acgen/run_regular",srv_run_regular_cb);
srv_run_resonant=nh.advertiseService("acgen/run_resonant",srv_run_resonant_cb);
//register subscribers
des_currents_res_subs=nh.subscribe("acgen/des_currents_reg",64,msg_des_currents_reg_cb);
des_duties_subs=nh.subscribe("acgen/des_duties",64,msg_des_duties_reg_cb);
ROS_INFO("Start spinning");
ros::spin();
}