Can view topics/nodes but can't subscribe when using sytemd services
I have a master(Ubuntu18.04+Melodic on Jetson Nano) and slave(Ubuntu 16.04+Kinetic on PC) conected properly. I am able to run ros nodes and have full duplex without any issues when these nodes are launched via terminal.
However, I want to start these nodes on bootup on the master, which I am trying to achieve by creating service. When I run the service, the nodes launch fine and I can echo topics receive messages just fine. However, when I try to echo topics on the slave PC, I get no messages. I am still able to view the topics list and publish to these topicis, but can't receive/echo messages in any topics.
When I run roswtf
on PC, I get following errors:
ERROR: Unknown host [ubuntu] for node [/basefootprint_to_laser_broadcaster]
ERROR Could not contact the following nodes: (with all the node names below it)
ERROR The following nodes should be connected but aren't: (with all the node names below it)
ERROR Errors connecting to the following services: (with all service names below)
* service [/basefootprint_to_laser_broadcaster/set_logger_level] appears to be malfunctioning: Unable to communicate with service [/basefootprint_to_laser_broadcaster/set_logger_level], address [rosrpc://ubuntu:49211]
I'm clueless what could've led to this issue? Any help/clue would be of much help. Thanks!
Edit: posting service and related bash file.
roscore.service (this is same as used by Ubiquity robotics, except that I swapped melodic by kinetic:
[Unit]
After=NetworkManager.service time-sync.target
[Service]
Type=forking
User=ubuntu
# Start roscore as a fork and then wait for the tcp port to be opened
# ----------------------------------------------------------------
# Source all the environment variables, start roscore in a fork
# Since the service type is forking, systemd doesn't mark it as
# 'started' until the original process exits, so we have the
# non-forked shell wait until it can connect to the tcp opened by
# roscore, and then exit, preventing conflicts with dependant services
ExecStart=/bin/sh -c ". /opt/ros/melodic/setup.sh; . ~/catkin_ws/devel/setup.sh; roscore & while ! echo exit | nc localhost 11311 > /dev/null; do sleep 1; done"
[Install]
WantedBy=multi-user.target
my_minimal.service:
[Unit]
Description=Mybot Minimal
After=roscore.service
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu
ExecStart=/home/ubuntu/mini.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
mini.sh:
#!/bin/bash
# trial upstart script
sleep 1
source /opt/ros/melodic/setup.bash
source ~/catkin_ws/devel/setup.bash
roslaunch my_pkg minimal.launch
Can you post the code/launch file you're using to start the nodes? Are
ROS_MASTER_URI
andROS_HOSTNAME
set on both machines? One thing to try is using the actual IP address instead of the hostname where applicable. I've had something similar happen. Basically, there was an unresolvable hostname somewhere such that the nodes could register with the master (topics visible), but they couldn't actually connect to send data (no messages).Hey @tryan, thanks for your comment! I'm actually able to run ROS over network properly when I launch nodes manually. This problem occurs when I'm creating a service (even then, I'm able to publish from slave but can't subscribe). I still tried swapping $(hostname).local with IP addresses, but observe no difference, still get same errors. I've even tried the same services with Kinetic master and Kinetic slave, which works fine. Is it something to do with different ROS versions? I don't see how that's a problem only when run using service. If someone can figure out the error, I'd really like to know why this is happening!
Since it works when you set things up manually, that makes me think there's some part of one of the scripts involved in the service that sets things up slightly differently. TBH I'm just guessing at this point, but in
roscore.service
I noticed there's alocalhost
reference as part of thenc
command; did you change that one, too, when you tried the IPs?Hey @tryan, sorry to get back so late, yes I did try replacing localhost with the IP address, it still doesn't work
No worries :). Did you already compare with your
.bashrc
? Since your setup works from a terminal, you could try sourcing that in your service. Here's a Stack Overflow discussion. It's not how you'd want to leave it, but it could be useful for troubleshooting.Hi, Is the issue solved. I'm facing the same issue. In my case both devices have melodic installed. Can see the data when I run them manually, but not when using .service files. Can anyone help?
Hi, unfortunately no, none of the suggestions have worked. Still an unsolved question..