Skip to content

Commit c0e8847

Browse files
committed
Split-off virelex_msgs, add trained models to virelex, misc fixes
While the monopackage pattern (containing both message interfaces and behavioral nodes) isn't intentionally unsupported by ROS2, it currently cannot support packages using `ament_cmake_python` to build C++ and Python code alongside `rosidl` message generation. This is a well-known and long-standing issue; see: ros2/rosidl_python#141 ament/ament_cmake#514 ament/ament_cmake#587 Accordingly, to support well-integrated inclusion of Python code in this package (i.e., by adding `run_vrx_experiments.py` to the CMake build system flow), this commit splits `virelex_msgs` out into a separate package. An argument could be made for converting `run_vrx_experiments.py` into a Python-syntax launch file, but it does a bit too much (defines a class, etc.) for that to feel like the correct option. In addition, this commit integrates the `pretrained_models` folder into the new `trained` subdirectory of `virelex`, providing a stable filesystem path to access those models during node execution (via `get_package_share_directory("virelex")`).
1 parent e643b0c commit c0e8847

23 files changed

+188
-87
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git/
2+
docker/

docker/Dockerfile.base-minimal

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ RUN --mount=type=cache,target=/var/cache/apt \
5555
--ignore-src \
5656
--rosdistro ${ROS_DISTRO} -y
5757

58+
RUN rm -r /ws/src
59+
60+
COPY vrx /ws/src/vrx
61+
# Build the project
62+
RUN . /opt/ros/${ROS_DISTRO}/setup.sh \
63+
&& cd /ws \
64+
&& colcon build --symlink-install --merge-install
65+
66+
RUN --mount=type=cache,target=/var/cache/apt \
67+
apt update \
68+
&& apt install -y --no-install-recommends \
69+
unzip \
70+
&& rm -rf /var/lib/apt/lists/* \
71+
&& apt clean -qq
72+
73+
RUN curl -L -s \
74+
-o /tmp/libtorch.zip \
75+
"https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.2.2%2Bcpu.zip" \
76+
&& \
77+
unzip "/tmp/libtorch.zip" -d "/tmp" \
78+
&& \
79+
cp -r /tmp/libtorch/* /usr/local \
80+
&& \
81+
rm -rf /tmp/libtorch.zip /tmp/libtorch
82+
5883
COPY . /ws/src/
5984
# Build the project
6085
RUN . /opt/ros/${ROS_DISTRO}/setup.sh \

rfarl/pyproject.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.setuptools]
6+
package-data = { "*" = ["*.json"] }
7+
8+
[project]
9+
name = "rfarl"
10+
version = "0.1.0"
11+
description = "Robust Field Autonomy Reinforcement-Learning"
12+
license = { text = "MIT" }
13+
authors = [
14+
{ name = "Xi Lin", email = "[email protected]" },
15+
]
16+
maintainers = [
17+
{ name = "Xi Lin", email = "[email protected]" },
18+
{ name = "Paul Szenher", email = "[email protected]" },
19+
]
20+
keywords=[
21+
'reinforcement-learning',
22+
]
23+
classifiers = [
24+
'License :: OSI Approved :: MIT License',
25+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
26+
]
27+
28+
dependencies = [
29+
"numpy",
30+
"torch",
31+
]

rfarl/rfarl/envs/marinenav/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
import scipy.spatial
3-
import marinenav_env.envs.utils.robot as robot
3+
import rfarl.envs.marinenav.vehicles.wamv as robot
44
import json
55
import copy
66

rfarl/setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
('share/ament_index/resource_index/packages', ['resource/' + PACKAGE_NAME]),
1111
('share/' + PACKAGE_NAME, ['package.xml']),
1212
],
13-
install_requires=[
14-
'setuptools',
15-
],
1613
author='Xi Lin',
1714
author_email='[email protected]',
1815
maintainer='Xi Lin',
@@ -22,8 +19,8 @@
2219
'reinforcement-learning',
2320
],
2421
classifiers=[
25-
'License :: OSI Approved :: MIT License'
26-
'Topic :: Scientific/Engineering :: Artificial Intelligence'
22+
'License :: OSI Approved :: MIT License',
23+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
2724
],
2825
license='MIT',
2926
entry_points={

virelex/CMakeLists.txt

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,30 @@ find_package(rclcpp REQUIRED)
1919
find_package(rosidl_default_generators REQUIRED)
2020
find_package(message_filters REQUIRED)
2121

22-
find_package(geometry_msgs REQUIRED)
2322
find_package(nav_msgs REQUIRED)
2423
find_package(sensor_msgs REQUIRED)
2524
find_package(std_msgs REQUIRED)
2625

2726
find_package(Eigen3 REQUIRED)
2827
find_package(Torch REQUIRED)
2928

29+
find_package(virelex_msgs REQUIRED)
30+
3031
# Include directories
3132
include_directories(
3233
${PROJECT_SOURCE_DIR}/include
3334
${EIGEN3_INCLUDE_DIR}
3435
${TORCH_INCLUDE_DIRS}
3536
)
3637

37-
# Generate message interfaces
38-
rosidl_generate_interfaces(${PROJECT_NAME}
39-
# cluster_msg
40-
"msg/PointCloudCluster.msg"
41-
# robot_info_msg
42-
"msg/RobotInfo.msg"
43-
# state_msg
44-
"msg/State.msg"
45-
DEPENDENCIES std_msgs sensor_msgs geometry_msgs
46-
)
47-
48-
# Define support target for message dependencies
49-
rosidl_get_typesupport_target(
50-
cpp_typesupport_target
51-
${PROJECT_NAME}
52-
rosidl_typesupport_cpp
53-
)
54-
5538
# action_planner
5639
add_executable(action_planner_node src/action_planner_node.cpp)
5740
ament_target_dependencies(action_planner_node
5841
rclcpp
5942
std_msgs
43+
virelex_msgs
6044
)
6145
target_link_libraries(action_planner_node
62-
${cpp_typesupport_target}
6346
${TORCH_LIBRARIES}
6447
)
6548
install(TARGETS
@@ -84,9 +67,7 @@ add_executable(lidar_processor_node src/lidar_processor_node.cpp)
8467
ament_target_dependencies(lidar_processor_node
8568
rclcpp
8669
sensor_msgs
87-
)
88-
target_link_libraries(lidar_processor_node
89-
${cpp_typesupport_target}
70+
virelex_msgs
9071
)
9172
install(TARGETS
9273
lidar_processor_node
@@ -102,20 +83,27 @@ ament_target_dependencies(state_processor_node
10283
message_filters
10384
std_msgs
10485
nav_msgs
105-
)
106-
target_link_libraries(state_processor_node
107-
${cpp_typesupport_target}
86+
virelex_msgs
10887
)
10988
install(TARGETS
11089
state_processor_node
11190
DESTINATION lib/${PROJECT_NAME}
11291
)
11392

114-
# Install launch files if any
93+
# Install launch and pretrained weight files
11594
install(DIRECTORY
95+
config
11696
launch
97+
trained
98+
models
99+
urdf
100+
worlds
117101
DESTINATION share/${PROJECT_NAME}/
118102
)
119103

104+
ament_python_install_package(${PROJECT_NAME}
105+
PACKAGE_DIR "python/${PROJECT_NAME}"
106+
)
107+
120108
ament_export_dependencies(rosidl_default_runtime)
121109
ament_package()

virelex/package.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111
- processing LiDAR point clouds (lidar_processor)
1212
- computing robot state (state_processor)
1313

14-
- customized message format for LiDAR point clouds (cluster_msg)
15-
- customized message format for robot info (robot_info_msg)
16-
- customized message format for state information (state_msg)
17-
1814
</description>
1915
<author email="[email protected]">Xi Lin</author>
2016
<maintainer email="[email protected]">Xi Lin</maintainer>
2117
<license>Apache-2.0</license>
2218

2319
<buildtool_depend>ament_cmake</buildtool_depend>
20+
<buildtool_depend>ament_cmake_python</buildtool_depend>
2421
<buildtool_depend>rosidl_default_generators</buildtool_depend>
2522
<exec_depend>rosidl_default_runtime</exec_depend>
2623
<member_of_group>rosidl_interface_packages</member_of_group>
@@ -33,8 +30,12 @@
3330
<depend>sensor_msgs</depend>
3431
<depend>std_msgs</depend>
3532

33+
<depend>virelex_msgs</depend>
3634
<exec_depend>rfarl</exec_depend>
3735

36+
<exec_depend>python3-numpy</exec_depend>
37+
<exec_depend>python3-scipy</exec_depend>
38+
3839
<export>
3940
<build_type>ament_cmake</build_type>
4041
</export>

virelex/python/virelex/__init__.py

Whitespace-only changes.

virelex/scripts/run_vrx_experiments.py renamed to virelex/python/virelex/run_vrx_experiments.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import time
55
from std_msgs.msg import Empty
66
from std_msgs.msg import Bool
7-
from virelex.msg import RobotInfo
7+
from virelex_msgs.msg import RobotInfo
88
import threading
99
import numpy as np
1010
import math
@@ -27,6 +27,8 @@
2727
import shutil
2828
import json
2929

30+
import ament_index_python.packages as rospack
31+
3032
def add_buoy_to_sdf(input_file, output_file, buoy_poses):
3133
shutil.copyfile(input_file, output_file)
3234
tree = ET.parse(output_file)
@@ -344,11 +346,11 @@ def end_simulation(self):
344346

345347
if __name__ == '__main__':
346348

347-
method = "the/method/used/in/vrx/experiments"
349+
method = "RL"
348350

349351
if method == "RL":
350-
agent_type = "RL/agent/used/in/vrx/experiments"
351-
model_path = "corresponding/torch/script/of/the/RL/model"
352+
agent_type = "AC-IQN"
353+
model_path = rospack.get_package_share_directory("virelex") + "/trained/traced_AC_IQN_model.pt"
352354
elif method == "APF":
353355
agent_type = "APF"
354356
model_path = " "
@@ -360,14 +362,13 @@ def end_simulation(self):
360362

361363

362364
# vrx envrionment configuration file
363-
sdf_file_dir = "install/share/vrx_gz/worlds"
365+
world_sdf_dir = rospack.get_package_share_directory("virelex") + "/worlds"
364366

365-
input_world = "sydney_regatta_original"
366-
input_sdf_file = f"{sdf_file_dir}/{input_world}.sdf"
367+
input_world = "sydney_regatta"
368+
output_world = "sydney_regatta_aux"
367369

368-
output_world = "sydney_regatta"
369-
output_sdf_file = f"{sdf_file_dir}/{output_world}.sdf"
370-
370+
input_sdf_file = f"{world_sdf_dir}/{input_world}.sdf"
371+
output_sdf_file = f"{world_sdf_dir}/{output_world}.sdf"
371372

372373
init_poses_data = []
373374
goals_data = []
@@ -385,7 +386,7 @@ def end_simulation(self):
385386
os.makedirs(result_file_dir)
386387

387388

388-
run_with_exp_config = True
389+
run_with_exp_config = False
389390
if run_with_exp_config:
390391
##### run an experiment with specified config #####
391392

0 commit comments

Comments
 (0)