Skip to content

Commit

Permalink
updates for carla 0.9.12 (#21)
Browse files Browse the repository at this point in the history
* updates for carla 0.9.12

* refactor gstreaming

* run CI on melodic and noetic

* include carla ros bridge in CI build
  • Loading branch information
hofbi authored Aug 18, 2021
1 parent 322a5e9 commit e611a30
Show file tree
Hide file tree
Showing 92 changed files with 912 additions and 1,308 deletions.
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 120

ignore =
# Ignore "whitespace before ':'" because it conflicts with black
E203,
# Ignore "linebrak before binary operator" because it conflicts with black
W503
1 change: 0 additions & 1 deletion .github/linters/.python-lint

This file was deleted.

45 changes: 37 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: CI

on: [push, pull_request]
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
check:
Expand All @@ -25,30 +29,55 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Lint Code Base
uses: docker://github/super-linter:v3.10.2
uses: docker://github/super-linter:v4.6.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_BASH: false # Already configured in make check
VALIDATE_CPP: false
VALIDATE_DOCKERFILE_HADOLINT: false
VALIDATE_GITHUB_ACTIONS: false
VALIDATE_PYTHON_FLAKE8: false # Already configured in make check
VALIDATE_PYTHON_PYLINT: false # Already configured in make check
VALIDATE_PYTHON_ISORT: false

ros:
runs-on: ubuntu-latest
container: ros:melodic-robot
strategy:
matrix:
include:
- ros_distro: melodic
python_suffix: ""
# - ros_distro: noetic
# python_suffix: 3
container:
image: ros:${{ matrix.ros_distro }}-robot
env:
DEBIAN_FRONTEND: "noninteractive"
steps:
- uses: actions/checkout@v2
- name: Setup
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y python-catkin-tools
bash -c "$GITHUB_WORKSPACE/install.sh"
sudo apt-get install -y python${{ matrix.python_suffix }}-catkin-tools python${{ matrix.python_suffix }}-osrf-pycommon apt-utils
$GITHUB_WORKSPACE/install.sh
- name: Init Workspace
run: |
mkdir -p $GITHUB_WORKSPACE/../catkin_ws/src
cd $GITHUB_WORKSPACE/../catkin_ws/src
ln -s $GITHUB_WORKSPACE
ln -s $GITHUB_WORKSPACE telecarla
ln -s $GITHUB_WORKSPACE/../ros-bridge ros-bridge
cd ..
catkin init
- name: Build and Check
run: bash -c "source /opt/ros/melodic/setup.bash && source /opt/carla-ros-bridge/melodic/setup.bash && cd $GITHUB_WORKSPACE/../catkin_ws && catkin build --summarize --no-status --force-color --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_CLANG_TIDY=clang-tidy-10"
shell: bash
run: |
source /opt/ros/${{ matrix.ros_distro }}/setup.bash
cd $GITHUB_WORKSPACE/../catkin_ws
catkin build --summarize --no-status --force-color --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_CLANG_TIDY=clang-tidy-10
- name: Test
run: bash -c "source /opt/ros/melodic/setup.bash && source /opt/carla-ros-bridge/melodic/setup.bash && cd $GITHUB_WORKSPACE/../catkin_ws && catkin run_tests --no-status --force-color && catkin_test_results"
shell: bash
run: |
source /opt/ros/${{ matrix.ros_distro }}/setup.bash
cd $GITHUB_WORKSPACE/../catkin_ws
catkin run_tests --no-status --force-color && catkin_test_results
5 changes: 0 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ jobs:
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PY_FILES = $(call file_finder,-name "*.py")
CPP_FILES = $(call file_finder,-regex '.*\.\(cpp\|hpp\|cu\|c\|h\)')
SH_FILES = $(call file_finder,-name "*.sh")

check: check_format check_sh_format pylint shellcheck
check: check_format check_sh_format pylint shellcheck flake8

format:
$(PY_FILES) | xargs black
Expand All @@ -21,6 +21,9 @@ check_format:
pylint:
$(PY_FILES) | xargs pylint --rcfile=.pylintrc

flake8:
$(PY_FILES) | xargs flake8

check_sh_format:
shfmt -d .

Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
version: '3'
services:
carla:
image: carlasim/carla:0.9.12
runtime: nvidia
network_mode: host
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
environment:
SDL_VIDEODRIVER: x11
DISPLAY: $DISPLAY
command: ./CarlaUE4.sh -opengl
telecarla:
build:
context: ./
dockerfile: docker/Dockerfile
image: telecarla
network_mode: host
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
environment:
Expand Down
21 changes: 12 additions & 9 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
FROM ros:melodic-robot
ARG CARLA_VERSION='0.9.12'

ARG CARLA_MAJOR_VERSION='0.9.10'
ARG CARLA_MINOR_VERSION='1'
FROM carlasim/carla:${CARLA_VERSION} as carla

FROM ros:noetic-robot

ARG CARLA_VERSION

ENV DEBIAN_FRONTEND='noninteractive'
ENV QT_X11_NO_MITSHM=1

RUN apt-get update && \
apt-get install --no-install-recommends -y \
python-catkin-tools \
python3-catkin-tools \
python3-osrf-pycommon \
x11-apps \
socat \
wget \
ubuntu-server \
ubuntu-desktop && \
rm -rf /var/lib/apt/lists/*

COPY --from=carla /home/carla/PythonAPI /opt/carla/PythonAPI
COPY . /home/catkin_ws/src/telecarla
WORKDIR /home/catkin_ws/src/telecarla
RUN ./install.sh

WORKDIR /home/catkin_ws
RUN wget https://carla-releases.s3.eu-west-3.amazonaws.com/Linux/CARLA_${CARLA_MAJOR_VERSION}.${CARLA_MINOR_VERSION}.tar.gz && \
mkdir -p carla && tar xzf CARLA_${CARLA_MAJOR_VERSION}.${CARLA_MINOR_VERSION}.tar.gz -C carla && \
python -m easy_install --no-deps carla/PythonAPI/carla/dist/carla-${CARLA_MAJOR_VERSION}-py2.7-linux-x86_64.egg && \
rm -rf carla CARLA_${CARLA_MAJOR_VERSION}.${CARLA_MINOR_VERSION}.tar.gz
RUN bash -c "source /opt/ros/melodic/setup.bash && source /opt/carla-ros-bridge/melodic/setup.bash && catkin init && catkin build"
RUN python3 -m easy_install --no-deps /opt/carla/PythonAPI/carla/dist/carla-${CARLA_VERSION}-py3.7-linux-x86_64.egg && \
ln -s /usr/bin/python3 /usr/bin/python
RUN bash -c "source /opt/ros/noetic/setup.bash && catkin build"

ENTRYPOINT [ "src/telecarla/docker/entrypoint.sh" ]
2 changes: 0 additions & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ set -e
# setup ros environment
# shellcheck disable=SC1090
source "/opt/ros/$ROS_DISTRO/setup.bash"
# shellcheck disable=SC1090
source "/opt/carla-ros-bridge/$ROS_DISTRO/setup.bash"
# shellcheck disable=SC1091
source "/home/catkin_ws/devel/setup.bash"

Expand Down
4 changes: 2 additions & 2 deletions gstreaming/cfg/RateControl.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

gen.add("bitrate", int_t, 0, "Encoder Bitrate Parameter in kbit/sec", 2000, 200, 5000)
gen.add("bitrate", int_t, 0, "Encoder Bitrate Parameter in kbit/sec", 2000, 100, 10000)

gen.add("fps", int_t, 0, "Temporal Resolution in frames/second", 20, 5, 25)
gen.add("fps", int_t, 0, "Temporal Resolution in frames/second", 20, 1, 100)
gen.add("spatial_scale", int_t, 0, "Spatial Resolution scale factor in percent", 100, 0, 100)

exit(gen.generate(PACKAGE, "gstreaming", "RateControl"))
3 changes: 2 additions & 1 deletion gstreaming/launch/rtsp/rtsp_server.launch
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
<arg name='stat_topic' default='/camera/stats'/>
<arg name='in_topic' default='/carla/ego_vehicle/camera/front/image'/>
<arg name='graph_viz' default="false"/>
<arg name='GST_DEBUG' default="2"/>

<env name="ROSCONSOLE_FORMAT" value="[${severity}] [${time}] [${node}]: ${message}"/>
<env name="GST_DEBUG" value="2"/>
<env name="GST_DEBUG" value="$(arg GST_DEBUG)"/>
<env name="GST_DEBUG_DUMP_DOT_DIR" value="." if="$(arg graph_viz)"/>

<group ns="server/$(arg server_id)">
Expand Down
3 changes: 2 additions & 1 deletion gstreaming/source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Libraries
add_subdirectory(common)
add_subdirectory(rtsp)
add_subdirectory(server)
add_subdirectory(client)

# Executeables
add_executable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ add_library(rtsp_client src/rtsp_client.cpp include/rtsp_client.h)

target_link_libraries(
rtsp_client
PUBLIC rtsp_common
PRIVATE gstreaming_common
PUBLIC gstreaming_common
PUBLIC ${GSTREAMER_LIBRARIES}
PUBLIC ${GLIB_LIBRARIES}
PUBLIC ${GSTREAMER_APP_LIBRARIES}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
#include <gst/app/gstappsink.h>
#include <gst/gstpipeline.h>

#include "rtsp_state.h"
#include "pipeline_state.h"

namespace lmt
{
namespace rtsp
{
namespace client
{
class RTSPClient
Expand All @@ -28,7 +26,7 @@ class RTSPClient
RTSPClient(RTSPClient&& rhs) = delete;
RTSPClient& operator=(RTSPClient&& rhs) = delete;

common::RTSPState start(const std::string& serverHost, int serverPort, const std::string& serverMount);
common::PipelineState start(const std::string& serverHost, int serverPort, const std::string& serverMount);
void stop();
void resume();

Expand All @@ -39,10 +37,9 @@ class RTSPClient
ImageCallback callBack_;
GstElement* pipeline_{nullptr};
GstAppSink* receiverAppSink_{nullptr};
common::RTSPState state_{common::RTSPState::stopped};
common::PipelineState state_{common::PipelineState::stopped};
};
} // namespace client
} // namespace rtsp
} // namespace lmt

#endif /* _LMT_RTSP_CLIENT_HH_ */
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <glib.h>
#include <gst/gst.h>

using namespace lmt::rtsp::client;
using namespace lmt::rtsp::common;
using namespace lmt::client;
using namespace lmt::common;

GstFlowReturn RTSPClient::onNewSampleFromSink(GstAppSink* appSink, RTSPClient* data)
{
Expand Down Expand Up @@ -44,11 +44,11 @@ GstFlowReturn RTSPClient::onNewSampleFromSink(GstAppSink* appSink, RTSPClient* d
return GST_FLOW_OK;
}

RTSPState RTSPClient::start(const std::string& serverHost, int serverPort, const std::string& serverMount)
PipelineState RTSPClient::start(const std::string& serverHost, int serverPort, const std::string& serverMount)
{
switch (state_)
{
case RTSPState::stopped: {
case PipelineState::stopped: {
// rtspsrc default: protocols=tcp+udp-mcast+udp
const auto cmd =
"rtspsrc location=rtsp://" + serverHost + ":" + std::to_string(serverPort) + "/" + serverMount +
Expand All @@ -71,11 +71,11 @@ RTSPState RTSPClient::start(const std::string& serverHost, int serverPort, const
else
{
GST_INFO("Client is PLAYING\n");
state_ = RTSPState::started;
state_ = PipelineState::started;
}
break;
}
case RTSPState::paused: {
case PipelineState::paused: {
resume();
break;
}
Expand All @@ -87,7 +87,7 @@ RTSPState RTSPClient::start(const std::string& serverHost, int serverPort, const

void RTSPClient::resume()
{
if (state_ == RTSPState::paused)
if (state_ == PipelineState::paused)
{
if (gst_element_set_state(pipeline_, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
{
Expand All @@ -103,12 +103,12 @@ void RTSPClient::resume()

void RTSPClient::stop()
{
if (state_ != RTSPState::stopped)
if (state_ != PipelineState::stopped)
{
GST_INFO("Gstreamer client terminating...\n");
gst_element_set_state(pipeline_, GST_STATE_NULL);
g_object_unref(pipeline_);
state_ = RTSPState::stopped;
state_ = PipelineState::stopped;
GST_INFO("Gstreamer client terminated\n");
}
}
Expand Down
3 changes: 2 additions & 1 deletion gstreaming/source/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_library(gstreaming_common include/gst_lifecycle.h src/gst_lifecycle.cpp)
add_library(gstreaming_common include/gst_lifecycle.h src/gst_lifecycle.cpp
include/pipeline_state.h src/pipeline_state.cpp)

target_link_libraries(
gstreaming_common
Expand Down
19 changes: 19 additions & 0 deletions gstreaming/source/common/include/pipeline_state.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef LMT_PIPELINE_STATE_H
#define LMT_PIPELINE_STATE_H

namespace lmt
{
namespace common
{
enum class PipelineState
{
started,
stopped,
paused,
starting,
stopping
};
}
} // namespace lmt

#endif // LMT_PIPELINE_STATE_H
1 change: 1 addition & 0 deletions gstreaming/source/common/src/pipeline_state.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "pipeline_state.h"
2 changes: 1 addition & 1 deletion gstreaming/source/include/gstreaming_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GStreamingClient
common::GstLifecycle gstLifecycle_;
GMainLoop* loop_{nullptr};
std::thread threadGstreamer_;
std::unique_ptr<rtsp::client::RTSPClient> rtspClient_{nullptr};
std::unique_ptr<client::RTSPClient> rtspClient_{nullptr};
image_transport::Publisher pub_;
};

Expand Down
2 changes: 1 addition & 1 deletion gstreaming/source/include/gstreaming_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GStreamingServer
std::string streamSource_;
GMainLoop* loop_{nullptr};
std::thread threadGstreamer_;
std::unique_ptr<rtsp::server::RTSPServer> rtspServer_{nullptr};
std::unique_ptr<server::RTSPServer> rtspServer_{nullptr};
ros::Subscriber subCamera_;
ros::Publisher pubStat_;
dynamic_reconfigure::Server<gstreaming::RateControlConfig> rateControl_;
Expand Down
3 changes: 0 additions & 3 deletions gstreaming/source/rtsp/CMakeLists.txt

This file was deleted.

6 changes: 0 additions & 6 deletions gstreaming/source/rtsp/common/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit e611a30

Please sign in to comment.