Skip to content

Commit

Permalink
Add carla sample node
Browse files Browse the repository at this point in the history
  • Loading branch information
VishGit1234 committed Feb 4, 2024
1 parent 2ab1c58 commit eec4e33
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 13 deletions.
63 changes: 63 additions & 0 deletions docker/simulation/carla_sample_node/carla_sample_node.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
ARG BASE_IMAGE=ghcr.io/watonomous/wato_monorepo/base:humble-ubuntu22.04

################################ Source ################################
FROM ${BASE_IMAGE} as source

WORKDIR ${AMENT_WS}/src

# Copy in source code
COPY src/simulation/carla_sample_node carla_sample_node
COPY src/wato_msgs/sample_msgs sample_msgs
COPY src/wato_msgs/simulation/common_msgs common_msgs
COPY src/wato_msgs/simulation/embedded_msgs embedded_msgs
COPY src/wato_msgs/simulation/path_planning_msgs path_planning_msgs

# Carla specific messages
RUN git clone --depth 1 https://github.com/ros-drivers/ackermann_msgs.git --branch ros2 && \
git clone --depth 1 https://github.com/ros-perception/image_common.git --branch $ROS_DISTRO && \
git clone --depth 1 https://github.com/carla-simulator/ros-carla-msgs.git --branch master

# Scan for rosdeps
RUN apt-get -qq update && rosdep update && \
rosdep install --from-paths . --ignore-src -r -s \
| grep 'apt-get install' \
| awk '{print $3}' \
| sort > /tmp/colcon_install_list

################################# Dependencies ################################
FROM ${BASE_IMAGE} as dependencies

# Install Rosdep requirements
COPY --from=source /tmp/colcon_install_list /tmp/colcon_install_list
RUN apt-fast install -qq -y --no-install-recommends $(cat /tmp/colcon_install_list)

# Copy in source code from source stage
WORKDIR ${AMENT_WS}
COPY --from=source ${AMENT_WS}/src src

# Dependency Cleanup
WORKDIR /
RUN apt-get -qq autoremove -y && apt-get -qq autoclean && apt-get -qq clean && \
rm -rf /root/* /root/.ros /tmp/* /var/lib/apt/lists/* /usr/share/doc/*

################################ Build ################################
FROM dependencies as build

# Build ROS2 packages
WORKDIR ${AMENT_WS}
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
colcon build \
--cmake-args -DCMAKE_BUILD_TYPE=Release

# Entrypoint will run before any CMD on launch. Sources ~/opt/<ROS_DISTRO>/setup.bash and ~/ament_ws/install/setup.bash
COPY docker/wato_ros_entrypoint.sh ${AMENT_WS}/wato_ros_entrypoint.sh
ENTRYPOINT ["./wato_ros_entrypoint.sh"]

################################ Prod ################################
FROM build as deploy

# Source Cleanup and Security Setup
RUN chown -R $USER:$USER ${AMENT_WS}
RUN rm -rf src/*

USER ${USER}
25 changes: 14 additions & 11 deletions modules/dev_overrides/docker-compose.simulation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,32 @@ x-fixuid: &fixuid

services:
carla_sim:
# <<: *fixuid
extends:
file: ../docker-compose.simulation.yaml
service: carla_sim
# command: tail -F anything
# volumes:
# - ${MONO_DIR}/src/simulation/carla_sim:/home/bolty/ament_ws/src/carla_sim

carla_ros_bridge:
<<: *fixuid
extends:
file: ../docker-compose.simulation.yaml
service: carla_ros_bridge
command: tail -F anything
# volumes:
# - ${MONO_DIR}/src/simulation/carla_sim:/home/bolty/ament_ws/src/carla_sim
# command: /bin/bash -c "ros2 launch carla_config carla.launch.py"

carla_viz:
# <<: *fixuid
extends:
file: ../docker-compose.simulation.yaml
service: carla_viz
# command: tail -F anything
# volumes:
# - ${MONO_DIR}/src/simulation/carla_sim:/home/bolty/ament_ws/src/carla_sim

carla_sample_node:
<<: *fixuid
extends:
file: ../docker-compose.simulation.yaml
service: carla_sample_node
command: tail -F anything
volumes:
- ${MONO_DIR}/src/simulation/carla_sample_node:/home/bolty/ament_ws/src/carla_sample_node

carla_notebooks:
build:
context: ../..
Expand All @@ -49,5 +52,5 @@ services:
- NVIDIA_VISIBLE_DEVICES=1
container_name: ${COMPOSE_PROJECT_NAME:?}_carla_notebooks
volumes:
- ../../src/simulation/carla_notebooks:/home/bolty/carla_notebooks
- ${MONO_DIR}/src/simulation/carla_notebooks:/home/bolty/carla_notebooks
command: jupyter notebook --allow-root --ip=0.0.0.0 --port=${CARLA_NOTEBOOKS_PORT:?} --no-browser --ServerApp.token='' --ServerApp.password=''
17 changes: 15 additions & 2 deletions modules/docker-compose.simulation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ services:
- USE_ACKERMANN_CONTROL=False
security_opt:
- seccomp:${MONO_DIR}/modules/seccomp_profile.json
command: /bin/bash -c "echo CARLA_ROS_BRIDGE disabled"
# command: /bin/bash -c "ros2 launch carla_config carla.launch.py"
# command: /bin/bash -c "echo CARLA_ROS_BRIDGE disabled"
command: /bin/bash -c "ros2 launch carla_config carla.launch.py"

carla_viz:
build:
Expand All @@ -58,3 +58,16 @@ services:
- CARLAVIZ_BACKEND_PORT=${CARLAVIZ_PORT_2}
entrypoint: ["/bin/bash", "-c", "./docker/carlaviz_entrypoint.sh > /dev/null 2>&1"]
restart: always

carla_sample_node:
build:
context: ..
dockerfile: docker/simulation/carla_sample_node/carla_sample_node.Dockerfile
cache_from:
- "${SIMULATION_CARLA_SAMPLE_NODE_IMAGE:?}:${TAG:?}"
- "${SIMULATION_CARLA_SAMPLE_NODE_IMAGE:?}:develop"
target: deploy
image: "${SIMULATION_CARLA_SAMPLE_NODE_IMAGE:?}:${TAG:?}"
security_opt:
- seccomp:${MONO_DIR}/modules/seccomp_profile.json
command: /bin/bash -c "ros2 launch carla_sample_node carla_sample_node.launch.py"
1 change: 1 addition & 0 deletions src/simulation/carla_sample_node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logs
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
##### IMPORTANT ####
"""
Uncomment the code under the main function (at the bottom of this file) to have the node actually run
"""


import rclpy
from rclpy.node import Node

from nav_msgs.msg import Odometry # For odometry
from sensor_msgs.msg import NavSatFix # For GNSS

from std_msgs.msg import Bool

import os

class Datalogger(Node):
def __init__(self):
super().__init__('datalogger')
self.gnssSubscription = self.create_subscription(
NavSatFix,
'/carla/ego_vehicle/gnss',
self.gnss_callback,
10
)
self.gnssSubscription # prevent unused variable warning
self.autopilotPublisher = self.create_publisher(
Bool,
'/carla/ego_vehicle/enable_autopilot',
10
)
self.timer = self.create_timer(10, self.timer_callback) # Publish autopilot message every 10 seconds
def gnss_callback(self, msg):
# with open("/home/docker/ament_ws/src/carla_sample_node/logs/gnss_" + self.containerId + ".txt", 'a+') as file:
# file.write(str(msg.latitude) + ", " + str(msg.longitude) + "\n")
self.get_logger().info(str(msg.latitude) + ", " + str(msg.longitude)) # print to screen
def timer_callback(self):
msg = Bool()
msg.data = True
self.autopilotPublisher.publish(msg)

def main(args=None):
# Uncomment the below lines to actually run the sample node

# rclpy.init(args=args)

# datalogger = Datalogger()

# rclpy.spin(datalogger)

# datalogger.destroy_node()
# rclpy.shutdown()
return

if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from launch import LaunchDescription
import launch_ros.actions

def generate_launch_description():
return LaunchDescription([
launch_ros.actions.Node(
namespace= "carla_sample_node", package='carla_sample_node', executable='carla_sample_node', output='screen'),
])
20 changes: 20 additions & 0 deletions src/simulation/carla_sample_node/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>carla_sample_node</name>
<version>0.0.0</version>
<description>Sample python node to read data from CARLA</description>
<maintainer email="[email protected]">Vishal Jayakumar</maintainer>
<license>TODO: License declaration</license>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<depend>rclpy</depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
4 changes: 4 additions & 0 deletions src/simulation/carla_sample_node/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/carla_sample_node
[install]
install_scripts=$base/lib/carla_sample_node
29 changes: 29 additions & 0 deletions src/simulation/carla_sample_node/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from setuptools import setup
from glob import glob
import os

package_name = 'carla_sample_node'

setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
('share/' + package_name, glob(os.path.join('launch', '*.launch.py')))
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='Vishal Jayakumar',
maintainer_email='[email protected]',
description='Sample python node to read data from CARLA',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'carla_sample_node = carla_sample_node.carla_sample_node:main'
],
},
)
25 changes: 25 additions & 0 deletions src/simulation/carla_sample_node/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# 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 License for the specific language governing permissions and
# limitations under the License.

from ament_copyright.main import main
import pytest


# Remove the `skip` decorator once the source file(s) have a copyright header
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'
25 changes: 25 additions & 0 deletions src/simulation/carla_sample_node/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# 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 License for the specific language governing permissions and
# limitations under the License.

from ament_flake8.main import main_with_errors
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc, errors = main_with_errors(argv=[])
assert rc == 0, \
'Found %d code style errors / warnings:\n' % len(errors) + \
'\n'.join(errors)
23 changes: 23 additions & 0 deletions src/simulation/carla_sample_node/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# 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 License for the specific language governing permissions and
# limitations under the License.

from ament_pep257.main import main
import pytest


@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found code style errors / warnings'
2 changes: 2 additions & 0 deletions watod_scripts/watod-setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ SIMULATION_CARLA_IMAGE=${SIMULATION_CARLA_IMAGE:-"$REGISTRY_URL/simulation/carla
SIMULATION_CARLA_ROS_BRIDGE_IMAGE=${SIMULATION_CARLA_ROS_BRIDGE_IMAGE:-"$REGISTRY_URL/simulation/carla_ros_bridge"}
SIMULATION_CARLAVIZ_IMAGE=${SIMULATION_CARLAVIZ_IMAGE:-"$REGISTRY_URL/simulation/carla_viz"}
SIMULATION_CARLA_NOTEBOOKS_IMAGE=${SIMULATION_CARLA_NOTEBOOKS_IMAGE:-"$REGISTRY_URL/simulation/carla_notebooks"}
SIMULATION_CARLA_SAMPLE_NODE_IMAGE=${SIMULATION_CARLA_SAMPLE_NODE_IMAGE:-"$REGISTRY_URL/simulation/carla_sample_node"}

# Interfacing
INTERFACING_CAN_IMAGE=${INTERFACING_CAN_IMAGE:-"$REGISTRY_URL/interfacing/can_interfacing"}
Expand Down Expand Up @@ -206,6 +207,7 @@ echo "SIMULATION_CARLA_IMAGE=$SIMULATION_CARLA_IMAGE" >> "$MODULES_DIR/.env"
echo "SIMULATION_CARLA_ROS_BRIDGE_IMAGE=$SIMULATION_CARLA_ROS_BRIDGE_IMAGE" >> "$MODULES_DIR/.env"
echo "SIMULATION_CARLAVIZ_IMAGE=$SIMULATION_CARLAVIZ_IMAGE" >> "$MODULES_DIR/.env"
echo "SIMULATION_CARLA_NOTEBOOKS_IMAGE=$SIMULATION_CARLA_NOTEBOOKS_IMAGE" >> "$MODULES_DIR/.env"
echo "SIMULATION_CARLA_SAMPLE_NODE_IMAGE=$SIMULATION_CARLA_SAMPLE_NODE_IMAGE" >> "$MODULES_DIR/.env"

# Interfacing
echo "INTERFACING_CAN_IMAGE=$INTERFACING_CAN_IMAGE" >> "$MODULES_DIR/.env"
Expand Down

0 comments on commit eec4e33

Please sign in to comment.