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

Change generated location ros2 #50

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ map/*
gt/*
launch/robot_spawner.launch.py

# Ignore generated models
models/*_day_*

# Ignore models that may not be published on Github
models/dandelion_*

# Ignore saved world descriptions
*.json

# Keep specific files
!map/.gitkeep
!gt/.gitkeep
Empty file removed Media/models/.gitkeep
Empty file.
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You can call the script using
```bash
ros2 run virtual_maize_field generate_world
```
The resulting file will be placed in `<workspace folder>/install/virtual_maize_field/share/virtual_maize_field/worlds/generated.world`. You can use this script by one of the defined config files or specifying the parameters below:
The resulting file will be placed in `$ROS_HOME/virtual_maize_field/generated.world`. You can use this script by one of the defined config files or specifying the parameters below:
<details>
<summary>Click to show all possible arguments</summary>

Expand Down Expand Up @@ -182,7 +182,7 @@ Worlds for the Field Robot Event 2022:
| *fre22_task_navigation* | Task navigation, curved rows that get more difficult (eg. have more and larger holes) to the left |
| *fre22_task_mapping* | Task mapping, field with random holes, bottles and weeds spread throughout the field. The cans, bottles and weeds have no collision box and are static. <br /><sub>This world needs dandelion models which were only distributed among competitors of the Field Robot Event 2022. They are not uploaded to Github because they cannot be open-sourced. If you don't have access to these models, check out the `fre21_task_3` worlds.</sub>|

Other sample Worlds:
Worlds for the Field Robot Event 2021:
| Name | Description |
|:---- |:----------- |
| *fre21_task_1* | Task 1, curved rows without holes |
Expand All @@ -195,9 +195,44 @@ You can use these config files when generating worlds, e.g.:
ros2 run virtual_maize_field generate_world fre22_task_navigation_mini
```

## Launching worlds
## Launching and using generated worlds
The launch file to launch the worlds is called `simulation.launch`. You can launch the launch file by running `ros2 launch virtual_maize_field simulation.launch.py`. By default the launch file will launch `generated_world.world`. You can launch any world by using the `world_name` arg. e.g. `ros2 launch virtual_maize_field simulation.launch.py world_name:=simple_row_level_1.world`.

To add your own robot in the world, use the generated `robot_spawner.launch.py`. This launches your robot at the correct position in the generated world. Your launch file to launch your robot should look like (replace `<<robot_name>>` with your robot name):

```python
from __future__ import annotations

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource

from virtual_maize_field import get_spawner_launch_file


def generate_launch_description() -> LaunchDescription:
robot_spawner_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([get_spawner_launch_file()]),
launch_arguments={"robot_name": "<<robot_name>>"}.items(),
)

return LaunchDescription([robot_spawner_launch])
```

Use the function `get_driving_pattern()` to get the path of the generated driving pattern:

```python
from __future__ import annotations

from pathlib import Path

from virtual_maize_field import get_driving_pattern

def read_driving_pattern() -> None:
driving_pattern = Path(get_driving_pattern()).read_text("utf-8")
print(f"The driving pattern is {driving_pattern}")
```

## License
Virtual Maize Field is copyright (C) 2021 *Farm Technology Group of Wageningen University & Research* and *Kamaro Engineering e.V.* and licensed under [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0).

Expand Down
Empty file removed gt/.gitkeep
Empty file.
25 changes: 0 additions & 25 deletions launch/rviz.launch.py

This file was deleted.

89 changes: 39 additions & 50 deletions launch/simulation.launch.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,38 @@
from __future__ import annotations

from os import environ, path

from ament_index_python.packages import get_package_share_directory
from launch_ros.actions import Node

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import Node


def generate_launch_description() -> LaunchDescription:
use_sim_time = LaunchConfiguration("use_sim_time")
gui = LaunchConfiguration("gui")
paused = LaunchConfiguration("paused")
headless = LaunchConfiguration("headless")
world_path = LaunchConfiguration("world_path")
world_name = LaunchConfiguration("world_name")
check_for_updates = LaunchConfiguration("check_for_updates")
_ros_home_path = environ.get("ROS_HOME", path.join(path.expanduser("~"), ".ros"))
cache_dir = path.join(_ros_home_path, "virtual_maize_field/")

# Create launch arguments
declare_use_sim_time_cmd = DeclareLaunchArgument(
name="use_sim_time", default_value="True"
)
declare_gui_cmd = DeclareLaunchArgument(name="gui", default_value="True")
declare_paused_cmd = DeclareLaunchArgument(name="paused", default_value="False")
declare_headless_cmd = DeclareLaunchArgument(name="headless", default_value="False")
declare_world_path_cmd = DeclareLaunchArgument(
name="world_path",
default_value=get_package_share_directory("virtual_maize_field") + "/worlds/",
)
declare_world_name_cmd = DeclareLaunchArgument(
name="world_name", default_value="generated.world"
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")
check_for_updates = LaunchConfiguration("check_for_updates", default=True)

gz_server_launch_file = path.join(
get_package_share_directory("gazebo_ros"), "launch", "gzserver.launch.py"
)
declare_check_for_updates_cmd = DeclareLaunchArgument(
name="check_for_updates", default_value="True"
gz_client_launch_file = path.join(
get_package_share_directory("gazebo_ros"), "launch", "gzclient.launch.py"
)

# Create nodes
start_gazebo_server_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
get_package_share_directory("gazebo_ros") + "/launch/gzserver.launch.py"
),
gz_server_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([gz_server_launch_file]),
launch_arguments={
"world": [world_path, world_name],
"pause": paused,
Expand All @@ -49,36 +41,33 @@ def generate_launch_description() -> LaunchDescription:
}.items(),
)

start_gazebo_client_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
get_package_share_directory("gazebo_ros") + "/launch/gzclient.launch.py"
),
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(),
)

start_check_updates_node_cmd = Node(
check_updates_node = Node(
package="virtual_maize_field",
executable="check_for_updates",
name="check_virtual_maize_field_updates",
condition=IfCondition(check_for_updates),
arguments={"use_sim_time": use_sim_time}.items(),
)

ld = LaunchDescription()

# Declare the launch options
ld.add_action(declare_use_sim_time_cmd)
ld.add_action(declare_gui_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)
ld.add_action(declare_check_for_updates_cmd)

# Add nodes
ld.add_action(start_gazebo_server_cmd)
ld.add_action(start_gazebo_client_cmd)
ld.add_action(start_check_updates_node_cmd)

return ld
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),
DeclareLaunchArgument(
name="check_for_updates", default_value=check_for_updates
),
gz_server_launch,
gz_client_launch,
check_updates_node,
]
)
Empty file removed map/.gitkeep
Empty file.
1 change: 0 additions & 1 deletion map/driving_pattern.txt

This file was deleted.

2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?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>4.7.4</version>
<version>5.0.0</version>
<description>A virtual maize field for agricultural robot simulation in Gazebo.</description>

<maintainer email="[email protected]">Field Robot Event Organization</maintainer>
Expand Down
Loading