ROS2 build leads to closing terminal

Hello everyone,

For a University project I am trying to use Pixhawk SITL with ROS, in particular ROS2.

My current setup is:
Ubuntu 20.04
ROS Noetic
ROS2 Foxy

I followed step by step the guide in: ROS 2 User Guide (PX4-ROS 2 Bridge) | PX4 User Guide

I was able to arrive at the point in which I have to launch:
$ source build_ros2_workspace.bash

It starts with a loading process which I assume is the building of the code, after approximately 10 seconds I can see an error message appearing and the terminal immediately closes, therefore I cannot even provide you a screenshot.

A similar thing happens when launching:
$ source build_all.bash

The terminal in which I launch the command closes briefly after, but a new one appears and it states the following:
************* Building ROS1 workspace *************

Catkin workspace /home/tom is already initialized. No action taken.

Profile: default
Extending: [env] /opt/ros/noetic
Workspace: /home/tom

Build Space: [missing] /home/tom/build
Devel Space: [missing] /home/tom/devel
Install Space: [unused] /home/tom/install
Log Space: [missing] /home/tom/logs
Source Space: [missing] /home/tom/src
DESTDIR: [unused] None

Devel Space Layout: linked
Install Space Layout: None

Additional CMake Args: None
Additional Make Args: None
Additional catkin Make Args: None
Internal Make Job Server: True
Cache Job Environments: False

Buildlisted Packages: None
Skiplisted Packages: None


WARNING: Source space /home/tom/src does
not yet exist.

[build] Error: Unable to find source space /home/tom/src
/bin/bash: line 15: /devel/setup.bash: No such file or directory

ROS1 workspace ready…

ROS_DISTRO was set to ‘noetic’ before. Please make sure that the environment does not mix paths from different distributions.

I edited my .bashrc file to source ROS2 foxy in new terminals and commented out the sourcing of noetic, but I still receive that last line of error message.

1 Like

I was able to make some progress in the matter.
To capture the closing terminal I used the “script” command before executing the build.

What I was able to understand was the need to use the following command:

source build_ros2_workspace.bash --verbose --ros_distro foxy --ros_path /opt/ros/foxy/setup.bash

By that I noticed that the package lark was missing and thus I installed it with

pip install lark

Now I am able to move slightly forward, the error that is now crippling my build is:

/home/tom/px4_ros_com_ros2/src/px4_ros_com/src/examples/offboard/offboard_control.cpp:175:6: error: ‘using TrajectorySetpoint = struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’ {aka ‘struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’} has no member named ‘x’
  175 |  msg.x = 0.0;
      |      ^
/home/tom/px4_ros_com_ros2/src/px4_ros_com/src/examples/offboard/offboard_control.cpp:176:6: error: ‘using TrajectorySetpoint = struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’ {aka ‘struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’} has no member named ‘y’
  176 |  msg.y = 0.0;
      |      ^
/home/tom/px4_ros_com_ros2/src/px4_ros_com/src/examples/offboard/offboard_control.cpp:177:6: error: ‘using TrajectorySetpoint = struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’ {aka ‘struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’} has no member named ‘z’
  177 |  msg.z = -5.0;
      |      ^
make[2]: *** [CMakeFiles/offboard_control.dir/build.make:76: CMakeFiles/offboard_control.dir/src/examples/offboard/offboard_control.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:121: CMakeFiles/offboard_control.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:146: all] Error 2
--- stderr: px4_ros_com
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1, mixed mode)
/home/tom/px4_ros_com_ros2/src/px4_ros_com/src/examples/offboard/offboard_control.cpp: In member function ‘void OffboardControl::publish_trajectory_setpoint() const’:
/home/tom/px4_ros_com_ros2/src/px4_ros_com/src/examples/offboard/offboard_control.cpp:175:6: error: ‘using TrajectorySetpoint = struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’ {aka ‘struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’} has no member named ‘x’
  175 |  msg.x = 0.0;
      |      ^
/home/tom/px4_ros_com_ros2/src/px4_ros_com/src/examples/offboard/offboard_control.cpp:176:6: error: ‘using TrajectorySetpoint = struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’ {aka ‘struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’} has no member named ‘y’
  176 |  msg.y = 0.0;
      |      ^
/home/tom/px4_ros_com_ros2/src/px4_ros_com/src/examples/offboard/offboard_control.cpp:177:6: error: ‘using TrajectorySetpoint = struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’ {aka ‘struct px4_msgs::msg::TrajectorySetpoint_<std::allocator<void> >’} has no member named ‘z’
  177 |  msg.z = -5.0;
      |      ^
make[2]: *** [CMakeFiles/offboard_control.dir/build.make:76: CMakeFiles/offboard_control.dir/src/examples/offboard/offboard_control.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:121: CMakeFiles/offboard_control.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:146: all] Error 2
---
Failed   <<< px4_ros_com [55.2s, exited with code 2]

I solved this issue by building manually first,

cd ~/px4_ros_com_ros2
source /opt/ros/foxy/setup.bash
colcon build --symlink-install --event-handlers console_direct+

and then

cd ~/px4_ros_com_ros2/src/px4_ros_com/scripts
source build_ros2_workspace.bash