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

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);

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()?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-18 04:31:28 -0500

Hello, this problem is very old but I encountered the same thing and I found no answer on the internet. The problem was that I had not specified the screen as the output of the serial node. So I added output="screen" to my launch file as shown below: <launch> <node name="serial_node" pkg="rosserial_python" type="serial_node.py" output="screen" required="true"> </node> </launch>

hopefully it will helps somebody

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 163 times

Last updated: May 30 '21