JetBot AI Kit: ROS

From Waveshare Wiki
Revision as of 09:53, 13 July 2022 by Eng52 (talk | contribs) (→‎Display Information on OLED)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

If you do not learn the ROS system, please refer to the ROS official tutorial before operating.

Preparation

Before installing the system, please refer to the install image.

Install ROS in Melodic version

  • The system image provided by Jetson Nano is based on Ubuntu 18.04, and supports installing ROS directly with apt. Use the following instructions to install in order, and pay attention to whether there is an error during the installation process.
# enable all Ubuntu packages:
sudo apt-add-repository universe
sudo apt-add-repository multiverse
sudo apt-add-repository restricted

# add ROS repository to apt sources
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

# install ROS Base
sudo apt-get update
sudo apt-get install ros-melodic-ros-base

# add ROS paths to environment
sudo sh -c 'echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc'

install python library

# pip should be installed
$ sudo apt-get install python-pip
# install Adafruit libraries
$ pip install Adafruit-MotorHAT
$ pip install Adafruit-SSD1306

Add i2c to user group

sudo usermod -aG i2c $USER

Create Catkin Workspace

  • Create catkin workspace and save ROS program package.
# create the catkin workspace
mkdir -p ~/workspace/catkin_ws/src
cd ~/workspace/catkin_ws
catkin_make

# add catkin_ws path to bashrc
sudo sh -c 'echo "source ~/workspace/catkin_ws/devel/setup.bash" >> ~/.bashrc'
  • Close the current terminal and reopen a new one. Check if ROS is installed successfully.
$ echo $ROS_PACKAGE_PATH 
/home/nvidia/workspace/catkin_ws/src:/opt/ros/melodic/share

Compile and Install Jetson-inference

# git and cmake should be installed
sudo apt-get install git cmake

# clone the repo and submodules
cd ~/workspace
git clone --recursive https://github.com/dusty-nv/jetson-inference
cd jetson-inference

# build from source
mkdir build
cd build
cmake ../
make

# install libraries
sudo make install

[Note] Since the Jetson nano servers are all overseas, some resources need to be able to access the Internet before they can be obtained, otherwise the installation may fail. In addition, you need to install the library.

sudo apt install libqt4-dev libglew-dev

Compile and Install ros_deep_learning

# install dependencies
sudo apt-get install ros-melodic-vision-msgs ros-melodic-image-transport ros-melodic-image-publisher

# clone the repo
cd ~/workspace/catkin_ws/src
git clone https://github.com/dusty-nv/ros_deep_learning

# make ros_deep_learning
cd ../    # cd ~/workspace/catkin_ws
catkin_make

# confirm that the package can be found
rospack find ros_deep_learning
/home/nvidia/workspace/catkin_ws/src/ros_deep_learning

Compile and Install ros_deep_learning

# install dependencies
sudo apt-get install ros-melodic-vision-msgs ros-melodic-image-transport ros-melodic-image-publisher

# clone the repo
cd ~/workspace/catkin_ws/src
git clone https://github.com/dusty-nv/ros_deep_learning

# make ros_deep_learning
cd ../    # cd ~/workspace/catkin_ws
catkin_make

# confirm that the package can be found
rospack find ros_deep_learning
/home/nvidia/workspace/catkin_ws/src/ros_deep_learning

Compile and Install jetbot_ros

# clone the repo
cd ~/workspace/catkin_ws/src
git clone https://github.com/waveshare/jetbot_ros

# build the package
cd ../    # cd ~/workspace/catkin_ws
catkin_make

# confirm that jetbot_ros package can be found
rospack find jetbot_ros
/home/nvidia/workspace/catkin_ws/src/jetbot_ros

Test Jetbot ROS

Open a new terminal and run ros core node.

 roscore

The output information is as follows, then ros works normally.

JetBot AI Kit Manual 35.jpg

[Note] The roscore core node must keep running, otherwise all other nodes will not work.

Run the Motor Node

  • Open another terminal, please do not close roscore. Run the following command to enable jetbot_motors node.
rosrun jetbot_ros jetbot_motors.py
  • Set up a new terminal, enter rosnode list to check whether jetbot_motors node has been enabled. Enter rostopic list to check the monitoring topic of the jetbot_motor node.
JetBot AI Kit Manual 36.jpg
  • [Note] As of 2019/02/22, jotbot-ros only implements the cmd_str method. If there are other updates in the future, you can find out by yourself
  • cmd_str controls jetbot movement by sending string commands (left/right/forward/backward/stop).

Test Motor Command

  • Open a new terminal and run the following test command to control jetbot movement.
rostopic pub /jetbot_motors/cmd_str std_msgs/String --once "forward"
rostopic pub /jetbot_motors/cmd_str std_msgs/String --once "backward"
rostopic pub /jetbot_motors/cmd_str std_msgs/String --once "left"
rostopic pub /jetbot_motors/cmd_str std_msgs/String --once "right"
rostopic pub /jetbot_motors/cmd_str std_msgs/String --once "stop"

Display Information on OLED

  • Create a new terminal to run the OLED node.
rosrun jetbot_ros jetbot_oled.py
  • jetbot_oled listens to /jetbot_oled/user_text topic, accepts character information and displays it. Run the following command to display "HELLO" characters rostopic pub /jetbot_oled/user_text std_msgs/String --once "HELLO!".

Use the keyboard to control jetbot movement

  • Create a new terminal to run the teleop_key node
rosrun jetbot_ros teleop_key.py
  • After the program runs, use the keyboard to input the four keys of W, S, D, and A to control the jetbot to move back and forth, left and right.

Use the Gamepad to Contro Jetbot

  • Plug the USB receiver of the gamepad to the jetbot.
  • Create a new terminal and enter the following command.
ls /dev/input
  • The display is as follows:
JetBot AI Kit Manual 37.jpg
  • Among them, js0 represents the joystick handle of the game. Enter the following command to test whether the device is working normally.
sudo jstest /dev/input/js0
JetBot AI Kit Manual 38.jpg
  • When you press different buttons on the remote controller, the corresponding button values ​​will change.
  • [Note] If the jstest command cannot be found after running the command, you need to run the following command to install the corresponding library.
sudo apt-get install joystick
  • Install the joy package and start the joy node. To get the joystick data published via ROS, we need to start the joy node.
sudo apt-get install ros-melodic-joy
rosrun joy joy_node
  • The displayed information is as follows:
JetBot AI Kit Manual 39.jpg
  • Create a new terminal and run the following command to display the joy node information
rostopic echo joy
  • When the joystick is pressed, a message similar to the following will be output.
JetBot AI Kit Manual 040.jpg
  • Among them, axes[ ] represents the data of the joystick, and buttons[ ] represents the data of the buttons.
  • At this time, although the gamepad can display the data released by ros. If you want to control the jetbot, you also need to run the teleop_joy node, receive the topic information published by the joy node, convert it to the /jetbot_motor/cmd_str topic, and send it to the jetbot_motors node to control the motor movement. Create a new terminal and run the following command to start the terminal teleop_joy node.
rosrun jetbot_ros teleop_joy.py
  • Install the A key of the gamepad, and then control the up, down, left, and right direction keys to control the jetbot to move, release the A key, and the jetbot stops.
  • Modify the values ​​of axes[ ] and buttons[ ] in the jetbot_ros/scripts/teleop_joy.py program to set different button controls.
JetBot AI Kit Manual 41.jpg

Use the Camera to Monitor

  • Enable jetbot_camera node and the jetbot camera video flow.
rosrun jetbot_ros jetbot_camera
  • Will post the topic jetbot_camera/raw with image format sensor_msgs::Image.
  • Run the following command to display the camera image.
rosrun rqt_image_view rqt_image_view
  • The following window will be displayed, select the topic as /jetbot_camera/raw.

JetBot AI Kit ROS001.jpg

  • Note: This command needs to be run in a graphical interface. You can install the ubuntu system and install ROS on the computer through a virtual machine.
  • Jetbot adds the following two lines at the end of the ~/.bashrc file
export ROS_HOSTNAME=jetbot.local
export ROS_MASTER_URI=http://jetbot.local:11311
  • Ubuntu system adds the following two lines at the end of the ~/.bashrc file
export ROS_HOSTNAME=ubuntu.local
export ROS_MASTER_URI=http://jetbot.local:11311
  • In this way, the jetbot and the ubuntu virtual machine can communicate through the ros node, so that the rqt_imge_view command can be run on the computer through the ubuntu virtual machine to view the real-time image of the jetbot camera.