Skip to content

Commit 4ae9e06

Browse files
committed
docs: add code comment
1 parent 0eb869e commit 4ae9e06

File tree

4 files changed

+64
-33
lines changed

4 files changed

+64
-33
lines changed

docs/src/installation_and_configuration.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,34 @@ control_mode: inverse # inverse, act 行动模式
6565
- port:在安装lerobot后,处于lerobot环境下,将设备连接到电脑运行`lerobot-find-port`,之后会出现一堆设备号,根据指示,拔掉连接线后按回车,即可获得串口号,控制板上的环境已经安装完毕,端口号为固定的 '/dev/ttyACM0'
6666
- hardware_mode: 在PC上调试的时候选择normal模式,在控制板上运行的时候,为rk3588
6767

68+
## 首次运行
69+
70+
#### 机械臂初始设置
71+
72+
连接机械臂后首次运行代码,由于没有硬件配置文件,需要初始化机械臂
73+
74+
正常会看见
75+
```
76+
"Move robot to the middle of its range of motion and press ENTER...."
77+
```
78+
之后将所有电机置于中点位置,按回车,之后缓慢的转动所有电机,到每个电机的上下限位,之后按回车,即可完成配置文件的录入。
79+
80+
#### 项目再次启动
81+
82+
如果已经生成配置文件,打开项目能看到
83+
84+
```
85+
"Press ENTER to use provided calibration file associated with the id {self.id}, or type 'c' and press ENTER to run calibration: "
86+
```
87+
88+
之后可以按ENTER进入项目,或者等待3秒进入项目,或者输入c + ENTER重新初始化。
89+
90+
配置文件路径为
91+
92+
```
93+
~/.cache/huggingface/lerobot/calibration/robots/lekiwi/None.json
94+
```
95+
96+
删除它后进入项目自动进入初始化模式
97+
6898
## 硬件连接设置

src/main.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@
2020
logger = logging.getLogger(__name__)
2121
logging.basicConfig(level=getattr(logging, get_log_level()))
2222

23-
CATCH_ACTION = [("shoulder_pan", -11),
24-
("gripper", 50),
25-
("wrist_flex", 88),
26-
("move_to", (0.0750, 0.1211)),
27-
("move_to", (0.0750, -0.04)),
28-
("gap", 0),
29-
("gripper", -40),
30-
("shoulder_pan", 11),
31-
("move_to", (0.07, 0.24)),
32-
("wrist_flex", 8)
23+
# 夹球的动作序列
24+
CATCH_ACTION = [("shoulder_pan", -11), # 对应1号舵机
25+
("gripper", 50), # 夹爪打开
26+
("wrist_flex", 88), # 腕部舵机转动角度
27+
("move_to", (0.0750, 0.1211)), # 机械臂坐标移动指令,x移动到范围为 0.22 - -0.22
28+
("move_to", (0.0750, -0.04)), # 机械臂移动到球的位置, y移动范围为 0.22 - -0.15
29+
("gap", 0), # 停顿指令
30+
("gripper", -40), # 夹爪关闭
31+
("shoulder_pan", 11), # 1号舵机归位
32+
("move_to", (0.07, 0.24)), # 把球举起
33+
("wrist_flex", 8) # 腕部配合移动
3334
]
3435

3536

@@ -46,14 +47,14 @@ def main():
4647
for key, value in start_obs.items():
4748
if key.endswith('.pos'):
4849
motor_name = key.removesuffix('.pos')
49-
start_positions[motor_name] = int(value) # Don't apply calibration coefficients
50+
start_positions[motor_name] = int(value)
5051

5152
print("Initial joint angles:")
5253
for joint_name, position in start_positions.items():
5354
print(f" {joint_name}: {position}°")
5455

55-
return_to_start_position(robot, start_obs, get_target_positions(), 0.9, get_fps())
56-
x0, y0 = 0.0989, 0.125
56+
return_to_start_position(robot, start_obs, get_target_positions(), 0.9, get_fps()) # 机械臂回到预设位置
57+
x0, y0 = 0.0989, 0.125 # 当前位置的xy坐标
5758
current_x, current_y = x0, y0
5859
command_step = 0
5960
try:
@@ -63,11 +64,11 @@ def main():
6364
current_obs = robot.get_observation()
6465
frame = current_obs["front"]
6566
if get_robot_status() == RobotStatus.FIND_BUCKET:
66-
result = get_red_bucket_local(frame)
67+
result = get_red_bucket_local(frame) # 找桶的算法
6768
else:
68-
result = yolo_infer(frame)
69+
result = yolo_infer(frame) # 找球的算法
6970

70-
if get_hardware_mode() == 'normal':
71+
if get_hardware_mode() == 'normal': # 摄像头视角显示,
7172
for box in result:
7273
x, y, w, h = box.x, box.y, box.w, box.h
7374
center_x = x + w // 2

src/move_controller.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,31 @@ def move_controller(direction: DirectionControl, result: list[Box]) -> dict[str,
2828
center_x = x + w // 2
2929
position = max(w, h)
3030
_last_ball_center_x = center_x
31-
if center_x < left:
32-
if abs(TARGET_CX - center_x) < target_w * 1.5:
31+
if center_x < left: # 如果球位于目标框左侧
32+
if abs(TARGET_CX - center_x) < target_w * 1.5: # 球与目标框中点距离小于目标框的1.5倍,慢速前进
3333
action = direction.get_action("rotate_left", 0)
3434
else:
3535
action = direction.get_action("rotate_left")
3636
_cycle_time = 0
37-
elif center_x > right:
38-
if abs(TARGET_CX - center_x) < target_w * 1.5:
37+
elif center_x > right: # 如果球位于目标框右侧
38+
if abs(TARGET_CX - center_x) < target_w * 1.5: # 与目标框中点距离小于目标框的1.5倍,慢速前进
3939
action = direction.get_action("rotate_right", 0)
4040
else:
4141
action = direction.get_action("rotate_right")
4242
_cycle_time = 0
43-
elif position < (TARGET_POSITION - 8) * 2:
43+
elif position < (TARGET_POSITION - 8) * 2: # 如果球在摄像头中的直径小于,目标框-8的2倍 ,则前进(可调)
4444
if position * 2 > TARGET_POSITION:
4545
action = direction.get_action("forward", 0)
4646
else:
4747
action = direction.get_action("forward")
4848
_cycle_time = 0
49-
elif position > (TARGET_POSITION + 10) * 2:
49+
elif position > (TARGET_POSITION + 10) * 2: # 如果球在摄像头中的直径大于,目标框+10的2倍 ,则后退(可调)
5050
action = direction.get_action("backward", 0)
5151
_cycle_time = 0
5252
else:
5353
action = direction.get_action(None)
5454
_cycle_time += 1
55-
if _cycle_time > 10:
55+
if _cycle_time > 10: # 10帧稳定存在,则进入下一流程
5656
set_robot_status(RobotStatus.PICK)
5757
_cycle_time = 0
5858
else:
@@ -74,31 +74,31 @@ def move_controller_for_bucket(direction: DirectionControl, result: list[Box]) -
7474
center_x = x + w // 2
7575
position = min(w, h)
7676
_last_ball_center_x = center_x
77-
if center_x < left:
77+
if center_x < left: # 如果桶位于目标框左侧
7878
if abs(TARGET_CX - center_x) < target_w:
7979
action = direction.get_action("rotate_left", 0)
8080
else:
8181
action = direction.get_action("rotate_left")
8282
_cycle_time = 0
83-
elif center_x > right:
83+
elif center_x > right: # 如果桶位于目标框右侧
8484
if abs(TARGET_CX - center_x) < target_w:
8585
action = direction.get_action("rotate_right", 0)
8686
else:
8787
action = direction.get_action("rotate_right")
8888
_cycle_time = 0
89-
elif position < TARGET_POSITION * 2.6:
90-
if TARGET_POSITION - position < target_h:
89+
elif position < TARGET_POSITION * 2.6: # 如果桶在摄像头中的直径小于目标框的2.6倍,则前进
90+
if TARGET_POSITION - position < target_h: # 保证快速前进,if可以去掉
9191
action = direction.get_action("forward")
9292
else:
9393
action = direction.get_action("forward")
9494
_cycle_time = 0
95-
elif position > TARGET_POSITION * 3:
95+
elif position > TARGET_POSITION * 3: # 如果桶在摄像头中的直径大于目标框的3倍,则后退
9696
action = direction.get_action("backward", 0)
9797
_cycle_time = 0
9898
else:
9999
action = direction.get_action(None)
100100
_cycle_time += 1
101-
if _cycle_time > 10:
101+
if _cycle_time > 10: # 10帧稳定存在,则进入下一流程
102102
set_robot_status(RobotStatus.PUT_BALL)
103103
_cycle_time = 0
104104
else:

src/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
class RobotStatus(Enum):
7-
SEARCH = "search"
8-
PICK = "pick"
9-
FIND_BUCKET = "find_bucket"
10-
PUT_BALL = "put_ball"
7+
SEARCH = "search" # 找球模式
8+
PICK = "pick" # 捡球模式
9+
FIND_BUCKET = "find_bucket" # 找桶模式
10+
PUT_BALL = "put_ball" # 放球模式
1111

1212

1313
class RobotControlModel(Enum):

0 commit comments

Comments
 (0)