Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ROS2 wrapper #3976

Merged
merged 123 commits into from
Dec 6, 2021
Merged

Add ROS2 wrapper #3976

merged 123 commits into from
Dec 6, 2021

Conversation

alonfaraj
Copy link
Contributor

@alonfaraj alonfaraj commented Aug 22, 2021

Fixes: #3830

About

Hi,

I found myself using AirSim & ROS but a lot of our logic and code is already implemented with ROS2.
I migrated the existing ROS wrapper to ROS2, with minimal changes as possible.

One major change is a new package contains all messages and services - airsim_interfaces.

Nodes:

  • airsim_node
  • pid_position_node

Packages:

  • airsim_interfaces
  • airsim_ros_pkgs

Not all launch files were migrated, only the main so far -

  • airsim_node.launch.py
  • static_transforms.launch.py
  • position_controller_simple.launch.py
  • airsim_with_simple_PD_position_controller.launch.py
  • dynamic_constraints.launch.py
  • rviz.launch.py

This PR probably need much more tests to check that everything work like ROS1 wrapper.
I thought it might be useful to share it with you guys, because ROS2 became very popular.

How Has This Been Tested?

Test configuration:

  • ROS2 Foxy/Galactic
  • Ubuntu 20.04

It might work on different ROS2/Ubuntu versions as well.
Didn't check it.

Ran this ROS2 wrapper node.
Tested on one Multirotor and one Car with different sensors using ros2 command tool and Rviz2

How to test it yourself?

  • Install gcc >= 8.0.0:
    sudo apt-get install gcc-8 g++-8Verify installation by gcc-8 --version
  • install ROS2 pkgs:
    sudo apt-get install ros-${ROS_DISTRO}-tf2-sensor-msgs ros-${ROS_DISTRO}-tf2-geometry-msgs ros-${ROS_DISTRO}-mavros* libyaml-cpp-dev
  • Verify you have colcon installed, if not - install it:
    https://colcon.readthedocs.io/en/released/user/installation.html
  • cd /AirSim/ros2
  • colcon build --cmake-args -DCMAKE_C_COMPILER=gcc-8 --cmake-args -DCMAKE_CXX_COMPILER=g++-8 --cmake-args -DCMAKE_BUILD_TYPE=Debug
    or for release DCMAKE_BUILD_TYPE=Release
  • source install/setup.bash
  • Run:
    ros2 launch airsim_ros_pkgs airsim_node.launch.py

Copy link
Contributor

@rajat2004 rajat2004 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small nitpicks, thanks a lot for cleaning up the code duplication from the ROS1 code!

ros2/src/airsim_ros_pkgs/src/airsim_ros_wrapper.cpp Outdated Show resolved Hide resolved
ros2/src/airsim_ros_pkgs/src/airsim_ros_wrapper.cpp Outdated Show resolved Hide resolved
ros2/src/airsim_ros_pkgs/src/airsim_ros_wrapper.cpp Outdated Show resolved Hide resolved
@alonfaraj
Copy link
Contributor Author

Thanks @rajat2004!
It's much cleaner.
Fixed now.

Copy link
Contributor

@rajat2004 rajat2004 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing which can be done later is to add it in Actions CI, to ensure that it compiles going forward. Docker container can also be used directly here to build

tools/Dockerfile-ROS2 Show resolved Hide resolved
@alonfaraj
Copy link
Contributor Author

alonfaraj commented Nov 21, 2021

You right, I guess it should be done after the PR is merged

@zimmy87
Copy link
Contributor

zimmy87 commented Nov 30, 2021

hey @alonfaraj, I tried following your steps to test the wrapper on Ubuntu locally, but I'm receiving the following compile time error:

/home/zimmy/Downloads/AirSim/ros2/build/airsim_interfaces/rosidl_generator_c/airsim_interfaces/msg/detail/environment__struct.h:27:10: fatal error: geographic_msgs/msg/detail/geo_point__struct.h: No such file or directory
   27 | #include "geographic_msgs/msg/detail/geo_point__struct.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

I tried remedying this by installing the ros-galactic-geographic-msgs package, but apt-get says I'm already at the latest version:

ros-galactic-geographic-msgs is already the newest version (1.0.4-5focal.20211011.201914).

Do you know if there's a another dependency I'm missing, or if there's a different gepgraphic-msgs package I need?

@jmackay2
Copy link
Contributor

jmackay2 commented Dec 1, 2021

hey @alonfaraj, I tried following your steps to test the wrapper on Ubuntu locally, but I'm receiving the following compile time error:

/home/zimmy/Downloads/AirSim/ros2/build/airsim_interfaces/rosidl_generator_c/airsim_interfaces/msg/detail/environment__struct.h:27:10: fatal error: geographic_msgs/msg/detail/geo_point__struct.h: No such file or directory
   27 | #include "geographic_msgs/msg/detail/geo_point__struct.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

I tried remedying this by installing the ros-galactic-geographic-msgs package, but apt-get says I'm already at the latest version:

ros-galactic-geographic-msgs is already the newest version (1.0.4-5focal.20211011.201914).

Do you know if there's a another dependency I'm missing, or if there's a different gepgraphic-msgs package I need?

I tested with the ros:galactic docker image and had to install the following:

apt install ros-galactic-cv-bridge ros-galactic-image-transport ros-galactic-geographic-msgs ros-galactic-mavros-msgs libyaml-cpp-dev

and it built fine.

Was ros sourced before building (i.e. source /opt/ros/galactic/setup.bash)?

@alonfaraj
Copy link
Contributor Author

alonfaraj commented Dec 1, 2021

Hi @zimmy87, sorry about that.
I'm not sure I completely understand.
I tested my dockerfile on both foxy and galactic and didn't have any issues during compilation.
If I changed the current FROM ros:foxy-ros-base to FROM ros:galactic-ros-base everything built fine.

You can see that the dockerfile include install of
ros-$ROS_DISTRO-tf2-sensor-msgs ros-$ROS_DISTRO-tf2-geometry-msgs ros-$ROS_DISTRO-mavros* ros-$ROS_DISTRO-vision-opencv ros-$ROS_DISTRO-image-transport
which should be enough to build it.

@zimmy87
Copy link
Contributor

zimmy87 commented Dec 3, 2021

Hey @alonfaraj and @jmackay2, thank you for the help. I figured out what was wrong with my ros2 installation: I was following the instructions here which installs from a downloaded tar.bz2 and then I was trying to use apt to install the rest of the dependencies. This ended up creating two different ros2 installations that didn't share the same packages. After uninstalling everything and following the instructions here instead, I was able to get the ros2 wrapper building.

What services do we expect to be supported in this version of the ros2 wrapper? I tried calling both /airsim_node/SimpleFlight/takeoff and /airsim_node/local_position_goal, but both seem to be crashing the airsim_node. Here's my repro steps:

  1. install ROS2 via steps here
  2. follow test steps in first post of this PR
  3. start airsim_node via ros2 launch airsim_ros_pkgs airsim_node.launch.py
  4. in a 2nd terminal, start pd_position_controller_simple_node via ros2 launch airsim_ros_pkgs position_controller_simple.launch.py
  5. in a 3rd terminal, execute either ros2 service call /airsim_node/SimpleFlight/takeoff airsim_interfaces/srv/Takeoff "{wait_on_last_task: True}" or ros2 service call /airsim_node/local_position_goal airsim_interfaces/srv/SetLocalPosition "{x: 1.0, y: 1.0, z: -5.0}"

expected: drone should move (either to takeoff or to target)
actual: airsim_node crashes with following error message:

[ERROR] [airsim_node-2]: process has died [pid 27214, exit code -6, cmd '/home/zimmy/Downloads/AirSim/ros2/install/airsim_ros_pkgs/lib/airsim_ros_pkgs/airsim_node --ros-args -r __node:=airsim_node --params-file /tmp/launch_params_lxyomrpc'].

Am I doing something wrong here or is this outside of the intended scope of this PR (in which case do we have a list somewhere of currently functional services so users know which ones to avoid calling)?

@alonfaraj
Copy link
Contributor Author

Hi @zimmy87, glad to hear you solved it!
You are doing everything right, I found those crashes 2 days ago and already fixed it here 8f5f660.
I guess you not on the latest code in the PR.
Let me know if that's fix it for you.

All the topic/services/nodes in ROS1 are supported in a similar way in this ROS2 PR, except airsim_tutorial_pkgs and airsim_car_with_joy_control.launch

@zimmy87
Copy link
Contributor

zimmy87 commented Dec 6, 2021

Thank you for the contribution @alonfaraj! I was able to get the scenario I mentioned previously working after updating to your latest commit. I think the current level of functionality is sufficient for merging. There's a couple things I noticed when testing that I think may be good things to investigate for any future PRs on this wrapper:

  • The success value in every response to my service calls was always set to False irregardless of whether the drone appeared to complete the desired action.
  • If I call the /airsim_node/SimpleFlight/land service after a call to /airsim_node/local_position_goal, the drone will move back to it's previous target position after landing.
  • I need to set SimMode to Multirotor in settings.json in order to launch airsim_node.launch.py. Even if I don't set this and select no in the "Choose Vehicle" dialog to select Multirotor mode manually, I will still get an error when launching airsim_node:
[airsim_node-2] terminate called after throwing an instance of 'std::invalid_argument'
[airsim_node-2]   what():  Unknown SimMode: , failed to set default vehicle settings
[ERROR] [airsim_node-2]: process has died [pid 15235, exit code -6, cmd '/home/zimmy/Downloads/AirSim/ros2/install/airsim_ros_pkgs/lib/airsim_ros_pkgs/airsim_node --ros-args -r __node:=airsim_node --params-file /tmp/launch_params_3l9lh0m8'].

@zimmy87 zimmy87 merged commit de1c8ae into microsoft:master Dec 6, 2021
@zimmy87
Copy link
Contributor

zimmy87 commented Dec 10, 2021

As per the behaviors I called out for future investigation, I didn't realize at the time that these were all occurring in the ROS1 wrapper as well, so these aren't being introduced in this PR. Feel free to disregard as these are just inherited from the ROS1 wrapper and should be addressed there as well.

@alonfaraj
Copy link
Contributor Author

alonfaraj commented Dec 10, 2021

@zimmy87 yep, you right.
I have seen you already fixed the services response in ros1.

Regarding the third behavior you mentioned - this is the same behavior in ros1 as well.
The idea is that when the node starts, it gets the settings.json file from the host as string and parse it like the simulation itself does.
So, assuming you started the simulation without settings.json, and create drone by clicking no in the popup, the settings file not get updated, so the ros node has no idea which vehicle are you using because it's empty and not contain SimMode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants