kuavo-humanoid-sdk 1.1.3a1252__py3-none-any.whl → 1.1.5__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.
Potentially problematic release.
This version of kuavo-humanoid-sdk might be problematic. Click here for more details.
- kuavo_humanoid_sdk/__init__.py +2 -0
- kuavo_humanoid_sdk/interfaces/data_types.py +44 -0
- kuavo_humanoid_sdk/kuavo/core/core.py +226 -20
- kuavo_humanoid_sdk/kuavo/core/ros/control.py +447 -13
- kuavo_humanoid_sdk/kuavo/core/ros/state.py +228 -5
- kuavo_humanoid_sdk/kuavo/core/ros/vision.py +13 -252
- kuavo_humanoid_sdk/kuavo/robot.py +108 -6
- kuavo_humanoid_sdk/kuavo/robot_arm.py +53 -7
- kuavo_humanoid_sdk/kuavo/robot_head.py +10 -0
- kuavo_humanoid_sdk/kuavo/robot_state.py +35 -2
- kuavo_humanoid_sdk/kuavo_strategy/__init__.py +2 -0
- kuavo_humanoid_sdk/kuavo_strategy/grasp_box/grasp_box_strategy.py +418 -0
- kuavo_humanoid_sdk/kuavo_strategy/kuavo_strategy.py +63 -0
- kuavo_humanoid_sdk/msg/kuavo_msgs/msg/_twoArmHandPoseCmd.py +20 -16
- kuavo_humanoid_sdk/msg/kuavo_msgs/srv/__init__.py +1 -0
- kuavo_humanoid_sdk/msg/kuavo_msgs/srv/_setMmCtrlFrame.py +273 -0
- kuavo_humanoid_sdk/msg/kuavo_msgs/srv/_twoArmHandPoseCmdSrv.py +15 -14
- {kuavo_humanoid_sdk-1.1.3a1252.dist-info → kuavo_humanoid_sdk-1.1.5.dist-info}/METADATA +1 -1
- {kuavo_humanoid_sdk-1.1.3a1252.dist-info → kuavo_humanoid_sdk-1.1.5.dist-info}/RECORD +21 -17
- {kuavo_humanoid_sdk-1.1.3a1252.dist-info → kuavo_humanoid_sdk-1.1.5.dist-info}/WHEEL +0 -0
- {kuavo_humanoid_sdk-1.1.3a1252.dist-info → kuavo_humanoid_sdk-1.1.5.dist-info}/top_level.txt +0 -0
kuavo_humanoid_sdk/__init__.py
CHANGED
|
@@ -60,6 +60,50 @@ class KuavoArmCtrlMode(Enum):
|
|
|
60
60
|
AutoSwing = 1
|
|
61
61
|
ExternalControl = 2
|
|
62
62
|
|
|
63
|
+
class KuavoManipulationMpcFrame(Enum):
|
|
64
|
+
"""Enum class representing the manipulation mpc frame for the Kuavo robot end effector.
|
|
65
|
+
|
|
66
|
+
Attributes:
|
|
67
|
+
KeepCurrentFrame: Keep the current frame (value: 0)
|
|
68
|
+
WorldFrame: World frame (value: 1)
|
|
69
|
+
LocalFrame: Local frame (value: 2)
|
|
70
|
+
VRFrame: VR frame (value: 3)
|
|
71
|
+
ManipulationWorldFrame: Manipulation world frame (value: 4)
|
|
72
|
+
"""
|
|
73
|
+
KeepCurrentFrame = 0
|
|
74
|
+
WorldFrame = 1
|
|
75
|
+
LocalFrame = 2
|
|
76
|
+
VRFrame = 3
|
|
77
|
+
ManipulationWorldFrame = 4
|
|
78
|
+
ERROR = -1
|
|
79
|
+
|
|
80
|
+
class KuavoManipulationMpcCtrlMode(Enum):
|
|
81
|
+
"""Enum class representing the control mode for the Kuavo robot manipulation MPC.
|
|
82
|
+
|
|
83
|
+
Attributes:
|
|
84
|
+
NoControl: No control (value: 0)
|
|
85
|
+
ArmOnly: Only control the arm (value: 1)
|
|
86
|
+
BaseOnly: Only control the base (value: 2)
|
|
87
|
+
BaseArm: Control both the base and the arm (value: 3)
|
|
88
|
+
ERROR: Error state (value: -1)
|
|
89
|
+
"""
|
|
90
|
+
NoControl = 0
|
|
91
|
+
ArmOnly = 1
|
|
92
|
+
BaseOnly = 2
|
|
93
|
+
BaseArm = 3
|
|
94
|
+
ERROR = -1
|
|
95
|
+
|
|
96
|
+
class KuavoManipulationMpcControlFlow(Enum):
|
|
97
|
+
"""Enum class representing the control data flow for the Kuavo robot manipulation.
|
|
98
|
+
|
|
99
|
+
Attributes:
|
|
100
|
+
ThroughFullBodyMpc: Control data flows through full-body MPC before entering WBC (value: 0)
|
|
101
|
+
DirectToWbc: Control data flows directly to WBC without full-body MPC (value: 1)
|
|
102
|
+
Error: Invalid control path (value: -1)
|
|
103
|
+
"""
|
|
104
|
+
ThroughFullBodyMpc = 0
|
|
105
|
+
DirectToWbc = 1
|
|
106
|
+
Error = -1
|
|
63
107
|
|
|
64
108
|
@dataclass
|
|
65
109
|
class EndEffectorState:
|
|
@@ -24,9 +24,9 @@ import numpy as np
|
|
|
24
24
|
from typing import Tuple
|
|
25
25
|
from transitions import Machine, State
|
|
26
26
|
|
|
27
|
-
from kuavo_humanoid_sdk.interfaces.data_types import KuavoArmCtrlMode, KuavoIKParams, KuavoPose
|
|
27
|
+
from kuavo_humanoid_sdk.interfaces.data_types import KuavoArmCtrlMode, KuavoIKParams, KuavoPose, KuavoManipulationMpcFrame, KuavoManipulationMpcCtrlMode, KuavoManipulationMpcControlFlow
|
|
28
28
|
from kuavo_humanoid_sdk.kuavo.core.ros.control import KuavoRobotControl, KuavoRobotControlWebsocket
|
|
29
|
-
from kuavo_humanoid_sdk.kuavo.core.ros.vision import KuavoRobotVisionCore
|
|
29
|
+
from kuavo_humanoid_sdk.kuavo.core.ros.vision import KuavoRobotVisionCore
|
|
30
30
|
from kuavo_humanoid_sdk.kuavo.core.ros.tools import KuavoRobotToolsCore
|
|
31
31
|
from kuavo_humanoid_sdk.kuavo.core.ros.state import KuavoRobotStateCore, KuavoRobotStateCoreWebsocket
|
|
32
32
|
from kuavo_humanoid_sdk.kuavo.core.ros.param import make_robot_param
|
|
@@ -37,15 +37,19 @@ ROBOT_STATES = [
|
|
|
37
37
|
State(name='stance', on_enter=['_on_enter_stance']),
|
|
38
38
|
State(name='walk', on_enter=['_on_enter_walk']),
|
|
39
39
|
State(name='trot', on_enter=['_on_enter_trot']),
|
|
40
|
-
State(name='custom_gait', on_enter=['_on_enter_custom_gait'])
|
|
40
|
+
State(name='custom_gait', on_enter=['_on_enter_custom_gait']),
|
|
41
|
+
State(name='command_pose_world', on_enter=['_on_enter_command_pose_world']),
|
|
42
|
+
State(name='command_pose', on_enter=['_on_enter_command_pose']),
|
|
41
43
|
]
|
|
42
44
|
|
|
43
45
|
# Define state transitions
|
|
44
46
|
ROBOT_TRANSITIONS = [
|
|
45
|
-
{'trigger': 'to_stance', 'source': ['walk', 'trot', 'custom_gait'], 'dest': 'stance'},
|
|
47
|
+
{'trigger': 'to_stance', 'source': ['walk', 'trot', 'custom_gait', 'command_pose_world', 'command_pose'], 'dest': 'stance'},
|
|
46
48
|
{'trigger': 'to_walk', 'source': ['stance', 'trot', 'custom_gait'], 'dest': 'walk'},
|
|
47
49
|
{'trigger': 'to_trot', 'source': ['stance', 'walk', 'custom_gait'], 'dest': 'trot'},
|
|
48
50
|
{'trigger': 'to_custom_gait', 'source': ['stance', 'custom_gait'], 'dest': 'custom_gait'},
|
|
51
|
+
{'trigger': 'to_command_pose_world', 'source': ['stance', 'command_pose_world'], 'dest': 'command_pose_world'},
|
|
52
|
+
{'trigger': 'to_command_pose', 'source': ['stance', 'command_pose'], 'dest': 'command_pose'},
|
|
49
53
|
]
|
|
50
54
|
|
|
51
55
|
class KuavoRobotCore:
|
|
@@ -69,14 +73,19 @@ class KuavoRobotCore:
|
|
|
69
73
|
if GlobalConfig.use_websocket:
|
|
70
74
|
self._control = KuavoRobotControlWebsocket()
|
|
71
75
|
self._rb_state = KuavoRobotStateCoreWebsocket()
|
|
72
|
-
self._robot_vision = KuavoRobotVisionCoreWebsocket()
|
|
73
76
|
else:
|
|
74
77
|
self._control = KuavoRobotControl()
|
|
75
78
|
self._rb_state = KuavoRobotStateCore()
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
|
|
80
|
+
# manipulation mpc
|
|
81
|
+
self._manipulation_mpc_frame = KuavoManipulationMpcFrame.KeepCurrentFrame
|
|
82
|
+
self._manipulation_mpc_ctrl_mode = KuavoManipulationMpcCtrlMode.NoControl
|
|
83
|
+
self._manipulation_mpc_control_flow = KuavoManipulationMpcControlFlow.ThroughFullBodyMpc
|
|
84
|
+
|
|
85
|
+
# robot vision
|
|
86
|
+
self._robot_vision = KuavoRobotVisionCore()
|
|
87
|
+
# robot ros tf
|
|
88
|
+
self._robot_tf_tool = KuavoRobotToolsCore()
|
|
80
89
|
|
|
81
90
|
self._arm_ctrl_mode = KuavoArmCtrlMode.AutoSwing
|
|
82
91
|
|
|
@@ -105,6 +114,21 @@ class KuavoRobotCore:
|
|
|
105
114
|
if arm_ctrl_mode is not None:
|
|
106
115
|
self._arm_ctrl_mode = arm_ctrl_mode
|
|
107
116
|
SDKLogger.debug(f"[Core] initialize arm control mode: {arm_ctrl_mode}")
|
|
117
|
+
|
|
118
|
+
# init manipulation mpc
|
|
119
|
+
manipulation_mpc_frame = self._rb_state.manipulation_mpc_frame
|
|
120
|
+
if manipulation_mpc_frame is not None:
|
|
121
|
+
self._manipulation_mpc_frame = manipulation_mpc_frame
|
|
122
|
+
SDKLogger.debug(f"[Core] initialize manipulation mpc frame: {manipulation_mpc_frame}")
|
|
123
|
+
manipulation_mpc_ctrl_mode = self._rb_state.manipulation_mpc_ctrl_mode
|
|
124
|
+
if manipulation_mpc_ctrl_mode is not None:
|
|
125
|
+
self._manipulation_mpc_ctrl_mode = manipulation_mpc_ctrl_mode
|
|
126
|
+
SDKLogger.debug(f"[Core] initialize manipulation mpc ctrl mode: {manipulation_mpc_ctrl_mode}")
|
|
127
|
+
manipulation_mpc_control_flow = self._rb_state.manipulation_mpc_control_flow
|
|
128
|
+
if manipulation_mpc_control_flow is not None:
|
|
129
|
+
self._manipulation_mpc_control_flow = manipulation_mpc_control_flow
|
|
130
|
+
SDKLogger.debug(f"[Core] initialize manipulation mpc control flow: {manipulation_mpc_control_flow}")
|
|
131
|
+
|
|
108
132
|
except Exception as e:
|
|
109
133
|
raise RuntimeError(f"[Core] initialize failed: \n"
|
|
110
134
|
f"{e}, please check the robot is launched, "
|
|
@@ -166,6 +190,21 @@ class KuavoRobotCore:
|
|
|
166
190
|
SDKLogger.debug(f"[Core] [StateMachine] State unchanged: already in custom_gait state")
|
|
167
191
|
return
|
|
168
192
|
SDKLogger.debug(f"[Core] [StateMachine] Entering custom_gait state, from {previous_state}")
|
|
193
|
+
|
|
194
|
+
def _on_enter_command_pose_world(self, event):
|
|
195
|
+
previous_state = event.transition.source
|
|
196
|
+
if self.state == previous_state:
|
|
197
|
+
SDKLogger.debug(f"[Core] [StateMachine] State unchanged: already in command_pose_world state")
|
|
198
|
+
return
|
|
199
|
+
SDKLogger.debug(f"[Core] [StateMachine] Entering command_pose_world state, from {previous_state}")
|
|
200
|
+
|
|
201
|
+
def _on_enter_command_pose(self, event):
|
|
202
|
+
previous_state = event.transition.source
|
|
203
|
+
if self.state == previous_state:
|
|
204
|
+
SDKLogger.debug(f"[Core] [StateMachine] State unchanged: already in command_pose state")
|
|
205
|
+
return
|
|
206
|
+
SDKLogger.debug(f"[Core] [StateMachine] Entering command_pose state, from {previous_state}")
|
|
207
|
+
|
|
169
208
|
""" -------------------------------------------------------------"""
|
|
170
209
|
|
|
171
210
|
""" --------------------------- Control -------------------------"""
|
|
@@ -301,6 +340,54 @@ class KuavoRobotCore:
|
|
|
301
340
|
|
|
302
341
|
return True
|
|
303
342
|
|
|
343
|
+
def control_command_pose(self, target_pose_x:float, target_pose_y:float, target_pose_z:float, target_pose_yaw:float)->bool:
|
|
344
|
+
"""
|
|
345
|
+
Control robot pose in base_link frame
|
|
346
|
+
|
|
347
|
+
Arguments:
|
|
348
|
+
- target_pose_x: x position (meters)
|
|
349
|
+
- target_pose_y: y position (meters)
|
|
350
|
+
- target_pose_z: z position (meters)
|
|
351
|
+
- target_pose_yaw: yaw angle (radians)
|
|
352
|
+
|
|
353
|
+
Returns:
|
|
354
|
+
bool: True if command was sent successfully, False otherwise
|
|
355
|
+
|
|
356
|
+
Raises:
|
|
357
|
+
RuntimeError: If robot is not in stance state
|
|
358
|
+
"""
|
|
359
|
+
if self.state != 'stance':
|
|
360
|
+
raise RuntimeError(f"[Core] control_command_pose failed: robot must be in stance state, current state: {self.state}")
|
|
361
|
+
|
|
362
|
+
# Add any parameter validation if needed
|
|
363
|
+
# e.g., limit ranges for safety
|
|
364
|
+
self.to_command_pose()
|
|
365
|
+
return self._control.control_command_pose(target_pose_x, target_pose_y, target_pose_z, target_pose_yaw)
|
|
366
|
+
|
|
367
|
+
def control_command_pose_world(self, target_pose_x:float, target_pose_y:float, target_pose_z:float, target_pose_yaw:float)->bool:
|
|
368
|
+
"""
|
|
369
|
+
Control robot pose in odom (world) frame
|
|
370
|
+
|
|
371
|
+
Arguments:
|
|
372
|
+
- target_pose_x: x position (meters)
|
|
373
|
+
- target_pose_y: y position (meters)
|
|
374
|
+
- target_pose_z: z position (meters)
|
|
375
|
+
- target_pose_yaw: yaw angle (radians)
|
|
376
|
+
|
|
377
|
+
Returns:
|
|
378
|
+
bool: True if command was sent successfully, False otherwise
|
|
379
|
+
|
|
380
|
+
Raises:
|
|
381
|
+
RuntimeError: If robot is not in stance state
|
|
382
|
+
"""
|
|
383
|
+
# if self.state != 'stance':
|
|
384
|
+
# raise RuntimeError(f"[Core] control_command_pose_world failed: robot must be in stance state, current state: {self.state}")
|
|
385
|
+
|
|
386
|
+
# Add any parameter validation if needed
|
|
387
|
+
# e.g., limit ranges for safety
|
|
388
|
+
self.to_command_pose_world()
|
|
389
|
+
return self._control.control_command_pose_world(target_pose_x, target_pose_y, target_pose_z, target_pose_yaw)
|
|
390
|
+
|
|
304
391
|
def execute_gesture(self, gestures:list)->bool:
|
|
305
392
|
return self._control.execute_gesture(gestures)
|
|
306
393
|
|
|
@@ -323,30 +410,111 @@ class KuavoRobotCore:
|
|
|
323
410
|
pitch_deg = pitch * 180 / math.pi
|
|
324
411
|
return self._control.control_robot_head(yaw_deg, pitch_deg)
|
|
325
412
|
|
|
326
|
-
def
|
|
413
|
+
def enable_head_tracking(self, target_id: int)->bool:
|
|
414
|
+
return self._control.enable_head_tracking(target_id)
|
|
415
|
+
|
|
416
|
+
def disable_head_tracking(self)->bool:
|
|
417
|
+
return self._control.disable_head_tracking()
|
|
418
|
+
|
|
419
|
+
def control_robot_arm_joint_positions(self, joint_data:list)->bool:
|
|
327
420
|
if self.state != 'stance':
|
|
328
|
-
raise RuntimeError(f"[Core]
|
|
421
|
+
raise RuntimeError(f"[Core] control_robot_arm_joint_positions failed: robot must be in stance state, current state: {self.state}")
|
|
329
422
|
|
|
330
423
|
# change to external control mode
|
|
331
424
|
if self._arm_ctrl_mode != KuavoArmCtrlMode.ExternalControl:
|
|
332
|
-
SDKLogger.debug("[Core]
|
|
425
|
+
SDKLogger.debug("[Core] control_robot_arm_joint_positions, current arm mode != ExternalControl, change it.")
|
|
333
426
|
if not self.change_robot_arm_ctrl_mode(KuavoArmCtrlMode.ExternalControl):
|
|
334
|
-
SDKLogger.warn("[Core]
|
|
427
|
+
SDKLogger.warn("[Core] control_robot_arm_joint_positions failed, change robot arm ctrl mode failed!")
|
|
335
428
|
return False
|
|
336
|
-
return self._control.
|
|
429
|
+
return self._control.control_robot_arm_joint_positions(joint_data)
|
|
337
430
|
|
|
338
|
-
def
|
|
431
|
+
def control_robot_arm_joint_trajectory(self, times:list, joint_q:list)->bool:
|
|
339
432
|
if self.state != 'stance':
|
|
340
|
-
raise RuntimeError("[Core]
|
|
433
|
+
raise RuntimeError("[Core] control_robot_arm_joint_trajectory failed: robot must be in stance state")
|
|
341
434
|
|
|
342
435
|
if self._arm_ctrl_mode != KuavoArmCtrlMode.ExternalControl:
|
|
343
|
-
SDKLogger.debug("[Core]
|
|
436
|
+
SDKLogger.debug("[Core] control_robot_arm_joint_trajectory, current arm mode != ExternalControl, change it.")
|
|
344
437
|
if not self.change_robot_arm_ctrl_mode(KuavoArmCtrlMode.ExternalControl):
|
|
345
|
-
SDKLogger.warn("[Core]
|
|
438
|
+
SDKLogger.warn("[Core] control_robot_arm_joint_trajectory failed, change robot arm ctrl mode failed!")
|
|
346
439
|
return False
|
|
347
440
|
|
|
348
|
-
return self._control.
|
|
441
|
+
return self._control.control_robot_arm_joint_trajectory(times, joint_q)
|
|
442
|
+
|
|
443
|
+
def control_robot_end_effector_pose(self, left_pose: KuavoPose, right_pose: KuavoPose, frame: KuavoManipulationMpcFrame)->bool:
|
|
444
|
+
if self._arm_ctrl_mode != KuavoArmCtrlMode.ExternalControl:
|
|
445
|
+
SDKLogger.debug("[Core] control_robot_end_effector_pose, current arm mode != ExternalControl, change it.")
|
|
446
|
+
if not self.change_robot_arm_ctrl_mode(KuavoArmCtrlMode.ExternalControl):
|
|
447
|
+
SDKLogger.warn("[Core] control_robot_end_effector_pose failed, change robot arm ctrl mode failed!")
|
|
448
|
+
return False
|
|
449
|
+
|
|
450
|
+
if self._manipulation_mpc_ctrl_mode == KuavoManipulationMpcCtrlMode.NoControl:
|
|
451
|
+
SDKLogger.debug("[Core] control_robot_end_effector_pose, manipulation mpc ctrl mode is NoControl, change it.")
|
|
452
|
+
if not self.change_manipulation_mpc_ctrl_mode(KuavoManipulationMpcCtrlMode.ArmOnly):
|
|
453
|
+
SDKLogger.warn("[Core] control_robot_end_effector_pose failed, change manipulation mpc ctrl mode failed!")
|
|
454
|
+
return False
|
|
455
|
+
|
|
456
|
+
return self._control.control_robot_end_effector_pose(left_pose, right_pose, frame)
|
|
349
457
|
|
|
458
|
+
def change_manipulation_mpc_frame(self, frame: KuavoManipulationMpcFrame)->bool:
|
|
459
|
+
timeout = 1.0
|
|
460
|
+
count = 0
|
|
461
|
+
while self._rb_state.manipulation_mpc_frame != frame:
|
|
462
|
+
SDKLogger.debug(f"[Core] Change manipulation mpc frame from {self._rb_state.manipulation_mpc_frame} to {frame}, retry: {count}")
|
|
463
|
+
self._control.change_manipulation_mpc_frame(frame)
|
|
464
|
+
if self._rb_state.manipulation_mpc_frame == frame:
|
|
465
|
+
break
|
|
466
|
+
if timeout <= 0:
|
|
467
|
+
SDKLogger.warn("[Core] Change manipulation mpc frame timeout!")
|
|
468
|
+
return False
|
|
469
|
+
timeout -= 0.1
|
|
470
|
+
time.sleep(0.1)
|
|
471
|
+
count += 1
|
|
472
|
+
if not hasattr(self, '_manipulation_mpc_frame_lock'):
|
|
473
|
+
self._manipulation_mpc_frame_lock = threading.Lock()
|
|
474
|
+
with self._manipulation_mpc_frame_lock:
|
|
475
|
+
self._manipulation_mpc_frame = frame
|
|
476
|
+
return True
|
|
477
|
+
|
|
478
|
+
def change_manipulation_mpc_ctrl_mode(self, control_mode: KuavoManipulationMpcCtrlMode)->bool:
|
|
479
|
+
timeout = 1.0
|
|
480
|
+
count = 0
|
|
481
|
+
while self._rb_state.manipulation_mpc_ctrl_mode != control_mode:
|
|
482
|
+
SDKLogger.debug(f"[Core] Change manipulation mpc ctrl mode from {self._rb_state.manipulation_mpc_ctrl_mode} to {control_mode}, retry: {count}")
|
|
483
|
+
self._control.change_manipulation_mpc_ctrl_mode(control_mode)
|
|
484
|
+
if self._rb_state.manipulation_mpc_ctrl_mode == control_mode:
|
|
485
|
+
break
|
|
486
|
+
if timeout <= 0:
|
|
487
|
+
SDKLogger.warn("[Core] Change manipulation mpc ctrl mode timeout!")
|
|
488
|
+
return False
|
|
489
|
+
timeout -= 0.1
|
|
490
|
+
time.sleep(0.1)
|
|
491
|
+
count += 1
|
|
492
|
+
if not hasattr(self, '_manipulation_mpc_ctrl_mode_lock'):
|
|
493
|
+
self._manipulation_mpc_ctrl_mode_lock = threading.Lock()
|
|
494
|
+
with self._manipulation_mpc_ctrl_mode_lock:
|
|
495
|
+
self._manipulation_mpc_ctrl_mode = control_mode
|
|
496
|
+
return True
|
|
497
|
+
|
|
498
|
+
def change_manipulation_mpc_control_flow(self, control_flow: KuavoManipulationMpcControlFlow)->bool:
|
|
499
|
+
timeout = 1.0
|
|
500
|
+
count = 0
|
|
501
|
+
while self._rb_state.manipulation_mpc_control_flow != control_flow:
|
|
502
|
+
SDKLogger.debug(f"[Core] Change manipulation mpc control flow from {self._rb_state.manipulation_mpc_control_flow} to {control_flow}, retry: {count}")
|
|
503
|
+
self._control.change_manipulation_mpc_control_flow(control_flow)
|
|
504
|
+
if self._rb_state.manipulation_mpc_control_flow == control_flow:
|
|
505
|
+
break
|
|
506
|
+
if timeout <= 0:
|
|
507
|
+
SDKLogger.warn("[Core] Change manipulation mpc control flow timeout!")
|
|
508
|
+
return False
|
|
509
|
+
timeout -= 0.1
|
|
510
|
+
time.sleep(0.1)
|
|
511
|
+
count += 1
|
|
512
|
+
if not hasattr(self, '_manipulation_mpc_control_flow_lock'):
|
|
513
|
+
self._manipulation_mpc_control_flow_lock = threading.Lock()
|
|
514
|
+
with self._manipulation_mpc_control_flow_lock:
|
|
515
|
+
self._manipulation_mpc_control_flow = control_flow
|
|
516
|
+
return True
|
|
517
|
+
|
|
350
518
|
def change_robot_arm_ctrl_mode(self, mode:KuavoArmCtrlMode)->bool:
|
|
351
519
|
timeout = 1.0
|
|
352
520
|
count = 0
|
|
@@ -376,12 +544,25 @@ class KuavoRobotCore:
|
|
|
376
544
|
return
|
|
377
545
|
|
|
378
546
|
# init_pos = [0.0]*14
|
|
379
|
-
# if not self.
|
|
547
|
+
# if not self.control_robot_arm_joint_trajectory([1.5], [init_pos]):
|
|
380
548
|
# SDKLogger.warn("[Core] robot arm reset failed, control robot arm traj failed!")
|
|
381
549
|
# return False
|
|
382
550
|
|
|
383
551
|
return self.change_robot_arm_ctrl_mode(KuavoArmCtrlMode.AutoSwing)
|
|
384
552
|
|
|
553
|
+
def robot_manipulation_mpc_reset(self)->bool:
|
|
554
|
+
if self._manipulation_mpc_ctrl_mode != KuavoManipulationMpcCtrlMode.NoControl:
|
|
555
|
+
SDKLogger.debug("[Core] robot manipulation mpc reset, current manipulation mpc ctrl mode != NoControl, change it.")
|
|
556
|
+
if not self.change_manipulation_mpc_ctrl_mode(KuavoManipulationMpcCtrlMode.NoControl):
|
|
557
|
+
SDKLogger.warn("[Core] robot manipulation mpc reset failed, change manipulation mpc ctrl mode failed!")
|
|
558
|
+
return False
|
|
559
|
+
if self._manipulation_mpc_control_flow != KuavoManipulationMpcControlFlow.ThroughFullBodyMpc:
|
|
560
|
+
SDKLogger.debug("[Core] robot manipulation mpc reset, current manipulation mpc control flow != ThroughFullBodyMpc, change it.")
|
|
561
|
+
if not self.change_manipulation_mpc_control_flow(KuavoManipulationMpcControlFlow.ThroughFullBodyMpc):
|
|
562
|
+
SDKLogger.warn("[Core] robot manipulation mpc reset failed, change manipulation mpc control flow failed!")
|
|
563
|
+
return False
|
|
564
|
+
return True
|
|
565
|
+
|
|
385
566
|
""" ------------------------------------------------------------------------"""
|
|
386
567
|
""" Arm Forward kinematics && Arm Inverse kinematics """
|
|
387
568
|
def arm_ik(self,
|
|
@@ -406,3 +587,28 @@ class KuavoRobotCore:
|
|
|
406
587
|
SDKLogger.debug(f"[Core] Received gait change notification: {gait_name} at time {current_time}")
|
|
407
588
|
# Call the transition method if it exists
|
|
408
589
|
getattr(self, to_method)()
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
if __name__ == "__main__":
|
|
593
|
+
DEBUG_MODE = 0
|
|
594
|
+
core = KuavoRobotCore()
|
|
595
|
+
core.initialize()
|
|
596
|
+
|
|
597
|
+
if DEBUG_MODE == 0:
|
|
598
|
+
time.sleep(1.0)
|
|
599
|
+
core.change_robot_arm_ctrl_mode(KuavoArmCtrlMode.ExternalControl)
|
|
600
|
+
core.change_manipulation_mpc_frame(KuavoManipulationMpcFrame.VRFrame)
|
|
601
|
+
core.change_manipulation_mpc_ctrl_mode(KuavoManipulationMpcCtrlMode.ArmOnly)
|
|
602
|
+
core.change_manipulation_mpc_control_flow(KuavoManipulationMpcControlFlow.DirectToWbc)
|
|
603
|
+
core.robot_manipulation_mpc_reset()
|
|
604
|
+
elif DEBUG_MODE == 1:
|
|
605
|
+
core.to_stance()
|
|
606
|
+
print("state now is to_stance:", core.state)
|
|
607
|
+
core.control_command_pose_world(0.0, 1.0, 0.0, 1.57)
|
|
608
|
+
print("state now is control_command_pose_world:", core.state)
|
|
609
|
+
elif DEBUG_MODE == 2:
|
|
610
|
+
core.to_trot()
|
|
611
|
+
print("state now is to_trot:", core.state)
|
|
612
|
+
time.sleep(3.0)
|
|
613
|
+
core.to_stance()
|
|
614
|
+
print("state now is to_stance:", core.state)
|