Skip to content

(New) Generate Sensor Message Interface

Hyunseok edited this page Mar 4, 2024 · 8 revisions

Generate a proto message

※ If you want custom proto message, follow the step from 'Install and build'.

Download and Install Protogen

If 'dotnet' command is not work, you need to install 'dotnet' package first as a prerequisite.

Prerequisite for Protogen installation based on Ubuntu.

Do below command first.

sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-6.0

If it failed to install dotnet-sdk-6.0, follow the official guideline for latest version. => Install the .NET SDK or the .NET Runtime on Ubuntu

$ wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
$ sudo dpkg -i packages-microsoft-prod.deb

$ sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-6.0

Download and Install

This package requires dotnet 6.0.

App: /home/yg/.dotnet/tools/protogen
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '6.0.0' (x64)
dotnet tool install --global protobuf-net.Protogen --version 3.2.12

Check

Now you can type and run command 'protogen' like below

yg@ros-sim:~$ protogen
Missing input file.

If your command is not found, please check following path. (/home/$USER/.dotnet/tools/protogen)

root@ros-sim:/opt# protogen
bash: protogen: command not found

Generate

Example for CSharp

$ protogen *.proto --proto_path=/home/yg/Work/sim-device/driver_sim/msgs/ --csharp_out=./

Script for simulation

Refer to script

#!/bin/bash
TARGET_PATH=$1

if [ -z ${TARGET_PATH} ]; then
  TARGET_PATH="./ProtobufMessages"
fi

## 1. check and edit here
##    set the location of protogen in absolute path
PROTOGEN="protogen"

## 2. check and edit here
##    set the location of protobuf messages in absolute path
PROTO_MSGS_PATH="../../../../sim-device/driver_sim/msgs/"

## 3. target protobuf message
##
TARGET_PROTO_MSGS=""

MSG="header any param param_v color "
MSG+="time vector2d vector3d quaternion pose pose_v poses_stamped "
MSG+="image images_stamped image_stamped camerasensor distortion camera_lens "
MSG+="laserscan laserscan_stamped raysensor "
MSG+="pointcloud "
MSG+="micom battery "
MSG+="contact contacts contactsensor wrench wrench_stamped joint_wrench "
MSG+="gps gps_sensor "
MSG+="imu imu_sensor "
MSG+="sonar sonar_stamped "
MSG+="sensor_noise "

for i in $MSG
do
  TARGET_PROTO_MSGS+="$i.proto "
done

command="$PROTOGEN -I$PROTO_MSGS_PATH --csharp_out=$TARGET_PATH $TARGET_PROTO_MSGS"
eval $command