#修改远程遥控控制方式 将左右轮速改成线速度和角速度
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package com.maibu.utils;
|
||||
|
||||
|
||||
import com.maibu.common.MiddleCommandConstant;
|
||||
import com.maibu.control.DiffSteer;
|
||||
import com.maibu.dto.LawnMoverProtocolEntity;
|
||||
import com.maibu.core.business.LawnMoverProtocolEntity;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
@@ -11,24 +10,29 @@ import java.util.List;
|
||||
|
||||
public class ControlUtils {
|
||||
|
||||
|
||||
public static LawnMoverProtocolEntity getCarControlMessage(DiffSteer diffSteer, int originX, int originY, List<Boolean> buttons) {
|
||||
public static LawnMoverProtocolEntity getCarControlMessage(DiffSteer diffSteer, int originX, int originY,
|
||||
List<Boolean> buttons, int maxLinear, int maxAngular) {
|
||||
LawnMoverProtocolEntity state = new LawnMoverProtocolEntity();
|
||||
diffSteer.calcWheelSpeed(originX, originY);
|
||||
diffSteer.calcLinearAngularSpeed(originX, originY, maxLinear, maxAngular);
|
||||
state.setCommandType(MiddleCommandConstant.remoteControl);
|
||||
state.setLeftWheelSpeed((short) diffSteer.getLeftWheelSpeed());
|
||||
state.setRightWheelSpeed((short) diffSteer.getRightWheelSpeed());
|
||||
|
||||
//对应的 button数组 L1 button【4】 R1 button【5】 A对应的button【0】 B对应button【1】 X对应button【2】 Y对应button【3】 button[7]急停
|
||||
//A升B降底盘 X割刀加速Y减速 L1点火 R1熄火
|
||||
state.setLinearSpeed(diffSteer.getLinearSpeed());
|
||||
state.setAngularSpeed(diffSteer.getAngularSpeed());
|
||||
|
||||
// 对应的 button数组 L1 button【4】 R1 button【5】 A对应的button【0】 B对应button【1】
|
||||
// X对应button【2】 Y对应button【3】 button[7]急停
|
||||
// A升B降底盘 X割刀加速Y减速 L1点火 R1熄火
|
||||
Boolean A = buttons.get(0);
|
||||
Boolean B = buttons.get(1);
|
||||
Boolean X = buttons.get(2);
|
||||
Boolean Y = buttons.get(3);
|
||||
Boolean L1 = buttons.get(4);
|
||||
Boolean R1 = buttons.get(5);
|
||||
Boolean eStop = buttons.get(8); //急停
|
||||
//底盘升降
|
||||
Boolean eStop = buttons.get(8); // 急停
|
||||
// 底盘升降
|
||||
int chassisLiftFlag = 0;
|
||||
if (A & !B) {
|
||||
chassisLiftFlag = 1;
|
||||
@@ -36,7 +40,7 @@ public class ControlUtils {
|
||||
chassisLiftFlag = 2;
|
||||
}
|
||||
state.setChassisLiftFlag((byte) chassisLiftFlag);
|
||||
//割刀加减速
|
||||
// 割刀加减速
|
||||
int mowerSpeedFlag = 0;
|
||||
if (X & !Y) {
|
||||
mowerSpeedFlag = 1;
|
||||
@@ -44,7 +48,7 @@ public class ControlUtils {
|
||||
mowerSpeedFlag = 2;
|
||||
}
|
||||
state.setMowerSpeedFlag((byte) mowerSpeedFlag);
|
||||
//点火熄火
|
||||
// 点火熄火
|
||||
int ignitionFlag = 0;
|
||||
if (L1 & !R1) {
|
||||
ignitionFlag = 1;
|
||||
@@ -55,26 +59,29 @@ public class ControlUtils {
|
||||
|
||||
int emergencyStopFlag = eStop ? 1 : 0;
|
||||
state.setEmergencyStopFlag((byte) emergencyStopFlag);
|
||||
// val toBytes = state.toBytes()
|
||||
// println("toBytes==" + LawnMoverProtocolEntity.printBytesToHex(toBytes))
|
||||
// val toBytes = state.toBytes()
|
||||
// println("toBytes==" + LawnMoverProtocolEntity.printBytesToHex(toBytes))
|
||||
return state;
|
||||
}
|
||||
|
||||
public static byte[] buildControlCommand(LawnMoverProtocolEntity entity) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(15);
|
||||
ByteBuffer buffer = ByteBuffer.allocate(27);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
buffer.put(entity.getHeader1());
|
||||
buffer.put(entity.getHeader2());
|
||||
buffer.put(entity.getCommandType());
|
||||
|
||||
buffer.putShort(entity.getLeftWheelSpeed());//左轮速度
|
||||
buffer.putShort(entity.getRightWheelSpeed());//右轮速度
|
||||
// buffer.putShort(entity.getLeftWheelSpeed());//左轮速度
|
||||
// buffer.putShort(entity.getRightWheelSpeed());//右轮速度
|
||||
|
||||
buffer.put(entity.getChassisLiftFlag());//底盘升降
|
||||
buffer.put(entity.getMowerSpeedFlag());//割刀加减速
|
||||
buffer.put(entity.getIgnitionFlag());//点火状态
|
||||
buffer.put(entity.getEmergencyStopFlag());//急停
|
||||
buffer.putDouble(entity.getAngularSpeed());// 左轮速度
|
||||
buffer.putDouble(entity.getLinearSpeed());// 右轮速度
|
||||
|
||||
buffer.put(entity.getChassisLiftFlag());// 底盘升降
|
||||
buffer.put(entity.getMowerSpeedFlag());// 割刀加减速
|
||||
buffer.put(entity.getIgnitionFlag());// 点火状态
|
||||
buffer.put(entity.getEmergencyStopFlag());// 急停
|
||||
|
||||
buffer.put((byte) 0x00);
|
||||
buffer.put((byte) 0x00);
|
||||
|
||||
Reference in New Issue
Block a user