A ROS workspace helps organize your robot code and files. Packages inside the workspace keep related code and resources together.
ROS workspace and package structure
workspace/
src/
package_name/
package.xml
CMakeLists.txt
src/
include/
launch/
msg/
srv/The workspace folder holds all your packages.
The src folder inside the workspace contains your packages.
my_robot_ws with a package navigation for navigation code.my_robot_ws/
src/
navigation/
package.xml
CMakeLists.txt
src/
launch/sensors package that defines custom messages and services.robot_ws/
src/
sensors/
package.xml
CMakeLists.txt
msg/
srv/This example shows how to create a ROS workspace named robot_ws and a package called my_package inside it. Then it builds the workspace and prepares the environment.
# Create a ROS workspace and package structure mkdir -p robot_ws/src cd robot_ws/src catkin_create_pkg my_package std_msgs rospy roscpp # The workspace now has: # robot_ws/ # src/ # my_package/ # package.xml # CMakeLists.txt # Build the workspace cd ../ catkin_make # Source the setup file source devel/setup.bash
Always run catkin_make or colcon build in the workspace root, not inside src.
Source the setup file after building to use your packages in the terminal.
Keep package names unique and descriptive to avoid confusion.
A ROS workspace organizes your robot code into packages.
Each package has its own folder with code, configuration, and metadata files.
Build the workspace and source the setup file to use your packages.
Practice
Solution
Step 1: Understand what a ROS workspace is
A ROS workspace is a directory where you keep your ROS packages organized and ready to build.Step 2: Identify the workspace role
The workspace allows you to build all packages together and manage dependencies easily.Final Answer:
To organize multiple ROS packages and build them together -> Option AQuick Check:
Workspace = Organize and build packages [OK]
- Confusing workspace with physical robot parts
- Thinking workspace runs nodes directly
- Assuming workspace replaces OS
Solution
Step 1: Identify metadata files in ROS packages
Every ROS package must have apackage.xmlfile that describes the package name, version, dependencies, and other metadata.Step 2: Differentiate from build files
CMakeLists.txtis for build instructions, not metadata.README.mdis documentation, andsetup.pyis for Python packages but not mandatory in ROS.Final Answer:
package.xml -> Option AQuick Check:
Metadata file = package.xml [OK]
- Confusing CMakeLists.txt with metadata
- Thinking README.md defines package info
- Assuming setup.py is mandatory for all packages
pkg1 and pkg2, what happens after running colcon build and then source install/setup.bash?Solution
Step 1: Understand
This command builds all packages in the workspace, compiling code and preparing install files.colcon buildroleStep 2: Understand
This command sets environment variables so ROS can find and use the newly built packages.source install/setup.bashroleFinal Answer:
The workspace is built and environment is set to use the packages -> Option CQuick Check:
Build + source = ready to use packages [OK]
- Thinking only one package builds
- Assuming packages get deleted after build
- Believing ROS master starts automatically
colcon build. What problem will you face?Solution
Step 1: Understand build necessity
ROS requires runningcolcon buildto compile and register new packages in the workspace environment.Step 2: Consequence of skipping build
If you skip building, ROS environment does not know about the new package, so it cannot find or use it.Final Answer:
ROS will not recognize the new package when you try to use it -> Option DQuick Check:
Build missing = package not recognized [OK]
- Assuming packages build automatically
- Thinking package deletion happens without build
- Believing package runs with errors without build
std_msgs. Which steps correctly update your workspace to include this dependency?Solution
Step 1: Add dependency in
You must declarepackage.xmlstd_msgsas a dependency inpackage.xmlso ROS knows your package needs it.Step 2: Update
ModifyCMakeLists.txtfor buildCMakeLists.txtto find and linkstd_msgsduring build.Step 3: Build workspace
Runcolcon buildto compile your package with the new dependency.Final Answer:
Add std_msgs to package.xml dependencies, update CMakeLists.txt, then run colcon build -> Option BQuick Check:
Declare dependency + update build + build workspace [OK]
- Only updating README.md without build changes
- Deleting package.xml unnecessarily
- Relying on rosdep without declaring dependencies
Ready to prove it?
Pass the test and this pattern moves unknown
