rosserial logging in setup()

asked 2021-05-30 08:39:50 -0500

fjp gravatar image

Hi, when using rosserial on a teensy 3.2 or 4.0, I noticed that logging inside the setup() function seems to only show the output after the first start. When the launch file that starts rosserial is executed again afterwards, the log output isn't shown.

I therefore assume the setup() method isn't called again, which would mean that publisher and subscribers defined in the setup() method keep running and don't get initialized again?

Here is the code that logs only the frist time:

#include <Arduino.h>
#include <ros.h>

ros::NodeHandle  nh;

ros::Subscriber<std_msgs::Empty> sub("reset", cb);
std_msgs::Int msg;
ros::Publisher pub_encoders("encoder_ticks", &msg);


  while (!nh.connected())
  nh.loginfo("Initialized publishers and subscribers");

  nh.loginfo("Get Parameters from Parameter Server");
  nh.getParam("/parameter/value", &g_value);
  String log_msg = String("/parameter/value: ") + String(g_value);


Where is the correct place to initialize publisher and subscriber?

My main question is, can we log in the setup() function or should we log only in the main loop()?

edit retag flag offensive close merge delete