Skip to content

Commit

Permalink
hal_hw_interface: Find HAL component directory from LD_LIBRARY_PATH
Browse files Browse the repository at this point in the history
The RT HAL comp is installed in the `CMAKE_LIBRARY_OUTPUT_DIRECTORY`,
and that path was templated into the launch file at build time, to be
passed on through `hal_mgr` and into the .hal files.

@machinekoder discovered that using `configure_file()` to template the
launch file back into the source directory caused trouble in
`industrial-ci`, for obvious reasons.

He had the good idea to find the install directory at run time by
searching `LD_LIBRARY_PATH`, which is set in `setup.bash`.

This patch undoes the previous system and does the search directly
inside `hal_mgr`.
  • Loading branch information
zultron committed Jul 19, 2018
1 parent f595f7b commit abaee13
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,3 +1,2 @@
autosave.halscope
/hal_hw_interface/launch/hal_hw_interface.launch
/simple_hardware_interfaces/doc/
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -175,8 +175,8 @@ position, velocity and acceleration, and connects them to the

Because the `hal_hw_interface` component is installed outside the
standard HAL component directory, its full path must be provided using
the `$LIBDIR` environment variable: `loadrt
$(LIBDIR)/hal_hw_interface`.
the `$COMP_DIR` environment variable: `loadrt
$(COMP_DIR)/hal_hw_interface`.

When the `hal_hw_interface` component loads, it creates six HAL pins
for each joint: three command output pins and three feedback input
Expand Down
6 changes: 0 additions & 6 deletions hal_hw_interface/CMakeLists.txt
Expand Up @@ -44,12 +44,6 @@ install(
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)

# Launch file
# - Add library path to help locate HAL comp
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/launch/${PROJECT_NAME}.in.launch
${CMAKE_CURRENT_SOURCE_DIR}/launch/${PROJECT_NAME}.launch @ONLY)

#######################
# HAL component build definitions

Expand Down
Expand Up @@ -17,10 +17,5 @@
type="hal_mgr.py"
output="screen"
required="true"
>
<env
name="LIBDIR"
value="@CMAKE_LIBRARY_OUTPUT_DIRECTORY@"
/>
</node>
/>
</launch>
11 changes: 9 additions & 2 deletions hal_hw_interface/src/hal_mgr.py
Expand Up @@ -40,6 +40,15 @@ def shutdown(msg = "Shutting down for unknown reason", res = 0):
rate = rospy.Rate(1) # 1hz
rospy.loginfo("hal_mgr: Initialized node")

# Find the hal_hw_interface comp's directory in LD_LIBRARY_PATH and put it
# into $COMP_DIR
comp_dir = ""
for path in os.environ.get('LD_LIBRARY_PATH','').split(':'):
if os.path.exists(os.path.join(path, 'hal_hw_interface.so')):
comp_dir = path
os.environ['COMP_DIR'] = comp_dir
rospy.loginfo("hal_mgr: COMP_DIR set to '%s'" % comp_dir)

# Get parameters
if not rospy.has_param(NAME):
shutdown("No parameters set for '%s'" % NAME, 1)
Expand All @@ -51,8 +60,6 @@ def shutdown(msg = "Shutting down for unknown reason", res = 0):
shutdown("%s has no 'hal_files' key" % NAME, 1)
if 'hal_file_dir' not in hal_mgr_config:
shutdown("%s has no 'hal_file_dir' key" % NAME, 1)
if 'LIBDIR' not in os.environ:
shutdown("No 'LIBDIR' environment variable defined", 1)

# Set up HAL
launcher.cleanup_session() # kill any running Machinekit instances
Expand Down
2 changes: 1 addition & 1 deletion hal_rrbot_control/halfiles/hal_hw_interface.hal
Expand Up @@ -2,7 +2,7 @@
newthread robot_hw_thread 10000000 fp

# Load the hal_hw_interface component
loadrt $(LIBDIR)/hal_hw_interface
loadrt $(COMP_DIR)/hal_hw_interface
addf hal_hw_interface robot_hw_thread

# Connect position command to feedback via limit3 comp to simulate
Expand Down

0 comments on commit abaee13

Please sign in to comment.