Skip to content

Commit bd524fb

Browse files
committed
增加海量文档
1 parent c291672 commit bd524fb

16 files changed

+680
-51
lines changed

README.MD

+134-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Piper 机械臂 SDK使用说明
22

3+
![ubuntu](https://img.shields.io/badge/Ubuntu-20.04-orange.svg)
4+
5+
Test:
6+
7+
|PYTHON |STATE|
8+
|---|---|
9+
|![python3.8](https://img.shields.io/badge/Python-3.8-blue.svg)|![Pass](https://img.shields.io/badge/Pass-blue.svg)|
10+
11+
本SDK用于接收can数据帧,然后处理为自定义数据类型,没有包括数据偏移帧
12+
13+
具体的接口函数的详细说明请看[Interface README](./asserts/INTERFACE.MD)
14+
15+
协议解析部分说明[Protocol README](./asserts/PROTOCOL_V1.MD)
16+
17+
消息部分说明[Msgs README](./asserts/MSGS.MD)
18+
319
## 安装方法
420

521
### 安装依赖
@@ -8,40 +24,58 @@
824
pip3 install python-can
925
```
1026

27+
```shell
28+
pip3 install piper_sdk
29+
```
30+
31+
### 安装can工具
32+
33+
```shell
34+
sudo apt update && sudo apt install can-utils ethtool
35+
```
36+
37+
这两个工具用来配置can模块
38+
1139
## 快速使用
1240

1341
### 使能can模块
1442

15-
**can模块设定脚本`can_config.sh`**
16-
1743
首先需要设置好shell脚本参数
1844

1945
#### 单条机械臂
2046

21-
`can_config.sh`中,`EXPECTED_CAN_COUNT`参数设置为`1`,因为一条机械臂使用一个can模块
22-
2347
##### pc只插入一个usb转can模块
2448

49+
- **此处使用`can_activate.sh`脚本**
50+
2551
直接执行
2652

2753
```bash
28-
bash can_config.sh can0 1000000
54+
bash can_activate.sh can0 1000000
2955
```
3056

3157
##### pc插入多个usb转can模块
3258

59+
- **此处使用`can_activate.sh`脚本**
60+
3361
拔掉所有can模块
3462

35-
只将连接到机械臂的can模块插入PC,执行`sudo ethtool -i can0 | grep bus`,并记录下`bus-info`的数值例如`1-2:1.0`
63+
只将连接到机械臂的can模块插入PC,执行
3664

37-
ps:**一般第一个插入的can模块会默认是can0,如果没有查询到can可以使用`ip link show`来显示所有can,然后先后插入查看can编号**
65+
```shell
66+
sudo ethtool -i can0 | grep bus
67+
```
68+
69+
并记录下`bus-info`的数值例如`1-2:1.0`
70+
71+
ps:**一般第一个插入的can模块会默认是can0,如果没有查询到can可以使用`bash find_all_can_port.sh`来查看刚才usb地址对应的can名称**
3872

3973
假设上面的操作记录的`bus-info`数值为`1-2:1.0`
4074

4175
然后执行,查看can设备是否激活成功
4276

4377
```bash
44-
bash can_config.sh can_piper 1000000 "1-2:1.0"
78+
bash can_activate.sh can_piper 1000000 "1-2:1.0"
4579
```
4680

4781
ps:**此处的意思是,1-2:1.0硬件编码的usb端口插入的can设备,名字被重命名为can_piper,波特率为1000000,并激活**
@@ -52,25 +86,112 @@ ps:**此处的意思是,1-2:1.0硬件编码的usb端口插入的can设备,
5286

5387
如果是四条机械臂,也就是两对主从机械臂
5488

89+
- **此处使用`can_config.sh`脚本**
90+
5591
`can_config.sh`中,`EXPECTED_CAN_COUNT`参数一般设置为`2`,因为四条机械臂使用两个can模块
5692

57-
然后将两个can模块中的其中一个(一般第一个插入左臂所在的模块)单独插入PC,执行`sudo ethtool -i can0 | grep bus`,并记录下`bus-info`的数值例如`1-2:1.0`
93+
然后将两个can模块中的其中一个(一般第一个插入左臂所在的模块)单独插入PC,执行
94+
95+
```shell
96+
sudo ethtool -i can0 | grep bus
97+
```
98+
99+
并记录下`bus-info`的数值例如`1-2:1.0`
58100

59-
接着插入下一个can模块,注意不可以与上次can模块插入的usb口相同,然后执行`sudo ethtool -i can1 | grep bus`
101+
接着插入下一个can模块,注意不可以与上次can模块插入的usb口相同,然后执行
60102

61-
ps:**一般第一个插入的can模块会默认是can0,第二个为can1,如果没有查询到can可以使用`ip link show`来显示所有can,然后先后插入查看can编号**
103+
```shell
104+
sudo ethtool -i can1 | grep bus
105+
```
106+
107+
ps:**一般第一个插入的can模块会默认是can0,第二个为can1,如果没有查询到can可以使用`bash find_all_can_port.sh`来查看刚才usb地址对应的can名称**
62108

63109
假设上面的操作记录的`bus-info`数值分别为`1-2:1.0``1-4:1.0`
64110

65-
则将下面的`USB_PORTS["1-9:1.0"]="can_left:1000000"`中的中括号内部的双引号内部的参数换为`1-2:1.0`,另一个同理
111+
则将下面的`USB_PORTS["1-9:1.0"]="can_left:1000000"`的中括号内部的双引号内部的参数换为`1-2:1.0`
112+
113+
另一个同理
114+
66115
`USB_PORTS["1-5:1.0"]="can_right:1000000"` -> `USB_PORTS["1-4:1.0"]="can_right:1000000"`
67116

68117
ps:**此处的意思是,1-2:1.0硬件编码的usb端口插入的can设备,名字被重命名为can_left,波特率为1000000,并激活**
69118

70-
然后执行`bash can_config.sh`,查看两个can设备是不是激活成功
119+
然后执行`bash can_config.sh`,查看终端输出是否激活成功
71120

72121
然后执行`ifconfig`查看是不是有`can_left``can_right`,如果有则can模块设置成功
73122

123+
## 读取机械臂消息
124+
125+
```python
126+
#!/usr/bin/env python3
127+
# -*-coding:utf8-*-
128+
# 读取机械臂消息并打印,需要先安装piper_sdk
129+
from typing import (
130+
Optional,
131+
)
132+
from piper_sdk import *
133+
134+
if __name__ == "__main__":
135+
# 实例化piper接口类
136+
piper = C_PiperInterface("can0")
137+
# 开启can设备连接
138+
piper.ConnectPort()
139+
while True:
140+
import time
141+
# 打印机械臂关节角度和夹爪消息
142+
print(piper.GetArmJointGripperMsgs())
143+
time.sleep(0.005)
144+
pass
145+
```
146+
147+
## 控制机械臂运动
148+
149+
```python
150+
#!/usr/bin/env python3
151+
# -*-coding:utf8-*-
152+
from typing import (
153+
Optional,
154+
)
155+
from piper_sdk import *
156+
157+
if __name__ == "__main__":
158+
# 实例化piper接口类
159+
piper = C_PiperInterface("can0")
160+
# 开启can设备连接
161+
piper.ConnectPort()
162+
# 使能机械臂所有电机
163+
piper.EnableArm(7)
164+
# 夹爪控制,发送位置0,扭矩1N,控制码为0x01,不设置当前为零点
165+
piper.GripperCtrl(0,1000,0x01, 0)
166+
factor = 57324.840764 #1000*180/3.14
167+
position = [0,0,0,0,0,0,0]
168+
count = 0
169+
while True:
170+
import time
171+
count = count + 1
172+
if(count == 0):
173+
position = [0,0,0,0,0,0,0]
174+
elif(count == 500):
175+
position = [0,0,0,0,0,0,0.005]
176+
elif(count == 1000):
177+
count = 0
178+
joint_0 = round(position[0]*factor)
179+
joint_1 = round(position[1]*factor)
180+
joint_2 = round(position[2]*factor)
181+
joint_3 = round(position[3]*factor)
182+
joint_4 = round(position[4]*factor)
183+
joint_5 = round(position[5]*factor)
184+
joint_6 = round(position[6]*1000*1000)
185+
piper.MotionCtrl_2(0x01, 0x01, 50)
186+
piper.JointCtrl(joint_0, joint_1, joint_2, joint_3, joint_4, joint_5)
187+
piper.GripperCtrl(abs(joint_6), 1000, 0x01, 0)
188+
piper.MotionCtrl_2(0x01, 0x01, 50)
189+
time.sleep(0.005)
190+
pass
191+
```
192+
74193
## 注意事项
75194

76195
- 需要先激活can设备,并且设置正确的波特率,才可以读取机械臂消息或者控制机械臂
196+
- C_PiperInterface 接口类在实例化时可传入激活的can路由名称,这个名称可以通过`ifconfig`得到
197+
- 有时执行can发送,终端反馈`Message NOT sent`,是can模块没有成功连接设备,先检查模块与机械臂的连接状态,然后将机械臂断电后上电,再尝试发送

DEVELOPMENT.MD asserts/DEVELOPMENT.MD

+18-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
本SDK用于接收can数据帧,然后处理为自定义数据类型
44

5-
## 程序结构
5+
ps:有些地方略写,代码中有详细的中文注释,本文这里只是理清结构
6+
7+
## 文件结构
68

79
```shell
810
piper_sdk
911
├── piper_msgs
1012
├── base
11-
├── config
1213
├── demo
1314
├── hardware_port
1415
├── __init__.py
@@ -19,6 +20,8 @@ piper_sdk
1920

2021
底层交互:
2122

23+
与can路由进行数据交互
24+
2225
```shell
2326
hardware_port
2427
├── can_encapsulation.py
@@ -31,6 +34,7 @@ hardware_port
3134

3235
```shell
3336
piper_msgs
37+
├── __init__.py
3438
├── msg_v1
3539
│ ├── arm_id_type_map.py
3640
│ ├── arm_messages.py
@@ -47,7 +51,8 @@ piper_msgs
4751
│ │ ├── arm_joint_feedback.py
4852
│ │ ├── arm_low_spd_feedback.py
4953
│ │ ├── arm_status.py
50-
│ │ └── gripper_feedback.py
54+
│ │ ├── gripper_feedback.py
55+
│ │ └── __init__.py
5156
│ ├── __init__.py
5257
│ └── transmit
5358
│ ├── arm_circular_pattern.py
@@ -65,7 +70,8 @@ piper_msgs
6570
│ ├── arm_motor_enable_disable.py
6671
│ ├── arm_param_enquiry_and_config.py
6772
│ ├── arm_search_motor_max_angle_spd_acc_limit.py
68-
│ └── arm_set_instruction_response.py
73+
│ ├── arm_set_instruction_response.py
74+
│ └── __init__.py
6975
└── msg_v2
7076
```
7177

@@ -89,3 +95,11 @@ protocol
8995
interface
9096
└── piper_interface.py
9197
```
98+
99+
## interface解析
100+
101+
具体的接口函数的详细说明请看[Interface README](./INTERFACE.MD)
102+
103+
## protocol解析
104+
105+
具体的数据解析协议函数的详细说明请看[Protocol README](./PROTOCOL_V1.MD)

0 commit comments

Comments
 (0)