ezgo 0.0.4__tar.gz → 0.0.5__tar.gz
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-0.0.4/src/ezgo.egg-info → ezgo-0.0.5}/PKG-INFO +1 -1
- {ezgo-0.0.4 → ezgo-0.0.5}/pyproject.toml +1 -1
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo/__init__.py +1 -1
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo/go2.py +153 -35
- {ezgo-0.0.4 → ezgo-0.0.5/src/ezgo.egg-info}/PKG-INFO +1 -1
- {ezgo-0.0.4 → ezgo-0.0.5}/LICENSE +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/README.md +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/setup.cfg +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo/camera.py +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo/go2_camera.py +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo/go2_vui.py +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo/ui.py +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo.egg-info/SOURCES.txt +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo.egg-info/dependency_links.txt +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo.egg-info/requires.txt +0 -0
- {ezgo-0.0.4 → ezgo-0.0.5}/src/ezgo.egg-info/top_level.txt +0 -0
|
@@ -87,7 +87,13 @@ class Go2:
|
|
|
87
87
|
def check_go2_connection(self):
|
|
88
88
|
"""检查机器狗IP连通性"""
|
|
89
89
|
try:
|
|
90
|
-
#
|
|
90
|
+
# 先尝试不使用sudo ping
|
|
91
|
+
result = subprocess.run(['ping', '-c', '1', '-W', '2', '192.168.123.161'],
|
|
92
|
+
capture_output=True, text=True, timeout=5)
|
|
93
|
+
if result.returncode == 0:
|
|
94
|
+
return True
|
|
95
|
+
|
|
96
|
+
# 如果不使用sudo失败,尝试使用sudo
|
|
91
97
|
result = subprocess.run(['sudo', 'ping', '-c', '1', '-W', '2', '192.168.123.161'],
|
|
92
98
|
capture_output=True, text=True, timeout=5)
|
|
93
99
|
return result.returncode == 0
|
|
@@ -104,26 +110,31 @@ class Go2:
|
|
|
104
110
|
def init(self):
|
|
105
111
|
"""初始化与Go2的连接"""
|
|
106
112
|
|
|
107
|
-
# 检查机器狗IP
|
|
113
|
+
# 检查机器狗IP连通性(仅作为警告,不阻止初始化)
|
|
108
114
|
if not self.check_go2_connection():
|
|
109
|
-
print("
|
|
110
|
-
|
|
115
|
+
print("警告:无法ping通机器狗IP,但继续尝试初始化SDK")
|
|
116
|
+
print("请确保机器狗已开机且网络连接正常")
|
|
111
117
|
|
|
112
|
-
|
|
118
|
+
try:
|
|
119
|
+
ChannelFactoryInitialize(0, self.interface)
|
|
113
120
|
|
|
114
|
-
|
|
115
|
-
|
|
121
|
+
# 启动状态订阅
|
|
122
|
+
self.sub_state(self.callback)
|
|
116
123
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
# 初始化运动控制客户端
|
|
125
|
+
self.sport_client = SportClient()
|
|
126
|
+
self.sport_client.SetTimeout(self.timeout)
|
|
127
|
+
self.sport_client.Init()
|
|
128
|
+
|
|
129
|
+
# 注意:视频流不再自动初始化,按需开启
|
|
130
|
+
# self.cap = self.open_video() # 移除自动初始化
|
|
131
|
+
|
|
132
|
+
self._initialized = True
|
|
133
|
+
print("Go2 SDK初始化成功")
|
|
134
|
+
return True
|
|
135
|
+
except Exception as e:
|
|
136
|
+
print(f"SDK初始化失败: {e}")
|
|
137
|
+
return False
|
|
127
138
|
|
|
128
139
|
|
|
129
140
|
def open_video(self, width: int = 480, height: int = 320):
|
|
@@ -594,67 +605,174 @@ class Go2:
|
|
|
594
605
|
|
|
595
606
|
def HandStand(self, flag: int):
|
|
596
607
|
"""倒立行走。"""
|
|
597
|
-
|
|
608
|
+
# 执行指令
|
|
609
|
+
self._call(lambda: self.sport_client.HandStand(bool(flag)))
|
|
610
|
+
if flag:
|
|
611
|
+
time.sleep(4)
|
|
612
|
+
self._call(lambda: self.sport_client.HandStand(False))
|
|
598
613
|
|
|
599
614
|
def LeftFlip(self):
|
|
600
615
|
"""左空翻。"""
|
|
601
|
-
|
|
616
|
+
# 执行指令
|
|
617
|
+
result = self._call(self.sport_client.LeftFlip)
|
|
618
|
+
return result == 0 if result is not None else False
|
|
602
619
|
|
|
603
620
|
def BackFlip(self):
|
|
604
621
|
"""后空翻。"""
|
|
605
|
-
|
|
622
|
+
# 执行指令
|
|
623
|
+
result = self._call(self.sport_client.BackFlip)
|
|
624
|
+
return result == 0 if result is not None else False
|
|
606
625
|
|
|
607
|
-
def FreeWalk(self, flag: int):
|
|
626
|
+
def FreeWalk(self, flag: int = None):
|
|
608
627
|
""" 灵动模式(默认步态)。"""
|
|
609
|
-
|
|
628
|
+
# 执行指令
|
|
629
|
+
if flag is None:
|
|
630
|
+
# 切换模式
|
|
631
|
+
result = self._call(lambda: self.sport_client.FreeWalk())
|
|
632
|
+
else:
|
|
633
|
+
# 根据flag值执行相应操作
|
|
634
|
+
if flag:
|
|
635
|
+
# 开启灵动模式
|
|
636
|
+
result = self._call(lambda: self.sport_client.FreeWalk())
|
|
637
|
+
else:
|
|
638
|
+
# 关闭灵动模式 - 切换到其他模式
|
|
639
|
+
result = self._call(lambda: self.sport_client.StandUp())
|
|
640
|
+
return result == 0 if result is not None else False
|
|
610
641
|
|
|
611
642
|
def FreeBound(self, flag: int):
|
|
612
643
|
""" 并腿跑模式。"""
|
|
613
|
-
|
|
644
|
+
# 执行指令
|
|
645
|
+
result = self._call(lambda: self.sport_client.FreeBound(bool(flag)))
|
|
646
|
+
success = result == 0 if result is not None else False
|
|
647
|
+
|
|
648
|
+
if flag and success:
|
|
649
|
+
# 如果成功开启,等待2秒后自动关闭(这是为了演示效果)
|
|
650
|
+
time.sleep(2)
|
|
651
|
+
self._call(lambda: self.sport_client.FreeBound(False))
|
|
652
|
+
|
|
653
|
+
return success
|
|
614
654
|
|
|
615
655
|
def FreeJump(self, flag: int):
|
|
616
656
|
""" 跳跃模式。"""
|
|
617
|
-
|
|
657
|
+
# 执行指令
|
|
658
|
+
result = self._call(lambda: self.sport_client.FreeJump(bool(flag)))
|
|
659
|
+
success = result == 0 if result is not None else False
|
|
660
|
+
|
|
661
|
+
if flag and success:
|
|
662
|
+
# 如果成功开启,等待4秒后自动关闭(这是为了演示效果)
|
|
663
|
+
time.sleep(4)
|
|
664
|
+
self._call(lambda: self.sport_client.FreeJump(False))
|
|
665
|
+
|
|
666
|
+
return success
|
|
618
667
|
|
|
619
668
|
def FreeAvoid(self, flag: int):
|
|
620
669
|
""" 闪避模式。"""
|
|
621
|
-
|
|
670
|
+
# 执行指令
|
|
671
|
+
result = self._call(lambda: self.sport_client.FreeAvoid(bool(flag)))
|
|
672
|
+
success = result == 0 if result is not None else False
|
|
673
|
+
|
|
674
|
+
if flag and success:
|
|
675
|
+
# 如果成功开启,等待2秒后自动关闭(这是为了演示效果)
|
|
676
|
+
time.sleep(2)
|
|
677
|
+
self._call(lambda: self.sport_client.FreeAvoid(False))
|
|
678
|
+
|
|
679
|
+
return success
|
|
622
680
|
|
|
623
681
|
def WalkUpright(self, flag: int):
|
|
624
682
|
""" 后腿直立模式。"""
|
|
625
|
-
|
|
683
|
+
# 执行指令
|
|
684
|
+
result = self._call(lambda: self.sport_client.WalkUpright(bool(flag)))
|
|
685
|
+
success = result == 0 if result is not None else False
|
|
686
|
+
|
|
687
|
+
if flag and success:
|
|
688
|
+
# 如果成功开启,等待4秒后自动关闭(这是为了演示效果)
|
|
689
|
+
time.sleep(4)
|
|
690
|
+
self._call(lambda: self.sport_client.WalkUpright(False))
|
|
691
|
+
|
|
692
|
+
return success
|
|
626
693
|
|
|
627
694
|
def CrossStep(self, flag: int):
|
|
628
695
|
""" 交叉步模式。"""
|
|
629
|
-
|
|
696
|
+
# 执行指令
|
|
697
|
+
result = self._call(lambda: self.sport_client.CrossStep(bool(flag)))
|
|
698
|
+
success = result == 0 if result is not None else False
|
|
699
|
+
|
|
700
|
+
if flag and success:
|
|
701
|
+
# 如果成功开启,等待4秒后自动关闭(这是为了演示效果)
|
|
702
|
+
time.sleep(4)
|
|
703
|
+
self._call(lambda: self.sport_client.CrossStep(False))
|
|
704
|
+
|
|
705
|
+
return success
|
|
630
706
|
|
|
631
707
|
def AutoRecoverSet(self, flag: int):
|
|
632
708
|
""" 设置自动翻身是否生效。"""
|
|
633
|
-
|
|
709
|
+
try:
|
|
710
|
+
# 执行指令
|
|
711
|
+
result = self._call(lambda: self.sport_client.AutoRecoverSet(bool(flag)))
|
|
712
|
+
return result == 0 if result is not None else False
|
|
713
|
+
except AttributeError:
|
|
714
|
+
print("警告: AutoRecoverSet 方法在当前SDK版本中不可用")
|
|
715
|
+
return False
|
|
634
716
|
|
|
635
717
|
def AutoRecoverGet(self):
|
|
636
718
|
""" 查询自动翻身是否生效。"""
|
|
637
|
-
|
|
719
|
+
try:
|
|
720
|
+
# 执行指令
|
|
721
|
+
result = self._call(self.sport_client.AutoRecoverGet)
|
|
722
|
+
return result if result is not None else False
|
|
723
|
+
except AttributeError:
|
|
724
|
+
print("警告: AutoRecoverGet 方法在当前SDK版本中不可用")
|
|
725
|
+
return False
|
|
638
726
|
|
|
639
727
|
def ClassicWalk(self, flag: int):
|
|
640
728
|
""" 经典步态。"""
|
|
641
|
-
|
|
729
|
+
try:
|
|
730
|
+
# 执行指令
|
|
731
|
+
result = self._call(lambda: self.sport_client.ClassicWalk(bool(flag)))
|
|
732
|
+
return result == 0 if result is not None else False
|
|
733
|
+
except AttributeError:
|
|
734
|
+
print("警告: ClassicWalk 方法在当前SDK版本中不可用")
|
|
735
|
+
return False
|
|
642
736
|
|
|
643
737
|
def TrotRun(self):
|
|
644
738
|
""" 进入常规跑步模式 """
|
|
645
|
-
|
|
739
|
+
try:
|
|
740
|
+
# 执行指令
|
|
741
|
+
result = self._call(self.sport_client.TrotRun)
|
|
742
|
+
return result == 0 if result is not None else False
|
|
743
|
+
except AttributeError:
|
|
744
|
+
print("警告: TrotRun 方法在当前SDK版本中不可用")
|
|
745
|
+
return False
|
|
646
746
|
|
|
647
747
|
def StaticWalk(self):
|
|
648
748
|
""" 进入常规行走模式"""
|
|
649
|
-
|
|
749
|
+
try:
|
|
750
|
+
# 执行指令
|
|
751
|
+
result = self._call(self.sport_client.StaticWalk)
|
|
752
|
+
return result == 0 if result is not None else False
|
|
753
|
+
except AttributeError:
|
|
754
|
+
print("警告: StaticWalk 方法在当前SDK版本中不可用")
|
|
755
|
+
return False
|
|
650
756
|
|
|
651
757
|
def EconomicGait(self):
|
|
652
758
|
""" 进入常规续航模式 """
|
|
653
|
-
|
|
759
|
+
try:
|
|
760
|
+
# 执行指令
|
|
761
|
+
result = self._call(self.sport_client.EconomicGait)
|
|
762
|
+
return result == 0 if result is not None else False
|
|
763
|
+
except AttributeError:
|
|
764
|
+
print("警告: EconomicGait 方法在当前SDK版本中不可用")
|
|
765
|
+
return False
|
|
654
766
|
|
|
655
767
|
def SwitchAvoidMode(self):
|
|
656
768
|
""" 闪避模式下,关闭摇杆未推时前方障碍物的闪避以及后方的障碍物躲避"""
|
|
657
|
-
|
|
769
|
+
try:
|
|
770
|
+
# 执行指令
|
|
771
|
+
result = self._call(self.sport_client.SwitchAvoidMode)
|
|
772
|
+
return result == 0 if result is not None else False
|
|
773
|
+
except AttributeError:
|
|
774
|
+
print("警告: SwitchAvoidMode 方法在当前SDK版本中不可用")
|
|
775
|
+
return False
|
|
658
776
|
|
|
659
777
|
def get_camera(self):
|
|
660
778
|
"""
|
|
@@ -674,7 +792,7 @@ class Go2:
|
|
|
674
792
|
"""
|
|
675
793
|
获取声光控制对象(按需初始化)
|
|
676
794
|
|
|
677
|
-
Returns:
|
|
795
|
+
Returns:
|
|
678
796
|
Go2VUI: 声光控制对象
|
|
679
797
|
"""
|
|
680
798
|
if not hasattr(self, '_vui') or self._vui is None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|