-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47c67c6
commit 761ff4d
Showing
5 changed files
with
326 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# OpenBot 控制器 | ||
|
||
<p align="center"> | ||
<a href="README.md">English</a> | | ||
<span>简体中文</span> | | ||
<a href="README.de-DE.md">Deutsch</a> | ||
</p> | ||
|
||
有几种方法可以控制 OpenBot 机器人。 | ||
|
||
## 蓝牙控制器 | ||
|
||
控制机器人最简单的方法是通过蓝牙连接游戏控制器。大多数蓝牙游戏控制器都应该可以使用。我们已经测试了[PS4 控制器](https://www.amazon.de/-/en/Sony-Dualshock-Gamepad-Playstation-Black/dp/B01LYWPQUN)、[XBox 控制器](https://www.amazon.de/-/en/QAT-00002/dp/B07SDFLVKD)和一些第三方控制器,例如[X3](https://www.amazon.com/Controller-Wireless-Joystick-Bluetooth-Android/dp/B08H5MM64P)。 | ||
|
||
## [Node.js 控制器](node-js) | ||
|
||
此控制器要求您的手机和计算机(例如笔记本电脑、树莓派)连接到同一个 WiFi 网络。成功连接后,您将获得实时低延迟视频流,并可以使用键盘从浏览器控制机器人。 | ||
|
||
特别感谢 Ivo Zivkov [[email protected]](mailto:[email protected]) 的开发。 | ||
|
||
## [Python 控制器](python) | ||
|
||
此控制器要求您的手机和计算机(例如笔记本电脑、树莓派)连接到同一个 WiFi 网络。成功连接后,您将获得实时 RTSP 视频流,并可以使用键盘从终端控制机器人。您可以使用 Python 脚本作为模板来开发自己的控制器。 | ||
|
||
特别感谢 Ivo Zivkov [[email protected]](mailto:[email protected]) 的开发。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Flutter 控制器应用 | ||
|
||
<p align="center"> | ||
<a href="README.md">English</a> | | ||
<span>简体中文</span> | | ||
<a href="README.de-DE.md">Deutsch</a> | ||
</p> | ||
|
||
这个控制器应用程序作为 [OpenBot](https://www.openbot.org) 车辆的 `远程控制器`,类似于 BT 控制器(例如 PS3/4 或 Xbox)。它运行在另一台 Android/iOS 设备上,除了控制功能外,还支持实时视频/音频流。 | ||
|
||
## 入门指南 | ||
首先在你的系统上安装 [Flutter](https://flutter.dev/)。选择适合你操作系统的下载选项,包括 Windows、macOS、Linux 和 ChromeOS。请按照官方 Flutter 安装指南进行详细安装:[Flutter 安装指南](https://docs.flutter.dev/get-started/install) | ||
|
||
### 使用终端 | ||
- 成功安装 Flutter 后,打开你的 **终端** 或 **命令提示符**。 | ||
- 将当前目录更改为存储 OpenBot 项目的位置,然后导航到 `OpenBot/controller/flutter`。 | ||
- 使用以下命令从终端运行 Flutter 应用程序。 | ||
|
||
#### 安装依赖项: | ||
```bash | ||
flutter pub get | ||
``` | ||
运行项目: | ||
```bash | ||
flutter run | ||
``` | ||
如果遇到任何问题,请运行以下命令: | ||
```bash | ||
flutter doctor | ||
``` | ||
### 使用编辑器 | ||
- 按照官方 Flutter 指南设置编辑器:[设置编辑器](https://docs.flutter.dev/tools/android-studio) | ||
- 确保你的编辑器已配置为 Flutter 开发。安装任何所需的插件或扩展,按照 Flutter 文档中的编辑器特定说明进行设置,以获得最佳开发体验。 | ||
|
||
- 设置完成后,在编辑器中打开项目,它将显示如下图所示。 | ||
|
||
<p float="left"> | ||
<img src="../../docs/images/android_editor.jpg" width="50%" /> | ||
</p> | ||
|
||
- 请按照上述类似的指示运行 Flutter 在终端中的命令,并直接使用 ``run`` 按钮进行后续运行。 | ||
|
||
<p float="left"> | ||
<img src="../../docs/images/run_editor.jpg" width="50%" /> | ||
</p> | ||
|
||
## 连接 | ||
|
||
启动控制器应用程序时,它会立即尝试连接到机器人并显示以下屏幕: | ||
|
||
<p float="left"> | ||
<img src="../../docs/images/flutter_controller_home.jpg" width="50%" /> | ||
</p> | ||
|
||
要将控制器连接到机器人,请将机器人的控制模式设置为 **Phone**。 | ||
例如,在 `FreeRoamFragment` 中,手机模式如下激活: | ||
|
||
<p float="left"> | ||
<img src="../../docs/images/phone_selection.gif" width="50%" /> | ||
</p> | ||
|
||
连接后,控制器应用程序将如下所示: | ||
|
||
<p float="left"> | ||
<img src="../../docs/images/flutter_controller_connected.jpg" width="50%" /> | ||
</p> | ||
|
||
在这里,你可以选择通过倾斜手机或使用屏幕上的控件来驾驶机器人。 | ||
|
||
***注意:*** 这应该足以连接,但如果在 30 秒后仍无法建立连接,请将机器人应用程序中的 `Control` 设置切换到 `Gamepad`,然后再切换回 `Phone` 以重新启动连接。如果仍然失败,请退出控制器应用程序并重新启动。再次在机器人应用程序中切换控制模式。 | ||
|
||
## 操作 | ||
|
||
### 屏幕控件 | ||
|
||
此模式允许用户通过 `双驱动` 模式中的两个滑块控制机器人车。你可以通过在每侧上下移动滑块拇指来左转/右转。当拇指移动到滑块中心以上/以下时,每侧的轮子将向前/向后转动。 | ||
|
||
<p float="left"> | ||
<img src="../../docs/images/flutter_controller_dual_drive_mode.jpg" width="50%" /> | ||
</p> | ||
|
||
- ``指示灯``:你还可以通过点击屏幕左上角的箭头来设置左/右转向指示灯 <img src="../../docs/images/keyboard_arrow_left-24px.svg" height="24"/> <img src="../../docs/images/keyboard_arrow_right-24px.svg" height="24"/>。 | ||
|
||
- ``切换摄像头``:在前置和后置摄像头模式之间切换。 | ||
- ``静音``:启用/禁用音频传输。 | ||
- ``镜像视图``:镜像视频流。 | ||
|
||
### 倾斜驾驶 | ||
|
||
控制器还可以使用其加速度计运动传感器来驾驶机器人。如果选择此选项,控制器将进入全屏(Zen)模式,仅显示视频和 `刹车` 和 `加速` 踏板。要退出此模式,请双击屏幕。 | ||
|
||
以下是 `倾斜模式` 屏幕的图片: | ||
|
||
<p float="left"> | ||
<img src="../../docs/images/flutter_controller_tilt_mode.jpg" width="50%" /> | ||
</p> | ||
|
||
使用 `加速` 和 `刹车` 按钮前进/后退。 | ||
|
||
- 按下 `加速` 按钮,机器人将在 2 秒内加速到全速。当你松开按钮时,机器人将减速至停止(停止速度设置为最大速度的 0%,可以调整)。 | ||
- 按下 `刹车` 按钮,机器人将立即停止。如果我们再按住刹车一秒钟,机器人将开始倒退,直到在一秒钟内达到最大倒车速度。当我们松开刹车时,机器人将停止。 | ||
- 通过左右倾斜控制器手机来转向机器人。 | ||
|
||
这里有一个控制器应用程序的 [技术概述](../../docs/technical/OpenBotController.pdf)。 |
11 changes: 11 additions & 0 deletions
11
controller/flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.zh-CN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<p align="center"> | ||
<a href="README.md">English</a> | | ||
<span>简体中文</span> | | ||
<a href="README.de-DE.md">Deutsch</a> | ||
</p> | ||
|
||
# 启动屏幕资源 | ||
|
||
您可以通过替换此目录中的图像文件来自定义启动屏幕。 | ||
|
||
您也可以通过打开 Flutter 项目的 Xcode 项目来完成此操作,方法是使用 `open ios/Runner.xcworkspace` 命令,选择项目导航器中的 `Runner/Assets.xcassets`,然后拖入所需的图像。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# OpenBot Nodejs 控制器 | ||
|
||
<p align="center"> | ||
<a href="README.md">English</a> | | ||
<span>简体中文</span> | | ||
<a href="README.de-DE.md">Deutsch</a> | ||
</p> | ||
|
||
## 术语 | ||
|
||
以下是本文档中将使用的一些术语: | ||
|
||
* ```机器人, bot``` - 这是运行在 [OpenBot](https://www.openbot.org/) 车辆上的手机上的 Android 软件。 | ||
* ```服务器``` - Node 服务器,本项目的服务器部分 | ||
* ```客户端, UI``` - 这是本项目的客户端部分。它在浏览器中运行。 | ||
|
||
## 简介 | ||
|
||
这是一个基于 [Node.js](https://nodejs.org/) 的项目,用于控制 [OpenBot](https://www.openbot.org/) 车辆。该软件由两部分组成——服务器和客户端。服务器是一个运行在与机器人同一网络中的计算机上的 Node.js 应用程序。客户端部分在浏览器中运行。 | ||
|
||
以下是浏览器的截图: | ||
|
||
 | ||
|
||
## 入门指南 | ||
|
||
您可以在 PC、RaspberryPi 类型设备甚至支持 ```Node.js``` 环境的 [Pi Zero](https://www.raspberrypi.com/products/raspberry-pi-zero/) 设备上运行此软件。首先确保您已安装 [Node.js](https://nodejs.org/),版本为 10 或更新版本。检查版本: | ||
|
||
node --version | ||
|
||
该软件位于 OpenBot 项目的 ```/controller/node-js``` 目录中。从 [github](https://github.com/isl-org/OpenBot) 检出代码后,进入此目录并运行以下命令: | ||
|
||
npm install | ||
npm start | ||
|
||
最后一个命令将启动服务器。如果您希望在后台无终端运行服务器,在 ```Linux/MacOS``` 上可以运行: | ||
|
||
npm run start-nohup | ||
|
||
或者直接运行: | ||
|
||
nohup npm start | ||
|
||
将浏览器指向服务器的 IP 地址和端口 8081,例如 [http://localhost:8081](http://localhost:8081),或 [http://192.168.1.100:8081](http://192.168.1.100:8081)。请注意,您可以从不同的计算机访问服务器,但机器人、服务器和浏览器 PC 需要在同一网络中。未来我们可以添加远程访问服务器的功能。 | ||
|
||
确保您的机器人连接在同一网络上。在机器人 Android 应用中,进入 ```General``` 面板并选择 ```Phone``` 作为控制器。这将把 Android 应用连接到 Node 服务器,并在 UI 上显示视频。 | ||
|
||
## 工作原理 | ||
|
||
1. Node 服务器创建并发布类型为 ```openbot.tcp``` 和名称为 ```OPEN_BOT_CONTROLLER``` 的 DNS 服务,端口为 19400。这使得机器人可以在不知道其 IP 地址的情况下自动找到服务器。机器人正在寻找此服务,并将在进入 ```Phone``` 控制器模式时建立 Socket 连接。 | ||
|
||
2. Node 服务器在端口 8081 创建一个 HTTP 服务器,并开始处理来自浏览器的请求。 | ||
|
||
3. 此外,Node 服务器在端口 7071 创建一个 WebSocket 服务器。这将用于直接与浏览器通信。因此,总结到目前为止,服务器已创建了两个 Socket 连接,一个到机器人,一个到浏览器。 | ||
|
||
4. 用户从浏览器输入键盘命令。这些按键通过 WebSocket 发送到服务器。服务器将这些命令转换为机器人可以理解的命令,如 ```{driveCmd: {r:0.4, l:0.34}}```(所有命令的列表可以在 Android 控制器的文档中找到 [这里](https://github.com/isl-org/OpenBot/blob/master/docs/technical/OpenBotController.pdf))。这些命令通过 Socket 连接发送到机器人。 | ||
|
||
5. 机器人通过 Socket 连接将状态信息发送回服务器,服务器将其转发到 UI。UI 可以使用此信息来增强其外观,如显示闪烁的指示灯等,但目前此状态被忽略。 | ||
|
||
6. Node 服务器还充当 WebRTC 信令代理。它在机器人和浏览器之间转发 WebRTC 协商命令。它重用开放的 Socket 连接,因此不需要额外的连接或配置。 | ||
|
||
 | ||
|
||
## 开发 | ||
|
||
此代码使用 [snowpack](https://www.snowpack.dev/) 作为快速、轻量级的构建工具。 | ||
|
||
我们使用 [eslint](https://eslint.org/) 进行代码检查和自动格式化。建议在提交新代码之前运行 lint 并修复任何错误。如果您使用 Visual Code,可以在 [这里](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) 获取插件。运行 linter 如下: | ||
|
||
npm run lint | ||
|
||
## 生产 | ||
|
||
要构建 ```client``` 的生产版本,请运行: | ||
|
||
npm run build | ||
|
||
这将优化客户端代码到 ```build``` 目录中,可以部署在服务器上。此外,我们需要设置一个进程管理器来重启服务器,可能还需要一个反向代理如 [nginx](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/),这尚未完成。 | ||
|
||
## 故障排除 | ||
|
||
* 有时浏览器不会显示命令菜单,只显示标题。这意味着 WebSocket 连接无法建立。这通常发生在刚启动服务器之后。如果检查浏览器控制台,可以找到无法连接的消息,如 ```WebSocket connection to 'ws://localhost:7071/ws' failed```,杀死所有 node 进程(pkill -9 node)并重新启动。重新加载页面,连接应能建立。 | ||
* 如果无法将手机连接到应用程序,请确保此应用程序的另一个实例未在此机器或同一网络中的另一台机器上运行。 | ||
|
||
## 已知错误 | ||
|
||
无。 | ||
|
||
## 待办事项/尝试 | ||
|
||
* 我们需要调查是否可以远程连接到服务器,以及 WebRTC 是否仍然有效。我们应该记录防火墙配置以使其成为可能。 | ||
* 我们需要创建一个 ```production``` 配置,可能使用 [pm2 进程管理器](https://www.npmjs.com/package/pm2) 和 [nginx](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/)。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Python 控制器 | ||
|
||
<p align="center"> | ||
<a href="README.md">English</a> | | ||
<span>简体中文</span> | | ||
<a href="README.de-DE.md">Deutsch</a> | ||
</p> | ||
|
||
这个 Python 程序允许你通过(无线)键盘控制机器人,并从摄像头接收视频流。该程序可以在任何连接到与机器人手机相同网络的计算机上运行。它在 Raspberry Pi 3 和 MacBook 上开发和测试。在按照以下步骤操作之前,请确保你已经获取了[源代码](https://github.com/isl-org/OpenBot#get-the-source-code)并导航到 `controller` 文件夹。 | ||
|
||
## 依赖项 | ||
|
||
我们建议为 OpenBot 创建一个 conda 环境(如果尚未创建)。有关安装 conda 的说明可以在[这里](https://docs.conda.io/projects/conda/en/latest/user-guide/install/)找到。你可以使用以下命令创建一个新环境: | ||
|
||
```bash | ||
conda create -n openbot python=3.7 | ||
``` | ||
|
||
如果你不想全局安装依赖项,请先激活你的 conda 环境: | ||
|
||
```bash | ||
conda activate openbot | ||
``` | ||
|
||
确保你在本地 OpenBot 仓库中的 `controller` 文件夹内。现在,你可以使用以下命令安装所有依赖项: | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## 控制机器人 | ||
|
||
注意:成功连接后,除非重新启动机器人应用,否则可能无法再次连接。 | ||
|
||
Python 脚本将等待传入连接。在安装了机器人应用的手机上,进入 FreeRoam 碎片并将控制模式切换到手机图标。机器人现在将尝试连接到 Python 脚本(与连接控制器应用的方式相同)。或者,你也可以使用 DefaultActivity 并选择 `Phone` 作为控制器。 | ||
|
||
### 使用 Pygame | ||
|
||
这些脚本允许你像玩赛车游戏一样使用键盘驾驶机器人。 | ||
|
||
运行不带视频的控制器: | ||
|
||
`python keyboard-pygame.py` | ||
|
||
运行带视频的控制器: | ||
|
||
`python keyboard-pygame.py --video` | ||
|
||
以下是使用方法: | ||
|
||
``` | ||
W: 前进 | ||
S: 后退 | ||
A: 向左转(驾驶时) | ||
D: 向右转(驾驶时) | ||
Q: 左旋转 | ||
E: 右旋转 | ||
M: 驾驶模式 | ||
N: 切换噪声 | ||
Left: 左转向灯 | ||
Right: 右转向灯 | ||
Up: 取消转向灯 | ||
Down: 网络模式 | ||
SPACE: 切换日志记录 | ||
ESC: 退出 | ||
``` | ||
|
||
### 使用 Click | ||
|
||
还有一个用于原型设计的脚本,允许以增量设置机器人控制,而不是动态控制。此脚本使用 click 库,需要终端保持焦点。 | ||
|
||
运行控制器: | ||
|
||
`python keyboard-click.py` | ||
|
||
以下是使用方法: | ||
|
||
```bash | ||
W: 增加速度 | ||
S: 减少速度 | ||
A: 向左转更多 | ||
D: 向右转更多 | ||
R: 重置控制 | ||
|
||
M: 驾驶模式 | ||
N: 切换噪声 | ||
Left: 左转向灯 | ||
Right: 右转向灯 | ||
Up: 取消转向灯 | ||
Down: 网络模式 | ||
SPACE: 切换日志记录 | ||
ESC: 退出 | ||
``` |