Skip to content

Commit

Permalink
Port pinpoint to ros2 and update carma script (#228)
Browse files Browse the repository at this point in the history
<!-- Thanks for the contribution, this is awesome. -->

# PR Details
## Description
This PR supports migration of pinpoint driver to ROS2 in this PR:
usdot-fhwa-stol/carma-torc-pinpoint-driver#46
- It adds ROS2 version of pinpoint to the configs
- It adds commands to include .env file in the image which started to be
convention on this PR:
usdot-fhwa-stol/carma-config#352
<!--- Describe your changes in detail -->

## Related GitHub Issue
NA
<!--- This project only accepts pull requests related to open GitHub
issues or Jira Keys -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please DO NOT name partially fixed issues, instead open an issue
specific to this fix -->
<!--- Please link to the issue here: -->

## Related Jira Key
https://usdot-carma.atlassian.net/browse/CAR-5907
<!-- e.g. CAR-123 -->

## Motivation and Context
Migration of pinpoint to ROS2
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
Set the config and tried starting without issue. Just needs to test on
actual Tahoe vehicle now.
NOTE: image intentionally comments out the other components other than
pinpoint

![image](https://github.com/usdot-fhwa-stol/carma-messenger/assets/20613282/8e656fa9-7638-48cf-966b-7c4c7618dfb0)

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Defect fix (non-breaking change that fixes an issue)
- [X] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that cause existing functionality
to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [X] I have added any new packages to the sonar-scanner.properties file
- [ ] My change requires a change to the documentation.
- [X] I have updated the documentation accordingly.
- [X] I have read the
[**CONTRIBUTING**](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/Contributing.md)
document.
- [X] I have added tests to cover my changes.
- [X] All new and existing tests passed.
  • Loading branch information
MishkaMN authored Jul 11, 2024
1 parent 20ef01f commit d2452e9
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 150 deletions.
10 changes: 6 additions & 4 deletions carma-messenger-config/chevrolet_tahoe_2018/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (C) 2018-2021 LEIDOS.
#
# Copyright (C) 2018-2024 LEIDOS.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Expand Down Expand Up @@ -35,5 +35,7 @@ LABEL org.label-schema.build-date=${BUILD_DATE}

ADD . /root/vehicle/config
VOLUME /opt/carma/vehicle/config
RUN mkdir -p /opt/carma/vehicle/config
RUN cp -a /root/vehicle/config/.env /opt/carma/vehicle/config/

CMD cp /root/vehicle/config/* /opt/carma/vehicle/config
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# the License.

# Docker Compose Spec Version
version: '2'

services:
roscore:
image: ${DOCKER_ORG}/carma-base:${DOCKER_TAG}
Expand Down Expand Up @@ -99,4 +97,4 @@ services:
- /opt/carma/logs:/opt/carma/logs
- /opt/carma/.ros:/opt/carma/.ros
- /opt/carma/vehicle:/opt/carma/vehicle
command: bash -c 'wait-for-it.sh localhost:11311 -- roslaunch /opt/carma/vehicle/config/drivers.launch drivers:=pinpoint_driver'
command: bash -c 'source /opt/carma/install/setup.bash && ros2 launch /opt/carma/vehicle/config/drivers.launch.py drivers:=pinpoint_driver'
36 changes: 0 additions & 36 deletions carma-messenger-config/chevrolet_tahoe_2018/drivers.launch

This file was deleted.

163 changes: 131 additions & 32 deletions carma-messenger-config/chevrolet_tahoe_2018/drivers.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,66 +29,165 @@
import launch.events

import launch_ros.actions
import launch_ros.events
import launch_ros.events
import launch_ros.events.lifecycle
import lifecycle_msgs.msg


def generate_launch_description():
"""
Launch desired CARMA Messenger drivers
"""

env_log_levels = EnvironmentVariable('CARMA_ROS_LOGGING_CONFIG', default_value='{ "default_level" : "WARN" }')
env_log_levels = EnvironmentVariable(
"CARMA_ROS_LOGGING_CONFIG", default_value='{ "default_level" : "WARN" }'
)

configuration_delay = LaunchConfiguration('configuration_delay')
configuration_delay = LaunchConfiguration("configuration_delay")
declare_configuration_delay_arg = DeclareLaunchArgument(
name ='configuration_delay', default_value='4.0')
name="configuration_delay", default_value="4.0"
)

drivers = LaunchConfiguration('drivers')
drivers = LaunchConfiguration("drivers")
declare_drivers_arg = DeclareLaunchArgument(
name = 'drivers', default_value = 'dsrc_driver', description = "Desired drivers to launch specified by package name."
name="drivers",
default_value="dsrc_driver",
description="Desired drivers to launch specified by package name.",
)

dsrc_group = GroupAction(
condition=IfCondition(PythonExpression(["'dsrc_driver' in '", drivers, "'.split()"])),
condition=IfCondition(
PythonExpression(["'dsrc_driver' in '", drivers, "'.split()"])
),
actions=[
PushRosNamespace(EnvironmentVariable('CARMA_INTR_NS', default_value='hardware_interface')),
PushRosNamespace(
EnvironmentVariable("CARMA_INTR_NS", default_value="hardware_interface")
),
IncludeLaunchDescription(
PythonLaunchDescriptionSource([ FindPackageShare('dsrc_driver'), '/launch/dsrc_driver.py']),
launch_arguments = {
'log_level' : GetLogLevel('dsrc_driver', env_log_levels),
}.items()
PythonLaunchDescriptionSource(
[FindPackageShare("dsrc_driver"), "/launch/dsrc_driver.py"]
),
launch_arguments={
"log_level": GetLogLevel("dsrc_driver", env_log_levels),
}.items(),
),
]
],
)

pinpoint_group = GroupAction(
condition=IfCondition(
PythonExpression(["'pinpoint_driver' in '", drivers, "'.split()"])
),
actions=[
PushRosNamespace(
EnvironmentVariable("CARMA_INTR_NS", default_value="hardware_interface")
),
IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[FindPackageShare("pinpoint"), "/launch/pinpoint.launch.py"]
),
launch_arguments={
"log_level": GetLogLevel("pinpoint", env_log_levels),
}.items(),
),
],
)

ros2_cmd = launch.substitutions.FindExecutable(name='ros2')
ros2_cmd = launch.substitutions.FindExecutable(name="ros2")

process_configure_dsrc_driver_node = launch.actions.ExecuteProcess(
cmd=[ros2_cmd, "lifecycle", "set", [ EnvironmentVariable('CARMA_INTR_NS', default_value='hardware_interface'), "/dsrc_driver_node" ], "configure"],
condition=IfCondition(
PythonExpression(["'dsrc_driver' in '", drivers, "'.split()"])
),
cmd=[
ros2_cmd,
"lifecycle",
"set",
[
EnvironmentVariable(
"CARMA_INTR_NS", default_value="hardware_interface"
),
"/dsrc_driver_node",
],
"configure",
],
)

configuration_trigger = launch.actions.TimerAction(
period=configuration_delay,
actions=[
process_configure_dsrc_driver_node
]
configured_event_handler_dsrc_driver_node = launch.actions.RegisterEventHandler(
launch.event_handlers.OnExecutionComplete(
target_action=process_configure_dsrc_driver_node,
on_completion=[
launch.actions.ExecuteProcess(
cmd=[
ros2_cmd,
"lifecycle",
"set",
[
EnvironmentVariable(
"CARMA_INTR_NS", default_value="hardware_interface"
),
"/dsrc_driver_node",
],
"activate",
],
)
],
)
)

configured_event_handler_dsrc_driver_node = launch.actions.RegisterEventHandler(launch.event_handlers.OnExecutionComplete(
target_action=process_configure_dsrc_driver_node,
on_completion=[
process_configure_pinpoint_node = launch.actions.ExecuteProcess(
condition=IfCondition(
PythonExpression(["'pinpoint_driver' in '", drivers, "'.split()"])
),
cmd=[
ros2_cmd,
"lifecycle",
"set",
[
EnvironmentVariable(
"CARMA_INTR_NS", default_value="hardware_interface"
),
"/pinpoint",
],
"configure",
],
)

configured_event_handler_pinpoint_node = launch.actions.RegisterEventHandler(
launch.event_handlers.OnExecutionComplete(
target_action=process_configure_pinpoint_node,
on_completion=[
launch.actions.ExecuteProcess(
cmd=[ros2_cmd, "lifecycle", "set", [ EnvironmentVariable('CARMA_INTR_NS', default_value='hardware_interface'), "/dsrc_driver_node" ], "activate"],
cmd=[
ros2_cmd,
"lifecycle",
"set",
[
EnvironmentVariable(
"CARMA_INTR_NS", default_value="hardware_interface"
),
"/pinpoint",
],
"activate",
],
)
]
],
)
)

return LaunchDescription([
declare_configuration_delay_arg,
declare_drivers_arg,
dsrc_group,
configuration_trigger,
configured_event_handler_dsrc_driver_node
])
configuration_trigger = launch.actions.TimerAction(
period=configuration_delay,
actions=[process_configure_dsrc_driver_node, process_configure_pinpoint_node],
)

return LaunchDescription(
[
declare_configuration_delay_arg,
declare_drivers_arg,
dsrc_group,
pinpoint_group,
configuration_trigger,
configured_event_handler_dsrc_driver_node,
configured_event_handler_pinpoint_node,
]
)
10 changes: 6 additions & 4 deletions carma-messenger-config/development/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (C) 2018-2021 LEIDOS.
#
# Copyright (C) 2018-2024 LEIDOS.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Expand Down Expand Up @@ -35,5 +35,7 @@ LABEL org.label-schema.build-date=${BUILD_DATE}

ADD . /root/vehicle/config
VOLUME /opt/carma/vehicle/config
RUN mkdir -p /opt/carma/vehicle/config
RUN cp -a /root/vehicle/config/.env /opt/carma/vehicle/config/

CMD cp /root/vehicle/config/* /opt/carma/vehicle/config
4 changes: 1 addition & 3 deletions carma-messenger-config/development/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# the License.

# Docker Compose Spec Version
version: '2'

services:
roscore:
image: ${DOCKER_ORG}/carma-base:${DOCKER_TAG}
Expand Down Expand Up @@ -86,4 +84,4 @@ services:
volumes:
- /opt/carma/logs:/opt/carma/logs
- /opt/carma/.ros:/opt/carma/.ros
command: bash -c 'wait-for-it.sh localhost:11311 -- roslaunch /opt/carma/vehicle/config/drivers.launch drivers:=pinpoint_driver'
command: bash -c 'source /opt/carma/install/setup.bash && ros2 launch /opt/carma/vehicle/config/drivers.launch.py drivers:=pinpoint_driver'
36 changes: 0 additions & 36 deletions carma-messenger-config/development/drivers.launch

This file was deleted.

Loading

0 comments on commit d2452e9

Please sign in to comment.