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

ros_ign_gazebo package, with launch and spawn #60

Merged
merged 4 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
76 changes: 76 additions & 0 deletions ros_ign_gazebo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
cmake_minimum_required(VERSION 3.5)

project(ros_ign_gazebo)

find_package(catkin
REQUIRED
COMPONENTS
roscpp
)

# Citadel
find_package(ignition-gazebo3 QUIET)
chapulina marked this conversation as resolved.
Show resolved Hide resolved
if (ignition-gazebo3_FOUND)
set(IGN_GAZEBO_VER ${ignition-gazebo3_VERSION_MAJOR})

find_package(ignition-transport8 REQUIRED)
set(IGN_TRANSPORT_VER ${ignition-transport8_VERSION_MAJOR})

find_package(ignition-msgs5 REQUIRED)
set(IGN_MSGS_VER ${ignition-msgs5_VERSION_MAJOR})

message(STATUS "Compiling against Ignition Citadel")

# Blueprint
else()
find_package(ignition-gazebo2 REQUIRED)
set(IGN_GAZEBO_VER ${ignition-gazebo2_VERSION_MAJOR})

find_package(ignition-transport7 REQUIRED)
set(IGN_TRANSPORT_VER ${ignition-transport7_VERSION_MAJOR})

find_package(ignition-msgs4 REQUIRED)
set(IGN_MSGS_VER ${ignition-msgs4_VERSION_MAJOR})

message(STATUS "Compiling against Ignition Blueprint")
endif()

ign_find_package(gflags
REQUIRED
PKGCONFIG gflags)

catkin_package()


include_directories(include ${catkin_INCLUDE_DIRS})

set(cpp_execs
create
)

foreach(exec ${cpp_execs})
add_executable(${exec} src/${exec}.cpp)
target_link_libraries(${exec}
${catkin_LIBRARIES}
gflags
ignition-msgs${IGN_MSGS_VER}::core
ignition-transport${IGN_TRANSPORT_VER}::core
)
install(TARGETS ${exec}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
endforeach()

install(
PROGRAMS
scripts/ign_gazebo
DESTINATION
${CATKIN_PACKAGE_BIN_DESTINATION})

install(
DIRECTORY
launch/
DESTINATION
${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
)

44 changes: 44 additions & 0 deletions ros_ign_gazebo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ROS + Ignition Gazebo

This package contains things that make it convenient to integrate ROS with
Ignition, such as:

* Launch files
* ROS-enabled executables

# Usage

> More usage examples can be seen on the
[ros_ign_gazebo_demos](https://github.com/osrf/ros_ign/tree/melodic/ros_ign_gazebo_demos)
package.

## Run Ignition Gazebo

There's a convenient launch file, try for example:

roslaunch ros_ign_gazebo ign_gazebo.launch ign_args:="shapes.sdf"

And you can directly call the executable, for example:

rosrun ros_ign_gazebo ign_gazebo shapes.sdf

![](images/shapes_demo.png)

## Spawn entities

The `create` executable can be used to spawn SDF or URDF entities from:

* A file on disk or from Ignition Fuel
* A ROS parameter

For example, start Ignition Gazebo:

`ign gazebo`

Then spawn a model:

`rosrun ros_ign_gazebo create -world default -file 'https://fuel.ignitionrobotics.org/1.0/openrobotics/models/Gazebo'`
chapulina marked this conversation as resolved.
Show resolved Hide resolved

See more options with:

`rosrun ros_ign_gazebo create --helpshort`
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<launch>
<arg name="args" default=""/>
<arg name="ign_args" default=""/>

<env name="IGN_GAZEBO_SYSTEM_PLUGIN_PATH" value="$(optenv LD_LIBRARY_PATH)" />

Expand All @@ -10,6 +10,6 @@
name="ign_gazebo"
chapulina marked this conversation as resolved.
Show resolved Hide resolved
output="screen"
required="true"
args="$(arg args)">
args="$(arg ign_args)">
</node>
</launch>
13 changes: 13 additions & 0 deletions ros_ign_gazebo/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<package format="2">
<name>ros_ign_gazebo</name>
<version>0.1.0</version>
<description>Tools for using Ignition Gazebo simulation with ROS.</description>
<license>Apache 2.0</license>
<maintainer email="[email protected]">Louise Poubel</maintainer>

<buildtool_depend>catkin</buildtool_depend>

<depend>libgflags-dev</depend>
<exec_depend>ignition-gazebo3</exec_depend>
<depend>roscpp</depend>
</package>
16 changes: 16 additions & 0 deletions ros_ign_gazebo/scripts/ign_gazebo
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# TODO This approach has way too many intermediate steps:
# * roslaunch runs this bash script
# * this script calls the ign tool (ruby)
# * the ruby tool finally calls the C interface
# This will make things harder to debug. A better approach could
# call directly into the C interface, but we need to avoid duplication.
new=""
for arg in "$@"
do
# Ignore roslaunch's args
if [[ $arg != __* ]]; then
new="$new $arg"
fi
done
ign gazebo $new
139 changes: 139 additions & 0 deletions ros_ign_gazebo/src/create.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright (C) 2019 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <gflags/gflags.h>
#include <ignition/math/Pose3.hh>
#include <ignition/msgs/entity_factory.pb.h>
#include <ignition/msgs/Utility.hh>
#include <ignition/transport/Node.hh>
#include <ros/ros.h>

#include <sstream>

DEFINE_string(world, "", "World name.");
DEFINE_string(file, "", "Load XML from a file.");
DEFINE_string(param, "", "Load XML from a ROS param.");
DEFINE_string(string, "", "Load XML from a string.");
DEFINE_string(name, "", "Name for spawned entity.");
DEFINE_bool(allow_renaming, false, "Rename entity if name already used.");
DEFINE_double(x, 0, "X component of initial position, in meters.");
DEFINE_double(y, 0, "Y component of initial position, in meters.");
DEFINE_double(z, 0, "Z component of initial position, in meters.");
DEFINE_double(R, 0, "Roll component of initial orientation, in radians.");
DEFINE_double(P, 0, "Pitch component of initial orientation, in radians.");
DEFINE_double(Y, 0, "Yaw component of initial orientation, in radians.");

// ROS interface for spawning entities into Ignition.
// Suggested for use with roslaunch and loading entities from ROS param.
// If these are not needed, just use the `ign service` command line instead.
int main(int _argc, char **_argv)
{
gflags::AllowCommandLineReparsing();
gflags::SetUsageMessage(
R"(Usage: create -world [arg] [-file FILE] [-param PARAM] [-string STRING]
[-name NAME] [-X X] [-Y Y] [-Z Z] [-Roll ROLL]
[-Pitch PITCH] [-Yaw YAW])");
gflags::ParseCommandLineFlags(&_argc, &_argv, true);

ros::init(_argc, _argv, "ign_create");
ros::NodeHandle nh;

// World
if (FLAGS_world.empty())
{
ROS_ERROR("World not set.");
return -1;
}
std::string service{"/world/" + FLAGS_world + "/create"};

// Request message
ignition::msgs::EntityFactory req;

// File
if (!FLAGS_file.empty())
{
req.set_sdf_filename(FLAGS_file);
}
// Param
else if (!FLAGS_param.empty())
{
std::string xmlStr;
if (nh.getParam(FLAGS_param, xmlStr))
{
req.set_sdf(xmlStr);
}
else
{
ROS_ERROR("Failed to get XML from param [%s].", FLAGS_param.c_str());
return -1;
}
}
// string
else if (!FLAGS_string.empty())
{
req.set_sdf(FLAGS_string);
}
else
{
ROS_ERROR("Must specify either -file, -param or -stdin");
return -1;
}

// Pose
ignition::math::Pose3d pose
{
FLAGS_x,
FLAGS_y,
FLAGS_z,
FLAGS_R,
FLAGS_P,
FLAGS_Y
};
ignition::msgs::Set(req.mutable_pose(), pose);

// Name
if (!FLAGS_name.empty())
{
req.set_name(FLAGS_name);
}

if (FLAGS_allow_renaming)
{
req.set_allow_renaming(FLAGS_allow_renaming);
}

// Request
ignition::transport::Node node;
ignition::msgs::Boolean rep;
bool result;
unsigned int timeout = 5000;
bool executed = node.Request(service, req, timeout, rep, result);

if (executed)
{
if (result && rep.data())
ROS_INFO("Requested creation of entity.");
else
ROS_ERROR("Failed request to create entity.\n %s", req.DebugString().c_str());
}
else
{
ROS_ERROR("Request to create entity from service [%s] timed out..\n %s",
service.c_str(), req.DebugString().c_str());
}

return 0;
}
22 changes: 6 additions & 16 deletions ros_ign_gazebo_demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,8 @@ project(ros_ign_gazebo_demos)

find_package(catkin REQUIRED)

# Citadel
find_package(ignition-gazebo3 QUIET)
if (NOT ignition-gazebo3_FOUND)
# Blueprint
find_package(ignition-gazebo2 QUIET)
if (NOT ignition-gazebo2_FOUND)
BUILD_ERROR ("Missing: Ignition Gazebo version 2 or 3")
endif()
endif()

catkin_package()

install(
PROGRAMS
scripts/ign_gazebo
DESTINATION
${CATKIN_PACKAGE_BIN_DESTINATION})

install(
DIRECTORY
launch/
Expand All @@ -36,3 +20,9 @@ install(
${CATKIN_PACKAGE_SHARE_DESTINATION}/rviz
)

install(
DIRECTORY
models/
DESTINATION
${CATKIN_PACKAGE_SHARE_DESTINATION}/models
)
24 changes: 12 additions & 12 deletions ros_ign_gazebo_demos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@

This package contains demos showing how to use Ignition Gazebo with ROS.

## Run Ignition Gazebo

There's a convenient launch file, try for example:

roslaunch ros_ign_gazebo_demos ign_gazebo.launch args:="shapes.sdf"

And you can directly call the executable, for example:

rosrun ros_ign_gazebo_demos ign_gazebo shapes.sdf

![](images/shapes_demo.png)

## Air pressure

Publishes fluid pressure readings.
Expand Down Expand Up @@ -132,3 +120,15 @@ Then send a command so the vehicle moves and drains the battery
rostopic pub /model/vehicle_blue/cmd_vel geometry_msgs/Twist "{linear: {x: 5.0}, angular: {z: 0.5}}"

![](images/battery_demo.png)

## Create entity

Launch simulation and spawn entities:

* Sphere from URDF loaded into ROS param
* Box from SDF file on Ignition Fuel
* Cylinder from SDF file

`roslaunch ros_ign_gazebo_demos create.launch`

![](images/create.png)
Binary file added ros_ign_gazebo_demos/images/create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ros_ign_gazebo_demos/launch/air_pressure.launch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<launch>

<include file="$(find ros_ign_gazebo_demos)/launch/ign_gazebo.launch">
<arg name="args" value="-r -v 3 sensors.sdf"/>
<include file="$(find ros_ign_gazebo)/launch/ign_gazebo.launch">
<arg name="ign_args" value="-r -v 3 sensors.sdf"/>
</include>

<node
Expand Down
Loading