# 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: 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://docs.petoi.com/chinese/api/ros.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.
