Ask Your Question
0

Can view topics/nodes but can't subscribe when using sytemd services

asked 2021-02-13 13:19:00 -0600

parzival gravatar image

updated 2021-03-17 10:03:26 -0600

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
edit retag flag offensive close merge delete

Comments

Can you post the code/launch file you're using to start the nodes? Are ROS_MASTER_URI and ROS_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).

tryan gravatar image tryan  ( 2021-02-13 20:11:01 -0600 )edit

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!

parzival gravatar image parzival  ( 2021-02-14 00:24:30 -0600 )edit

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 a localhost reference as part of the nc command; did you change that one, too, when you tried the IPs?

tryan gravatar image tryan  ( 2021-02-15 09:33:03 -0600 )edit

Hey @tryan, sorry to get back so late, yes I did try replacing localhost with the IP address, it still doesn't work

parzival gravatar image parzival  ( 2021-03-17 10:26:21 -0600 )edit

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.

tryan gravatar image tryan  ( 2021-03-17 13:16:54 -0600 )edit

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?

Aditya_chandra gravatar image Aditya_chandra  ( 2021-04-22 08:29:57 -0600 )edit

Hi, unfortunately no, none of the suggestions have worked. Still an unsolved question..

parzival gravatar image parzival  ( 2021-04-24 08:02:17 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-01-03 21:11:27 -0600

kaorusha gravatar image

I had similar problem. Changing both master and slave ip explicitly fix this. Change your ~/.bashrc as the follow, using explicitly ip address, not hostname or localhost.

export ROS_MASTER_URI=http://xxx.xxx.xxx.xxx:11311
export ROS_HOSTNAME=xxx.xxx.xxx.xxx

Detailed roswtf output for this issue:

slave PC:

ERROR Could not contact the following nodes: * /talker * /rosout

ERROR The following nodes should be connected but aren't: * /talker->/rosout (/rosout)

ERROR Errors connecting to the following services: * service [/rosout/get_loggers] appears to be malfunctioning: Unable to communicate with service [/rosout/get_loggers], address [rosrpc://remote_PC:54615] * service [/rosout/set_logger_level] appears to be malfunctioning: Unable to communicate with service [/rosout/set_logger_level], address [rosrpc://remote_PC:54615] * service [/talker/get_loggers] appears to be malfunctioning: Unable to communicate with service [/talker/get_loggers], address [rosrpc://172.16.173.217 :60549] * service [/talker/set_logger_level] appears to be malfunctioning: Unable to communicate with service [/talker/set_logger_level], address [rosrpc://172.16.173.217 :60549]

remote PC:

ERROR Communication with [/talker] raised an error: URL can't contain control characters. '172.16.173.217 ' (found at least ' ')

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-02-13 13:19:00 -0600

Seen: 203 times

Last updated: Jan 03