#修改远程遥控控制方式 将左右轮速改成线速度和角速度
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
package com.maibu.constant;
|
||||
|
||||
import com.maibu.core.business.DeviceRunParam;
|
||||
import com.maibu.core.enums.ConnectionCloseReason;
|
||||
import io.netty.util.AttributeKey;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Data
|
||||
import com.maibu.core.business.DeviceRunParam;
|
||||
import com.maibu.core.enums.ConnectionCloseReason;
|
||||
|
||||
import io.netty.util.AttributeKey;
|
||||
|
||||
|
||||
public class Constant {
|
||||
|
||||
public static final AttributeKey<String> ATT_DEVICE_ID = AttributeKey.valueOf("deviceId");
|
||||
|
||||
public static final AttributeKey<CompletableFuture<DeviceRunParam>> READ_CONFIG_KEY =
|
||||
AttributeKey.valueOf("READ_CONFIG");
|
||||
public static final AttributeKey<CompletableFuture<DeviceRunParam>> READ_CONFIG_KEY = AttributeKey
|
||||
.valueOf("READ_CONFIG");
|
||||
|
||||
public static final AttributeKey<ConnectionCloseReason> ATT_CLOSE_REASON = AttributeKey.valueOf("closeReason");
|
||||
|
||||
@@ -27,5 +27,10 @@ public class Constant {
|
||||
|
||||
public static final String mqttHandleKey = "hostHandle";
|
||||
|
||||
public static final Long hostOfflineInterval = 10000L; //单位毫秒
|
||||
public static final Long hostOfflineInterval = 10000L; // 单位毫秒
|
||||
|
||||
// ==================== 远程控制 ====================
|
||||
public static final String protocol_version = "1.4.3";
|
||||
public static final String remote_control_msg_prefix = "remote-msg";
|
||||
public static final String remote_control_cmd_prefix = "remote-cmd";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.maibu.core.business;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@Data
|
||||
public class LawnMoverProtocolEntity {
|
||||
|
||||
public LawnMoverProtocolEntity() {
|
||||
Header1 = (byte) 0xAB;
|
||||
Header2 = (byte) 0xAA;
|
||||
CommandType = 0x00;
|
||||
LeftWheelSpeed = 0x0000;
|
||||
RightWheelSpeed = 0x0000;
|
||||
ChassisLiftFlag = 0x00;
|
||||
MowerSpeedFlag = 0x00;
|
||||
IgnitionFlag = 0x00;
|
||||
EmergencyStopFlag = 0x00;
|
||||
Crc16 = 0x0000;
|
||||
EndFlag1 = (byte) 0xAA;
|
||||
EndFlag2 = (byte) 0xAB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LawnMoverProtocolEntity{" +
|
||||
"Header1=" + Header1 +
|
||||
", Header2=" + Header2 +
|
||||
", CommandType=" + CommandType +
|
||||
", LeftWheelSpeed=" + LeftWheelSpeed +
|
||||
", RightWheelSpeed=" + RightWheelSpeed +
|
||||
", ChassisLiftFlag=" + ChassisLiftFlag +
|
||||
", MowerSpeedFlag=" + MowerSpeedFlag +
|
||||
", IgnitionFlag=" + IgnitionFlag +
|
||||
", EmergencyStopFlag=" + EmergencyStopFlag +
|
||||
", Crc16=" + Crc16 +
|
||||
", EndFlag1=" + EndFlag1 +
|
||||
", EndFlag2=" + EndFlag2 +
|
||||
'}';
|
||||
}
|
||||
|
||||
public byte[] toBytes() {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(27);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN); // 根据协议决定字节序
|
||||
buffer.put(Header1);
|
||||
buffer.put(Header2);
|
||||
buffer.put(CommandType);
|
||||
buffer.putDouble(linearSpeed);
|
||||
buffer.putDouble(angularSpeed);
|
||||
buffer.put(ChassisLiftFlag);
|
||||
buffer.put(MowerSpeedFlag);
|
||||
buffer.put(IgnitionFlag);
|
||||
buffer.put(EmergencyStopFlag);
|
||||
buffer.putShort(Crc16); // 如果要计算真实 CRC16 可在此插入计算逻辑
|
||||
buffer.put(EndFlag1);
|
||||
buffer.put(EndFlag2);
|
||||
return buffer.array();
|
||||
}
|
||||
|
||||
public static String printBytesToHex(byte[] bytes) {
|
||||
StringBuilder sb = new StringBuilder(bytes.length * 3);
|
||||
for (byte b : bytes) {
|
||||
sb.append(String.format("%02X ", b));
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将控制指令字节数组解析为实体对象
|
||||
*/
|
||||
public static LawnMoverProtocolEntity parseControlCommand(byte[] data) {
|
||||
if (data == null || data.length != 27) {
|
||||
throw new IllegalArgumentException("控制指令长度必须为15字节");
|
||||
}
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
LawnMoverProtocolEntity entity = new LawnMoverProtocolEntity();
|
||||
|
||||
// 帧头
|
||||
entity.setHeader1(buffer.get());
|
||||
entity.setHeader2(buffer.get());
|
||||
|
||||
// 命令类型
|
||||
entity.setCommandType(buffer.get());
|
||||
|
||||
// 左右轮速度:int16
|
||||
entity.setLinearSpeed(buffer.getDouble());
|
||||
entity.setAngularSpeed(buffer.getDouble());
|
||||
|
||||
// 控制标志:uint8
|
||||
entity.setChassisLiftFlag(buffer.get());
|
||||
entity.setMowerSpeedFlag(buffer.get());
|
||||
entity.setIgnitionFlag(buffer.get());
|
||||
entity.setEmergencyStopFlag(buffer.get());
|
||||
|
||||
// 预留字段
|
||||
buffer.get();
|
||||
buffer.get();
|
||||
|
||||
// 帧尾
|
||||
entity.setEndFlag1(buffer.get());
|
||||
entity.setEndFlag2(buffer.get());
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
// 包头起始字节1
|
||||
private byte Header1;
|
||||
// 包头起始字节2
|
||||
private byte Header2;
|
||||
// 指令类型
|
||||
private byte CommandType;
|
||||
// 左轮速度:16位有符号
|
||||
private short LeftWheelSpeed;
|
||||
// 右轮速度:16位有符号
|
||||
private short RightWheelSpeed;
|
||||
|
||||
private double linearSpeed;
|
||||
|
||||
private double angularSpeed;
|
||||
// 底盘升降标志位
|
||||
private byte ChassisLiftFlag;
|
||||
// 割刀速度标志位
|
||||
private byte MowerSpeedFlag;
|
||||
// 点火标志位
|
||||
private byte IgnitionFlag;
|
||||
// 保留位
|
||||
private byte EmergencyStopFlag;
|
||||
// Crc校验
|
||||
private short Crc16;
|
||||
// 包尾字节1
|
||||
private byte EndFlag1;
|
||||
// 包尾字节2
|
||||
private byte EndFlag2;
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.maibu.core.business.device;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.maibu.constant.Constant;
|
||||
import com.maibu.core.business.*;
|
||||
import com.maibu.core.business.path.LatAndLngEntity;
|
||||
import com.maibu.core.business.path.RoutePlanSendEntity;
|
||||
@@ -148,7 +149,7 @@ public class NettyDevice extends Connector {
|
||||
dto.setMode(workRecord.getMode());
|
||||
dto.setTimestamp(System.currentTimeMillis());
|
||||
dto.setMessage_id(task.getId() + "_" + System.currentTimeMillis());
|
||||
dto.setProtocol_version("1.4");
|
||||
dto.setProtocol_version(Constant.protocol_version);
|
||||
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
String.format(MqttTopic.MOWER_TASK_ROUTE_SET, task.getDeviceId()),
|
||||
@@ -361,7 +362,7 @@ public class NettyDevice extends Connector {
|
||||
dto.setMode(workRecord.getMode());
|
||||
dto.setTimestamp(System.currentTimeMillis());
|
||||
dto.setMessage_id(task.getId() + "_" + System.currentTimeMillis());
|
||||
dto.setProtocol_version("1.4");
|
||||
dto.setProtocol_version(Constant.protocol_version);
|
||||
|
||||
PointEntity point = new PointEntity();
|
||||
if (!StringUtils.isEmpty(workRecord.getMode())) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.maibu.core.host;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 上位机远程控制参数
|
||||
* DeviceRemoteControlDTO
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class DeviceRemoteControlDTO extends HostBase {
|
||||
private String command_id;
|
||||
private ParamDetail data;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.maibu.core.host;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ParamDetail {
|
||||
private short left_wheel_rpm; // 左轮转速
|
||||
private short right_wheel_rpm; // 右轮转速
|
||||
|
||||
private double linear_speed; // 线速度
|
||||
private double angular_speed; // 角速度
|
||||
|
||||
private int chassis_lift; // 底盘升降 0:停止 1:升 2:降
|
||||
private int cutter; // 割刀加减速 0:停止 1:加速 2:减速
|
||||
private int ignition; // 点火熄火 0:停止 1:点火 2:熄火
|
||||
private int emergency_stop; // 急停 0:正常 1:急停
|
||||
private int valid_for_ms; // 指令有效时间,单位毫秒
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class MqttTopic {
|
||||
|
||||
// ==================== 远程控制 ====================
|
||||
/** 远程控制指令下发:前进/后退/转向/割草等(平台->设备),对应 TCP 0x00 remoteControl */
|
||||
public static final String MOWER_CONTROL_SET = "mower/%s/action/control/set";
|
||||
public static final String MOWER_CONTROL_SET = "mower/%s/control/remote/set";
|
||||
|
||||
// ==================== 任务管理 ====================
|
||||
/** 路径规划下发(平台->设备),对应 TCP 0x01 path */
|
||||
|
||||
Reference in New Issue
Block a user