Skip to content

Commit

Permalink
Add Dockerfile for Noetic (#164)
Browse files Browse the repository at this point in the history
* add dockerfile

* trim down zshrc

* chenged docker file name

* update readme

* updated workflow for image pushing

* readme update

* rename tag

* update dockerfile and action

* change github branch to noetic

* typo

* add arm64 platform

* try clang format

* update for tag

* remove additional gcc versions

* sequential build

* fix ifelse in dockerfile
  • Loading branch information
Serafadam authored Nov 16, 2022
1 parent b6d7aca commit 50483d9
Show file tree
Hide file tree
Showing 23 changed files with 564 additions and 547 deletions.
95 changes: 53 additions & 42 deletions .github/workflows/main.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ on:
workflow_dispatch:
push:
branches:
- main
- devel
- noetic
tags:
- 'v*'
pull_request:
branches:
- main
- devel
- noetic

jobs:

Expand All @@ -35,6 +33,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-20.04]
ROS_DISTRO: [melodic, noetic]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -75,48 +74,60 @@ jobs:
target-ros1-distro: noetic
skip-tests: true


ROS2-build:
runs-on: ubuntu-20.04
docker-build:
name: Build and Upload to Docker Hub
runs-on: ubuntu-latest
strategy:
matrix:
ros_distribution: [foxy]

fail-fast: false
matrix:
ROS_DISTRO: [noetic]
env:
PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'luxonis/depthai-ros') && startsWith(github.ref, 'refs/tags/v') }}
steps:
- uses: actions/checkout@v2

- name: ${{ matrix.ros_distribution }} build
uses: ros-tooling/[email protected]
with:
required-ros-distributions: ${{ matrix.ros_distribution }}
- name: Checkout
uses: actions/checkout@v3

- name: Installing libusb
run: sudo apt-get install libusb-1.0-0-dev
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Installing DepthAi Core
run: sudo wget -qO- https://raw.githubusercontent.com/luxonis/depthai-ros/$GITHUB_SHA/install_dependencies.sh | sudo bash

- name: Build depthai-bridge ${{ matrix.ros_distribution }}
uses: ros-tooling/[email protected]
with:
# vcs-repo-file-url: "${{ github.workspace }}/.github/workflows/examples.repos"
# package-name: depthai_examples
target-ros2-distro: ${{ matrix.ros_distribution }}
skip-tests: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v1
if: env.PUSH == 'true'
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASS }}
- name: Get Version
if: env.PUSH == 'true'
id: vars
run: echo ::set-output name=short_ref::${GITHUB_REF#refs/*/}

- name: Build
uses: docker/build-push-action@v3
if: env.PUSH == 'false'
with:
build-args: |
ROS_DISTRO=${{ matrix.ROS_DISTRO }}
USE_RVIZ=1
platforms: |
amd64
arm64
no-cache: true

# build_:
# runs-on: ubuntu-18.04
# steps:
# - uses: actions/checkout@v2
# - uses: ros-tooling/[email protected]
# with:
# required-ros-distributions: melodic
# - run: sudo wget -qO- https://raw.githubusercontent.com/luxonis/depthai-ros/noetic-devel/install_dependencies.sh | sudo bash
# - uses: ros-tooling/[email protected]
# with:
# # vcs-repo-file-url: "${{ github.workspace }}/.github/workflows/examples.repos"
# # package-name: depthai_examples
# target-ros1-distro: melodic
# skip-tests: true
- name: Build and Push
uses: docker/build-push-action@v3
if: env.PUSH == 'true'
with:
build-args: |
ROS_DISTRO=${{ matrix.ROS_DISTRO }}
USE_RVIZ=1
platforms: |
amd64
arm64
push: ${{ env.PUSH }}
no-cache: true
tags: |
luxonis/depthai-ros:${{ matrix.ROS_DISTRO }}-${{ steps.vars.outputs.short_ref }}
luxonis/depthai-ros:${{ matrix.ROS_DISTRO }}-latest
8 changes: 8 additions & 0 deletions .zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export ZSH="$HOME/.oh-my-zsh"

ZSH_THEME="robbyrussell"

plugins=(git)

source $ZSH/oh-my-zsh.sh

21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ARG ROS_DISTRO=noetic
FROM ros:${ROS_DISTRO}-ros-base
ARG USE_RVIZ
ARG BUILD_SEQUENTIAL=0
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get -y install --no-install-recommends software-properties-common git libusb-1.0-0-dev wget zsh python3-catkin-tools

ENV DEBIAN_FRONTEND=dialog
RUN sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

ENV WS=/ws
RUN mkdir -p $WS/src
COPY ./ .$WS/src/depthai_ros
RUN cd .$WS/ && rosdep install --from-paths src --ignore-src -y
RUN if [ "$BUILD_SEQUENTIAL" = "1" ] ; then cd .$WS/ && . /opt/ros/noetic/setup.sh && catkin build -p 1; else cd .$WS/ && . /opt/ros/noetic/setup.sh && catkin build; fi
RUN if [ "$USE_RVIZ" = "1" ] ; then echo "RVIZ ENABLED" && sudo apt install -y ros-noetic-rviz ros-noetic-rviz-imu-plugin ; else echo "RVIZ NOT ENABLED"; fi
RUN echo "if [ -f ${WS}/devel/setup.zsh ]; then source ${WS}/devel/setup.zsh; fi" >> $HOME/.zshrc
RUN echo "if [ -f ${WS}/devel/setup.bash ]; then source ${WS}/devel/setup.bash; fi" >> $HOME/.bashrc
ENTRYPOINT [ "/ws/src/depthai_ros/entrypoint.sh" ]
CMD ["zsh"]
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ sudo udevadm control --reload-rules && sudo udevadm trigger
Install depthai-ros. (Available for Noetic, foxy, galactic and humble)
`sudo apt install ros-<distro>-depthai-ros`

## Docker
You can additionally build and run docker images on your local machine. To do that, add USB rules as in above step, clone the repository and inside it run (it matters on which branch you are on):
```
docker build --build-arg USE_RVIZ=1 -t depthai-ros .
```
If you find out that you run out of RAM during building, you can also set `BUILD_SEQUENTIAL=1` to build packages one at a time, it should take longer, but use less RAM.
`RUN_RVIZ` arg means rviz will be installed inside docker. If you want to run it you need to also execute following command (you'll have to do it again after restarting your PC):
```
xhost +local:docker
```

Then you can run your image in following way:
```
docker run -it -v /dev/:/dev/ --privileged -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix depthai-ros
```
will run an interactive docker session.
### Running on ROS1
```
docker run -it -v /dev/:/dev/ --privileged -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix depthai_ros roslaunch depthai_examples stereo_inertial_node.launch
```
Will only start `stereo_inertial_node` launch file (you can try different commands).
### Running on ROS2
```
docker run -it -v /dev/:/dev/ --privileged -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix depthai_ros roslaunch depthai_examples stereo_inertial_node.launch.py
```
## Install from source

### Install dependencies
Expand Down Expand Up @@ -101,4 +126,4 @@ ros2 launch depthai_examples mobile_publisher.launch.py camera_model:=OAK-D-LITE

### Users can write Custom converters and plug them in for bridge Publisher.
If there a standard Message or usecase for which we have not provided a ros msg or
converter feel free to create a issue or reach out to us on our discord community. We would be happy to add more.
converter feel free to create a issue or reach out to us on our discord community. We would be happy to add more.
12 changes: 3 additions & 9 deletions depthai_bridge/include/depthai_bridge/BridgePublisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,24 @@
#include <type_traits>
#include <typeinfo>

#include "depthai/depthai.hpp"

#include "boost/make_shared.hpp"
#include "boost/shared_ptr.hpp"
#include "camera_info_manager/camera_info_manager.h"
#include "depthai/depthai.hpp"
#include "image_transport/image_transport.h"
#include "ros/console.h"
#include "ros/ros.h"
#include "boost/make_shared.hpp"
#include "boost/shared_ptr.hpp"
#include "sensor_msgs/Image.h"


namespace dai {

namespace ros {


namespace StdMsgs = std_msgs;
namespace ImageMsgs = sensor_msgs;
using ImagePtr = ImageMsgs::ImagePtr;
namespace rosOrigin = ::ros;


template <class RosMsg, class SimMsg>
class BridgePublisher {
public:
Expand Down Expand Up @@ -61,7 +57,6 @@ class BridgePublisher {
*/
std::shared_ptr<rosOrigin::Publisher> advertise(int queueSize, std::false_type);


BridgePublisher(const BridgePublisher& other);

void addPublisherCallback();
Expand Down Expand Up @@ -172,7 +167,6 @@ BridgePublisher<RosMsg, SimMsg>::BridgePublisher(const BridgePublisher& other) {
}
}


template <class RosMsg, class SimMsg>
void BridgePublisher<RosMsg, SimMsg>::daiCallback(std::string name, std::shared_ptr<ADatatype> data) {
auto daiDataPtr = std::dynamic_pointer_cast<SimMsg>(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class DisparityConverter {
std::chrono::time_point<std::chrono::steady_clock> _steadyBaseTime;

::ros::Time _rosBaseTime;

};

} // namespace ros
Expand Down
1 change: 0 additions & 1 deletion depthai_bridge/include/depthai_bridge/ImuConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class ImuConverter {
ImuSyncMethod _syncMode;
std::chrono::time_point<std::chrono::steady_clock> _steadyBaseTime;
::ros::Time _rosBaseTime;

};

} // namespace ros
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class SpatialDetectionConverter {
bool _normalized;
std::chrono::time_point<std::chrono::steady_clock> _steadyBaseTime;
::ros::Time _rosBaseTime;

};

/** TODO(sachin): Do we need to have ros msg -> dai bounding box ?
Expand Down
19 changes: 9 additions & 10 deletions depthai_bridge/include/depthai_bridge/depthaiUtility.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#pragma once

#include <chrono>
#include <ros/ros.h>

#include <chrono>

namespace dai {

namespace ros {

enum LogLevel { DEBUG, INFO, WARN, ERROR, FATAL };

#define DEPTHAI_ROS_LOG_STREAM(loggerName, level, isOnce, args) \
if(isOnce) { \
ROS_LOG_STREAM_ONCE(static_cast<::ros::console::Level>(level), std::string(ROSCONSOLE_NAME_PREFIX) + "." + loggerName, args); \
} else { \
ROS_LOG_STREAM(static_cast<::ros::console::Level>(level), std::string(ROSCONSOLE_NAME_PREFIX) + "." + loggerName, args); \
}
#define DEPTHAI_ROS_LOG_STREAM(loggerName, level, isOnce, args) \
if(isOnce) { \
ROS_LOG_STREAM_ONCE(static_cast<::ros::console::Level>(level), std::string(ROSCONSOLE_NAME_PREFIX) + "." + loggerName, args); \
} else { \
ROS_LOG_STREAM(static_cast<::ros::console::Level>(level), std::string(ROSCONSOLE_NAME_PREFIX) + "." + loggerName, args); \
}

// DEBUG stream macros on top of ROS logger
#define DEPTHAI_ROS_DEBUG_STREAM(loggerName, args) DEPTHAI_ROS_LOG_STREAM(loggerName, dai::ros::LogLevel::DEBUG, false, args)
Expand All @@ -42,10 +42,9 @@ enum LogLevel { DEBUG, INFO, WARN, ERROR, FATAL };

#define DEPTHAI_ROS_FATAL_STREAM_ONCE(loggerName, args) DEPTHAI_ROS_LOG_STREAM(loggerName, dai::ros::LogLevel::FATAL, true, args)


inline ::ros::Time getFrameTime(::ros::Time rosBaseTime,
std::chrono::time_point<std::chrono::steady_clock> steadyBaseTime,
std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> currTimePoint) {
std::chrono::time_point<std::chrono::steady_clock> steadyBaseTime,
std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> currTimePoint) {
auto elapsedTime = currTimePoint - steadyBaseTime;
uint64_t nSec = rosBaseTime.toNSec() + std::chrono::duration_cast<std::chrono::nanoseconds>(elapsedTime).count();
auto currTime = rosBaseTime;
Expand Down
1 change: 0 additions & 1 deletion depthai_bridge/src/DisparityConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ void DisparityConverter::toRosMsg(std::shared_ptr<dai::ImgFrame> inData, std::de
return;
}


DisparityImagePtr DisparityConverter::toRosMsgPtr(std::shared_ptr<dai::ImgFrame> inData) {
std::deque<DisparityMsgs::DisparityImage> msgQueue;
toRosMsg(inData, msgQueue);
Expand Down
2 changes: 0 additions & 2 deletions depthai_bridge/src/ImageConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ std::unordered_map<dai::RawImgFrame::Type, std::string> ImageConverter::planarEn

ImageConverter::ImageConverter(bool interleaved) : _daiInterleaved(interleaved), _steadyBaseTime(std::chrono::steady_clock::now()) {
_rosBaseTime = ::ros::Time::now();

}

ImageConverter::ImageConverter(const std::string frameName, bool interleaved)
: _frameName(frameName), _daiInterleaved(interleaved), _steadyBaseTime(std::chrono::steady_clock::now()) {
_rosBaseTime = ::ros::Time::now();

}

void ImageConverter::toRosMsg(std::shared_ptr<dai::ImgFrame> inData, std::deque<ImageMsgs::Image>& outImageMsgs) {
Expand Down
1 change: 0 additions & 1 deletion depthai_bridge/src/ImuConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ImuConverter::ImuConverter(const std::string& frameName, ImuSyncMethod syncMode,
_sequenceNum(0),
_steadyBaseTime(std::chrono::steady_clock::now()) {
_rosBaseTime = ::ros::Time::now();

}

void ImuConverter::FillImuData_LinearInterpolation(std::vector<IMUPacket>& imuPackets, std::deque<ImuMsgs::Imu>& imuMsgs) {
Expand Down
Loading

0 comments on commit 50483d9

Please sign in to comment.