rosserial logging in setup()
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);
setup()
{
nh.initNode();
nh.advertise(pub);
nh.subscribe(my_sub);
while (!nh.connected())
{
nh.spinOnce();
}
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);
nh.loginfo(log_msg.c_str());
}
...
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()?