> For the complete documentation index, see [llms.txt](https://docs.petoi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.petoi.com/chinese/api/ros.md).

# ROS

ROS 接口

&#x20;ROS 安装包可以供开发人员轻松连接到 ROS 环境。 建议将 ROS 与 Raspberry Pi 一起使用。

### 在树莓派上使用ROS

目前建议使用docker安装ROS

* 在树莓派上安装 docker (详情参考[文档](https://phoenixnap.com/kb/docker-on-raspberry-pi))

```bash
sudo apt-get update && sudo apt-get upgrade
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker pi
# test installation
docker run hello-world
```

* 准备工作环境

```bash
mkdir -p workspace/src
cd workspace/src
git clone https://github.com/PetoiCamp/ros_opencat
cd ros_opencat
git submodule init && git submodule update
cd ../../..
```

* 运行容器

```bash
docker run -v path/to/workspace:/workspace \
-it --rm --privileged --network host --name ros ros:noetic-robot
```

* 源文件和并在容器内构建

```bash
cd /workspace
source /opt/ros/noetic/setup.bash
catkin_makbase
source devel/setup.bash
```

* 运行例程 (更多参考示例)

```bash
rosrun opencat_examples opencat_examples_serial
```

### 使用ROS实现远程控制

Ros 在设计时考虑了分布式计算。 这是一个关于如何在不同机器上运行节点的简单示例。

* 在主机上（通常比 Raspberry Pi 更强大）

```bash
# launch server
roscore
```

* 在树莓派上运行服务节点

```bash
export ROS_MASTER_URI=http://<Host_IP>:11311/
rosrun opencat_server opencat_service_node
```

* 从主机发送指令

```basic
rosrun opencat_examples opencat_examples_client_cpp
```

### 例程

* 使用 serial 库

```batch
rosrun opencat_examples opencat_examples_serial
```

* 使用 ROS 服务

```bash
# start core
roscore
# start service server
rosrun opencat_server opencat_service_node
# examples using oppencat ros service in C++
rosrun opencat_examples opencat_examples_client_cpp
# examples using opencat ros service in python
rosrun opencat_examples opencat_examples_client_py
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.petoi.com/chinese/api/ros.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
