USB 摄像头+远程遥控+中英的适配+topic的集成和状态的使用到相应页面
This commit is contained in:
@@ -35,26 +35,43 @@ class RemoteControlRepositoryImpl implements RemoteControlRepository {
|
||||
|
||||
@override
|
||||
void sendControlMachineCmd(MachineControlStatusEntity status) {
|
||||
// 1. 调用算法:将摇杆坐标 (x, y) 转换为左右轮电机转速
|
||||
// 1. 调用算法:将摇杆坐标 (x, y) 转换为线速度/角速度(物理量)
|
||||
final speeds = _diffSteer.calculate(status.originX, status.originY);
|
||||
_logger.logWithLevel(
|
||||
'⚙️ [电机速度] left: ${speeds['left']}, right: ${speeds['right']}',
|
||||
);
|
||||
final linear = speeds['linear']!;
|
||||
final angular = speeds['angular']!;
|
||||
|
||||
// 2. 调用 Codec:生成协议要求的 8 字节 Payload
|
||||
// 2. 调用 Codec:生成协议要求的 20 字节 Payload(线速度/角速度 double 直传)
|
||||
final payload = MachineProtocolCodec.encodeRemoteControlPayload(
|
||||
left: speeds['left']!,
|
||||
right: speeds['right']!,
|
||||
linear: linear,
|
||||
angular: angular,
|
||||
lift: status.chassisLift,
|
||||
mower: status.mowerSpeed,
|
||||
ignition: status.ignitionStatus,
|
||||
emergency: status.isEmergency ? 1 : 0,
|
||||
);
|
||||
|
||||
// 联调日志:三段式打印 ①滑块/摇杆原始数据 ②乘完系数的发送值 ③包装后的整帧字节(联调结束可移除)
|
||||
_logger.logWithLevel(
|
||||
'🔗 [联调-0x00] 遥控发送明细\n'
|
||||
'① 滑块/摇杆原始数据: x=${status.originX} y=${status.originY} '
|
||||
'lift=${status.chassisLift} mower=${status.mowerSpeed} '
|
||||
'ignition=${status.ignitionStatus} emergency=${status.isEmergency ? 1 : 0}\n'
|
||||
'② 乘后发送值: linear=${linear.toStringAsFixed(3)} m/s, angular=${angular.toStringAsFixed(3)} rad/s\n'
|
||||
'③ 包装后整帧(27字节): ab aa 00 | ${_hex(payload.sublist(0, 8))} | '
|
||||
'${_hex(payload.sublist(8, 16))} | ${_hex(payload.sublist(16, 20))} | 00 00 | aa ab\n'
|
||||
' 包头+cmd | linear@帧[3..10] | angular@帧[11..18] | '
|
||||
'lift,mower,ignition,emergency@帧[19..22] | CRC | 包尾',
|
||||
shouldLog: true,
|
||||
);
|
||||
|
||||
// 3. 调用 TcpClient 发送指令
|
||||
_tcpClient.sendRaw(MachineProtocolConstants.cmdRemoteControl, payload);
|
||||
}
|
||||
|
||||
/// 字节转十六进制字符串,供联调对包使用
|
||||
String _hex(List<int> bytes) =>
|
||||
bytes.map((b) => b.toRadixString(16).padLeft(2, '0')).join(' ');
|
||||
|
||||
@override
|
||||
Stream<RawPacket> get responseStream => _tcpClient.packetStream;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user