Software Backend/ros2

ros2 javascript (nodejs) test

light_meal 2023. 3. 18. 10:52
728x90

Create docker

docker run -itd --rm --name=jstest ubuntu:20.04 bash
docker exec -it jstest bash

 

Install node js

https://github.com/nodesource/distributions

apt update & apt install sudo curl
curl -fsSL <https://deb.nodesource.com/setup_18.x> | sudo -E bash - &&\\
sudo apt-get install -y nodejs

 

Install Ros2 galactic

https://docs.ros.org/en/galactic/Installation/Ubuntu-Install-Debians.html

locale  # check for UTF-8

sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

locale  # verify settings
sudo apt install software-properties-common -y
sudo add-apt-repository universe
sudo apt update && sudo apt install curl
sudo curl -sSL <https://raw.githubusercontent.com/ros/rosdistro/master/ros.key> -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] <http://packages.ros.org/ros2/ubuntu> $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt update
sudo apt upgrade -y
sudo apt install ros-galactic-desktop
sudo apt install ros-dev-tools

 

Ros2 Install Success Test

source /opt/ros/galactic/setup.bash
ros2 run demo_nodes_cpp talker

 

Install rclnodejs

cd /home
git clone <https://github.com/RobotWebTools/rclnodejs.git>
cd rclnodejs
npx rclnodejs-cli -h
npx rclnodejs-cli generate-ros-messages
npx rclnodejs-cli create-package -h

 

  • create package
npx rclnodejs-cli create-package mypkg --typescript

 

  • build
cd mypkg
npm run build
colcon build

 

  • run
ros2 launch mypkg example.launch.py

 

  • check pub msg & other terminal
cd /home/rclnodejs/mypkg
source install/setup.bash
ros2 topic echo foo
728x90