kuavo-humanoid-sdk 1.1.5__py3-none-any.whl → 1.1.6__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 +0 -2
- kuavo_humanoid_sdk/interfaces/data_types.py +0 -90
- kuavo_humanoid_sdk/kuavo/__init__.py +0 -3
- kuavo_humanoid_sdk/kuavo/core/core.py +20 -238
- kuavo_humanoid_sdk/kuavo/core/ros/control.py +27 -1087
- kuavo_humanoid_sdk/kuavo/core/ros/param.py +4 -142
- kuavo_humanoid_sdk/kuavo/core/ros/state.py +19 -556
- kuavo_humanoid_sdk/kuavo/core/ros_env.py +1 -229
- kuavo_humanoid_sdk/kuavo/dexterous_hand.py +2 -6
- kuavo_humanoid_sdk/kuavo/leju_claw.py +2 -6
- kuavo_humanoid_sdk/kuavo/robot.py +27 -150
- kuavo_humanoid_sdk/kuavo/robot_arm.py +7 -53
- kuavo_humanoid_sdk/kuavo/robot_head.py +0 -10
- kuavo_humanoid_sdk/kuavo/robot_info.py +2 -7
- kuavo_humanoid_sdk/kuavo/robot_state.py +4 -41
- kuavo_humanoid_sdk/msg/kuavo_msgs/msg/__init__.py +0 -7
- kuavo_humanoid_sdk/msg/kuavo_msgs/srv/__init__.py +0 -5
- kuavo_humanoid_sdk/msg/kuavo_msgs/srv/_playmusic.py +20 -26
- kuavo_humanoid_sdk/msg/motion_capture_ik/msg/__init__.py +9 -0
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/msg/_armHandPose.py +2 -2
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/msg/_handPose.py +2 -2
- kuavo_humanoid_sdk/msg/motion_capture_ik/msg/_headBodyPose.py +145 -0
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/msg/_ikSolveError.py +13 -13
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/msg/_ikSolveParam.py +2 -2
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/msg/_robotArmQVVD.py +2 -2
- kuavo_humanoid_sdk/msg/motion_capture_ik/msg/_robotHandPosition.py +225 -0
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/msg/_twoArmHandPose.py +13 -13
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/msg/_twoArmHandPoseCmd.py +30 -34
- kuavo_humanoid_sdk/msg/motion_capture_ik/srv/__init__.py +4 -0
- kuavo_humanoid_sdk/msg/{kuavo_msgs/srv/_setMmCtrlFrame.py → motion_capture_ik/srv/_changeArmCtrlMode.py} +37 -35
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/srv/_changeArmCtrlModeKuavo.py +5 -5
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/srv/_fkSrv.py +13 -13
- kuavo_humanoid_sdk/msg/{kuavo_msgs → motion_capture_ik}/srv/_twoArmHandPoseCmdSrv.py +37 -38
- {kuavo_humanoid_sdk-1.1.5.dist-info → kuavo_humanoid_sdk-1.1.6.dist-info}/METADATA +1 -2
- {kuavo_humanoid_sdk-1.1.5.dist-info → kuavo_humanoid_sdk-1.1.6.dist-info}/RECORD +37 -46
- kuavo_humanoid_sdk/common/global_config.py +0 -16
- kuavo_humanoid_sdk/common/websocket_kuavo_sdk.py +0 -23
- kuavo_humanoid_sdk/kuavo/core/audio.py +0 -36
- kuavo_humanoid_sdk/kuavo/core/ros/audio.py +0 -176
- kuavo_humanoid_sdk/kuavo/core/ros/tools.py +0 -158
- kuavo_humanoid_sdk/kuavo/core/ros/vision.py +0 -283
- kuavo_humanoid_sdk/kuavo/robot_audio.py +0 -39
- kuavo_humanoid_sdk/kuavo/robot_tool.py +0 -62
- kuavo_humanoid_sdk/kuavo/robot_vision.py +0 -90
- kuavo_humanoid_sdk/kuavo_strategy/__init__.py +0 -2
- kuavo_humanoid_sdk/kuavo_strategy/grasp_box/grasp_box_strategy.py +0 -418
- kuavo_humanoid_sdk/kuavo_strategy/kuavo_strategy.py +0 -63
- kuavo_humanoid_sdk/msg/kuavo_msgs/srv/_SpeechSynthesis.py +0 -270
- {kuavo_humanoid_sdk-1.1.5.dist-info → kuavo_humanoid_sdk-1.1.6.dist-info}/WHEEL +0 -0
- {kuavo_humanoid_sdk-1.1.5.dist-info → kuavo_humanoid_sdk-1.1.6.dist-info}/top_level.txt +0 -0
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import rospy
|
|
2
|
+
import copy
|
|
2
3
|
import time
|
|
3
4
|
from typing import Tuple
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
from kuavo_humanoid_sdk.msg.ocs2_msgs.msg import mpc_observation
|
|
13
|
-
except:
|
|
14
|
-
pass
|
|
15
|
-
|
|
16
|
-
from kuavo_humanoid_sdk.interfaces.data_types import (KuavoImuData, KuavoJointData, KuavoOdometry, KuavoManipulationMpcFrame,
|
|
17
|
-
KuavoArmCtrlMode, EndEffectorState, KuavoDexHandTouchState,
|
|
18
|
-
KuavoManipulationMpcCtrlMode, KuavoManipulationMpcControlFlow)
|
|
5
|
+
from std_msgs.msg import Float64
|
|
6
|
+
from nav_msgs.msg import Odometry
|
|
7
|
+
from sensor_msgs.msg import JointState
|
|
8
|
+
from kuavo_humanoid_sdk.msg.kuavo_msgs.msg import sensorsData, lejuClawState, gaitTimeName, dexhandTouchState
|
|
9
|
+
from kuavo_msgs.srv import changeArmCtrlMode, changeArmCtrlModeRequest, getCurrentGaitName, getCurrentGaitNameRequest
|
|
10
|
+
from kuavo_humanoid_sdk.msg.ocs2_msgs.msg import mpc_observation
|
|
11
|
+
from kuavo_humanoid_sdk.interfaces.data_types import (KuavoImuData, KuavoJointData, KuavoOdometry,
|
|
12
|
+
KuavoArmCtrlMode, EndEffectorState, KuavoDexHandTouchState)
|
|
19
13
|
from kuavo_humanoid_sdk.kuavo.core.ros.param import make_robot_param, EndEffectorType
|
|
20
14
|
from kuavo_humanoid_sdk.common.logger import SDKLogger
|
|
21
|
-
|
|
22
|
-
from kuavo_humanoid_sdk.msg.kuavo_msgs.srv import (changeArmCtrlMode, changeArmCtrlModeRequest,setMmCtrlFrame, setMmCtrlFrameRequest,
|
|
23
|
-
changeTorsoCtrlMode, changeTorsoCtrlModeRequest)
|
|
15
|
+
|
|
24
16
|
from collections import deque
|
|
25
17
|
from typing import Tuple, Optional
|
|
26
18
|
|
|
@@ -58,7 +50,6 @@ class GaitManager:
|
|
|
58
50
|
return "No_Gait"
|
|
59
51
|
return self._gait_time_names[-1][1]
|
|
60
52
|
|
|
61
|
-
|
|
62
53
|
class KuavoRobotStateCore:
|
|
63
54
|
_instance = None
|
|
64
55
|
|
|
@@ -158,11 +149,6 @@ class KuavoRobotStateCore:
|
|
|
158
149
|
self._arm_ctrl_mode = self._srv_get_arm_ctrl_mode()
|
|
159
150
|
self._initialized = True
|
|
160
151
|
|
|
161
|
-
# 获取manipulation mpc 相关参数
|
|
162
|
-
self._manipulation_mpc_frame = self._srv_get_manipulation_mpc_frame()
|
|
163
|
-
self._manipulation_mpc_ctrl_mode = self._srv_get_manipulation_mpc_ctrl_mode()
|
|
164
|
-
self._manipulation_mpc_control_flow = self._srv_get_manipulation_mpc_control_flow()
|
|
165
|
-
|
|
166
152
|
@property
|
|
167
153
|
def com_height(self)->float:
|
|
168
154
|
# odom.position.z - terrain_height = com_height
|
|
@@ -187,27 +173,6 @@ class KuavoRobotStateCore:
|
|
|
187
173
|
self._arm_ctrl_mode = mode
|
|
188
174
|
return self._arm_ctrl_mode
|
|
189
175
|
|
|
190
|
-
@property
|
|
191
|
-
def manipulation_mpc_ctrl_mode(self)->KuavoManipulationMpcCtrlMode:
|
|
192
|
-
mode = self._srv_get_manipulation_mpc_ctrl_mode()
|
|
193
|
-
if mode is not None:
|
|
194
|
-
self._manipulation_mpc_ctrl_mode = mode
|
|
195
|
-
return self._manipulation_mpc_ctrl_mode
|
|
196
|
-
|
|
197
|
-
@property
|
|
198
|
-
def manipulation_mpc_frame(self)->KuavoManipulationMpcFrame:
|
|
199
|
-
frame = self._srv_get_manipulation_mpc_frame()
|
|
200
|
-
if frame is not None:
|
|
201
|
-
self._manipulation_mpc_frame = frame
|
|
202
|
-
return self._manipulation_mpc_frame
|
|
203
|
-
|
|
204
|
-
@property
|
|
205
|
-
def manipulation_mpc_control_flow(self)->KuavoManipulationMpcControlFlow:
|
|
206
|
-
flow = self._srv_get_manipulation_mpc_control_flow()
|
|
207
|
-
if flow is not None:
|
|
208
|
-
self._manipulation_mpc_control_flow = flow
|
|
209
|
-
return self._manipulation_mpc_control_flow
|
|
210
|
-
|
|
211
176
|
@property
|
|
212
177
|
def eef_state(self)->Tuple[EndEffectorState, EndEffectorState]:
|
|
213
178
|
return self._eef_state
|
|
@@ -277,10 +242,10 @@ class KuavoRobotStateCore:
|
|
|
277
242
|
self._gait_changed_callbacks.append(callback)
|
|
278
243
|
|
|
279
244
|
""" ------------------------------- callback ------------------------------- """
|
|
280
|
-
def _terrain_height_callback(self, msg)->None:
|
|
245
|
+
def _terrain_height_callback(self, msg:Float64)->None:
|
|
281
246
|
self._terrain_height = msg.data
|
|
282
247
|
|
|
283
|
-
def _sensors_data_raw_callback(self, msg)->None:
|
|
248
|
+
def _sensors_data_raw_callback(self, msg:sensorsData)->None:
|
|
284
249
|
# update imu data
|
|
285
250
|
self._imu_data = KuavoImuData(
|
|
286
251
|
gyro = (msg.imu_data.gyro.x, msg.imu_data.gyro.y, msg.imu_data.gyro.z),
|
|
@@ -296,7 +261,7 @@ class KuavoRobotStateCore:
|
|
|
296
261
|
acceleration = copy.deepcopy(msg.joint_data.joint_current if hasattr(msg.joint_data, 'joint_current') else msg.joint_data.joint_torque)
|
|
297
262
|
)
|
|
298
263
|
|
|
299
|
-
def _odom_callback(self, msg)->None:
|
|
264
|
+
def _odom_callback(self, msg:Odometry)->None:
|
|
300
265
|
# update odom data
|
|
301
266
|
self._odom_data = KuavoOdometry(
|
|
302
267
|
position = (msg.pose.pose.position.x, msg.pose.pose.position.y, msg.pose.pose.position.z),
|
|
@@ -305,7 +270,7 @@ class KuavoRobotStateCore:
|
|
|
305
270
|
angular = (msg.twist.twist.angular.x, msg.twist.twist.angular.y, msg.twist.twist.angular.z)
|
|
306
271
|
)
|
|
307
272
|
|
|
308
|
-
def _lejuclaw_state_callback(self, msg)->None:
|
|
273
|
+
def _lejuclaw_state_callback(self, msg:lejuClawState)->None:
|
|
309
274
|
self._eef_state = (EndEffectorState(
|
|
310
275
|
# left claw
|
|
311
276
|
position = [msg.data.position[0]],
|
|
@@ -320,7 +285,7 @@ class KuavoRobotStateCore:
|
|
|
320
285
|
state=EndEffectorState.GraspingState(msg.state[1])
|
|
321
286
|
))
|
|
322
287
|
|
|
323
|
-
def _dexterous_hand_state_callback(self, msg)->None:
|
|
288
|
+
def _dexterous_hand_state_callback(self, msg:JointState)->None:
|
|
324
289
|
self._eef_state = (EndEffectorState(
|
|
325
290
|
# left hand
|
|
326
291
|
position = list(msg.position[:len(msg.position)//2]),
|
|
@@ -335,7 +300,7 @@ class KuavoRobotStateCore:
|
|
|
335
300
|
state=EndEffectorState.GraspingState.UNKNOWN
|
|
336
301
|
))
|
|
337
302
|
|
|
338
|
-
def _dexhand_touch_state_callback(self, msg)->None:
|
|
303
|
+
def _dexhand_touch_state_callback(self, msg:dexhandTouchState)->None:
|
|
339
304
|
# Update touch state for both hands
|
|
340
305
|
self._dexhand_touch_state = (
|
|
341
306
|
KuavoDexHandTouchState(
|
|
@@ -358,7 +323,7 @@ class KuavoRobotStateCore:
|
|
|
358
323
|
) # Right hand touch state
|
|
359
324
|
)
|
|
360
325
|
|
|
361
|
-
def _humanoid_mpc_gait_changed_callback(self, msg):
|
|
326
|
+
def _humanoid_mpc_gait_changed_callback(self, msg: gaitTimeName):
|
|
362
327
|
"""
|
|
363
328
|
Callback function for gait change messages.
|
|
364
329
|
Updates the current gait name when a gait change occurs.
|
|
@@ -366,7 +331,7 @@ class KuavoRobotStateCore:
|
|
|
366
331
|
SDKLogger.debug(f"[State] Received gait change message: {msg.gait_name} at time {msg.start_time}")
|
|
367
332
|
self._gait_manager.add(msg.start_time, msg.gait_name)
|
|
368
333
|
|
|
369
|
-
def _humanoid_mpc_observation_callback(self, msg) -> None:
|
|
334
|
+
def _humanoid_mpc_observation_callback(self, msg: mpc_observation) -> None:
|
|
370
335
|
"""
|
|
371
336
|
Callback function for MPC observation messages.
|
|
372
337
|
Updates the current MPC state and input data.
|
|
@@ -413,505 +378,3 @@ class KuavoRobotStateCore:
|
|
|
413
378
|
except Exception as e:
|
|
414
379
|
SDKLogger.error(f"Service call failed: {e}")
|
|
415
380
|
return None
|
|
416
|
-
|
|
417
|
-
def _srv_get_manipulation_mpc_ctrl_mode(self, )->KuavoManipulationMpcCtrlMode:
|
|
418
|
-
try:
|
|
419
|
-
service_name = '/mobile_manipulator_get_mpc_control_mode'
|
|
420
|
-
rospy.wait_for_service(service_name, timeout=2.0)
|
|
421
|
-
get_mode_srv = rospy.ServiceProxy(service_name, changeTorsoCtrlMode)
|
|
422
|
-
|
|
423
|
-
req = changeTorsoCtrlModeRequest()
|
|
424
|
-
|
|
425
|
-
resp = get_mode_srv(req)
|
|
426
|
-
if not resp.result:
|
|
427
|
-
SDKLogger.error(f"Failed to get manipulation mpc control mode: {resp.message}")
|
|
428
|
-
return KuavoManipulationMpcCtrlMode.ERROR
|
|
429
|
-
return KuavoManipulationMpcCtrlMode(resp.mode)
|
|
430
|
-
except rospy.ServiceException as e:
|
|
431
|
-
SDKLogger.error(f"Service call to {service_name} failed: {e}")
|
|
432
|
-
except rospy.ROSException as e: # For timeout from wait_for_service
|
|
433
|
-
SDKLogger.error(f"Failed to connect to service {service_name}: {e}")
|
|
434
|
-
except Exception as e:
|
|
435
|
-
SDKLogger.error(f"Failed to get manipulation mpc control mode: {e}")
|
|
436
|
-
return KuavoManipulationMpcCtrlMode.ERROR
|
|
437
|
-
|
|
438
|
-
def _srv_get_manipulation_mpc_frame(self, )->KuavoManipulationMpcFrame:
|
|
439
|
-
try:
|
|
440
|
-
service_name = '/get_mm_ctrl_frame'
|
|
441
|
-
rospy.wait_for_service(service_name, timeout=2.0)
|
|
442
|
-
get_frame_srv = rospy.ServiceProxy(service_name, setMmCtrlFrame)
|
|
443
|
-
|
|
444
|
-
req = setMmCtrlFrameRequest()
|
|
445
|
-
|
|
446
|
-
resp = get_frame_srv(req)
|
|
447
|
-
if not resp.result:
|
|
448
|
-
SDKLogger.error(f"Failed to get manipulation mpc frame: {resp.message}")
|
|
449
|
-
return KuavoManipulationMpcFrame.ERROR
|
|
450
|
-
return KuavoManipulationMpcFrame(resp.currentFrame)
|
|
451
|
-
except rospy.ServiceException as e:
|
|
452
|
-
SDKLogger.error(f"Service call to {service_name} failed: {e}")
|
|
453
|
-
except rospy.ROSException as e: # For timeout from wait_for_service
|
|
454
|
-
SDKLogger.error(f"Failed to connect to service {service_name}: {e}")
|
|
455
|
-
except Exception as e:
|
|
456
|
-
SDKLogger.error(f"Failed to get manipulation mpc frame: {e}")
|
|
457
|
-
return KuavoManipulationMpcFrame.ERROR
|
|
458
|
-
|
|
459
|
-
def _srv_get_manipulation_mpc_control_flow(self, )->KuavoManipulationMpcControlFlow:
|
|
460
|
-
try:
|
|
461
|
-
service_name = '/get_mm_wbc_arm_trajectory_control'
|
|
462
|
-
rospy.wait_for_service(service_name, timeout=2.0)
|
|
463
|
-
get_mode_srv = rospy.ServiceProxy(service_name, changeArmCtrlMode)
|
|
464
|
-
|
|
465
|
-
req = changeArmCtrlModeRequest()
|
|
466
|
-
|
|
467
|
-
resp = get_mode_srv(req)
|
|
468
|
-
if not resp.result:
|
|
469
|
-
SDKLogger.error(f"Failed to get manipulation mpc wbc arm trajectory control mode: {resp.message}")
|
|
470
|
-
return KuavoManipulationMpcControlFlow.Error
|
|
471
|
-
return KuavoManipulationMpcControlFlow(resp.mode)
|
|
472
|
-
except rospy.ServiceException as e:
|
|
473
|
-
SDKLogger.error(f"Service call to {service_name} failed: {e}")
|
|
474
|
-
except rospy.ROSException as e: # For timeout from wait_for_service
|
|
475
|
-
SDKLogger.error(f"Failed to connect to service {service_name}: {e}")
|
|
476
|
-
except Exception as e:
|
|
477
|
-
SDKLogger.error(f"Failed to get manipulation mpc wbc arm trajectory control mode: {e}")
|
|
478
|
-
return KuavoManipulationMpcControlFlow.Error
|
|
479
|
-
|
|
480
|
-
def _srv_get_manipulation_mpc_ctrl_mode(self, )->KuavoManipulationMpcCtrlMode:
|
|
481
|
-
try:
|
|
482
|
-
service_name = '/mobile_manipulator_get_mpc_control_mode'
|
|
483
|
-
rospy.wait_for_service(service_name, timeout=2.0)
|
|
484
|
-
get_mode_srv = rospy.ServiceProxy(service_name, changeTorsoCtrlMode)
|
|
485
|
-
|
|
486
|
-
req = changeTorsoCtrlModeRequest()
|
|
487
|
-
|
|
488
|
-
resp = get_mode_srv(req)
|
|
489
|
-
if not resp.result:
|
|
490
|
-
SDKLogger.error(f"Failed to get manipulation mpc control mode: {resp.message}")
|
|
491
|
-
return KuavoManipulationMpcCtrlMode.ERROR
|
|
492
|
-
return KuavoManipulationMpcCtrlMode(resp.mode)
|
|
493
|
-
except rospy.ServiceException as e:
|
|
494
|
-
SDKLogger.error(f"Service call to {service_name} failed: {e}")
|
|
495
|
-
except rospy.ROSException as e: # For timeout from wait_for_service
|
|
496
|
-
SDKLogger.error(f"Failed to connect to service {service_name}: {e}")
|
|
497
|
-
except Exception as e:
|
|
498
|
-
SDKLogger.error(f"Failed to get manipulation mpc control mode: {e}")
|
|
499
|
-
return KuavoManipulationMpcCtrlMode.ERROR
|
|
500
|
-
|
|
501
|
-
def _srv_get_manipulation_mpc_frame(self, )->KuavoManipulationMpcFrame:
|
|
502
|
-
try:
|
|
503
|
-
service_name = '/get_mm_ctrl_frame'
|
|
504
|
-
rospy.wait_for_service(service_name, timeout=2.0)
|
|
505
|
-
get_frame_srv = rospy.ServiceProxy(service_name, setMmCtrlFrame)
|
|
506
|
-
|
|
507
|
-
req = setMmCtrlFrameRequest()
|
|
508
|
-
|
|
509
|
-
resp = get_frame_srv(req)
|
|
510
|
-
if not resp.result:
|
|
511
|
-
SDKLogger.error(f"Failed to get manipulation mpc frame: {resp.message}")
|
|
512
|
-
return KuavoManipulationMpcFrame.ERROR
|
|
513
|
-
return KuavoManipulationMpcFrame(resp.currentFrame)
|
|
514
|
-
except rospy.ServiceException as e:
|
|
515
|
-
SDKLogger.error(f"Service call to {service_name} failed: {e}")
|
|
516
|
-
except rospy.ROSException as e: # For timeout from wait_for_service
|
|
517
|
-
SDKLogger.error(f"Failed to connect to service {service_name}: {e}")
|
|
518
|
-
except Exception as e:
|
|
519
|
-
SDKLogger.error(f"Failed to get manipulation mpc frame: {e}")
|
|
520
|
-
return KuavoManipulationMpcFrame.ERROR
|
|
521
|
-
|
|
522
|
-
def _srv_get_manipulation_mpc_control_flow(self, )->KuavoManipulationMpcControlFlow:
|
|
523
|
-
try:
|
|
524
|
-
service_name = '/get_mm_wbc_arm_trajectory_control'
|
|
525
|
-
rospy.wait_for_service(service_name, timeout=2.0)
|
|
526
|
-
get_mode_srv = rospy.ServiceProxy(service_name, changeArmCtrlMode)
|
|
527
|
-
|
|
528
|
-
req = changeArmCtrlModeRequest()
|
|
529
|
-
|
|
530
|
-
resp = get_mode_srv(req)
|
|
531
|
-
if not resp.result:
|
|
532
|
-
SDKLogger.error(f"Failed to get manipulation mpc wbc arm trajectory control mode: {resp.message}")
|
|
533
|
-
return KuavoManipulationMpcControlFlow.Error
|
|
534
|
-
return KuavoManipulationMpcControlFlow(resp.mode)
|
|
535
|
-
except rospy.ServiceException as e:
|
|
536
|
-
SDKLogger.error(f"Service call to {service_name} failed: {e}")
|
|
537
|
-
except rospy.ROSException as e: # For timeout from wait_for_service
|
|
538
|
-
SDKLogger.error(f"Failed to connect to service {service_name}: {e}")
|
|
539
|
-
except Exception as e:
|
|
540
|
-
SDKLogger.error(f"Failed to get manipulation mpc wbc arm trajectory control mode: {e}")
|
|
541
|
-
return KuavoManipulationMpcControlFlow.Error
|
|
542
|
-
|
|
543
|
-
def _srv_get_manipulation_mpc_ctrl_mode(self, )->KuavoManipulationMpcCtrlMode:
|
|
544
|
-
try:
|
|
545
|
-
service_name = '/mobile_manipulator_get_mpc_control_mode'
|
|
546
|
-
rospy.wait_for_service(service_name, timeout=2.0)
|
|
547
|
-
get_mode_srv = rospy.ServiceProxy(service_name, changeTorsoCtrlMode)
|
|
548
|
-
|
|
549
|
-
req = changeTorsoCtrlModeRequest()
|
|
550
|
-
|
|
551
|
-
resp = get_mode_srv(req)
|
|
552
|
-
if not resp.result:
|
|
553
|
-
SDKLogger.error(f"Failed to get manipulation mpc control mode: {resp.message}")
|
|
554
|
-
return KuavoManipulationMpcCtrlMode.ERROR
|
|
555
|
-
return KuavoManipulationMpcCtrlMode(resp.mode)
|
|
556
|
-
except rospy.ServiceException as e:
|
|
557
|
-
SDKLogger.error(f"Service call to {service_name} failed: {e}")
|
|
558
|
-
except rospy.ROSException as e: # For timeout from wait_for_service
|
|
559
|
-
SDKLogger.error(f"Failed to connect to service {service_name}: {e}")
|
|
560
|
-
except Exception as e:
|
|
561
|
-
SDKLogger.error(f"Failed to get manipulation mpc control mode: {e}")
|
|
562
|
-
return KuavoManipulationMpcCtrlMode.ERROR
|
|
563
|
-
|
|
564
|
-
def _srv_get_manipulation_mpc_frame(self, )->KuavoManipulationMpcFrame:
|
|
565
|
-
try:
|
|
566
|
-
service_name = '/get_mm_ctrl_frame'
|
|
567
|
-
rospy.wait_for_service(service_name, timeout=2.0)
|
|
568
|
-
get_frame_srv = rospy.ServiceProxy(service_name, setMmCtrlFrame)
|
|
569
|
-
|
|
570
|
-
req = setMmCtrlFrameRequest()
|
|
571
|
-
|
|
572
|
-
resp = get_frame_srv(req)
|
|
573
|
-
if not resp.result:
|
|
574
|
-
SDKLogger.error(f"Failed to get manipulation mpc frame: {resp.message}")
|
|
575
|
-
return KuavoManipulationMpcFrame.ERROR
|
|
576
|
-
return KuavoManipulationMpcFrame(resp.currentFrame)
|
|
577
|
-
except rospy.ServiceException as e:
|
|
578
|
-
SDKLogger.error(f"Service call to {service_name} failed: {e}")
|
|
579
|
-
except rospy.ROSException as e: # For timeout from wait_for_service
|
|
580
|
-
SDKLogger.error(f"Failed to connect to service {service_name}: {e}")
|
|
581
|
-
except Exception as e:
|
|
582
|
-
SDKLogger.error(f"Failed to get manipulation mpc frame: {e}")
|
|
583
|
-
return KuavoManipulationMpcFrame.ERROR
|
|
584
|
-
|
|
585
|
-
def _srv_get_manipulation_mpc_control_flow(self, )->KuavoManipulationMpcControlFlow:
|
|
586
|
-
try:
|
|
587
|
-
service_name = '/get_mm_wbc_arm_trajectory_control'
|
|
588
|
-
rospy.wait_for_service(service_name, timeout=2.0)
|
|
589
|
-
get_mode_srv = rospy.ServiceProxy(service_name, changeArmCtrlMode)
|
|
590
|
-
|
|
591
|
-
req = changeArmCtrlModeRequest()
|
|
592
|
-
|
|
593
|
-
resp = get_mode_srv(req)
|
|
594
|
-
if not resp.result:
|
|
595
|
-
SDKLogger.error(f"Failed to get manipulation mpc wbc arm trajectory control mode: {resp.message}")
|
|
596
|
-
return KuavoManipulationMpcControlFlow.Error
|
|
597
|
-
return KuavoManipulationMpcControlFlow(resp.mode)
|
|
598
|
-
except rospy.ServiceException as e:
|
|
599
|
-
SDKLogger.error(f"Service call to {service_name} failed: {e}")
|
|
600
|
-
except rospy.ROSException as e: # For timeout from wait_for_service
|
|
601
|
-
SDKLogger.error(f"Failed to connect to service {service_name}: {e}")
|
|
602
|
-
except Exception as e:
|
|
603
|
-
SDKLogger.error(f"Failed to get manipulation mpc wbc arm trajectory control mode: {e}")
|
|
604
|
-
return KuavoManipulationMpcControlFlow.Error
|
|
605
|
-
class KuavoRobotStateCoreWebsocket:
|
|
606
|
-
_instance = None
|
|
607
|
-
|
|
608
|
-
def __new__(cls, *args, **kwargs):
|
|
609
|
-
if not cls._instance:
|
|
610
|
-
cls._instance = super().__new__(cls)
|
|
611
|
-
return cls._instance
|
|
612
|
-
|
|
613
|
-
def __init__(self):
|
|
614
|
-
if not hasattr(self, '_initialized'):
|
|
615
|
-
try:
|
|
616
|
-
self.websocket = WebSocketKuavoSDK()
|
|
617
|
-
if not self.websocket.client.is_connected:
|
|
618
|
-
SDKLogger.error("Failed to connect to WebSocket server")
|
|
619
|
-
raise ConnectionError("Failed to connect to WebSocket server")
|
|
620
|
-
|
|
621
|
-
# Initialize subscribers
|
|
622
|
-
self._sub_sensors_data = roslibpy.Topic(self.websocket.client, '/sensors_data_raw', 'kuavo_msgs/sensorsData')
|
|
623
|
-
self._sub_odom = roslibpy.Topic(self.websocket.client, '/odom', 'nav_msgs/Odometry')
|
|
624
|
-
self._sub_terrain_height = roslibpy.Topic(self.websocket.client, '/humanoid/mpc/terrainHeight', 'std_msgs/Float64')
|
|
625
|
-
self._sub_gait_time_name = roslibpy.Topic(self.websocket.client, '/humanoid_mpc_gait_time_name', 'kuavo_msgs/gaitTimeName')
|
|
626
|
-
self._sub_mpc_observation = roslibpy.Topic(self.websocket.client, '/humanoid_mpc_observation', 'ocs2_msgs/mpc_observation')
|
|
627
|
-
|
|
628
|
-
# service calls are time-consuming after subscription, place them before subscription
|
|
629
|
-
kuavo_info = make_robot_param()
|
|
630
|
-
|
|
631
|
-
# Subscribe to topics
|
|
632
|
-
self._sub_sensors_data.subscribe(self._sensors_data_raw_callback)
|
|
633
|
-
self._sub_odom.subscribe(self._odom_callback)
|
|
634
|
-
self._sub_terrain_height.subscribe(self._terrain_height_callback)
|
|
635
|
-
self._sub_gait_time_name.subscribe(self._humanoid_mpc_gait_changed_callback)
|
|
636
|
-
self._sub_mpc_observation.subscribe(self._humanoid_mpc_observation_callback)
|
|
637
|
-
|
|
638
|
-
if kuavo_info is None:
|
|
639
|
-
SDKLogger.error("Failed to get robot parameters")
|
|
640
|
-
raise RuntimeError("Failed to get robot parameters")
|
|
641
|
-
|
|
642
|
-
self._ee_type = kuavo_info['end_effector_type']
|
|
643
|
-
if self._ee_type == EndEffectorType.LEJUCLAW:
|
|
644
|
-
self._sub_lejuclaw_state = roslibpy.Topic(self.websocket.client, '/leju_claw_state', 'kuavo_msgs/lejuClawState')
|
|
645
|
-
self._sub_lejuclaw_state.subscribe(self._lejuclaw_state_callback)
|
|
646
|
-
elif self._ee_type == EndEffectorType.QIANGNAO:
|
|
647
|
-
self._sub_dexhand_state = roslibpy.Topic(self.websocket.client, '/dexhand/state', 'sensor_msgs/JointState')
|
|
648
|
-
self._sub_dexhand_state.subscribe(self._dexterous_hand_state_callback)
|
|
649
|
-
elif self._ee_type == EndEffectorType.QIANGNAO_TOUCH:
|
|
650
|
-
self._sub_dexhand_state = roslibpy.Topic(self.websocket.client, '/dexhand/state', 'sensor_msgs/JointState')
|
|
651
|
-
self._sub_dexhand_touch_state = roslibpy.Topic(self.websocket.client, '/dexhand/touch_state', 'kuavo_msgs/dexhandTouchState')
|
|
652
|
-
self._sub_dexhand_state.subscribe(self._dexterous_hand_state_callback)
|
|
653
|
-
self._sub_dexhand_touch_state.subscribe(self._dexhand_touch_state_callback)
|
|
654
|
-
# Initialize touch state for both hands
|
|
655
|
-
self._dexhand_touch_state = (
|
|
656
|
-
KuavoDexHandTouchState(
|
|
657
|
-
data=(KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
|
658
|
-
KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
|
659
|
-
KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
|
660
|
-
KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
|
661
|
-
KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
|
|
662
|
-
),
|
|
663
|
-
KuavoDexHandTouchState(
|
|
664
|
-
data=(KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
|
665
|
-
KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
|
666
|
-
KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
|
667
|
-
KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
|
668
|
-
KuavoDexHandTouchState.KuavoTouchState(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
|
|
669
|
-
)
|
|
670
|
-
)
|
|
671
|
-
|
|
672
|
-
""" data """
|
|
673
|
-
self._terrain_height = 0.0
|
|
674
|
-
self._imu_data = KuavoImuData(
|
|
675
|
-
gyro = (0.0, 0.0, 0.0),
|
|
676
|
-
acc = (0.0, 0.0, 0.0),
|
|
677
|
-
free_acc = (0.0, 0.0, 0.0),
|
|
678
|
-
quat = (0.0, 0.0, 0.0, 0.0)
|
|
679
|
-
)
|
|
680
|
-
self._joint_data = KuavoJointData(
|
|
681
|
-
position = [0.0] * 28,
|
|
682
|
-
velocity = [0.0] * 28,
|
|
683
|
-
torque = [0.0] * 28,
|
|
684
|
-
acceleration = [0.0] * 28
|
|
685
|
-
)
|
|
686
|
-
self._odom_data = KuavoOdometry(
|
|
687
|
-
position = (0.0, 0.0, 0.0),
|
|
688
|
-
orientation = (0.0, 0.0, 0.0, 0.0),
|
|
689
|
-
linear = (0.0, 0.0, 0.0),
|
|
690
|
-
angular = (0.0, 0.0, 0.0)
|
|
691
|
-
)
|
|
692
|
-
self._eef_state = (EndEffectorState(
|
|
693
|
-
position = [0.0] * 12 if kuavo_info['end_effector_type'].startswith('qiangnao') else [0.0] * 2,
|
|
694
|
-
velocity = [0.0] * 12 if kuavo_info['end_effector_type'].startswith('qiangnao') else [0.0] * 2,
|
|
695
|
-
effort = [0.0] * 12 if kuavo_info['end_effector_type'].startswith('qiangnao') else [0.0] * 2,
|
|
696
|
-
state=EndEffectorState.GraspingState.UNKNOWN
|
|
697
|
-
), EndEffectorState(
|
|
698
|
-
position = [0.0] * 12 if kuavo_info['end_effector_type'].startswith('qiangnao') else [0.0] * 2,
|
|
699
|
-
velocity = [0.0] * 12 if kuavo_info['end_effector_type'].startswith('qiangnao') else [0.0] * 2,
|
|
700
|
-
effort = [0.0] * 12 if kuavo_info['end_effector_type'].startswith('qiangnao') else [0.0] * 2,
|
|
701
|
-
state=EndEffectorState.GraspingState.UNKNOWN
|
|
702
|
-
))
|
|
703
|
-
|
|
704
|
-
# gait manager
|
|
705
|
-
self._gait_manager = GaitManager()
|
|
706
|
-
self._prev_gait_name = self.gait_name
|
|
707
|
-
|
|
708
|
-
# Wait for first MPC observation data
|
|
709
|
-
self._mpc_observation_data = None
|
|
710
|
-
start_time = time.time()
|
|
711
|
-
while self._mpc_observation_data is None:
|
|
712
|
-
if time.time() - start_time > 1.0: # 1.0s timeout
|
|
713
|
-
SDKLogger.warn("Timeout waiting for MPC observation data")
|
|
714
|
-
break
|
|
715
|
-
SDKLogger.debug("Waiting for first MPC observation data...")
|
|
716
|
-
time.sleep(0.1)
|
|
717
|
-
|
|
718
|
-
if self._mpc_observation_data is not None:
|
|
719
|
-
if self._gait_manager.is_empty:
|
|
720
|
-
self._prev_gait_name = self.gait_name()
|
|
721
|
-
SDKLogger.debug(f"[State] Adding initial gait state: {self._prev_gait_name} at time {self._mpc_observation_data['time']}")
|
|
722
|
-
self._gait_manager.add(self._mpc_observation_data['time'], self._prev_gait_name)
|
|
723
|
-
|
|
724
|
-
# 获取当前手臂控制模式
|
|
725
|
-
self._arm_ctrl_mode = self._srv_get_arm_ctrl_mode()
|
|
726
|
-
self._initialized = True
|
|
727
|
-
except Exception as e:
|
|
728
|
-
SDKLogger.error(f"Failed to initialize KuavoRobotStateCoreWebsocket: {e}")
|
|
729
|
-
raise
|
|
730
|
-
|
|
731
|
-
@property
|
|
732
|
-
def com_height(self)->float:
|
|
733
|
-
return self._odom_data.position[2] - self._terrain_height
|
|
734
|
-
|
|
735
|
-
@property
|
|
736
|
-
def imu_data(self)->KuavoImuData:
|
|
737
|
-
return self._imu_data
|
|
738
|
-
|
|
739
|
-
@property
|
|
740
|
-
def joint_data(self)->KuavoJointData:
|
|
741
|
-
return self._joint_data
|
|
742
|
-
|
|
743
|
-
@property
|
|
744
|
-
def odom_data(self)->KuavoOdometry:
|
|
745
|
-
return self._odom_data
|
|
746
|
-
|
|
747
|
-
@property
|
|
748
|
-
def arm_control_mode(self) -> KuavoArmCtrlMode:
|
|
749
|
-
mode = self._srv_get_arm_ctrl_mode()
|
|
750
|
-
if mode is not None:
|
|
751
|
-
self._arm_ctrl_mode = mode
|
|
752
|
-
return self._arm_ctrl_mode
|
|
753
|
-
|
|
754
|
-
@property
|
|
755
|
-
def eef_state(self)->Tuple[EndEffectorState, EndEffectorState]:
|
|
756
|
-
return self._eef_state
|
|
757
|
-
|
|
758
|
-
@property
|
|
759
|
-
def dexhand_touch_state(self)-> Tuple[KuavoDexHandTouchState, KuavoDexHandTouchState]:
|
|
760
|
-
if self._ee_type != EndEffectorType.QIANGNAO_TOUCH:
|
|
761
|
-
raise Exception("This robot does not support touch state")
|
|
762
|
-
return self._dexhand_touch_state
|
|
763
|
-
|
|
764
|
-
@property
|
|
765
|
-
def current_observation_time(self) -> float:
|
|
766
|
-
if self._mpc_observation_data is None:
|
|
767
|
-
return None
|
|
768
|
-
return self._mpc_observation_data.time
|
|
769
|
-
|
|
770
|
-
@property
|
|
771
|
-
def current_gait_mode(self) -> int:
|
|
772
|
-
if self._mpc_observation_data is None:
|
|
773
|
-
return None
|
|
774
|
-
return self._mpc_observation_data.mode
|
|
775
|
-
|
|
776
|
-
def gait_name(self)->str:
|
|
777
|
-
return self._srv_get_current_gait_name()
|
|
778
|
-
|
|
779
|
-
def is_gait(self, gait_name: str) -> bool:
|
|
780
|
-
return self._gait_manager.get_gait(self._mpc_observation_data['time']) == gait_name
|
|
781
|
-
|
|
782
|
-
def register_gait_changed_callback(self, callback):
|
|
783
|
-
if not hasattr(self, '_gait_changed_callbacks'):
|
|
784
|
-
self._gait_changed_callbacks = []
|
|
785
|
-
|
|
786
|
-
from inspect import signature
|
|
787
|
-
sig = signature(callback)
|
|
788
|
-
if len(sig.parameters) != 2:
|
|
789
|
-
raise ValueError("Callback must accept 2 parameters: current_time (float), gait_name (str)")
|
|
790
|
-
if callback not in self._gait_changed_callbacks:
|
|
791
|
-
self._gait_changed_callbacks.append(callback)
|
|
792
|
-
|
|
793
|
-
def _terrain_height_callback(self, msg)->None:
|
|
794
|
-
self._terrain_height = msg['data']
|
|
795
|
-
|
|
796
|
-
def _sensors_data_raw_callback(self, msg)->None:
|
|
797
|
-
# update imu data
|
|
798
|
-
self._imu_data = KuavoImuData(
|
|
799
|
-
gyro = (msg['imu_data']['gyro']['x'], msg['imu_data']['gyro']['y'], msg['imu_data']['gyro']['z']),
|
|
800
|
-
acc = (msg['imu_data']['acc']['x'], msg['imu_data']['acc']['y'], msg['imu_data']['acc']['z']),
|
|
801
|
-
free_acc = (msg['imu_data']['free_acc']['x'], msg['imu_data']['free_acc']['y'], msg['imu_data']['free_acc']['z']),
|
|
802
|
-
quat = (msg['imu_data']['quat']['x'], msg['imu_data']['quat']['y'], msg['imu_data']['quat']['z'], msg['imu_data']['quat']['w'])
|
|
803
|
-
)
|
|
804
|
-
# update joint data
|
|
805
|
-
self._joint_data = KuavoJointData(
|
|
806
|
-
position = copy.deepcopy(msg['joint_data']['joint_q']),
|
|
807
|
-
velocity = copy.deepcopy(msg['joint_data']['joint_v']),
|
|
808
|
-
torque = copy.deepcopy(msg['joint_data']['joint_vd']),
|
|
809
|
-
acceleration = copy.deepcopy(msg['joint_data'].get('joint_current', msg['joint_data']['joint_torque']))
|
|
810
|
-
)
|
|
811
|
-
|
|
812
|
-
def _odom_callback(self, msg)->None:
|
|
813
|
-
# update odom data
|
|
814
|
-
self._odom_data = KuavoOdometry(
|
|
815
|
-
position = (msg['pose']['pose']['position']['x'], msg['pose']['pose']['position']['y'], msg['pose']['pose']['position']['z']),
|
|
816
|
-
orientation = (msg['pose']['pose']['orientation']['x'], msg['pose']['pose']['orientation']['y'], msg['pose']['pose']['orientation']['z'], msg['pose']['pose']['orientation']['w']),
|
|
817
|
-
linear = (msg['twist']['twist']['linear']['x'], msg['twist']['twist']['linear']['y'], msg['twist']['twist']['linear']['z']),
|
|
818
|
-
angular = (msg['twist']['twist']['angular']['x'], msg['twist']['twist']['angular']['y'], msg['twist']['twist']['angular']['z'])
|
|
819
|
-
)
|
|
820
|
-
|
|
821
|
-
def _lejuclaw_state_callback(self, msg)->None:
|
|
822
|
-
self._eef_state = (EndEffectorState(
|
|
823
|
-
position = [msg['data']['position'][0]],
|
|
824
|
-
velocity = [msg['data']['velocity'][0]],
|
|
825
|
-
effort = [msg['data']['effort'][0]],
|
|
826
|
-
state=EndEffectorState.GraspingState(msg['state'][0])
|
|
827
|
-
), EndEffectorState(
|
|
828
|
-
position = [msg['data']['position'][1]],
|
|
829
|
-
velocity = [msg['data']['velocity'][1]],
|
|
830
|
-
effort = [msg['data']['effort'][1]],
|
|
831
|
-
state=EndEffectorState.GraspingState(msg['state'][1])
|
|
832
|
-
))
|
|
833
|
-
|
|
834
|
-
def _dexterous_hand_state_callback(self, msg)->None:
|
|
835
|
-
self._eef_state = (EndEffectorState(
|
|
836
|
-
position = list(msg['position'][:len(msg['position'])//2]),
|
|
837
|
-
velocity = list(msg['velocity'][:len(msg['velocity'])//2]),
|
|
838
|
-
effort = list(msg['effort'][:len(msg['effort'])//2]),
|
|
839
|
-
state=EndEffectorState.GraspingState.UNKNOWN
|
|
840
|
-
), EndEffectorState(
|
|
841
|
-
position = list(msg['position'][len(msg['position'])//2:]),
|
|
842
|
-
velocity = list(msg['velocity'][len(msg['velocity'])//2:]),
|
|
843
|
-
effort = list(msg['effort'][len(msg['effort'])//2:]),
|
|
844
|
-
state=EndEffectorState.GraspingState.UNKNOWN
|
|
845
|
-
))
|
|
846
|
-
|
|
847
|
-
def _dexhand_touch_state_callback(self, msg)->None:
|
|
848
|
-
self._dexhand_touch_state = (
|
|
849
|
-
KuavoDexHandTouchState(
|
|
850
|
-
data=tuple(KuavoDexHandTouchState.KuavoTouchState(
|
|
851
|
-
sensor['normal_force1'], sensor['normal_force2'], sensor['normal_force3'],
|
|
852
|
-
sensor['tangential_force1'], sensor['tangential_force2'], sensor['tangential_force3'],
|
|
853
|
-
sensor['tangential_direction1'], sensor['tangential_direction2'], sensor['tangential_direction3'],
|
|
854
|
-
sensor['self_proximity1'], sensor['self_proximity2'], sensor['mutual_proximity'],
|
|
855
|
-
sensor['status']
|
|
856
|
-
) for sensor in msg['left_hand'])
|
|
857
|
-
),
|
|
858
|
-
KuavoDexHandTouchState(
|
|
859
|
-
data=tuple(KuavoDexHandTouchState.KuavoTouchState(
|
|
860
|
-
sensor['normal_force1'], sensor['normal_force2'], sensor['normal_force3'],
|
|
861
|
-
sensor['tangential_force1'], sensor['tangential_force2'], sensor['tangential_force3'],
|
|
862
|
-
sensor['tangential_direction1'], sensor['tangential_direction2'], sensor['tangential_direction3'],
|
|
863
|
-
sensor['self_proximity1'], sensor['self_proximity2'], sensor['mutual_proximity'],
|
|
864
|
-
sensor['status']
|
|
865
|
-
) for sensor in msg['right_hand'])
|
|
866
|
-
)
|
|
867
|
-
)
|
|
868
|
-
|
|
869
|
-
def _humanoid_mpc_gait_changed_callback(self, msg):
|
|
870
|
-
SDKLogger.debug(f"[State] Received gait change message: {msg['gait_name']} at time {msg['start_time']}")
|
|
871
|
-
self._gait_manager.add(msg['start_time'], msg['gait_name'])
|
|
872
|
-
|
|
873
|
-
def _humanoid_mpc_observation_callback(self, msg) -> None:
|
|
874
|
-
try:
|
|
875
|
-
SDKLogger.debug(f"[State] Received MPC observation message: {msg}")
|
|
876
|
-
self._mpc_observation_data = msg
|
|
877
|
-
if hasattr(self, '_initialized'):
|
|
878
|
-
curr_time = self._mpc_observation_data['time']
|
|
879
|
-
current_gait = self._gait_manager.get_gait(curr_time)
|
|
880
|
-
if self._prev_gait_name != current_gait:
|
|
881
|
-
SDKLogger.debug(f"[State] Gait changed to: {current_gait} at time {curr_time}")
|
|
882
|
-
self._prev_gait_name = current_gait
|
|
883
|
-
if hasattr(self, '_gait_changed_callbacks') and self._gait_changed_callbacks is not None:
|
|
884
|
-
for callback in self._gait_changed_callbacks:
|
|
885
|
-
callback(curr_time, current_gait)
|
|
886
|
-
except Exception as e:
|
|
887
|
-
SDKLogger.error(f"Error processing MPC observation: {e}")
|
|
888
|
-
|
|
889
|
-
def _srv_get_arm_ctrl_mode(self)-> KuavoArmCtrlMode:
|
|
890
|
-
try:
|
|
891
|
-
service = roslibpy.Service(self.websocket.client, '/humanoid_get_arm_ctrl_mode', 'kuavo_msgs/changeArmCtrlMode')
|
|
892
|
-
request = {}
|
|
893
|
-
response = service.call(request)
|
|
894
|
-
return KuavoArmCtrlMode(response.get('mode', 0))
|
|
895
|
-
except Exception as e:
|
|
896
|
-
SDKLogger.error(f"Service call failed: {e}")
|
|
897
|
-
return None
|
|
898
|
-
|
|
899
|
-
def _srv_get_current_gait_name(self)->str:
|
|
900
|
-
try:
|
|
901
|
-
service = roslibpy.Service(self.websocket.client, '/humanoid_get_current_gait_name', 'kuavo_msgs/getCurrentGaitName')
|
|
902
|
-
request = {}
|
|
903
|
-
response = service.call(request)
|
|
904
|
-
if response.get('success', False):
|
|
905
|
-
return response['gait_name']
|
|
906
|
-
return None
|
|
907
|
-
except Exception as e:
|
|
908
|
-
SDKLogger.error(f"Service call failed: {e}")
|
|
909
|
-
return None
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
if __name__ == "__main__":
|
|
913
|
-
state = KuavoRobotStateCore()
|
|
914
|
-
print(state.manipulation_mpc_frame)
|
|
915
|
-
print(state.manipulation_mpc_control_flow)
|
|
916
|
-
print(state.manipulation_mpc_ctrl_mode)
|
|
917
|
-
print(state.arm_control_mode)
|