> For the complete documentation index, see [llms.txt](https://www.learnros2.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.learnros2.com/ros/cookbook/useful-commands.md).

# Useful Commands

## Create Workspace

A ROS2 project workspace has a standard structure. First, we create the root directory of the workspace&#x20;

```
mkdir MyRosWorkspace
```

Then, we go to the workspace directory and create a build directory

```
cd MyRosWorkspace
mkdir build
```

## Create C++ Package

Go to the workspace root directory and use the `pkg create` command. For instance

```
cd MyRosWorkspace
ros2 pkg create MyFirstProject --build-type ament_cmake
```

## Create Python Package

Go to the workspace root directory and use the `pkg create` command. For instance

```
cd MyRosWorkspace
ros2 pkg create MyPythonProject --build-type ament_python
```

## Build  Workspace

To build the workspace, we use the following command:

```
rosdep install -i --from-path src --rosdistro humble -y
colcon build --symlink-install
```

The first command checks missing dependencies and the second command build the whole workspace. To build a specific package, use the following command:

```
colcon build --packages-select <package name>
```

## How to specify the namespace and node name in the command line?

In ROS2, the namespace and node name can be specified in the command line through the remap. For more information, please refer to the design doc [Remapping Names](https://design.ros2.org/articles/static_remapping.html). The command below shows the syntax:

```
ros2 run <package> <executable> --ros-arg -r __ns:=/MyNamespace -r __name:=MyNodeName
```

## How to check URDF file

To validate a URDF, you can use the following command:

```
check_urdf <urdf-file-path>
```

## How to turn on the debug info when launch the stack?

Use the `-d` option. For example:

```
ros2 launch -d <package> <launch-filename>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.learnros2.com/ros/cookbook/useful-commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
