This commit is contained in:
linbo 2025-08-27 16:46:12 +08:00
parent bb6dbe5bdd
commit a6ab0f3790
10 changed files with 79 additions and 14 deletions

View File

@ -2,7 +2,7 @@ from .client import CMVRGrpcClient
from .enums import CMVRErrorCode, DeviceState, FingerType from .enums import CMVRErrorCode, DeviceState, FingerType
from .models import ( from .models import (
MicState, SpeakerState, CameraState, MicState, SpeakerState, CameraState,
RH56DFTPDexHand, DexHandState, FacialExpressionState, FreedomState, DexHandState, FacialExpressionState,
FingerTactileData, PalmTactileData, HandTactileSensors FingerTactileData, PalmTactileData, HandTactileSensors
) )
@ -10,6 +10,6 @@ __all__ = [
'CMVRGrpcClient', 'CMVRGrpcClient',
'CMVRErrorCode', 'DeviceState', 'FingerType', 'CMVRErrorCode', 'DeviceState', 'FingerType',
'MicState', 'SpeakerState', 'CameraState', 'MicState', 'SpeakerState', 'CameraState',
'RH56DFTPDexHand', 'DexHandState', 'FacialExpressionState', 'FreedomState', 'DexHandState', 'FacialExpressionState',
'FingerTactileData', 'PalmTactileData', 'HandTactileSensors' 'FingerTactileData', 'PalmTactileData', 'HandTactileSensors'
] ]

View File

@ -6,7 +6,7 @@ from typing import Tuple
from .enums import CMVRErrorCode from .enums import CMVRErrorCode
from .models import CameraState from .models import CameraState
from .models import Rs2Intrinsics
class CameraClient: class CameraClient:
"""相机客户端""" """相机客户端"""
@ -116,6 +116,23 @@ class CameraClient:
# 将字节数据转换为numpy数组 # 将字节数据转换为numpy数组
img_data = np.frombuffer(response.color_frame.data, dtype=np.uint8) img_data = np.frombuffer(response.color_frame.data, dtype=np.uint8)
# 从 Protobuf 消息中读取 intrinsics 数据
protobuf_intrinsics = response.intrinsics
# 构造 Python 数据类对象(字段名称完全对应)
python_intrinsics = Rs2Intrinsics(
cx=protobuf_intrinsics.cx,
cy=protobuf_intrinsics.cy,
fx=protobuf_intrinsics.fx,
fy=protobuf_intrinsics.fy,
coeffs=list(protobuf_intrinsics.coeffs) # Protobuf repeated 字段通常是列表类型,直接转换
)
# 示例:访问读取后的数据
print(f"主点坐标: ({python_intrinsics.cx}, {python_intrinsics.cy})")
print(f"焦距: ({python_intrinsics.fx}, {python_intrinsics.fy})")
print(f"畸变系数: {python_intrinsics.coeffs}")
# 重塑为图像格式 (height, width, channels) # 重塑为图像格式 (height, width, channels)
channels = 3 # 假设是RGB图像 channels = 3 # 假设是RGB图像
if size == width * height * channels: if size == width * height * channels:

View File

@ -4,7 +4,7 @@ from typing import Tuple
from typing import Dict from typing import Dict
from .enums import CMVRErrorCode, FingerType from .enums import CMVRErrorCode, FingerType
from .models import DexHandState, RH56DFTPDexHand, HandTactileSensors from .models import DexHandState, FreedomState, HandTactileSensors
class DexHandClient: class DexHandClient:
"""灵巧手客户端""" """灵巧手客户端"""
@ -57,7 +57,7 @@ class DexHandClient:
# 填充手指状态 # 填充手指状态
for i, hand_state in enumerate(response.state.hands): for i, hand_state in enumerate(response.state.hands):
if i < len(state.hands): if i < len(state.hands):
state.hands[i] = RH56DFTPDexHand( state.hands[i] = FreedomState(
angle=hand_state.angle, angle=hand_state.angle,
speed=hand_state.speed, speed=hand_state.speed,
force=hand_state.force, force=hand_state.force,

View File

@ -30,9 +30,18 @@ class CameraState:
width: int = 0 width: int = 0
height: int = 0 height: int = 0
fps: int = 0 fps: int = 0
@dataclass
class CameraIntrinsics:
"""相机内参与Protobuf Rs2Intrinsics对齐"""
cx: float = 0.0 # 对应Protobuf tag=1
cy: float = 0.0 # 对应Protobuf tag=2
fx: float = 0.0 # 对应Protobuf tag=3
fy: float = 0.0 # 对应Protobuf tag=4
# 畸变系数固定5个元素k1, k2, p1, p2, k3与Protobuf tag=5对齐
coeffs: List[float] = field(default_factory=lambda: [0.0]*5)
@dataclass @dataclass
class RH56DFTPDexHand: class FreedomState:
"""灵巧手自由度状态""" """灵巧手自由度状态"""
dof_id: int = 0 dof_id: int = 0
angle: int = 0 angle: int = 0
@ -48,7 +57,7 @@ class RH56DFTPDexHand:
class DexHandState: class DexHandState:
"""灵巧手整体状态""" """灵巧手整体状态"""
is_initialized: bool = False is_initialized: bool = False
hands: List[RH56DFTPDexHand] = field(default_factory=lambda: [RH56DFTPDexHand() for _ in range(6)]) hands: List[FreedomState] = field(default_factory=lambda: [FreedomState() for _ in range(6)])
@dataclass @dataclass
class FacialExpressionState: class FacialExpressionState:

View File

@ -659,8 +659,8 @@ def test_microphone():
print(f"开始录音失败,错误码: {result}") print(f"开始录音失败,错误码: {result}")
if __name__ == "__main__": if __name__ == "__main__":
test_biohead() # test_biohead()
# test_camera() test_camera()
# test_rgb_image_stream() # test_rgb_image_stream()
# test_dexhand() # test_dexhand()
# test_sensor_data_stream() # test_sensor_data_stream()

View File

@ -21,6 +21,14 @@ message FrameData {
bool is_key_frame = 6; bool is_key_frame = 6;
} }
message CameraIntrinsics {
float cx = 1; //
float cy = 2; //
float fx = 3; // x方向焦距
float fy = 4; // y方向焦距
repeated float coeffs = 5 [packed = true]; // 5
}
message CameraState { message CameraState {
bool is_initialized = 1; bool is_initialized = 1;
bool is_opened = 2; bool is_opened = 2;
@ -71,6 +79,7 @@ message GetRGBImageCommand {
message Feedback { message Feedback {
CommandHeader.Feedback header = 1; CommandHeader.Feedback header = 1;
FrameData color_frame = 2; FrameData color_frame = 2;
CameraIntrinsics intrinsics = 3;
} }
} }
@ -82,6 +91,7 @@ message GetDepthImageCommand {
message Feedback { message Feedback {
CommandHeader.Feedback header = 1; CommandHeader.Feedback header = 1;
FrameData depth_frame = 2; FrameData depth_frame = 2;
CameraIntrinsics intrinsics = 3;
} }
} }
@ -94,6 +104,7 @@ message GetRGBDImagesCommand {
CommandHeader.Feedback header = 1; CommandHeader.Feedback header = 1;
FrameData color_frame = 2; FrameData color_frame = 2;
FrameData depth_frame = 3; FrameData depth_frame = 3;
CameraIntrinsics intrinsics = 4;
} }
} }
@ -126,7 +137,8 @@ message GetRGBImageStreamCommand {
message Feedback { message Feedback {
CommandHeader.Feedback header = 1; CommandHeader.Feedback header = 1;
FrameData color_frame = 2; FrameData color_frame = 2;
int32 seq_no = 3; CameraIntrinsics intrinsics = 3;
int32 seq_no = 4;
} }
} }
@ -139,7 +151,8 @@ message GetDepthImageStreamCommand {
message Feedback { message Feedback {
CommandHeader.Feedback header = 1; CommandHeader.Feedback header = 1;
FrameData depth_frame = 2; FrameData depth_frame = 2;
int32 seq_no = 3; CameraIntrinsics intrinsics = 3;
int32 seq_no = 4;
} }
} }
@ -153,7 +166,8 @@ message GetRGBDImagesStreamCommand {
CommandHeader.Feedback header = 1; CommandHeader.Feedback header = 1;
FrameData color_frame = 2; FrameData color_frame = 2;
FrameData depth_frame = 3; FrameData depth_frame = 3;
int32 seq_no = 4; CameraIntrinsics intrinsics = 4;
int32 seq_no = 5;
} }
} }

View File

@ -28,3 +28,16 @@ message CommandHeader {
google.protobuf.Timestamp timestamp = 3; // google.protobuf.Timestamp timestamp = 3; //
} }
} }
message ConfigParam {
string param_name = 1;
oneof param_value {
int32 int_value = 2; //
double double_value = 3; //
string string_value = 4; //
bool bool_value = 5; //
bytes bytes_value = 6; //
}
}

View File

@ -9,7 +9,7 @@ message FreedomValue {
float value = 2; // 0-1 float value = 2; // 0-1
} }
message RH56DFTPDexHand { message FreedomState {
int32 dof_id = 1; // ID int32 dof_id = 1; // ID
int32 angle = 2; // int32 angle = 2; //
int32 speed = 3; // int32 speed = 3; //
@ -57,7 +57,7 @@ message SensorData {
message DexHandState { message DexHandState {
bool is_initialized = 1; // bool is_initialized = 1; //
repeated RH56DFTPDexHand hands = 2; // repeated FreedomState hands = 2; //
} }
message GetDexHandStateCommand { message GetDexHandStateCommand {

View File

@ -48,3 +48,12 @@ message GetSystemStatusCommand {
repeated DeviceList device_list = 7; repeated DeviceList device_list = 7;
} }
} }
message UpdateParamsCommand {
message Request {}
message Feedback {
CommandHeader.Feedback header = 1;
repeated ConfigParam params = 2;
}
}

View File

@ -8,4 +8,7 @@ package cmvr.api;
service SystemService { service SystemService {
rpc GetSystemInfo(GetSystemInfoCommand.Request) returns (GetSystemInfoCommand.Feedback) {} rpc GetSystemInfo(GetSystemInfoCommand.Request) returns (GetSystemInfoCommand.Feedback) {}
rpc GetSystemStatus(GetSystemStatusCommand.Request) returns (GetSystemStatusCommand.Feedback) {} rpc GetSystemStatus(GetSystemStatusCommand.Request) returns (GetSystemStatusCommand.Feedback) {}
rpc UpdateParams(UpdateParamsCommand.Request) returns (UpdateParamsCommand.Feedback) {}
} }