<aside> 👉
Summary from ELEC4260 & 5660 @ HKUST (By Yiyan PENG)
Version: Ubuntu 20.04
& ROS 1 (noetic)
Last primary update: 2025-Feb-15
</aside>
ROS connects robots and supports communications and infrastructure.
ROS is better in Ubuntu. There are multiple ways to run Ubuntu and then ROS.
# check topics
rostopic list
# manually publish topics
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist "xxx"
# rostopic pub --rate <freq_in_Hz> <topic_name> <msgs_data_type> <msgs_content>
# check topic content
rostopic echo <topic_name>
# save topic content in bags
rosbag record <topic_name_1> <topic_name_2> <xxx> # as many as want
# replay
rosbag replay <rosbag_name> # check the flag to see specific function features
# Create a Workspace folder
mkdir -p ~/catkin_ws/src
# initialize the Workspace for the Package
cd ~/catkin_ws/src
# init workspace for workspace's src folder
catkin_init_workspace # CMakeLists.txt will be created for the "src" package folder
# Return to main Workspace & Build the Workspace
cd .. # pwd: ~/catkin_ws
catkin_make # build workspace -> "build" & "devel" folder will be created under the main Workspace
# Create ROS Package with <pkg_name> definition and dependences
cd ~/catkin_ws/src
catkin_create_pkg <pkg_name> std_msgs roscpp rospy
# Build again the Main Workspace
cd .. # pwd: ~/catkin_ws
catkin_make
Your code should be in this path → workspace/src/package/src/your_code
Publisher (Romeo)
#include <ros/ros.h>
#include <std_msgs/String.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "romeo_node");
printf("This is Romeo!\\n");
ros::NodeHandle nh;
ros::Publisher romeo_pub = nh.advertise<std_msgs::String>("romeo_topic", 2);
ros::Rate loop_rate(2);
while (ros::ok())
{
std_msgs::String msg;
msg.data = "Romeo is still alive!";
romeo_pub.publish(msg);
loop_rate.sleep();
}
return 0;
}
Subscriber (Godfather subscribe romeo_topic
)