Skip to content

Commit

Permalink
Merge pull request #2 from bhaney/main
Browse files Browse the repository at this point in the history
RSDK-4180, RSDK-3053, RSDK-3417, RSDK-3884 Create Intel RealSense C++ Module
  • Loading branch information
bhaney authored Aug 2, 2023
2 parents 58ea8f3 + cb165f0 commit b333796
Show file tree
Hide file tree
Showing 11 changed files with 13,059 additions and 447 deletions.
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# compile the binary
SDK_LOCATION = /usr/local
CPP_COMPILER = g++
THIRD_PARTY_SOURCES = third_party/fpng.cpp third_party/lodepng.cpp
SERVER_TARGETS = $(THIRD_PARTY_SOURCES) camera_realsense.cpp

GCC_FLAGS = -O4 -pthread -Wredundant-move -Wpessimizing-move -Wl,-ldl
ifeq ($(shell arch), x86_64)
GCC_FLAGS += -mpclmul -msse2 -msse4.2
endif

SDK_INCLUDE = -I$(SDK_LOCATION)/include -I$(SDK_LOCATION)/include/viam/api -L$(SDK_LOCATION)/lib
SDK_FLAGS = -lviamsdk -lviam_rust_utils -lviamapi

LIB_FLAGS = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags grpc++ realsense2 --libs protobuf grpc++ libturbojpeg realsense2)

camera-module: $(SERVER_TARGETS)
$(CPP_COMPILER) -std=c++17 -o viam-camera-realsense camera_realsense.cpp $(THIRD_PARTY_SOURCES) $(SDK_INCLUDE) $(LIB_FLAGS) $(SDK_FLAGS) $(GCC_FLAGS)

default: camera-module

format: *.cpp
clang-format -i --style="{BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 100}" *.cpp

all: default

clean:
rm -rf viam-camera-realsense

clean-all: clean
git clean -fxd

# Docker
TAG_VERSION := latest

# Module
# Creates appimage cmake build.
# Builds docker image with viam-cpp-sdk and camera-realsense installed.
.PHONY: build
build:
docker build -t viam-camera-realsense:$(TAG_VERSION) \
--memory=16g \
--build-arg TAG=$(TAG_VERSION) \
-f ./etc/Dockerfile.debian.bookworm ./

# Runs docker image with shell.
run-docker: build
docker run \
--device /dev/fuse \
--cap-add SYS_ADMIN \
-it viam-camera-realsense:$(TAG_VERSION)

package:
cd etc && \
appimage-builder --recipe viam-camera-realsense-aarch64.yml


# Copies binary and AppImage from container to host.
copy-bin:
rm -rf bin | true && \
mkdir -p bin && \
docker rm viam-camera-realsense-bin | true && \
docker run -d -it --name viam-camera-realsense-bin viam-camera-realsense:$(TAG_VERSION) && \
docker exec --workdir /root/opt/src/viam-camera-realsense viam-camera-realsense-bin make package
docker cp viam-camera-realsense-bin:/root/opt/src/viam-camera-realsense/etc/viam-camera-realsense-latest-aarch64.AppImage ./bin && \
docker stop viam-camera-realsense-bin && \
docker rm viam-camera-realsense-bin

appimage: build copy-bin

71 changes: 69 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,69 @@
# camera-realsense
C++ camera module for the RealSense
# Intel RealSense Modular Component

## Getting Started
For Linux Distros, the simplest way of getting the camera server is by using Docker. The command

```
git clone https://github.com/viamrobotics/viam-camera-realsense/
cd viam-camera-realsense/
make appimage
```

will build a Docker image and compile a binary for the `aarch64` architecture, which will be placed in the `bin/` directory.

## Building From Source

It's first best to try to build from source within Docker. Try to do the following commands:

```
make build
make run-docker
# within Docker
cd ~/opt/src/viam-camera-realsense
make camera-module
# if you want to make the AppImage, then also do
make package
```

If you would like to try to gather all of the dependencies yourself and not use Docker, you will need:

- [librealsense](https://github.com/IntelRealSense/librealsense)
- `git checkout` and install from source.
- be sure to use cmake flags `cmake .. -DBUILD_EXAMPLES=false -DBUILD_GRAPHICAL_EXAMPLES=false -DCMAKE_BUILD_TYPE=Release`
- [libjpegturbo](https://github.com/libjpeg-turbo/libjpeg-turbo)
- [libprotobuf](https://github.com/protocolbuffers/protobuf)
- [Viam C++ SDK](https://github.com/viamrobotics/viam-cpp-sdk/)
- specifically `libviamsdk`, `libviamapi`, and `libviam_rust_utils`

then do `make camera-module` to compile the binary, and `make package` to create the AppImage.

## Attributes and Sample Config

The attributes for the module are as follows:
- `sensors` (required): a list that contain the strings `color` and/or `depth`. The sensor that comes first in the list is designated the "main sensor" and will be the image that gets returned by `get_image` calls and what will appear in the Control tab on app.viam.
- `width_px`, `height_px`: the width and height of the output images. If the RealSense cannot produce the requested resolution, the component will fail to be built.
- `little_endian_depth`: a bool that specifices whether raw depth data should be encoded in a little-endian byte order. By default it is `false`, and encodes the raw depth data in a big-endian byte order.
```
{
"components": [
{
"name": "myRealSense",
"attributes": {
"sensors": ["color","depth"],
"width_px": 640,
"height_px": 480,
"little_endian_depth": false,
},
"namespace": "rdk",
"type": "camera",
"model": "viam:camera:realsense"
}
],
"modules": [
{
"executable_path": "/home/user/viam-camera-realsense",
"name": "intel"
}
],
}
```
Loading

0 comments on commit b333796

Please sign in to comment.