Skip to content

Commit

Permalink
Refactor to Ignition Gazebo
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick-v-E committed Jan 19, 2024
1 parent cc89a4d commit f8c0b2f
Show file tree
Hide file tree
Showing 25 changed files with 322 additions and 195 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Virtual Maize Field (ROS 2)
## Virtual Maize Field (ROS 2 Ignition Gazebo)

### Version 5.0.0 (2024-01-20)
* Refactor to Ignition Gazebo ([#57](https://github.com/FieldRobotEvent/virtual_maize_field/pull/57))
* Change location of generated files ([#56](https://github.com/FieldRobotEvent/virtual_maize_field/pull/56))
* Remove outdated script that checks for updates ([#56](https://github.com/FieldRobotEvent/virtual_maize_field/pull/56))

Expand Down
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.5)
project(virtual_maize_field)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)

ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/hooks/resource_paths.dsv.in")
ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/hooks/resource_paths.sh")

ament_python_install_package(${PROJECT_NAME})

#============================================================================
# Nodes

install(
PROGRAMS virtual_maize_field/generate_world.py
DESTINATION lib/${PROJECT_NAME}
RENAME generate_world
)

#============================================================================
# Resources
install(
DIRECTORY
config
map
models
worlds
gt
launch
DESTINATION share/${PROJECT_NAME}
)

ament_package()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
This is a package to procedurally generate randomized fields with rows of plants for Gazebo.
</p>

![Screenshot of a generated map with maize plants](./misc/screenshot_v5.0_classic.png)
![Screenshot of a generated map with maize plants](./misc/screenshot_v5.0_ign.png)

ROS Distro | Gazebo version | Branch | Build status
:---------: | :----: | :----: | :----------:
Expand Down
4 changes: 4 additions & 0 deletions hooks/resource_paths.dsv.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
prepend-non-duplicate;IGN_GAZEBO_RESOURCE_PATH;@CMAKE_INSTALL_PREFIX@/share/@PROJECT_NAME@/models
prepend-non-duplicate;IGN_GAZEBO_RESOURCE_PATH;@CMAKE_INSTALL_PREFIX@/share/@PROJECT_NAME@/

prepend-non-duplicate;LD_LIBRARY_PATH;@CMAKE_INSTALL_PREFIX@/lib
4 changes: 4 additions & 0 deletions hooks/resource_paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ament_prepend_unique_value IGN_GAZEBO_RESOURCE_PATH "$AMENT_CURRENT_PREFIX/share/virtual_maize_field/models"
ament_prepend_unique_value IGN_GAZEBO_RESOURCE_PATH "$AMENT_CURRENT_PREFIX/share/virtual_maize_field"

ament_prepend_unique_value LD_LIBRARY_PATH "$AMENT_CURRENT_PREFIX/lib"
111 changes: 74 additions & 37 deletions launch/simulation.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,94 @@
from os import environ, path

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.conditions import IfCondition
from launch import LaunchDescription, SomeSubstitutionsType
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, LogInfo
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch.substitutions import (
LaunchConfiguration,
PathJoinSubstitution,
PythonExpression,
)


def construct_gz_args(
world_file: SomeSubstitutionsType,
paused: SomeSubstitutionsType,
headless: SomeSubstitutionsType,
) -> SomeSubstitutionsType:
paused_arg = PythonExpression(['"" if "', paused, '".lower() == "true" else "-r "'])
headless_arg = PythonExpression(
['"-s " if "', headless, '".lower() == "true" else ""']
)

return PythonExpression(["'", headless_arg, paused_arg, world_file, "'"])


def generate_launch_description() -> LaunchDescription:
_ros_home_path = environ.get("ROS_HOME", path.join(path.expanduser("~"), ".ros"))
cache_dir = path.join(_ros_home_path, "virtual_maize_field/")

use_sim_time = LaunchConfiguration("use_sim_time", default=True)
gui = LaunchConfiguration("gui", default=True)
paused = LaunchConfiguration("paused", default=False)
headless = LaunchConfiguration("headless", default=False)
world_path = LaunchConfiguration("world_path", default=cache_dir)
world_name = LaunchConfiguration("world_name", default="generated.world")
use_sim_time = LaunchConfiguration("use_sim_time")
paused = LaunchConfiguration("paused")
headless = LaunchConfiguration("headless")
world_path = LaunchConfiguration("world_path")
world_name = LaunchConfiguration("world_name")

gz_server_launch_file = path.join(
get_package_share_directory("gazebo_ros"), "launch", "gzserver.launch.py"
# Create launch arguments
declare_use_sim_time_cmd = DeclareLaunchArgument(
name="use_sim_time", default_value="True"
)
declare_paused_cmd = DeclareLaunchArgument(
name="paused", default_value="False", description="Start simulation paused."
)
declare_headless_cmd = DeclareLaunchArgument(
name="headless",
default_value="False",
description="Start headless simulation (without rendering).",
)
declare_world_path_cmd = DeclareLaunchArgument(
name="world_path",
default_value=cache_dir,
description="Path to the directory containing the world SDF files.",
)
gz_client_launch_file = path.join(
get_package_share_directory("gazebo_ros"), "launch", "gzclient.launch.py"
declare_world_name_cmd = DeclareLaunchArgument(
name="world_name",
default_value="generated_field.sdf",
description="Name of the world file.",
)

gz_server_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([gz_server_launch_file]),
gz_args = construct_gz_args(
PathJoinSubstitution([world_path, world_name]),
paused,
headless,
)

log_gz_args = LogInfo(msg=["Start Ignition Gazebo with gz_args: '", gz_args, "'"])

# Create nodes
gz = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
path.join(
get_package_share_directory("ros_gz_sim"), "launch", "gz_sim.launch.py"
),
),
launch_arguments={
"world": [world_path, world_name],
"pause": paused,
"verbose": "true",
"gz_args": gz_args,
"use_sim_time": use_sim_time,
}.items(),
)

gz_client_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([gz_client_launch_file]),
condition=IfCondition(PythonExpression([gui, " and not ", headless])),
launch_arguments={"use_sim_time": use_sim_time}.items(),
)
ld = LaunchDescription()

return LaunchDescription(
[
DeclareLaunchArgument(name="use_sim_time", default_value=use_sim_time),
DeclareLaunchArgument(name="gui", default_value=gui),
DeclareLaunchArgument(name="paused", default_value=paused),
DeclareLaunchArgument(name="headless", default_value=headless),
DeclareLaunchArgument(name="world_path", default_value=world_path),
DeclareLaunchArgument(name="world_name", default_value=world_name),
gz_server_launch,
gz_client_launch,
]
)
# Declare the launch options
ld.add_action(declare_use_sim_time_cmd)
ld.add_action(declare_paused_cmd)
ld.add_action(declare_headless_cmd)
ld.add_action(declare_world_path_cmd)
ld.add_action(declare_world_name_cmd)

# Add nodes
ld.add_action(log_gz_args)
ld.add_action(gz)

return ld
5 changes: 5 additions & 0 deletions models/beer/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<uri>model://beer/materials/textures</uri>
<name>Beer/Diffuse</name>
</script>
<pbr>
<metal>
<albedo_map>model://beer/materials/textures/beer.png</albedo_map>
</metal>
</pbr>
</material>
</visual>
</link>
Expand Down
15 changes: 15 additions & 0 deletions models/location_marker_a/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<uri>model://location_marker_a/materials/textures</uri>
<name>location_marker_a/logo</name>
</script>
<pbr>
<metal>
<albedo_map>model://location_marker_a/materials/textures/fre_logo.png</albedo_map>
</metal>
</pbr>
</material>
</visual>
<visual name="visual_top">
Expand All @@ -47,6 +52,11 @@
<uri>model://location_marker_a/materials/textures</uri>
<name>location_marker_a/logo</name>
</script>
<pbr>
<metal>
<albedo_map>model://location_marker_a/materials/textures/fre_logo.png</albedo_map>
</metal>
</pbr>
</material>
</visual>
<visual name="visual_code">
Expand All @@ -62,6 +72,11 @@
<uri>model://location_marker_a/materials/textures</uri>
<name>location_marker_a/qr_code</name>
</script>
<pbr>
<metal>
<albedo_map>model://location_marker_a/materials/textures/location_marker_a.png</albedo_map>
</metal>
</pbr>
</material>
</visual>
</link>
Expand Down
15 changes: 15 additions & 0 deletions models/location_marker_b/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<uri>model://location_marker_b/materials/textures</uri>
<name>location_marker_b/logo</name>
</script>
<pbr>
<metal>
<albedo_map>model://location_marker_b/materials/textures/fre_logo.png</albedo_map>
</metal>
</pbr>
</material>
</visual>
<visual name="visual_top">
Expand All @@ -47,6 +52,11 @@
<uri>model://location_marker_b/materials/textures</uri>
<name>location_marker_b/logo</name>
</script>
<pbr>
<metal>
<albedo_map>model://location_marker_b/materials/textures/fre_logo.png</albedo_map>
</metal>
</pbr>
</material>
</visual>
<visual name="visual_code">
Expand All @@ -62,6 +72,11 @@
<uri>model://location_marker_b/materials/textures</uri>
<name>location_marker_b/qr_code</name>
</script>
<pbr>
<metal>
<albedo_map>model://location_marker_b/materials/textures/location_marker_b.png</albedo_map>
</metal>
</pbr>
</material>
</visual>
</link>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added models/materials/textures/flat_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added models/materials/textures/grass_color.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added models/materials/textures/grass_displacement.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added models/materials/textures/grass_normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added models/materials/textures/grass_roughness.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions models/nettle/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<uri>model://nettle/materials/textures/</uri>
<name>nettle_leaf</name>
</script>
<pbr>
<metal>
<albedo_map>model://nettle/materials/textures/nettle.png</albedo_map>
</metal>
</pbr>
</material>
</visual>
</link>
Expand Down
5 changes: 5 additions & 0 deletions models/start/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<uri>model://start/materials/textures</uri>
<name>start/texture</name>
</script>
<pbr>
<metal>
<albedo_map>model://start/materials/textures/arrow.png</albedo_map>
</metal>
</pbr>
</material>
</visual>

Expand Down
5 changes: 5 additions & 0 deletions models/unknown_weed/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<uri>model://unknown_weed/materials/textures/</uri>
<name>unknown_weed_leaf</name>
</script>
<pbr>
<metal>
<albedo_map>model://unknown_weed/materials/textures/unknown_weed.png</albedo_map>
</metal>
</pbr>
</material>
</visual>
</link>
Expand Down
13 changes: 7 additions & 6 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>virtual_maize_field</name>
<version>5.0.0</version>
<version>4.7.4</version>
<description>A virtual maize field for agricultural robot simulation in Gazebo.</description>

<maintainer email="info@fieldrobot.com">Field Robot Event Organization</maintainer>

<license file="LICENSE">GPLv3</license>
<url type="website">https://www.fieldrobot.com/event/</url>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_python</buildtool_depend>

<depend>python3-rospkg</depend>
<depend>python3-jinja2</depend>
<depend>python3-opencv</depend>
Expand All @@ -19,12 +22,10 @@
<depend>python3-yaml</depend>

<depend>ros2launch</depend>
<depend>gazebo_ros</depend>
<depend>gazebo_ros_pkgs</depend>
<depend>ros-gz</depend>
<depend>ros-gz-sim</depend>

<export>
<build_type>ament_python</build_type>
<gazebo_ros gazebo_model_path="${prefix}/models"/>
<gazebo_ros gazebo_media_path="${prefix}"/>
<build_type>ament_cmake</build_type>
</export>
</package>
Empty file removed resource/virtual_maize_field
Empty file.
4 changes: 0 additions & 4 deletions setup.cfg

This file was deleted.

Loading

0 comments on commit f8c0b2f

Please sign in to comment.