Skip to content

Commit c291672

Browse files
committed
first commit
1 parent f4959c1 commit c291672

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4723
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.VSCodeCounter
2+
.vscode
3+
*.log
4+
__pycache__
5+
*.7z
6+
*.zip
7+
*.tar

DEVELOPMENT.MD

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# PIPER SDK 开发文档
2+
3+
本SDK用于接收can数据帧,然后处理为自定义数据类型
4+
5+
## 程序结构
6+
7+
```shell
8+
piper_sdk
9+
├── piper_msgs
10+
├── base
11+
├── config
12+
├── demo
13+
├── hardware_port
14+
├── __init__.py
15+
├── interface
16+
├── protocol
17+
└── README.MD
18+
```
19+
20+
底层交互:
21+
22+
```shell
23+
hardware_port
24+
├── can_encapsulation.py
25+
└── __init__.py
26+
```
27+
28+
机械臂数据变量:
29+
30+
预留v2版本,为日后修改数据格式留出余量
31+
32+
```shell
33+
piper_msgs
34+
├── msg_v1
35+
│ ├── arm_id_type_map.py
36+
│ ├── arm_messages.py
37+
│ ├── arm_msg_type.py
38+
│ ├── can_id.py
39+
│ ├── feedback
40+
│ │ ├── arm_crash_protection_rating_feedback.py
41+
│ │ ├── arm_end_pose.py
42+
│ │ ├── arm_feedback_current_end_vel_acc_param.py
43+
│ │ ├── arm_feedback_current_motor_angle_limit_max_spd.py
44+
│ │ ├── arm_feedback_current_motor_max_acc_limit.py
45+
│ │ ├── arm_feedback_joint_vel_acc.py
46+
│ │ ├── arm_high_spd_feedback.py
47+
│ │ ├── arm_joint_feedback.py
48+
│ │ ├── arm_low_spd_feedback.py
49+
│ │ ├── arm_status.py
50+
│ │ └── gripper_feedback.py
51+
│ ├── __init__.py
52+
│ └── transmit
53+
│ ├── arm_circular_pattern.py
54+
│ ├── arm_crash_protection_rating_config.py
55+
│ ├── arm_end_vel_acc_param_config.py
56+
│ ├── arm_gripper_ctrl.py
57+
│ ├── arm_joint_config.py
58+
│ ├── arm_joint_ctrl.py
59+
│ ├── arm_light_ctrl.py
60+
│ ├── arm_master_slave_config.py
61+
│ ├── arm_motion_ctrl_1.py
62+
│ ├── arm_motion_ctrl_2.py
63+
│ ├── arm_motion_ctrl_cartesian.py
64+
│ ├── arm_motor_angle_limit_max_spd_config.py
65+
│ ├── arm_motor_enable_disable.py
66+
│ ├── arm_param_enquiry_and_config.py
67+
│ ├── arm_search_motor_max_angle_spd_acc_limit.py
68+
│ └── arm_set_instruction_response.py
69+
└── msg_v2
70+
```
71+
72+
机械臂协议解析:
73+
74+
暂为v1版本,为日后修改协议留出余量
75+
76+
```shell
77+
protocol
78+
├── piper_protocol_base.py
79+
└── protocol_v1
80+
├── piper_protocol_v1.py
81+
└── __init__.py
82+
```
83+
84+
机械臂实际接口:
85+
86+
具体使用部分接口,抽象为具体功能函数,部分功能可能需要二次封装
87+
88+
```shell
89+
interface
90+
└── piper_interface.py
91+
```

README.MD

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Piper 机械臂 SDK使用说明
2+
3+
## 安装方法
4+
5+
### 安装依赖
6+
7+
```shell
8+
pip3 install python-can
9+
```
10+
11+
## 快速使用
12+
13+
### 使能can模块
14+
15+
**can模块设定脚本`can_config.sh`**
16+
17+
首先需要设置好shell脚本参数
18+
19+
#### 单条机械臂
20+
21+
`can_config.sh`中,`EXPECTED_CAN_COUNT`参数设置为`1`,因为一条机械臂使用一个can模块
22+
23+
##### pc只插入一个usb转can模块
24+
25+
直接执行
26+
27+
```bash
28+
bash can_config.sh can0 1000000
29+
```
30+
31+
##### pc插入多个usb转can模块
32+
33+
拔掉所有can模块
34+
35+
只将连接到机械臂的can模块插入PC,执行`sudo ethtool -i can0 | grep bus`,并记录下`bus-info`的数值例如`1-2:1.0`
36+
37+
ps:**一般第一个插入的can模块会默认是can0,如果没有查询到can可以使用`ip link show`来显示所有can,然后先后插入查看can编号**
38+
39+
假设上面的操作记录的`bus-info`数值为`1-2:1.0`
40+
41+
然后执行,查看can设备是否激活成功
42+
43+
```bash
44+
bash can_config.sh can_piper 1000000 "1-2:1.0"
45+
```
46+
47+
ps:**此处的意思是,1-2:1.0硬件编码的usb端口插入的can设备,名字被重命名为can_piper,波特率为1000000,并激活**
48+
49+
然后执行`ifconfig`查看是否有`can_piper`,如果有则can模块设置成功
50+
51+
#### 两对机械臂(四条)
52+
53+
如果是四条机械臂,也就是两对主从机械臂
54+
55+
`can_config.sh`中,`EXPECTED_CAN_COUNT`参数一般设置为`2`,因为四条机械臂使用两个can模块
56+
57+
然后将两个can模块中的其中一个(一般第一个插入左臂所在的模块)单独插入PC,执行`sudo ethtool -i can0 | grep bus`,并记录下`bus-info`的数值例如`1-2:1.0`
58+
59+
接着插入下一个can模块,注意不可以与上次can模块插入的usb口相同,然后执行`sudo ethtool -i can1 | grep bus`
60+
61+
ps:**一般第一个插入的can模块会默认是can0,第二个为can1,如果没有查询到can可以使用`ip link show`来显示所有can,然后先后插入查看can编号**
62+
63+
假设上面的操作记录的`bus-info`数值分别为`1-2:1.0``1-4:1.0`
64+
65+
则将下面的`USB_PORTS["1-9:1.0"]="can_left:1000000"`中的中括号内部的双引号内部的参数换为`1-2:1.0`,另一个同理
66+
`USB_PORTS["1-5:1.0"]="can_right:1000000"` -> `USB_PORTS["1-4:1.0"]="can_right:1000000"`
67+
68+
ps:**此处的意思是,1-2:1.0硬件编码的usb端口插入的can设备,名字被重命名为can_left,波特率为1000000,并激活**
69+
70+
然后执行`bash can_config.sh`,查看两个can设备是不是激活成功
71+
72+
然后执行`ifconfig`查看是不是有`can_left``can_right`,如果有则can模块设置成功
73+
74+
## 注意事项
75+
76+
- 需要先激活can设备,并且设置正确的波特率,才可以读取机械臂消息或者控制机械臂

__init__.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
from .piper_msgs.msg_v1 import *
3+
from .protocol.protocol_v1 import *
4+
from .hardware_port.can_encapsulation import C_STD_CAN
5+
from .base.piper_base import C_PiperBase
6+
from .interface.piper_interface import C_PiperInterface
7+
8+
__all__ = [
9+
'C_PiperParserBase',
10+
'C_PiperParserV1',
11+
'ArmMsgEndPoseFeedBack',
12+
'PiperMessage',
13+
'CanIDPiper',
14+
'ArmMsgJointFeedBack',
15+
'ArmMsgType',
16+
'ArmMsgStatus',
17+
'ArmMsgGripperFeedBack',
18+
'C_STD_CAN',
19+
'C_PiperBase',
20+
'C_PiperInterface'
21+
]
22+

base/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
from .piper_base import C_PiperBase
3+
4+
__all__ = [
5+
'C_PiperBase'
6+
]
7+

base/piper_base.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
# -*-coding:utf8-*-
3+
4+
#机械臂控制base
5+
6+
import can
7+
from can.message import Message
8+
from typing import (
9+
Optional,
10+
)
11+
from typing import Type
12+
13+
from ..interface.piper_interface import C_PiperInterface
14+
from ..hardware_port.can_encapsulation import C_STD_CAN
15+
16+
class C_PiperBase(C_PiperInterface):
17+
def __init__(self, can_name: str = "can0") -> None:
18+
super().__init__(can_name)
19+
20+
def Connect(self, can_name:str):
21+
return self.ConnectPort(can_name)

0 commit comments

Comments
 (0)