ezgo 0.0.16__py3-none-any.whl → 0.0.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ezgo/go2.py +64 -10
- {ezgo-0.0.16.dist-info → ezgo-0.0.18.dist-info}/METADATA +61 -15
- {ezgo-0.0.16.dist-info → ezgo-0.0.18.dist-info}/RECORD +6 -6
- {ezgo-0.0.16.dist-info → ezgo-0.0.18.dist-info}/LICENSE +0 -0
- {ezgo-0.0.16.dist-info → ezgo-0.0.18.dist-info}/WHEEL +0 -0
- {ezgo-0.0.16.dist-info → ezgo-0.0.18.dist-info}/top_level.txt +0 -0
ezgo/go2.py
CHANGED
|
@@ -63,10 +63,14 @@ class Go2:
|
|
|
63
63
|
self._moving = False
|
|
64
64
|
self._move_params = (0, 0, 0)
|
|
65
65
|
self._move_thread = None
|
|
66
|
-
|
|
66
|
+
|
|
67
|
+
# 步态模式保持 - 用于持续保持常规运动模式
|
|
68
|
+
self._gait_mode = None # 当前保持的步态模式: 'trot', 'static', 'economic' 或 None
|
|
69
|
+
self._gait_mode_lock = threading.Lock() # 步态模式锁
|
|
70
|
+
|
|
67
71
|
# 摄像头对象
|
|
68
72
|
self.camera = None
|
|
69
|
-
|
|
73
|
+
|
|
70
74
|
# 声光控制对象
|
|
71
75
|
self._vui = None
|
|
72
76
|
|
|
@@ -283,18 +287,18 @@ class Go2:
|
|
|
283
287
|
if self.error_code in forbidden_move_states:
|
|
284
288
|
print(f"当前状态不允许移动: {self.error_code} - {error_code.get(self.error_code, '未知状态')}")
|
|
285
289
|
return False
|
|
286
|
-
|
|
290
|
+
|
|
287
291
|
# 限制速度范围
|
|
288
292
|
vx = max(-1.0, min(1.0, vx)) # 前后速度限制在-1到1之间
|
|
289
293
|
vy = max(-1.0, min(1.0, vy)) # 左右速度限制在-1到1之间
|
|
290
294
|
vyaw = max(-2.0, min(2.0, vyaw)) # 转动速度限制在-2到2之间
|
|
291
|
-
|
|
295
|
+
|
|
292
296
|
def move_thread():
|
|
293
297
|
ret = self.sport_client.Move(vx, vy, vyaw)
|
|
294
298
|
success = ret == 0
|
|
295
299
|
# print(f"Move 执行结果: {ret}, 成功: {success}")
|
|
296
300
|
return success
|
|
297
|
-
|
|
301
|
+
|
|
298
302
|
t = threading.Thread(target=move_thread)
|
|
299
303
|
t.start()
|
|
300
304
|
t.join()
|
|
@@ -318,6 +322,14 @@ class Go2:
|
|
|
318
322
|
|
|
319
323
|
try:
|
|
320
324
|
while time.time() - start_time < duration:
|
|
325
|
+
# 如果设置了步态模式,先保持该模式
|
|
326
|
+
with self._gait_mode_lock:
|
|
327
|
+
if self._gait_mode is not None:
|
|
328
|
+
self._maintain_gait_mode()
|
|
329
|
+
|
|
330
|
+
# 短暂延迟,让步态模式生效
|
|
331
|
+
time.sleep(0.02)
|
|
332
|
+
|
|
321
333
|
if not self.Move(vx, vy, vyaw):
|
|
322
334
|
return False
|
|
323
335
|
time.sleep(0.1) # 每100ms调用一次
|
|
@@ -382,6 +394,14 @@ class Go2:
|
|
|
382
394
|
def continuous_move():
|
|
383
395
|
while self._moving:
|
|
384
396
|
# 持续移动不需要每次都检查状态,因为已经在开始时检查过
|
|
397
|
+
# 但需要保持步态模式
|
|
398
|
+
with self._gait_mode_lock:
|
|
399
|
+
if self._gait_mode is not None:
|
|
400
|
+
self._maintain_gait_mode()
|
|
401
|
+
|
|
402
|
+
# 短暂延迟,让步态模式生效
|
|
403
|
+
time.sleep(0.02)
|
|
404
|
+
|
|
385
405
|
try:
|
|
386
406
|
ret = self.sport_client.Move(vx, vy, vyaw)
|
|
387
407
|
success = ret == 0
|
|
@@ -637,7 +657,7 @@ class Go2:
|
|
|
637
657
|
return result == 0 if result is not None else False
|
|
638
658
|
|
|
639
659
|
def FreeWalk(self, flag: int = None):
|
|
640
|
-
"""
|
|
660
|
+
""" 灵动模式(默认步态)。开启后会清除常规运动模式的保持。"""
|
|
641
661
|
# 执行指令
|
|
642
662
|
if flag is None:
|
|
643
663
|
# 切换模式
|
|
@@ -645,8 +665,11 @@ class Go2:
|
|
|
645
665
|
else:
|
|
646
666
|
# 根据flag值执行相应操作
|
|
647
667
|
if flag:
|
|
648
|
-
# 开启灵动模式
|
|
668
|
+
# 开启灵动模式 - 清除步态模式保持
|
|
649
669
|
result = self._call(lambda: self.sport_client.FreeWalk())
|
|
670
|
+
if result == 0:
|
|
671
|
+
with self._gait_mode_lock:
|
|
672
|
+
self._gait_mode = None
|
|
650
673
|
else:
|
|
651
674
|
# 关闭灵动模式 - 切换到其他模式
|
|
652
675
|
result = self._call(lambda: self.sport_client.StandUp())
|
|
@@ -717,31 +740,62 @@ class Go2:
|
|
|
717
740
|
print("警告: ClassicWalk 方法在当前SDK版本中不可用")
|
|
718
741
|
return False
|
|
719
742
|
|
|
743
|
+
def _maintain_gait_mode(self):
|
|
744
|
+
"""保持当前的步态模式(内部函数)"""
|
|
745
|
+
if self._gait_mode == 'trot':
|
|
746
|
+
try:
|
|
747
|
+
# 使用_call确保同步执行
|
|
748
|
+
self.sport_client.TrotRun()
|
|
749
|
+
except:
|
|
750
|
+
pass
|
|
751
|
+
elif self._gait_mode == 'static':
|
|
752
|
+
try:
|
|
753
|
+
self.sport_client.StaticWalk()
|
|
754
|
+
except:
|
|
755
|
+
pass
|
|
756
|
+
elif self._gait_mode == 'economic':
|
|
757
|
+
try:
|
|
758
|
+
self.sport_client.EconomicGait()
|
|
759
|
+
except:
|
|
760
|
+
pass
|
|
761
|
+
|
|
720
762
|
def TrotRun(self):
|
|
721
|
-
"""
|
|
763
|
+
""" 进入常规跑步模式(保持模式,直到切换到其他模式或调用FreeWalk) """
|
|
722
764
|
try:
|
|
723
765
|
# 执行指令
|
|
724
766
|
result = self._call(self.sport_client.TrotRun)
|
|
767
|
+
if result == 0:
|
|
768
|
+
with self._gait_mode_lock:
|
|
769
|
+
self._gait_mode = 'trot'
|
|
770
|
+
print("已进入常规跑步模式(持续保持)")
|
|
725
771
|
return result == 0 if result is not None else False
|
|
726
772
|
except AttributeError:
|
|
727
773
|
print("警告: TrotRun 方法在当前SDK版本中不可用")
|
|
728
774
|
return False
|
|
729
775
|
|
|
730
776
|
def StaticWalk(self):
|
|
731
|
-
"""
|
|
777
|
+
""" 进入常规行走模式(保持模式,直到切换到其他模式或调用FreeWalk)"""
|
|
732
778
|
try:
|
|
733
779
|
# 执行指令
|
|
734
780
|
result = self._call(self.sport_client.StaticWalk)
|
|
781
|
+
if result == 0:
|
|
782
|
+
with self._gait_mode_lock:
|
|
783
|
+
self._gait_mode = 'static'
|
|
784
|
+
print("已进入常规行走模式(持续保持)")
|
|
735
785
|
return result == 0 if result is not None else False
|
|
736
786
|
except AttributeError:
|
|
737
787
|
print("警告: StaticWalk 方法在当前SDK版本中不可用")
|
|
738
788
|
return False
|
|
739
789
|
|
|
740
790
|
def EconomicGait(self):
|
|
741
|
-
"""
|
|
791
|
+
""" 进入常规续航模式(保持模式,直到切换到其他模式或调用FreeWalk) """
|
|
742
792
|
try:
|
|
743
793
|
# 执行指令
|
|
744
794
|
result = self._call(self.sport_client.EconomicGait)
|
|
795
|
+
if result == 0:
|
|
796
|
+
with self._gait_mode_lock:
|
|
797
|
+
self._gait_mode = 'economic'
|
|
798
|
+
print("已进入常规续航模式(持续保持)")
|
|
745
799
|
return result == 0 if result is not None else False
|
|
746
800
|
except AttributeError:
|
|
747
801
|
print("警告: EconomicGait 方法在当前SDK版本中不可用")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ezgo
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.18
|
|
4
4
|
Summary: 宇树Go2机器狗Python控制库
|
|
5
5
|
Author-email: ezgo <noreply@example.com>
|
|
6
6
|
License: MIT
|
|
@@ -208,24 +208,44 @@ import ezgo
|
|
|
208
208
|
robot = ezgo.Go2() # 需要unitree-sdk2py
|
|
209
209
|
if robot.init():
|
|
210
210
|
# 步态模式切换
|
|
211
|
-
robot.FreeWalk(True) #
|
|
211
|
+
robot.FreeWalk(True) # 开启灵动模式(默认步态)
|
|
212
212
|
robot.FreeWalk(False) # 关闭灵动模式
|
|
213
|
-
|
|
214
|
-
#
|
|
215
|
-
robot.FreeBound(True) # 并腿跑模式(
|
|
216
|
-
robot.
|
|
217
|
-
robot.
|
|
218
|
-
robot.
|
|
219
|
-
robot.
|
|
220
|
-
|
|
221
|
-
#
|
|
222
|
-
robot.
|
|
223
|
-
robot.
|
|
224
|
-
robot.
|
|
225
|
-
|
|
213
|
+
|
|
214
|
+
# 特殊步态(需手动开启/关闭)
|
|
215
|
+
robot.FreeBound(True) # 并腿跑模式(flag=1开启,flag=0关闭)
|
|
216
|
+
robot.FreeBound(False) # 关闭并腿跑模式
|
|
217
|
+
robot.FreeJump(True) # 跳跃模式(flag=1开启,flag=0关闭)
|
|
218
|
+
robot.FreeJump(False) # 关闭跳跃模式
|
|
219
|
+
robot.FreeAvoid(True) # 闪避模式(flag=1开启,flag=0关闭)
|
|
220
|
+
robot.FreeAvoid(False) # 关闭闪避模式
|
|
221
|
+
robot.WalkUpright(True) # 后腿直立模式(flag=1开启,flag=0关闭)
|
|
222
|
+
robot.WalkUpright(False) # 关闭后腿直立模式
|
|
223
|
+
robot.CrossStep(True) # 交叉步模式(flag=1开启,flag=0关闭)
|
|
224
|
+
robot.CrossStep(False) # 关闭交叉步模式
|
|
225
|
+
|
|
226
|
+
# 常规运动模式(持续保持,直到切换到其他模式)
|
|
227
|
+
robot.TrotRun() # 进入常规跑步模式(持续保持)
|
|
228
|
+
robot.StaticWalk() # 进入常规行走模式(持续保持)
|
|
229
|
+
robot.EconomicGait() # 进入常规续航模式(持续保持)
|
|
230
|
+
robot.ClassicWalk(True) # 开启经典步态(flag=1开启,flag=0关闭)
|
|
226
231
|
robot.ClassicWalk(False) # 关闭经典步态
|
|
232
|
+
|
|
233
|
+
# 切换回灵动模式会清除常规运动模式的保持
|
|
234
|
+
robot.FreeWalk(True) # 开启灵动模式,清除之前的常规模式
|
|
235
|
+
|
|
236
|
+
# 示例:使用常规跑步模式完成动作组合
|
|
237
|
+
robot.TrotRun() # 进入常规跑步模式
|
|
238
|
+
robot.Forward(0.5, 2) # 前进2秒(保持在跑步模式)
|
|
239
|
+
robot.TurnLeft(0.5, 2) # 左转2秒(仍保持在跑步模式)
|
|
240
|
+
robot.Forward(0.3, 1) # 继续前进1秒(仍保持在跑步模式)
|
|
227
241
|
```
|
|
228
242
|
|
|
243
|
+
**重要说明**:
|
|
244
|
+
- `TrotRun()`、`StaticWalk()`、`EconomicGait()` 调用后会**持续保持**该模式
|
|
245
|
+
- 移动控制函数(`Move`、`Forward`、`TurnLeft` 等)会自动保持当前设置的步态模式
|
|
246
|
+
- 要退出常规运动模式,可调用 `FreeWalk(True)` 切换回灵动模式
|
|
247
|
+
- 其他模式函数(`FreeBound`、`FreeJump` 等)仍需手动控制开启/关闭
|
|
248
|
+
|
|
229
249
|
### 特技动作
|
|
230
250
|
|
|
231
251
|
```python
|
|
@@ -417,6 +437,32 @@ pip install opencv-python numpy Pillow netifaces
|
|
|
417
437
|
|
|
418
438
|
## 更新日志
|
|
419
439
|
|
|
440
|
+
### v0.0.18 (2026-02-04)
|
|
441
|
+
**修复**:
|
|
442
|
+
- 🐛 修复步态模式保持机制,确保在每次 Move 调用前都正确保持步态
|
|
443
|
+
- 🐛 在 MoveForDuration 和 StartMove 循环中添加步态模式保持逻辑
|
|
444
|
+
- 🐛 添加短暂延迟让步态模式生效后再执行 Move 指令
|
|
445
|
+
|
|
446
|
+
**改进**:
|
|
447
|
+
- 🔧 优化步态保持时序,确保步态模式在移动前完全生效
|
|
448
|
+
- 🔧 移除 Move 函数内部不必要的步态保持调用,避免重复
|
|
449
|
+
|
|
450
|
+
### v0.0.17 (2026-02-04)
|
|
451
|
+
**新增功能**:
|
|
452
|
+
- ✨ 常规运动模式(`TrotRun`、`StaticWalk`、`EconomicGait`)现在支持持续保持
|
|
453
|
+
- ✨ 移动控制函数自动保持当前设置的步态模式
|
|
454
|
+
- ✨ 添加步态模式锁机制,确保线程安全
|
|
455
|
+
|
|
456
|
+
**修复**:
|
|
457
|
+
- 🐛 修复常规运动模式在移动后自动关闭的问题
|
|
458
|
+
- 🐛 修复使用经典步态/跑步模式等组合动作时模式失效的问题
|
|
459
|
+
- 🐛 `FreeWalk(True)` 现在会清除常规运动模式的保持
|
|
460
|
+
|
|
461
|
+
**改进**:
|
|
462
|
+
- 🔧 优化步态模式保持机制,确保移动过程中模式不被打断
|
|
463
|
+
- 🔧 更新文档说明,明确常规运动模式的持续保持特性
|
|
464
|
+
- 🔧 添加模式切换的清晰示例
|
|
465
|
+
|
|
420
466
|
### v0.0.16 (2026-02-04)
|
|
421
467
|
**修复**:
|
|
422
468
|
- 🐛 修复 MoveForDuration 函数在 duration 时间结束后未自动停止移动的问题
|
|
@@ -2,12 +2,12 @@ ezgo/__init__.py,sha256=XdJGNtFRNZwouVByMsopJ7APB23zkdAa7v5NvLrcpLw,2268
|
|
|
2
2
|
ezgo/camera.py,sha256=Vsr44vFtaop4LE0DlWyOHyvxF-jHnVO8iMPUwp5mbsE,2538
|
|
3
3
|
ezgo/ezcamera.py,sha256=6-3y-1X_L60QsWdsd5-caLoj7Quy9rpyHdp3Tq3JFbU,6536
|
|
4
4
|
ezgo/eztk.py,sha256=MHWkkZYIL1AFjUXFu2Qq8U9idJV_E1VxFUBe82dvbyA,10463
|
|
5
|
-
ezgo/go2.py,sha256=
|
|
5
|
+
ezgo/go2.py,sha256=Ccx4WKFre7kjtADTUDz8ky1YRuOkSRjutBGxz7fOPHE,33770
|
|
6
6
|
ezgo/go2_camera.py,sha256=nawUSLyvqTNiVRQ2sM-UdoJzqwZcySltLbCfUb0G9Qc,8614
|
|
7
7
|
ezgo/go2_vui.py,sha256=52I4Y8uqGkW9muDEnDzQ236HqVVTIgNIN_2gW5RTC48,10161
|
|
8
8
|
ezgo/ui.py,sha256=jUik6maaoemI2vsBM92OLZfJfskg54W7hwMls_gxppg,2777
|
|
9
|
-
ezgo-0.0.
|
|
10
|
-
ezgo-0.0.
|
|
11
|
-
ezgo-0.0.
|
|
12
|
-
ezgo-0.0.
|
|
13
|
-
ezgo-0.0.
|
|
9
|
+
ezgo-0.0.18.dist-info/LICENSE,sha256=Zk4eZBT3KaBhqM3LB_xN7QquwnoWsEHAoA6eLdE6W5M,1060
|
|
10
|
+
ezgo-0.0.18.dist-info/METADATA,sha256=DnPe457ryYE6uMjnfqvUWW8TWCuBRZa3RTfJI198JY0,20360
|
|
11
|
+
ezgo-0.0.18.dist-info/WHEEL,sha256=WnJ8fYhv8N4SYVK2lLYNI6N0kVATA7b0piVUNvqIIJE,91
|
|
12
|
+
ezgo-0.0.18.dist-info/top_level.txt,sha256=BdCFEVD5V_4FxUtvH0BVlZKgxYnp7EKNsYs5OyFxj-g,5
|
|
13
|
+
ezgo-0.0.18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|