You are on page 1of 17

IMSE-7139

Cyber Physical Systems


Lab1

Prof. Ning Xi

1
Objective: Simple understanding of ROS: ROS is
the publish/subscribe middle-ware itself

Tasks:
 Build a simulation world and build a map based on it (group)
 Write a simple publisher and subscriber with python (individual)

2
Simulate hkubot in Gazebo
 Install simulation model
• Run “sudo apt-get install ros-kinetic-
controller-manager ros-kinetic-gmapping
ros-kinetic-move-base ros-kinetic-map-
server ros-kinetic-navigation ros-kinetic-
teb-local-planner”
• Run “sudo apt-get install ros-kinetic-
gazebo-ros-control”
• Run “sudo apt-get install ros-kinetic- 3

kobuki”
Simulate hkubot in Gazebo
 Install simulation model
• Run “cd ~/.gazebo/”
• Run “mkdir -p models”
• Run “cd models”
• Run “wget
http://file.ncnynl.com/ros/gazebo_models.txt”
• Run “wget -i gazebo_models.txt”
• Uncompress szarobotsim.tar.gz to Home folder
• Run “cd szarobotsim”
4

• Run “catkin_make”
Build simulation environment
• Run “source ~/szarobotsim/devel/setup.bash”
• Run “roslaunch my_simrobot my_simrobot_bringup.launch”
• Open a new terminal and run “source
~/szarobotsim/devel/setup.bash”
• Run “rosrun teleop_twist_keyboard
teleop_twist_keyboard.py” and move your robot
• Open a new terminal and run “source
~/szarobotsim/devel/setup.bash”
• Run “roslaunch my_simrobot robot_test_rviz.launch”
• Add Image to show rgb camera data and depth camera data
• Add LaserScan to show Lidar data during navigation
5
Build a map
• Run “source ~/szarobotsim/devel/setup.bash”
I
• Run “roslaunch my_simrobot gmappingsim_bringup.launch”
• Run “rosrun teleop_twist_keyboard teleop_twist_keyboard.py” J K L

and move your robot to build map


,
• Run “rosrun map_server map_saver -f ~/mymap”ation

6
Write a publisher to publish velocity (python)

 Step1: create a ROS workspace


• Run “mkdir -p ~/catkin_ws/src”
• Run “cd ~/catkin_ws/”
• Run “catkin_make”
• Run “source devel/setup.bash”
• Run “echo $ROS_PACKAGE_PATH”

7
Write a publisher to publish velocity (python)

 Step2: create and build a ROS package


• Run “cd ~/catkin_ws/src”
• Run “catkin_create_pkg beginner_tutorials_py std_msgs
rospy”
• Run “cd ..”
• Run “catkin_make”
• Run “source ~/catkin_ws/devel/setup.bash”
8
Write a publisher to publish velocity (python)

 Step3: write publisher to publish velocity topic


• Run “roscd beginner_tutorials_py”
• Run “mkdir scripts”
• Run “cd scripts”
• Create a new documents: talker.py
• Run “gedit talker.py”
9
• Run “chmod +x talker.py”
• Run “cd ..”
• Open CMakeLists.txt and check it having the following lines
• Run “gedit CMakeLists.txt”

11
 Step4: examine publisher nodes
• Run “roscore”
• Run “cd ~/catkin_ws”
• Run “source devel/setup.bash”
• Run “rosrun turtlesim turtlesim_node”
• Open new terminal
• Run “source catkin_ws/devel/setup.bash”
• Run “rosrun beginner_tutorials_py talker.py”
12
/cmd_vel
 Step4: examine publisher and subscriber nodes

• Open new terminal and Run “source ~/szarobotsim/devel/setup.bash”


• Run “roslaunch my_simrobot my_simrobot_bringup.launch”
• Open new terminal and Run “source ~/szarobotsim/devel/setup.bash”
• Run “roslaunch my_simrobot robot_test_rviz.launch”
• Run “cd ~/catkin_ws”
• Run “source devel/setup.bash”
• Run “rosrun beginner_tutorials_py talker.py”
14
 Step5: configure Rviz parameters
• Modify “Fixed Frame”, “Odometry”

15
Tests:
• Load the robot model in simulation, create
your own simulation environment, put the
screenshot in your report. (Group Report)
• Scan the map of your created environment in
simulation, put the screenshot in your report.
(Group Report)
• Control the robot to follow a circle in the
simulation environment. (Group Report)
• Drive your turtle and hkurobot to draw a “9”
as shown on the right. (Individual Report)
(Tips: you can change the value of msg.linear.x and
msg.angular.z to drive your turtle)
Assignment:
◼ Write a report after class to finish your group report and answer
the following questions individually:
• Take “hkubot” as an example to describe the working process of
ROS.
• Control the “hkubot” to draw “9” in the simulation environment,
with codes and screenshots in your report.
• Explain how you realize the publisher and subscriber in this
experiment.
• Please present a method to transmit the real-time position/velocity
data of the hkubot to another program running in your computer.17

You might also like