Skip to content

Commit

Permalink
Merge pull request #6 from IOES-Lab/dave-sensor
Browse files Browse the repository at this point in the history
Moved nortek_dvl500_300 to separate package dave_sensor_models
  • Loading branch information
rakeshv24 authored Jun 29, 2024
2 parents a5bf461 + 2ee418e commit a07a1d7
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 23 deletions.
18 changes: 9 additions & 9 deletions examples/dave_demos/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Examples

### 1. Launching a Dave Model using Fuel URI
### 1. Launching a Dave Object Model using Fuel URI

To launch a Dave model directly from a Fuel URI, follow these steps:

Expand All @@ -13,25 +13,25 @@ To launch a Dave model directly from a Fuel URI, follow these steps:
2. Launch the model using the specified launch file:

```bash
ros2 launch dave_demos model_in_empty_world.launch.py model_name:='mossy_cinder_block'
ros2 launch dave_demos object_in_empty_world.launch.py object_name:='mossy_cinder_block'
```

This method simplifies the process by pulling the model directly from Fuel, ensuring you always have the latest version without needing to manage local files.

### 2. Launching a Dave Model using Downloaded Model Files
### 2. Launching a Dave Sensor Model using Downloaded Model Files

If you prefer to use model files downloaded from Fuel, proceed as follows:

1. Add a hook within the `dave_object_models` package to configure the necessary environment variables for Gazebo model lookup.
1. Add a hook within the `dave_sensor_models` package to configure the necessary environment variables for Gazebo model lookup.

```bash
cd <path-to-dave_ws>/src/dave/models/dave_object_models
cd <path-to-dave_ws>/src/dave/models/dave_sensor_models
mkdir hooks && cd hooks
touch dave_object_models.dsv.in
echo "prepend-non-duplicate;GZ_SIM_RESOURCE_PATH;@CMAKE_INSTALL_PREFIX@/share/@PROJECT_NAME@" >> dave_object_models.dsv.in
touch dave_sensor_models.dsv.in
echo "prepend-non-duplicate;GZ_SIM_RESOURCE_PATH;@CMAKE_INSTALL_PREFIX@/share/@PROJECT_NAME@" >> dave_sensor_models.dsv.in
```

2. Append the following line to the CMakeLists.txt file in the `dave_object_models` package:
2. Append the following line to the CMakeLists.txt file in the `dave_sensor_models` package:

```bash
ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/hooks/${PROJECT_NAME}.dsv.in")
Expand All @@ -47,7 +47,7 @@ If you prefer to use model files downloaded from Fuel, proceed as follows:
4. Launch the model using the provided launch file:

```bash
ros2 launch dave_demos model_in_empty_world.launch.py model_name:='nortek_dvl500_300'
ros2 launch dave_demos sensor_in_empty_world.launch.py sensor_name:='nortek_dvl500_300'
```

This approach gives you more control over the models you use, allowing for offline use and customization. It's especially useful when working in environments with limited internet connectivity or when specific model versions are required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def generate_launch_description():
use_sim = LaunchConfiguration("use_sim")
model_name = LaunchConfiguration("model_name")
object_name = LaunchConfiguration("object_name")
gazebo_world_file = LaunchConfiguration("gazebo_world_file")

# Declare the launch arguments with default values
Expand All @@ -24,9 +24,9 @@ def generate_launch_description():
description="Flag to indicate whether to use simulation",
),
DeclareLaunchArgument(
"model_name",
"object_name",
default_value="mossy_cinder_block",
description="Name of the model to load",
description="Name of the object model to load",
),
]

Expand Down Expand Up @@ -63,13 +63,13 @@ def generate_launch_description():
[
FindPackageShare("dave_object_models"),
"launch",
"upload_model.launch.py",
"upload_object.launch.py",
]
)
]
),
launch_arguments={
"model_name": model_name,
"object_name": object_name,
"use_sim": use_sim,
}.items(),
)
Expand Down
79 changes: 79 additions & 0 deletions examples/dave_demos/launch/sensor_in_empty_world.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.conditions import IfCondition
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
use_sim = LaunchConfiguration("use_sim")
sensor_name = LaunchConfiguration("sensor_name")
gazebo_world_file = LaunchConfiguration("gazebo_world_file")

# Declare the launch arguments with default values
args = [
DeclareLaunchArgument(
"gazebo_world_file",
default_value="empty.sdf",
description="Gazebo world file to launch",
),
DeclareLaunchArgument(
"use_sim",
default_value="true",
description="Flag to indicate whether to use simulation",
),
DeclareLaunchArgument(
"sensor_name",
default_value="nortek_dvl500_300",
description="Name of the model to load",
),
]

# Include the first launch file
gz_sim_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[
PathJoinSubstitution(
[
FindPackageShare("ros_gz_sim"),
"launch",
"gz_sim.launch.py",
]
)
]
),
launch_arguments=[
(
"gz_args",
[
"-r ",
gazebo_world_file,
],
),
],
condition=IfCondition(use_sim),
)

# Include the second launch file with model name
model_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[
PathJoinSubstitution(
[
FindPackageShare("dave_sensor_models"),
"launch",
"upload_sensor.launch.py",
]
)
]
),
launch_arguments={
"sensor_name": sensor_name,
"use_sim": use_sim,
}.items(),
)

include = [gz_sim_launch, model_launch]

return LaunchDescription(args + include)
2 changes: 1 addition & 1 deletion models/dave_object_models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(dave_object_models)
find_package(ament_cmake REQUIRED)

install(
DIRECTORY description launch meshes
DIRECTORY description launch
DESTINATION share/dave_object_models
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version='1.0'?>

<model>
<name>mossy_cinder_block</name>
<version>1.0</version>
<sdf version="1.7">model.sdf</sdf>

<description>
A mossy cinder block
</description>
</model>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<sdf version="1.5">
<sdf version="1.7">
<include>
<name>mossy_cinder_block</name>
<pose>0 0 0 0 0 0</pose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@


def generate_launch_description():
model_name = LaunchConfiguration("model_name")
object_name = LaunchConfiguration("object_name")
use_sim = LaunchConfiguration("use_sim")

args = [
DeclareLaunchArgument(
"model_name",
"object_name",
default_value="model",
description="Name of the model to load",
description="Name of the object model to load",
),
DeclareLaunchArgument(
"use_sim",
Expand All @@ -28,15 +28,15 @@ def generate_launch_description():
[
FindPackageShare("dave_object_models"),
"description",
model_name,
object_name,
"model.sdf",
]
)

gz_spawner = Node(
package="ros_gz_sim",
executable="create",
arguments=["-name", model_name, "-file", description_file],
arguments=["-name", object_name, "-file", description_file],
output="both",
condition=IfCondition(use_sim),
parameters=[{"use_sim_time": use_sim}],
Expand Down
2 changes: 1 addition & 1 deletion models/dave_object_models/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>dave_object_models</name>
<version>0.1.0</version>
<description>Dave model description files are placed here.</description>
<description>Dave object model description files are placed here.</description>
<maintainer email="[email protected]">Rakesh Vivekanandan</maintainer>
<license>MIT</license>
<buildtool_depend>ament_cmake</buildtool_depend>
Expand Down
11 changes: 11 additions & 0 deletions models/dave_robot_models/description/rexrov/model.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version='1.0'?>

<model>
<name>rexrov</name>
<version>1.0</version>
<sdf version="1.7">model.sdf</sdf>

<description>
Rexrov underwater vehicle
</description>
</model>
14 changes: 14 additions & 0 deletions models/dave_sensor_models/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.8)
project(dave_sensor_models)

find_package(ament_cmake REQUIRED)

install(
DIRECTORY description launch meshes
DESTINATION share/dave_sensor_models
)

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

ament_package()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version='1.0'?>

<model>
<name>dvl500_300</name>
<version>1.0</version>
<sdf version="1.7">model.sdf</sdf>

<description>
Nortek DVL500-300m
</description>
</model>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<sdf version="1.6">
<sdf version="1.7">
<model name="dvl500_300">
<link name="dvl500_base_link">
<pose>0 0 0 0 0 0</pose>
Expand Down
1 change: 1 addition & 0 deletions models/dave_sensor_models/hooks/dave_sensor_models.dsv.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prepend-non-duplicate;GZ_SIM_RESOURCE_PATH;@CMAKE_INSTALL_PREFIX@/share/@PROJECT_NAME@
53 changes: 53 additions & 0 deletions models/dave_sensor_models/launch/upload_sensor.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, RegisterEventHandler, LogInfo
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch.conditions import IfCondition
from launch_ros.substitutions import FindPackageShare
from launch.event_handlers import OnProcessExit
from launch_ros.actions import Node


def generate_launch_description():
sensor_name = LaunchConfiguration("sensor_name")
use_sim = LaunchConfiguration("use_sim")

args = [
DeclareLaunchArgument(
"sensor_name",
default_value="",
description="Name of the sensor to load",
),
DeclareLaunchArgument(
"use_sim",
default_value="true",
description="Flag to indicate whether to use simulation",
),
]

description_file = PathJoinSubstitution(
[
FindPackageShare("dave_sensor_models"),
"description",
sensor_name,
"model.sdf",
]
)

gz_spawner = Node(
package="ros_gz_sim",
executable="create",
arguments=["-name", sensor_name, "-file", description_file],
output="both",
condition=IfCondition(use_sim),
parameters=[{"use_sim_time": use_sim}],
)

nodes = [gz_spawner]

event_handlers = [
RegisterEventHandler(
OnProcessExit(target_action=gz_spawner, on_exit=LogInfo(msg="Model Uploaded"))
)
]

return LaunchDescription(args + nodes + event_handlers)
14 changes: 14 additions & 0 deletions models/dave_sensor_models/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?><package format="3">
<name>dave_sensor_models</name>
<version>0.1.0</version>
<description>Dave sensor model description files are placed here.</description>
<maintainer email="[email protected]">Rakesh Vivekanandan</maintainer>
<license>MIT</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<export>
<build_type>ament_cmake</build_type>
<!-- This doesn't work yet https://github.com/gazebosim/ros_gz/pull/492 -->
<!-- <gazebo_ros gazebo_model_path="${prefix}/meshes"/> -->
</export>
</package>

0 comments on commit a07a1d7

Please sign in to comment.