Skip to content

Instantly share code, notes, and snippets.

@sk413025
Last active September 3, 2021 11:28
Show Gist options
  • Save sk413025/87bd44a573e9a599e4a46a64a782c708 to your computer and use it in GitHub Desktop.
Save sk413025/87bd44a573e9a599e4a46a64a782c708 to your computer and use it in GitHub Desktop.

Only tested on Ubuntu AMD64/x86.

xhost +local:root
  • Pull the prebuild docker image. (Fornon-Nvidia GPU)
docker run -it \
    --rm \
    --name rclpy_bot \
    --privileged \
    --net=host \
    --env=DISPLAY \
    --env=QT_X11_NO_MITSHM=1 \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    ntklab/rclpy_bot \
    /bin/bash
  • For the Nvidia GPU, use the following command instead.
docker run -it \
    --rm \
    --gpus all \
    --name rclpy_bot \
    --privileged \
    --net=host \
    --env=DISPLAY \
    --env=QT_X11_NO_MITSHM=1 \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    ntklab/rclpy_bot \
    /bin/bash
  • Start rviz2. If it opens successfully, you can close it and move on to the next rocket example.
source /opt/ros/foxy/setup.sh
rviz2
  • Run the rocket example. You should see a standing rocket.
source /opt/ros/foxy/setup.sh
python3 /rocketbot/rocketbot/rocketbot_node.py
  • Open another terminal, then enter the new session.
docker exec -ti rclpy_bot bash
  • Create thrust_rv_ctr.py, then paste the following example.
vim /thrust_rv_ctr.py
import rclpy
import time
from rclpy.node import Node
from random import random
from geometry_msgs.msg import Vector3

rclpy.init()
node = Node('thrust_ctr')
thrust_pub = node.create_publisher(Vector3, 'thrust', 10)

thrust_msg = Vector3()

while True:
    thrust_msg.x = random() * 25
    thrust_msg.y = random() * 25
    thrust_msg.z = random() * 25
    thrust_pub.publish(thrust_msg)
    time.sleep(0.5)
  • Run the example. You will see the rocket flying randomly.
source /opt/ros/foxy/setup.sh
python3 /thrust_rv_ctr.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment