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 option to change material color from ROS. #486

Merged
merged 21 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Galactic | Edifice | [galactic](https://github.com/gazebosim/ros_gz/tree/galacti
Galactic | Fortress | [galactic](https://github.com/gazebosim/ros_gz/tree/galactic) | only from source
Humble | Fortress | [humble](https://github.com/gazebosim/ros_gz/tree/humble) | https://packages.ros.org
Humble | Garden | [humble](https://github.com/gazebosim/ros_gz/tree/humble) | [gazebo packages](https://gazebosim.org/docs/latest/ros_installation#gazebo-garden-with-ros-2-humble-iron-or-rolling-use-with-caution-)[^1]
Humble | Harmonic | [humble](https://github.com/gazebosim/ros_gz/tree/humble) | only from source
Humble | Harmonic | [humble](https://github.com/gazebosim/ros_gz/tree/humble) | [gazebo packages](https://gazebosim.org/docs/harmonic/ros_installation#-gazebo-harmonic-with-ros-2-humble-iron-or-rolling-use-with-caution-)[^1]
Rolling | Edifice | [ros2](https://github.com/gazebosim/ros_gz/tree/ros2) | only from source
Rolling | Fortress | [ros2](https://github.com/gazebosim/ros_gz/tree/ros2) | https://packages.ros.org
Rolling | Garden | [ros2](https://github.com/gazebosim/ros_gz/tree/ros2) | only from source
Expand Down
156 changes: 79 additions & 77 deletions ros_gz_bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,69 @@ The following message types can be bridged for topics:

| ROS type | Gazebo type |
bperseghetti marked this conversation as resolved.
Show resolved Hide resolved
|--------------------------------------|:--------------------------------------:|
| builtin_interfaces/msg/Time | ignition::msgs::Time |
| std_msgs/msg/Bool | ignition::msgs::Boolean |
| std_msgs/msg/ColorRGBA | ignition::msgs::Color |
| std_msgs/msg/Empty | ignition::msgs::Empty |
| std_msgs/msg/Float32 | ignition::msgs::Float |
| std_msgs/msg/Float64 | ignition::msgs::Double |
| std_msgs/msg/Header | ignition::msgs::Header |
| std_msgs/msg/Int32 | ignition::msgs::Int32 |
| std_msgs/msg/UInt32 | ignition::msgs::UInt32 |
| std_msgs/msg/String | ignition::msgs::StringMsg |
| geometry_msgs/msg/Wrench | ignition::msgs::Wrench |
| geometry_msgs/msg/WrenchStamped | ignition::msgs::Wrench |
| geometry_msgs/msg/Quaternion | ignition::msgs::Quaternion |
| geometry_msgs/msg/Vector3 | ignition::msgs::Vector3d |
| geometry_msgs/msg/Point | ignition::msgs::Vector3d |
| geometry_msgs/msg/Pose | ignition::msgs::Pose |
| geometry_msgs/msg/PoseArray | ignition::msgs::Pose_V |
| geometry_msgs/msg/PoseWithCovariance | ignition::msgs::PoseWithCovariance |
| geometry_msgs/msg/PoseStamped | ignition::msgs::Pose |
| geometry_msgs/msg/Transform | ignition::msgs::Pose |
| geometry_msgs/msg/TransformStamped | ignition::msgs::Pose |
| geometry_msgs/msg/Twist | ignition::msgs::Twist |
| geometry_msgs/msg/TwistStamped | ignition::msgs::Twist |
| geometry_msgs/msg/TwistWithCovariance| ignition::msgs::TwistWithCovariance |
| nav_msgs/msg/Odometry | ignition::msgs::Odometry |
| nav_msgs/msg/Odometry | ignition::msgs::OdometryWithCovariance |
| rcl_interfaces/msg/ParameterValue | ignition::msgs::Any |
| ros_gz_interfaces/msg/Altimeter | ignition::msgs::Altimeter |
| ros_gz_interfaces/msg/Contact | ignition::msgs::Contact |
| ros_gz_interfaces/msg/Contacts | ignition::msgs::Contacts |
| ros_gz_interfaces/msg/Dataframe | ignition::msgs::Dataframe |
| ros_gz_interfaces/msg/Entity | ignition::msgs::Entity |
| ros_gz_interfaces/msg/Float32Array | ignition::msgs::Float_V |
| ros_gz_interfaces/msg/GuiCamera | ignition::msgs::GUICamera |
| ros_gz_interfaces/msg/JointWrench | ignition::msgs::JointWrench |
| ros_gz_interfaces/msg/Light | ignition::msgs::Light |
| ros_gz_interfaces/msg/SensorNoise | ignition::msgs::SensorNoise |
| ros_gz_interfaces/msg/StringVec | ignition::msgs::StringMsg_V |
| ros_gz_interfaces/msg/TrackVisual | ignition::msgs::TrackVisual |
| ros_gz_interfaces/msg/VideoRecord | ignition::msgs::VideoRecord |
| ros_gz_interfaces/msg/WorldControl | ignition::msgs::WorldControl |
| rosgraph_msgs/msg/Clock | ignition::msgs::Clock |
| sensor_msgs/msg/BatteryState | ignition::msgs::BatteryState |
| sensor_msgs/msg/CameraInfo | ignition::msgs::CameraInfo |
| sensor_msgs/msg/FluidPressure | ignition::msgs::FluidPressure |
| sensor_msgs/msg/Imu | ignition::msgs::IMU |
| sensor_msgs/msg/Image | ignition::msgs::Image |
| sensor_msgs/msg/JointState | ignition::msgs::Model |
| sensor_msgs/msg/Joy | ignition::msgs::Joy |
| sensor_msgs/msg/LaserScan | ignition::msgs::LaserScan |
| sensor_msgs/msg/MagneticField | ignition::msgs::Magnetometer |
| sensor_msgs/msg/NavSatFix | ignition::msgs::NavSat |
| sensor_msgs/msg/PointCloud2 | ignition::msgs::PointCloudPacked |
| tf2_msgs/msg/TFMessage | ignition::msgs::Pose_V |
| trajectory_msgs/msg/JointTrajectory | ignition::msgs::JointTrajectory |
| builtin_interfaces/msg/Time | gz::msgs::Time |
| actuator_msgs/msg/Actuators | gz::msgs::Actuators |
| std_msgs/msg/Bool | gz::msgs::Boolean |
| std_msgs/msg/ColorRGBA | gz::msgs::Color |
| std_msgs/msg/Empty | gz::msgs::Empty |
| std_msgs/msg/Float32 | gz::msgs::Float |
| std_msgs/msg/Float64 | gz::msgs::Double |
| std_msgs/msg/Header | gz::msgs::Header |
| std_msgs/msg/Int32 | gz::msgs::Int32 |
| std_msgs/msg/UInt32 | gz::msgs::UInt32 |
| std_msgs/msg/String | gz::msgs::StringMsg |
| geometry_msgs/msg/Wrench | gz::msgs::Wrench |
| geometry_msgs/msg/WrenchStamped | gz::msgs::Wrench |
| geometry_msgs/msg/Quaternion | gz::msgs::Quaternion |
| geometry_msgs/msg/Vector3 | gz::msgs::Vector3d |
| geometry_msgs/msg/Point | gz::msgs::Vector3d |
| geometry_msgs/msg/Pose | gz::msgs::Pose |
| geometry_msgs/msg/PoseArray | gz::msgs::Pose_V |
| geometry_msgs/msg/PoseWithCovariance | gz::msgs::PoseWithCovariance |
| geometry_msgs/msg/PoseStamped | gz::msgs::Pose |
| geometry_msgs/msg/Transform | gz::msgs::Pose |
| geometry_msgs/msg/TransformStamped | gz::msgs::Pose |
| geometry_msgs/msg/Twist | gz::msgs::Twist |
| geometry_msgs/msg/TwistStamped | gz::msgs::Twist |
| geometry_msgs/msg/TwistWithCovariance| gz::msgs::TwistWithCovariance |
| nav_msgs/msg/Odometry | gz::msgs::Odometry |
| nav_msgs/msg/Odometry | gz::msgs::OdometryWithCovariance |
| rcl_interfaces/msg/ParameterValue | gz::msgs::Any |
| ros_gz_interfaces/msg/Altimeter | gz::msgs::Altimeter |
| ros_gz_interfaces/msg/Contact | gz::msgs::Contact |
| ros_gz_interfaces/msg/Contacts | gz::msgs::Contacts |
| ros_gz_interfaces/msg/Dataframe | gz::msgs::Dataframe |
| ros_gz_interfaces/msg/Entity | gz::msgs::Entity |
| ros_gz_interfaces/msg/Float32Array | gz::msgs::Float_V |
| ros_gz_interfaces/msg/GuiCamera | gz::msgs::GUICamera |
| ros_gz_interfaces/msg/JointWrench | gz::msgs::JointWrench |
| ros_gz_interfaces/msg/Light | gz::msgs::Light |
| ros_gz_interfaces/msg/MaterialColor | gz::msgs::MaterialColor |
| ros_gz_interfaces/msg/SensorNoise | gz::msgs::SensorNoise |
| ros_gz_interfaces/msg/StringVec | gz::msgs::StringMsg_V |
| ros_gz_interfaces/msg/TrackVisual | gz::msgs::TrackVisual |
| ros_gz_interfaces/msg/VideoRecord | gz::msgs::VideoRecord |
| ros_gz_interfaces/msg/WorldControl | gz::msgs::WorldControl |
| rosgraph_msgs/msg/Clock | gz::msgs::Clock |
| sensor_msgs/msg/BatteryState | gz::msgs::BatteryState |
| sensor_msgs/msg/CameraInfo | gz::msgs::CameraInfo |
| sensor_msgs/msg/FluidPressure | gz::msgs::FluidPressure |
| sensor_msgs/msg/Imu | gz::msgs::IMU |
| sensor_msgs/msg/Image | gz::msgs::Image |
| sensor_msgs/msg/JointState | gz::msgs::Model |
| sensor_msgs/msg/Joy | gz::msgs::Joy |
| sensor_msgs/msg/LaserScan | gz::msgs::LaserScan |
| sensor_msgs/msg/MagneticField | gz::msgs::Magnetometer |
| sensor_msgs/msg/NavSatFix | gz::msgs::NavSat |
| sensor_msgs/msg/PointCloud2 | gz::msgs::PointCloudPacked |
| tf2_msgs/msg/TFMessage | gz::msgs::Pose_V |
| trajectory_msgs/msg/JointTrajectory | gz::msgs::JointTrajectory |

And the following for services:

| ROS type | Gazebo request | Gazebo response |
|--------------------------------------|:--------------------------:| --------------------- |
| ros_gz_interfaces/srv/ControlWorld | ignition.msgs.WorldControl | ignition.msgs.Boolean |
| ros_gz_interfaces/srv/ControlWorld | gz.msgs.WorldControl | gz.msgs.Boolean |

Run `ros2 run ros_gz_bridge parameter_bridge -h` for instructions.

Expand All @@ -78,7 +80,7 @@ Start the parameter bridge which will watch the specified topics.
```
# Shell A:
. ~/bridge_ws/install/setup.bash
ros2 run ros_gz_bridge parameter_bridge /chatter@std_msgs/msg/String@ignition.msgs.StringMsg
ros2 run ros_gz_bridge parameter_bridge /chatter@std_msgs/msg/String@gz.msgs.StringMsg
```

Now we start the ROS listener.
Expand All @@ -93,7 +95,7 @@ Now we start the Gazebo Transport talker.

```
# Shell C:
ign topic -t /chatter -m ignition.msgs.StringMsg -p 'data:"Hello"'
gz topic -t /chatter -m gz.msgs.StringMsg -p 'data:"Hello"'
```

## Example 1b: ROS 2 talker and Gazebo Transport listener
Expand All @@ -103,14 +105,14 @@ Start the parameter bridge which will watch the specified topics.
```
# Shell A:
. ~/bridge_ws/install/setup.bash
ros2 run ros_gz_bridge parameter_bridge /chatter@std_msgs/msg/String@ignition.msgs.StringMsg
ros2 run ros_gz_bridge parameter_bridge /chatter@std_msgs/msg/String@gz.msgs.StringMsg
```

Now we start the Gazebo Transport listener.

```
# Shell B:
ign topic -e -t /chatter
gz topic -e -t /chatter
```

Now we start the ROS talker.
Expand All @@ -131,14 +133,14 @@ First we start Gazebo Sim (don't forget to hit play, or Gazebo Sim won't generat

```
# Shell A:
ign gazebo sensors_demo.sdf
gz gazebo sensors_demo.sdf
```

Let's see the topic where camera images are published.

```
# Shell B:
ign topic -l | grep image
gz topic -l | grep image
/rgbd_camera/depth_image
/rgbd_camera/image
```
Expand All @@ -148,7 +150,7 @@ Then we start the parameter bridge with the previous topic.
```
# Shell B:
. ~/bridge_ws/install/setup.bash
ros2 run ros_gz_bridge parameter_bridge /rgbd_camera/image@sensor_msgs/msg/Image@ignition.msgs.Image
ros2 run ros_gz_bridge parameter_bridge /rgbd_camera/image@sensor_msgs/msg/Image@gz.msgs.Image
```

Now we start the ROS GUI:
Expand Down Expand Up @@ -189,15 +191,15 @@ On terminal B, we start a ROS 2 listener:

And terminal C, publish an Gazebo message:

`ign topic -t /chatter -m ignition.msgs.StringMsg -p 'data:"Hello"'`
`gz topic -t /chatter -m gz.msgs.StringMsg -p 'data:"Hello"'`

At this point, you should see the ROS 2 listener echoing the message.

Now let's try the other way around, ROS 2 -> Gazebo.

On terminal D, start an Igntion listener:
On terminal D, start an gz listener:

`ign topic -e -t /chatter`
`gz topic -e -t /chatter`

And on terminal E, publish a ROS 2 message:

Expand All @@ -215,7 +217,7 @@ On terminal A, start the service bridge:

On terminal B, start Gazebo, it will be paused by default:

`ign gazebo shapes.sdf`
`gz gazebo shapes.sdf`

On terminal C, make a ROS request to unpause simulation:

Expand All @@ -237,35 +239,35 @@ bridge may be specified:
# Set just topic name, applies to both
- topic_name: "chatter"
ros_type_name: "std_msgs/msg/String"
gz_type_name: "ignition.msgs.StringMsg"
gz_type_name: "gz.msgs.StringMsg"

# Set just ROS topic name, applies to both
- ros_topic_name: "chatter_ros"
ros_type_name: "std_msgs/msg/String"
gz_type_name: "ignition.msgs.StringMsg"
gz_type_name: "gz.msgs.StringMsg"

# Set just GZ topic name, applies to both
- gz_topic_name: "chatter_ign"
- gz_topic_name: "chatter_gz"
ros_type_name: "std_msgs/msg/String"
gz_type_name: "ignition.msgs.StringMsg"
gz_type_name: "gz.msgs.StringMsg"

# Set each topic name explicitly
- ros_topic_name: "chatter_both_ros"
gz_topic_name: "chatter_both_ign"
gz_topic_name: "chatter_both_gz"
ros_type_name: "std_msgs/msg/String"
gz_type_name: "ignition.msgs.StringMsg"
gz_type_name: "gz.msgs.StringMsg"

# Full set of configurations
- ros_topic_name: "ros_chatter"
gz_topic_name: "ign_chatter"
gz_topic_name: "gz_chatter"
ros_type_name: "std_msgs/msg/String"
gz_type_name: "ignition.msgs.StringMsg"
gz_type_name: "gz.msgs.StringMsg"
subscriber_queue: 5 # Default 10
publisher_queue: 6 # Default 10
lazy: true # Default "false"
direction: BIDIRECTIONAL # Default "BIDIRECTIONAL" - Bridge both directions
# "GZ_TO_ROS" - Bridge Ignition topic to ROS
# "ROS_TO_GZ" - Bridge ROS topic to Ignition
# "GZ_TO_ROS" - Bridge gz topic to ROS
# "ROS_TO_GZ" - Bridge ROS topic to gz
```

To run the bridge node with the above configuration:
Expand Down
16 changes: 16 additions & 0 deletions ros_gz_bridge/include/ros_gz_bridge/convert/ros_gz_interfaces.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018 Open Source Robotics Foundation, Inc.
// Copyright (C) 2024 CogniPilot Foundation
// Copyright (C) 2024 Rudis Laboratories LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -24,6 +26,7 @@
#include <gz/msgs/float_v.pb.h>
#include <gz/msgs/gui_camera.pb.h>
#include <gz/msgs/light.pb.h>
#include <gz/msgs/material_color.pb.h>
#include <gz/msgs/param.pb.h>
#include <gz/msgs/param_v.pb.h>
#include <gz/msgs/sensor_noise.pb.h>
Expand All @@ -41,6 +44,7 @@
#include <ros_gz_interfaces/msg/float32_array.hpp>
#include <ros_gz_interfaces/msg/gui_camera.hpp>
#include <ros_gz_interfaces/msg/light.hpp>
#include <ros_gz_interfaces/msg/material_color.hpp>
#include <ros_gz_interfaces/msg/param_vec.hpp>
#include <ros_gz_interfaces/msg/sensor_noise.hpp>
#include <ros_gz_interfaces/msg/string_vec.hpp>
Expand Down Expand Up @@ -159,6 +163,18 @@ convert_gz_to_ros(
const gz::msgs::Light & gz_msg,
ros_gz_interfaces::msg::Light & ros_msg);

template<>
void
convert_ros_to_gz(
const ros_gz_interfaces::msg::MaterialColor & ros_msg,
gz::msgs::MaterialColor & gz_msg);

template<>
void
convert_gz_to_ros(
const gz::msgs::MaterialColor & gz_msg,
ros_gz_interfaces::msg::MaterialColor & ros_msg);

template<>
void
convert_ros_to_gz(
Expand Down
3 changes: 3 additions & 0 deletions ros_gz_bridge/ros_gz_bridge/mappings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Copyright 2022 Open Source Robotics Foundation, Inc.
# Copyright (C) 2024 CogniPilot Foundation
# Copyright (C) 2024 Rudis Laboratories LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,6 +64,7 @@
Mapping('GuiCamera', 'GUICamera'),
Mapping('JointWrench', 'JointWrench'),
Mapping('Light', 'Light'),
Mapping('MaterialColor', 'MaterialColor'),
Mapping('ParamVec', 'Param'),
Mapping('ParamVec', 'Param_V'),
Mapping('SensorNoise', 'SensorNoise'),
Expand Down
37 changes: 37 additions & 0 deletions ros_gz_bridge/src/convert/ros_gz_interfaces.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018 Open Source Robotics Foundation, Inc.
// Copyright (C) 2024 CogniPilot Foundation
// Copyright (C) 2024 Rudis Laboratories LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -380,6 +382,41 @@ convert_gz_to_ros(
ros_msg.intensity = gz_msg.intensity();
}

template<>
void
convert_ros_to_gz(
const ros_gz_interfaces::msg::MaterialColor & ros_msg,
gz::msgs::MaterialColor & gz_msg)
{
convert_ros_to_gz(ros_msg.header, (*gz_msg.mutable_header()));

gz_msg.set_name(ros_msg.name);

convert_ros_to_gz(ros_msg.ambient, *gz_msg.mutable_ambient());
convert_ros_to_gz(ros_msg.diffuse, *gz_msg.mutable_diffuse());
convert_ros_to_gz(ros_msg.specular, *gz_msg.mutable_specular());
convert_ros_to_gz(ros_msg.emissive, *gz_msg.mutable_emissive());

gz_msg.set_parent_name(ros_msg.parent_name);
}

template<>
void
convert_gz_to_ros(
const gz::msgs::MaterialColor & gz_msg,
ros_gz_interfaces::msg::MaterialColor & ros_msg)
{
convert_gz_to_ros(gz_msg.header(), ros_msg.header);

ros_msg.name = gz_msg.name();
convert_gz_to_ros(gz_msg.ambient(), ros_msg.ambient);
convert_gz_to_ros(gz_msg.diffuse(), ros_msg.diffuse);
convert_gz_to_ros(gz_msg.specular(), ros_msg.specular);
convert_gz_to_ros(gz_msg.emissive(), ros_msg.emissive);

ros_msg.parent_name = gz_msg.parent_name();
}

template<>
void
convert_ros_to_gz(
Expand Down
Loading
Loading