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

Accessing topics from multiple ros2 workspaces, sourced separately

asked 2022-08-15 00:33:02 -0600

nsimon gravatar image

Hello, I am new to ros2 and could use some advice. I would like to subscribe to a ros2 topic from one workspace, and publish that information to a separate ros2 topic on a separate workspace. Given that these workspaces are each sourced independently, and the topics only available in terminals where they are sourced, I'm not sure how to go about this. If it makes any difference, I would likely end up doing this in a python script instead of a terminal. Information on my platform and stack is at the bottom.

1st workspace: ros2-vicon-receiver
This workspace uses a Vicon (motion capture) datastream to create a ros2 topic of object position estimates.

source ~/ros2-vicon-receiver/vicon_receiver/install/setup.bash ros2 launch vicon_receiver client.launch.py ros2 topic echo /vicon/vicon_object/vicon_object
This outputs the vicon position information:
x_trans: -123.21699523925781
y_trans: 208.47030639648438
z_trans: 9545.1748046875
x_rot: 0.6378947496414185
y_rot: 0.5461642742156982
z_rot: -0.3194762170314789
w: 0.43901005387306213
segment_name: vicon_object
subject_name: vicon_object
frame_number: 216956
translation_type: Global

I would like to capture this position information and publish it to another ros2 topic in a different workspace (below).

2nd workspace: px4_ros_com
This workspace publishes ros2 topics to the PX4 flight controller over a bridge using micrortps. source ~/px4_ros_com_ros2/install/setup.bash micrortps_agent start -t UDP ros2 topic pub /fmu/vehicle_mocap_odometry/in <msg_type> '<args>'
I plan to use a script to convert the information from the first workspace into the args that the second workspace requires.


For both workspaces, my env | grep ROS is:
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_LOCALHOST_ONLY=0
ROS_DISTRO=foxy

Platform:
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
Kernel: 5.4.0-124-generic
x86_64 GNU/Linux

Thank you very much!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-06 14:19:37 -0600

brieb gravatar image

I recently figured out how to do this (and it took me a LONG time). I have existing packages deployed on a host that include various messages and services, and I wanted to add new functionality that reads those messages and does other things with them. I built my subscriber in python. Sourcing an overlay is the way to go.

My package that is deployed on the host contains the interfaces, so first I source this with the following:

source ~/interfaces_ws/install/setup.bash

This sources the ROS distribution (Foxy in my case too) as well as the interfaces I use in my overlay workspace. Now, in a separate workspace, I use the local_setup.bash

source ~/overlay_ws/install/local_setup.bash

Now, when I import my dependencies (for the interfaces I need) into my new Python node, I can read the messages, without disturbing the existing interfaces_ws/ packages on my host.

So in your case, run the first node(s):

source ~/ros2-vicon-receiver/vicon_receiver/install/setup.bash 
ros2 launch vicon_receiver client.launch.py

Then in a new terminal run your code:

# source the underlay
source ~/ros2-vicon-receiver/vicon_receiver/install/setup.bash
# now source the overlay
source ~/px4_ros_com_ros2/install/local_setup.bash
# now run your code
ros2 run your_python_pkg your_python_node

Now, I am currently trying to do the same thing for existing services, but running into issues. That's how I happened upon this question, and hopefully my experience can help you.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-08-15 00:31:50 -0600

Seen: 397 times

Last updated: Apr 06 '23