Difference between revisions of "Jetbot ROS"
(→Use the keyboard to control jetbot movement) |
(→Use The Keyboard To Control Jetbot Movement) |
||
(55 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Linux Version == | == Linux Version == | ||
+ | |||
+ | JetPack 4.5.1 / Ubuntu 18.04 | ||
Use: jetson-nx-jp451-sd-card-image | Use: jetson-nx-jp451-sd-card-image | ||
− | Note: the process below will likely exceed the disk capacity of a 16GB filesystem,so a larger SD card should be used( | + | Note: the process below will likely exceed the disk capacity of a 16GB filesystem,so a larger SD card should be used. ( Advice more than 64GB ) |
== Install ROS == | == Install ROS == | ||
Line 43: | Line 45: | ||
</pre> | </pre> | ||
− | + | == Create The Catkin Workspace == | |
Create a ROS Catkin workspace to contain our ROS packages. | Create a ROS Catkin workspace to contain our ROS packages. | ||
Line 62: | Line 64: | ||
</pre> | </pre> | ||
− | + | == Install Jetbot Ros == | |
Clone and build the jetbot_ros repo. | Clone and build the jetbot_ros repo. | ||
Line 88: | Line 90: | ||
Next, let's check that the different components of the robot are working under ROS. | Next, let's check that the different components of the robot are working under ROS. | ||
− | First open a new terminal, and start roscore | + | First open a new terminal, and start roscore. |
<pre>$ roscore | <pre>$ roscore | ||
Line 97: | Line 99: | ||
| style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | Roscore | | style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | Roscore | ||
|- | |- | ||
− | | style="text-align: center;" | [[File:Roscore.png|300px|thumb| | + | | style="text-align: center;" | [[File:Roscore.png|300px|thumb|center]] |
|} | |} | ||
− | ''' Running the | + | ''' Running the motors ''' |
Open a new terminal, and start the jetbot_motors node. | Open a new terminal, and start the jetbot_motors node. | ||
Line 117: | Line 119: | ||
| style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | Rosnode list | | style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | Rosnode list | ||
|- | |- | ||
− | | style="text-align: center;" | [[File:Rosnode list.png|300px|thumb| | + | | style="text-align: center;" | [[File:Rosnode list.png|300px|thumb|center]] |
|} | |} | ||
− | ''' Using the | + | ''' Using the debug OLED ''' |
If you have an SSD1306 debug OLED on your JetBot, you can run the jetbot_oled node to display system information and user-defined text. | If you have an SSD1306 debug OLED on your JetBot, you can run the jetbot_oled node to display system information and user-defined text. | ||
Line 131: | Line 133: | ||
{| border="1" cellpadding="1" style="width:300px;" | {| border="1" cellpadding="1" style="width:300px;" | ||
|- | |- | ||
− | | style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | | + | | style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | OLED print |
|- | |- | ||
− | | style="text-align: center;" | [[File:Ros oled.jpg|300px|thumb| | + | | style="text-align: center;" | [[File:Ros oled.jpg|300px|thumb|center]] |
|} | |} | ||
− | == Use the keyboard to control jetbot movement | + | == Remote Control Jetbot == |
+ | |||
+ | ''' Use the keyboard to control jetbot movement ''' | ||
Open a new terminal to run teleop_key node.After the program is running, input W, S, D, A four keys on the keyboard to control the jetbot to move forward, backward, right, and left. | Open a new terminal to run teleop_key node.After the program is running, input W, S, D, A four keys on the keyboard to control the jetbot to move forward, backward, right, and left. | ||
Line 143: | Line 147: | ||
</pre> | </pre> | ||
− | + | Can see the running action from the jetbot_motors node terminal. | |
{| border="1" cellpadding="1" style="width:300px;" | {| border="1" cellpadding="1" style="width:300px;" | ||
Line 149: | Line 153: | ||
| style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | Motors node | | style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | Motors node | ||
|- | |- | ||
− | | style="text-align: center;" | [[File:Motors node.png|300px|thumb]] | + | | style="text-align: center;" | [[File:Motors node.png|300px|thumb|center]] |
+ | |} | ||
+ | |||
+ | == Create Lidar Scan Node == | ||
+ | |||
+ | Let’s create a package. | ||
+ | |||
+ | <pre>$ cd ~/catkin_ws/src | ||
+ | $ catkin_create_pkg laser_values rospy | ||
+ | $ cd laser_values | ||
+ | $ mkdir launch | ||
+ | </pre> | ||
+ | |||
+ | Add a python script under src with the following code. | ||
+ | |||
+ | <pre>import rospy | ||
+ | from sensor_msgs.msg import LaserScan | ||
+ | |||
+ | def callback(msg): | ||
+ | print len(msg.ranges) | ||
+ | |||
+ | def callback(msg): | ||
+ | # values at 0 degree | ||
+ | print msg.ranges[0] | ||
+ | |||
+ | rospy.init_node('scan_values') | ||
+ | sub = rospy.Subscriber('/scan', LaserScan, callback) | ||
+ | rospy.spin() | ||
+ | </pre> | ||
+ | |||
+ | Then create a launch file under lunch directory to launch the script. | ||
+ | |||
+ | <pre><launch> | ||
+ | <node pkg="laser_values" type="scan.py" name="scan_values" output="screen"> | ||
+ | |||
+ | </node> | ||
+ | </launch> | ||
+ | </pre> | ||
+ | |||
+ | First open a new terminal, and start roscore. | ||
+ | |||
+ | <pre>$ roscore | ||
+ | </pre> | ||
+ | |||
+ | Open a new terminal, and start the laser.launch node. | ||
+ | |||
+ | <pre>$ roslaunch laser_values laser.launch | ||
+ | </pre> | ||
+ | |||
+ | == Install Rviz == | ||
+ | |||
+ | Install rviz by entering the following commands in the terminal. | ||
+ | |||
+ | <pre>$ sudo apt update | ||
+ | $ sudo apt install rviz | ||
+ | </pre> | ||
+ | |||
+ | First open a new terminal, and start roscore. | ||
+ | |||
+ | <pre>$ roscore | ||
+ | </pre> | ||
+ | |||
+ | Open a new terminal, and start the rviz node. | ||
+ | |||
+ | <pre>$ rosrun rviz rviz | ||
+ | </pre> | ||
+ | |||
+ | == Install RP Lidar SDK == | ||
+ | |||
+ | First install rplidar sdk. | ||
+ | |||
+ | <pre>$ cd rplidar_sdk_v1.X.X/sdk/sdk/ | ||
+ | $ make | ||
+ | $ ls /dev/ttyUSB* | ||
+ | </pre> | ||
+ | |||
+ | Check the ttyusb0, it's rplidar work. | ||
+ | |||
+ | {| border="1" cellpadding="1" style="width:300px;" | ||
+ | |- | ||
+ | | style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | ttyuUSB0 | ||
+ | |- | ||
+ | | style="text-align: center;" | [[File:Ttyusb0.png|300px|thumb|center]] | ||
+ | |} | ||
+ | |||
+ | Setting com port permission. | ||
+ | |||
+ | <pre>$ sudo chmod 666 /dev/ttyUSB0 | ||
+ | </pre> | ||
+ | |||
+ | == Jetbot SLAM == | ||
+ | |||
+ | Clone and build the rplidar_ros repo. | ||
+ | |||
+ | <pre>$ cd ~/catkin_ws/src | ||
+ | $ git clone -b slam https://github.com/robopeak/rplidar_ros | ||
+ | $ cd ~/catkin_ws | ||
+ | $ catkin_make | ||
+ | </pre> | ||
+ | |||
+ | Preview the point cloud. | ||
+ | |||
+ | <pre>$ roslaunch rplidar_ros view_rplidar.launch | ||
+ | </pre> | ||
+ | |||
+ | {| border="1" cellpadding="1" style="width:300px;" | ||
+ | |- | ||
+ | | style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | Point cloud | ||
+ | |- | ||
+ | | style="text-align: center;" | [[File:Point cloud.png|300px|thumb|center]] | ||
+ | |} | ||
+ | |||
+ | Clone and build the hector_slam repo. | ||
+ | |||
+ | <pre>$ cd ~/catkin_ws/src | ||
+ | $ git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam | ||
+ | $ cd ~/catkin_ws | ||
+ | $ catkin_make | ||
+ | </pre> | ||
+ | |||
+ | Preview the SLAM. | ||
+ | |||
+ | <pre>$ roslaunch rplidar_ros view_slam.launch | ||
+ | </pre> | ||
+ | |||
+ | {| border="1" cellpadding="1" style="width:300px;" | ||
+ | |- | ||
+ | | style="width: 389px; background-color: rgb(80, 80, 80); color: rgb(255, 255, 255); text-align: center;" | SLAM | ||
+ | |- | ||
+ | | style="text-align: center;" | [[File:SLAM.png|300px|thumb|center]] | ||
|} | |} |
Latest revision as of 09:41, 23 November 2022
Contents
Linux Version
JetPack 4.5.1 / Ubuntu 18.04
Use: jetson-nx-jp451-sd-card-image
Note: the process below will likely exceed the disk capacity of a 16GB filesystem,so a larger SD card should be used. ( Advice more than 64GB )
Install ROS
Install ROS melodic
# 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'
Close and restart the terminal.
Install python and adafruit libraries
# pip should be installed $ sudo apt-get install python-pip # install Adafruit libraries $ pip install Adafruit-MotorHAT $ pip install Adafruit-SSD1306
Add i2c too user
$ sudo usermod -aG i2c $USER
Create The Catkin Workspace
Create a ROS Catkin workspace to contain our ROS packages.
# 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 and open a new terminal window. Verify that your catkin_ws is visible to ROS.
$ echo $ROS_PACKAGE_PATH /home/nvidia/workspace/catkin_ws/src:/opt/ros/melodic/share
Install Jetbot Ros
Clone and build the jetbot_ros repo.
# git and cmake should be installed $ sudo apt-get install git cmake # 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
Running the ROS master
Next, let's check that the different components of the robot are working under ROS.
First open a new terminal, and start roscore.
$ roscore
Roscore |
Running the motors
Open a new terminal, and start the jetbot_motors node.
$ rosrun jetbot_ros jetbot_motors.py
Open a new terminal, and check jetbot_motors node is open.
$ rosnode list $ rostopic list
Rosnode list |
Using the debug OLED
If you have an SSD1306 debug OLED on your JetBot, you can run the jetbot_oled node to display system information and user-defined text.
$ rosrun jetbot_ros jetbot_oled.py
By default, jetbot_oled will refresh the display every second with the latest memory usage, disk space, and IP addresses.
OLED print |
Remote Control Jetbot
Use the keyboard to control jetbot movement
Open a new terminal to run teleop_key node.After the program is running, input W, S, D, A four keys on the keyboard to control the jetbot to move forward, backward, right, and left.
$ rosrun jetbot_ros teleop_key.py
Can see the running action from the jetbot_motors node terminal.
Motors node |
Create Lidar Scan Node
Let’s create a package.
$ cd ~/catkin_ws/src $ catkin_create_pkg laser_values rospy $ cd laser_values $ mkdir launch
Add a python script under src with the following code.
import rospy from sensor_msgs.msg import LaserScan def callback(msg): print len(msg.ranges) def callback(msg): # values at 0 degree print msg.ranges[0] rospy.init_node('scan_values') sub = rospy.Subscriber('/scan', LaserScan, callback) rospy.spin()
Then create a launch file under lunch directory to launch the script.
<launch> <node pkg="laser_values" type="scan.py" name="scan_values" output="screen"> </node> </launch>
First open a new terminal, and start roscore.
$ roscore
Open a new terminal, and start the laser.launch node.
$ roslaunch laser_values laser.launch
Install Rviz
Install rviz by entering the following commands in the terminal.
$ sudo apt update $ sudo apt install rviz
First open a new terminal, and start roscore.
$ roscore
Open a new terminal, and start the rviz node.
$ rosrun rviz rviz
Install RP Lidar SDK
First install rplidar sdk.
$ cd rplidar_sdk_v1.X.X/sdk/sdk/ $ make $ ls /dev/ttyUSB*
Check the ttyusb0, it's rplidar work.
ttyuUSB0 |
Setting com port permission.
$ sudo chmod 666 /dev/ttyUSB0
Jetbot SLAM
Clone and build the rplidar_ros repo.
$ cd ~/catkin_ws/src $ git clone -b slam https://github.com/robopeak/rplidar_ros $ cd ~/catkin_ws $ catkin_make
Preview the point cloud.
$ roslaunch rplidar_ros view_rplidar.launch
Point cloud |
Clone and build the hector_slam repo.
$ cd ~/catkin_ws/src $ git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam $ cd ~/catkin_ws $ catkin_make
Preview the SLAM.
$ roslaunch rplidar_ros view_slam.launch
SLAM |