add 机器狗开发相关基础配置
This commit is contained in:
parent
32fae04b46
commit
46003424a3
173
README.md
173
README.md
|
@ -1,3 +1,176 @@
|
|||
# zkdog
|
||||
|
||||
这里是基于宇树科技机器狗go1二次开发相关配置经验,以及一些问题的解决方案,包括python版本的机器狗的控制api的二次封装,方便大家快速开发。
|
||||
|
||||
|
||||
# Go1系统架构图(二开)
|
||||
|
||||

|
||||
|
||||
[Go1系统架构图 (yuque.com)](https://www.yuque.com/ironfatty/nly1un/fscioc)
|
||||
|
||||
主控板:MCU(192.168.123.10)
|
||||
|
||||
运动控制主板:RasPi 4B(192.168.123.161)
|
||||
|
||||
感知主板:Nano(头部、192.168.123.13)、Nano(机身、192.168.123.14)、Nano或NX(机身、192.168.123.15)
|
||||
|
||||
# 一、基础环境配置
|
||||
|
||||
如何进入各个板子?
|
||||
|
||||
```bash
|
||||
# 首先连接机器狗的wifi 密码 00000000
|
||||
# 进入运动控制主板
|
||||
ssh pi@192.168.12.1 # 密码 123
|
||||
|
||||
# 进入主控板之后,可以进入其他板子
|
||||
ssh unitree@192.168.123.XX # 密码 123
|
||||
|
||||
```
|
||||
|
||||
## 1.网络环境配置
|
||||
|
||||
网络环境配置有两种解决办法,一种是采用官方给出的方案,采用内置无线网卡实现运动控制主板上网(弊端:其他板子无法上网)另一种则是采用有线上网的方式;这里推荐采用配置http代理的方式实现无侵入式实现所有板子上网的问题。[网络配置详情](docs/网络环境配置.md)。
|
||||
|
||||
## 2.开发环境配置
|
||||
|
||||
### 2.1 code-server配置
|
||||
|
||||
树莓派/nx 板子 arm64机器 版本不需要太高即可
|
||||
|
||||
code-server-3.9.3-linux-arm64.tar.gz
|
||||
|
||||
[https://github.com/coder/code-server/releases?page=4](https://github.com/coder/code-server/releases?page=4)
|
||||
|
||||
```bash
|
||||
# 安装
|
||||
tar -zxvf code-server-3.9.3-linux-arm64.tar.gz
|
||||
mv code-server-3.9.3-linux-arm64 code-server
|
||||
|
||||
# 第一次运行生成配置
|
||||
cd code-server/bin
|
||||
./code-server
|
||||
# 编辑配置文件
|
||||
vim ~/.config/code-server/config.yaml
|
||||
|
||||
#bind-addr: 0.0.0.0:8888
|
||||
#auth: password
|
||||
#password: 123456
|
||||
#cert: false
|
||||
|
||||
# 软链接
|
||||
sudo ln -s /home/unitree/alg/code-server/bin/code-server /usr/bin/code-server
|
||||
|
||||
# 配置启动文件
|
||||
vim code-start.sh
|
||||
|
||||
nohup code-server > /home/unitree/alg/code-server.log 2>&1 &
|
||||
|
||||
# 修改权限code-start.sh
|
||||
sudo chmod +x code-start.sh
|
||||
```
|
||||
|
||||
配置code-srever开机自启
|
||||
|
||||
rc.local脚本是一个ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令。该脚本位于/etc/路径下,需要root权限才能修改。
|
||||
|
||||
该脚本具体格式如下:
|
||||
|
||||
```bash
|
||||
sudo vim /etc/rc.local
|
||||
#!/bin/sh -e
|
||||
#
|
||||
# rc.local
|
||||
#
|
||||
# This script is executed at the end of each multiuser runlevel.
|
||||
# Make sure that the script will "exit 0" on success or any other
|
||||
# value on error.
|
||||
#
|
||||
# In order to enable or disable this script just change the execution
|
||||
# bits.
|
||||
#
|
||||
# By default this script does nothing.
|
||||
|
||||
sh /home/unitree/alg/code-start.sh
|
||||
|
||||
exit 0
|
||||
```
|
||||
|
||||
注意: 一定要将命令添加在 exit 0之前
|
||||
|
||||
### 2.2 主控板nginx 新增配置(切记不要修改内部配置)
|
||||
|
||||
```bash
|
||||
sudo vim /etc/nginx/sites-available/default
|
||||
|
||||
location /codeServer {
|
||||
proxy_pass ~~http://127.0.0.1:8080/~~ 修改为配置的 code-server 地址;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection upgrade;
|
||||
proxy_set_header Accept-Encoding gzip;
|
||||
}
|
||||
|
||||
# 重启nginx服务,
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
|
||||
# 启动之后,我们看一下 Nginx 是否处于运行状态。
|
||||
sudo service nginx status
|
||||
```
|
||||
|
||||
配置完成后可通过192.168.12.1/codeServer访问code-server 服务, 如果配置不生效,请检测http代理是否规避掉 需要nginx代理的ip
|
||||
|
||||
### 2.3 python 环境配置 (建议不要直接在内部python环境安装第三方包,防止冲突)
|
||||
|
||||
```bash
|
||||
# 安装python3.6
|
||||
# 下载python3.6.4
|
||||
|
||||
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
|
||||
|
||||
# 解压
|
||||
tar -zxvf Python-3.6.4.tgz
|
||||
|
||||
# 创建目录
|
||||
sudo mkdir /home/unitree/python3.6
|
||||
|
||||
#编译安装(在解压出来的目录下执行)
|
||||
#建议make和make install 分两步
|
||||
|
||||
sudo ./configure --prefix=/home/unitree/python3.6
|
||||
|
||||
sudo make
|
||||
sudo make install
|
||||
|
||||
#添加软链接
|
||||
sudo ln -s /home/unitree/python3.6/bin/python3.6 /usr/bin/python36
|
||||
|
||||
ls -al # 查看软链接
|
||||
|
||||
# 如果新装的python中含有pip 同上可添加软链接的形式, 否则后期pip使用可以按如下方式
|
||||
# python36 -m pip list
|
||||
python36 -m pip install XXX
|
||||
```
|
||||
|
||||
# 二、ZKMetaApi 使用
|
||||
|
||||
[树莓派](https://www.notion.so/9c8d11399244490c9b2dff68d7615425?pvs=21)
|
||||
|
||||
[网络环境配置](https://www.notion.so/53feab27fa484d3eaa811142fe9a2583?pvs=21)
|
||||
|
||||
[**在 Ubuntu 22.04 | 20.04 | 安装和配置 Squid 代理服务器**](https://www.notion.so/Ubuntu-22-04-20-04-Squid-8da9c72d7e0d4d05bc2fdc10f42c45c7?pvs=21)
|
||||
|
||||
[python 安装](https://www.notion.so/python-6c49013286f04cb2a1dc9d7a55a6e3a8?pvs=21)
|
||||
|
||||
setproxy
|
||||
|
||||
unsetproxy
|
||||
|
||||
sudo systemctl start squid
|
||||
sudo systemctl enable squid
|
||||
sudo systemctl status squid
|
||||
|
||||
[code-server部署](https://www.notion.so/code-server-83d083651b8f45f5bb02f60e321c0353?pvs=21)
|
||||
|
||||
[clash 代理配置](https://www.notion.so/clash-591f407ca8b44899ba07c0f98b78178b?pvs=21)
|
|
@ -0,0 +1,263 @@
|
|||
# 在 Ubuntu 22.04 | 20.04 | 安装和配置 Squid 代理服务器
|
||||
|
||||
Squid 是一个代理和缓存服务器。它充当代理,将请求转发到所需的目的地,但也保存请求的内容。如果另一台服务器在鱿鱼服务器中尚未过期之前请求相同的信息,它将向请求者提供相同的内容,从而提高下载速度并节省带宽。
|
||||
|
||||
---
|
||||
|
||||
Squid 代理服务器支持缓存通过不同协议请求的内容,例如http、SSL 请求、DNS 查找和FTP。本指南介绍如何在 Ubuntu 22.04|20.04 上安装和配置 Squid 代理
|
||||
|
||||
## **在 Ubuntu 22.04|20.04 上安装 Squid 代理服务器**
|
||||
|
||||
首先,更新您的系统软件包。请注意,对于所有命令,我将以 root 用户身份运行它们
|
||||
|
||||
```sql
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
```
|
||||
|
||||
检查升级成功后是否需要重启系统。
|
||||
|
||||
```
|
||||
[ -e /var/run/reboot-required ] && sudo reboot
|
||||
```
|
||||
|
||||
接下来,在 Ubuntu 上安装鱿鱼代理。在 Ubuntu 中安装 Squid 代理很容易,因为它已经在 Ubuntu 20 存储库中可用。使用以下命令确认这一点。
|
||||
|
||||
```
|
||||
sudo apt-cache policy squid
|
||||
```
|
||||
|
||||
输出
|
||||
|
||||

|
||||
|
||||
要安装 Squid 代理,请运行以下命令。还可以在系统启动时启动然后检查状态
|
||||
|
||||
```
|
||||
sudo apt install -y squid
|
||||
sudo systemctl start squid
|
||||
sudo systemctl enable squid
|
||||
sudo systemctl status squid
|
||||
```
|
||||
|
||||
如果鱿鱼正确安装并运行,您应该输出如下所示:
|
||||
|
||||

|
||||
|
||||
## **在 Ubuntu 22.04|20.04 上配置 Squid 代理服务器**
|
||||
|
||||
默认的 Squid 代理配置文件位于 */etc/squid/squid.conf 中。* 该文件已经有许多至少可以工作的设置,但我们可以修改以适应我们的偏好。首先,创建原始文件的备份。
|
||||
|
||||
```powershell
|
||||
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.orig
|
||||
```
|
||||
|
||||
现在,在*/etc/squid/squid.conf*中进行自定义设置。使用您喜欢的文件编辑器打开文件
|
||||
|
||||
```
|
||||
sudo vim /etc/squid/squid.conf
|
||||
```
|
||||
|
||||
### **1.更改squid默认端口**
|
||||
|
||||
默认的 Squid tcp 端口是 3128。要更改此端口,请打开 squid.conf 文件并查找 *http_port* 行。更改为您所需的端口号并保存文件。
|
||||
|
||||
```powershell
|
||||
#http_port 3128
|
||||
http_port 8080
|
||||
```
|
||||
|
||||
确保允许该端口通过防火墙
|
||||
|
||||
```
|
||||
sudo ufw allow 8080/tcp
|
||||
sudo ufw enable
|
||||
```
|
||||
|
||||
### **2.设置Squid缓存大小**
|
||||
|
||||
要设置所需的高速缓存,请使用以下设置。对于我的情况,我使用 *256* MB
|
||||
|
||||
```
|
||||
cache_mem 256 MB
|
||||
```
|
||||
|
||||
### **3. 指定要使用的 DNS 名称服务器**
|
||||
|
||||
要定义您自己的 DNS 服务器,请使用如下所示的命令
|
||||
|
||||
```
|
||||
dns_nameservers 8.8.8.8 8.8.4.4
|
||||
```
|
||||
|
||||
### **4.Squid ACL和http_access**
|
||||
|
||||
现在,编辑squid.conf 添加您选择的规则。代理服务器会选择性地选择通过它的内容。我们可以允许来自特定网络/IP 地址的访问并拒绝其他网络/IP 地址。它还可用于通过限制对某些网站的访问或基于某些关键字阻止内容来过滤流量。这是通过使用 ACL(访问控制列表)来实现的,ACL 定义允许什么和拒绝什么。 Http_access 根据 ACL 定义允许或拒绝。
|
||||
|
||||
## **如何为 Squid 代理服务器定义 ACL**
|
||||
|
||||
ACL(访问控制列表)是定义允许哪些内容通过代理服务器以及拒绝哪些内容的语句。每个语句必须以 **acl** 开头,后跟规则名称。名称后面是**acltype**,最后是**参数**或**文件。** 在使用文件的情况下,文件中的每一行必须仅包含一项。
|
||||
|
||||
```
|
||||
acl aclname acltype argument..
|
||||
acl aclname acltpe “file”…
|
||||
```
|
||||
|
||||
默认定义的ACL规则如图所示。您可以通过在每行开头添加 # 来选择禁用。要创建新规则,请按照以下示例操作:
|
||||
|
||||
示例1:允许局域网网络通过Squid代理服务器
|
||||
|
||||
创建acl规则
|
||||
|
||||
```
|
||||
acl my_lan src 192.168.100.0/24
|
||||
```
|
||||
|
||||
现在,使用 **http_access** 指令根据定义的规则允许或拒绝。在我们的例子中,我们需要允许
|
||||
|
||||
```
|
||||
http_access allow my_lan
|
||||
```
|
||||
|
||||
请注意,每次创建 ACL 访问规则时的最后一条规则应该是**拒绝全部**。当您允许所有必需的站点时应执行此操作,否则您可能会阻止自己访问某些所需的站点。
|
||||
|
||||
```sql
|
||||
http_access deny all
|
||||
```
|
||||
|
||||
## **拒绝访问 Squid 代理服务器中的特定网站**
|
||||
|
||||
当处理多个网站时,将所有网站放在一个文件中然后调用它会更容易且更有组织性,否则您将在 acl 规则中列出引用。在我们的示例中,我将在squid 目录中创建一个名为deniedsites.squid 的文件。
|
||||
|
||||
```
|
||||
sudo vim /etc/squid/deniedsites.squid
|
||||
```
|
||||
|
||||
添加您希望拒绝访问的站点。就我而言,我使用的是 facebook 和 youtube。之后保存文件。
|
||||
|
||||
```
|
||||
.facebook.com
|
||||
.youtube.com
|
||||
```
|
||||
|
||||
现在打开squid.conf并为被拒绝的站点创建acl规则并添加拒绝规则然后保存文件。
|
||||
|
||||
```
|
||||
acl deniedsites dstdomain “/etc/squid/deniedsites.squid”
|
||||
http_access deny deniedsites
|
||||
```
|
||||
|
||||
如果您要在 acl 规则中列出站点:
|
||||
|
||||
```
|
||||
acl deniedsites dstdomain facebook.com youtube.com
|
||||
http_access deny deniedsites
|
||||
```
|
||||
|
||||
注意每次修改后都必须重启squid服务器
|
||||
|
||||
```
|
||||
sudo systemctl restart squid
|
||||
```
|
||||
|
||||
## **如何在Squid代理服务器中根据某些关键字来阻止流量**
|
||||
|
||||
创建一个包含关键字的文件。使用文件名创建拒绝流量的 ACL 规则。
|
||||
|
||||
```
|
||||
sudo vim /etc/squid/keywords.squid.
|
||||
```
|
||||
|
||||
添加您的关键字并保存。
|
||||
|
||||
```
|
||||
gamble
|
||||
nudes
|
||||
xxx
|
||||
```
|
||||
|
||||
编辑squid.conf以创建acl和拒绝规则保存并记住**重新启动squid。**
|
||||
|
||||
```powershell
|
||||
acl keywords url_regex -i "/etc/squid/keywords.squid"
|
||||
http_access deny keywords
|
||||
```
|
||||
|
||||
您的文件最终出现并添加了如下内容。
|
||||
|
||||
对于 ACL
|
||||
|
||||

|
||||
|
||||
对于http_访问
|
||||
|
||||

|
||||
|
||||
要在 Squid 代理服务器中打开端口,请使用如下所示的命令语法
|
||||
|
||||
```xml
|
||||
acl Safe_ports port <port-number>
|
||||
```
|
||||
|
||||
## **如何屏蔽 Squid 代理服务器上的传出流量**
|
||||
|
||||
代理服务器应该通过暴露代理 IP 地址而不是我们自己的 IP 地址来隐藏我们的身份。但是,代理可以通过 http 传出流量让我们的 IP 获知。要禁用此功能,请编辑 **squid.conf** 文件并通过标头禁用。 为此,请检查带有 **#via on** 的行。取消注释并从***开启***更改为***关闭。***
|
||||
|
||||
```powershell
|
||||
# via on
|
||||
via off
|
||||
```
|
||||
|
||||
此外,代理服务器不应在其转发的 http 请求中附加客户端 IP 地址。通过修改 **squid.conf** 文件中的以下行来禁用此功能。
|
||||
|
||||
为了避免泄露您的 Squid 代理服务器,您可以删除 Squid 代理标头。在TAG中添加以下行;请求头访问。
|
||||
|
||||
```sql
|
||||
request_header_access From deny all
|
||||
request_header_access Server deny all
|
||||
request_header_access WWW-Authenticate deny all
|
||||
request_header_access Link deny all
|
||||
request_header_access Cache-Control deny all
|
||||
request_header_access Proxy-Connection deny all
|
||||
request_header_access X-Cache deny all
|
||||
request_header_access X-Cache-Lookup deny all
|
||||
request_header_access X-Forwarded-For deny all
|
||||
request_header_access Pragma deny all
|
||||
request_header_access Keep-Alive deny all
|
||||
```
|
||||
|
||||
保存squid.conf文件并记得重新启动squid
|
||||
|
||||
```
|
||||
systemctl restart squid
|
||||
```
|
||||
|
||||
## **如何检查Squid配置错误**
|
||||
|
||||
下面的命令将指出您的配置文件中可能存在错误的地方
|
||||
|
||||
```
|
||||
sudo squid -k parse
|
||||
```
|
||||
|
||||
## **连接代理服务器**
|
||||
|
||||
```bash
|
||||
sudo nano /etc/environment
|
||||
|
||||
export http_proxy="http://username:password@proxyipaddress:proxyport"
|
||||
export https_proxy="http://username:password@proxyipaddress:proxyport"
|
||||
export no_proxy="localhost, 127.0.0.1"
|
||||
# 用代理的IP地址和端口替换proxyipaddress和proxyport。
|
||||
|
||||
export http_proxy="http://192.168.12.246:3128"
|
||||
export https_proxy="http://192.168.12.246:3128"
|
||||
export no_proxy="localhost, 127.0.0.1"
|
||||
# 接下来
|
||||
|
||||
sudo visudo
|
||||
# 将下面的行添加到文件中,这样sudo将使用您刚刚创建的环境变量:
|
||||
|
||||
Defaults env_keep+="http_proxy https_proxy no_proxy"
|
||||
|
||||
# 重启
|
||||
```
|
Binary file not shown.
After Width: | Height: | Size: 389 KiB |
|
@ -0,0 +1,87 @@
|
|||
# 网络环境配置
|
||||
|
||||
# 一、官方提供的网络配置方式
|
||||
|
||||
[宇树机器狗连接网络的相关说明 (yuque.com)](https://www.yuque.com/ironfatty/nly1un/ft1yvm)
|
||||
|
||||
## 1.Go1-Edu树莓派内置无线网卡设置
|
||||
|
||||
Go1-Edu运动控制主机树莓派上内置了一个可以用来连接WiFi的无线网卡wlan0(wlan1用来发射热点),有些时候,可以临时用来连接网络(但是更建议使用外置的无线或者有线的网卡)。
|
||||
|
||||
### 1.1连接WiFi
|
||||
|
||||
打开机器狗背部的盖子,将HDMI显示器和鼠标键盘插在靠近网口的接口上。
|
||||
|
||||

|
||||
|
||||
在树莓派的桌面右上角,点击网络图标连接网络。
|
||||
|
||||
### 1.2设置路由表
|
||||
|
||||
如果连接上WiFi,但是无法上外网,可以尝试如下步骤:
|
||||
|
||||
打开终端:
|
||||
|
||||
```bash
|
||||
ifconfig
|
||||
#查看wlan0的网络信息,查看网关地址
|
||||
ping 192.168.xxx.1
|
||||
#xxx为上一步查看到的wlan0的地址,ping一下通不通,正常应该是通的
|
||||
ping baidu.com
|
||||
#ping一下百度,正常可以解析出IP,但是网络不可达,如果是这种情况,则执行下一步
|
||||
sudo route add default gw 192.168.xxx.1
|
||||
#添加无线网络的网关地址到路由表
|
||||
ping baidu.com
|
||||
#再次ping百度,可以ping通,正常已经可以上网
|
||||
```
|
||||
|
||||
重启后,该设置会恢复,需要再次添加网关到路由表。
|
||||
|
||||
## 2.故障排除
|
||||
|
||||
### 2.1没有无线信号
|
||||
|
||||
如果在树莓派的桌面上无法连接WiFi,可以尝试如下步骤:
|
||||
|
||||
打开终端:
|
||||
|
||||
```bash
|
||||
sudo ifconfig wlan0 down
|
||||
sudo ifconfig wlan0 up
|
||||
```
|
||||
|
||||
此时应该就可以通过桌面连接网络了。
|
||||
|
||||
# 二、搭建http代理服务器
|
||||
|
||||
机器狗内部程序依赖出厂环境,避免对机器狗内部环境及网络造成影响,采用此方式进行上网。
|
||||
|
||||
## 1.搭建代理服务器
|
||||
|
||||
[在 Ubuntu 22.04 | 20.04 | 安装和配置 Squid 代理服务器](Squid代理服务器.md)
|
||||
|
||||
## 2.**连接代理服务器**
|
||||
|
||||
```bash
|
||||
sudo vim /etc/environment
|
||||
|
||||
export http_proxy="http://username:password@proxyipaddress:proxyport"
|
||||
export https_proxy="http://username:password@proxyipaddress:proxyport"
|
||||
export no_proxy="localhost, 127.0.0.1"
|
||||
# 用代理的IP地址和端口替换proxyipaddress和proxyport。
|
||||
|
||||
export http_proxy="http://192.168.12.246:3128"
|
||||
export https_proxy="http://192.168.12.246:3128"
|
||||
export no_proxy="localhost, 127.0.0.1, 192.168.123.15, 192.168.123.14, 192.168.123.13, 192.168.123.161"
|
||||
# 建议增加 192.168.123.*
|
||||
# 接下来
|
||||
|
||||
sudo visudo
|
||||
# 将下面的行添加到文件中,这样sudo将使用您刚刚创建的环境变量:
|
||||
|
||||
Defaults env_keep+="http_proxy https_proxy no_proxy"
|
||||
|
||||
# 重启
|
||||
```
|
||||
|
||||
注:代理服务器需要连接机器狗的wifi,然后在需要网络的板子上进行上述配置之后,重启即可上网。
|
Loading…
Reference in New Issue