LearningROS 2 Fundamentals
ROS 2 CLI & Workspace | ROS 2 CLI & Workspace Setup
Pelajari command line tools dan setup workspace ROS 2 | Learn ROS 2 command line tools and workspace setup
Apa itu ROS 2?
0 dari 5 halaman selesai
In Progress
Scroll sampai 80% untuk menandai halaman selesai.
ROS 2 CLI & Workspace
๐ฏ Learning Objectives
Setelah materi ini: (1) Menguasai ROS 2 CLI commands, (2) Membuat dan build workspace, (3) Membuat package Python/C++.
๐ฅ๏ธ ROS 2 CLI Overview
ROS 2 CLI menggunakan pattern: ros2 <verb> <resource> [options]
# Common verbs
ros2 run # Run a node
ros2 launch # Launch multiple nodes
ros2 topic # Interact with topics
ros2 service # Interact with services
ros2 node # Interact with nodes
ros2 param # Manage parameters
ros2 bag # Record/playback data๐ Workspace Structure
ros2_ws/ # Workspace root
โโโ src/ # Source packages
โ โโโ my_package/
โ โโโ another_package/
โ โโโ ...
โโโ build/ # Build artifacts (auto-generated)
โโโ install/ # Installed packages (auto-generated)
โโโ log/ # Build logs (auto-generated)Creating a Workspace
# Create workspace directory
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
# Build (even if empty)
colcon build
# Source the workspace
source install/setup.bash๐ฆ Creating Packages
Python Package
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_python \
--node-name my_node \
my_python_pkg
# Structure:
# my_python_pkg/
# โโโ package.xml
# โโโ setup.py
# โโโ setup.cfg
# โโโ my_python_pkg/
# โ โโโ __init__.py
# โ โโโ my_node.py
# โโโ resource/C++ Package
ros2 pkg create --build-type ament_cmake \
--node-name my_node \
my_cpp_pkg๐จ Building Packages
cd ~/ros2_ws
# Build all packages
colcon build
# Build specific package
colcon build --packages-select my_package
# Build with symlinks (for Python - faster dev)
colcon build --symlink-install๐ก Pro Tip: Gunakan --symlink-install untuk Python packages agar tidak
perlu rebuild setelah edit code.
๐ Running Nodes
# Source workspace first!
source ~/ros2_ws/install/setup.bash
# Run a node
ros2 run my_package my_node
# Run with parameters
ros2 run my_package my_node --ros-args -p param_name:=value
# Run with remapping
ros2 run my_package my_node --ros-args -r old_topic:=new_topic๐ง Essential CLI Commands
Topic Commands
ros2 topic list # List all topics
ros2 topic echo /topic_name # Print topic data
ros2 topic hz /topic_name # Check publish rate
ros2 topic info /topic_name # Topic info
ros2 topic pub /topic msg_type "data" # Publish onceNode Commands
ros2 node list # List running nodes
ros2 node info /node_name # Node detailsService Commands
ros2 service list # List services
ros2 service call /srv srv_type "args" # Call serviceParameter Commands
ros2 param list # List all parameters
ros2 param get /node param_name # Get parameter
ros2 param set /node param_name val # Set parameter๐งช Quick Exercise
# Terminal 1: Run turtlesim
ros2 run turtlesim turtlesim_node
# Terminal 2: Explore!
ros2 node list
ros2 topic list
ros2 topic echo /turtle1/pose
ros2 service listโญ๏ธ Next Steps
Konsep Dasar ROS 2 | ROS 2 Core Concepts
Memahami Nodes, Topics, Services, dan Actions di ROS 2 | Understanding Nodes, Topics, Services, and Actions in ROS 2
Launch Files | Launch System
Automate starting multiple ROS 2 nodes dengan launch files | Automate starting multiple ROS 2 nodes with launch files