fix: 调试
This commit is contained in:
parent
b23fae3a3f
commit
31eebdc65d
@ -9,7 +9,6 @@ import com.cmvr.common.exception.GlobalException;
|
|||||||
import com.cmvr.common.utils.http.CallAPIUtil;
|
import com.cmvr.common.utils.http.CallAPIUtil;
|
||||||
import com.cmvr.common.utils.uuid.IdUtils;
|
import com.cmvr.common.utils.uuid.IdUtils;
|
||||||
import com.cmvr.edge.client.model.EdgeCommonVO;
|
import com.cmvr.edge.client.model.EdgeCommonVO;
|
||||||
import com.cmvr.edge.client.model.humanoid.EdgeMoveJVO;
|
|
||||||
import com.cmvr.edge.client.service.EdgeBioHeadService;
|
import com.cmvr.edge.client.service.EdgeBioHeadService;
|
||||||
import com.cmvr.edge.client.service.EdgeHumanoidRobotService;
|
import com.cmvr.edge.client.service.EdgeHumanoidRobotService;
|
||||||
import com.cmvr.test.enums.FlowiseActionEnum;
|
import com.cmvr.test.enums.FlowiseActionEnum;
|
||||||
@ -22,15 +21,14 @@ import com.cmvr.test.model.vo.FlowiseChatRequestVO;
|
|||||||
import com.cmvr.test.model.vo.FlowiseStartRequestVO;
|
import com.cmvr.test.model.vo.FlowiseStartRequestVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -61,12 +59,6 @@ public class FlowiseActionService {
|
|||||||
@Resource(name = "threadPoolTaskExecutor")
|
@Resource(name = "threadPoolTaskExecutor")
|
||||||
private final ThreadPoolTaskExecutor executor;
|
private final ThreadPoolTaskExecutor executor;
|
||||||
|
|
||||||
/**
|
|
||||||
* 整个动作是否在运行(张嘴 + 摆头)
|
|
||||||
*/
|
|
||||||
private final AtomicBoolean actionRunning = new AtomicBoolean(true);
|
|
||||||
|
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
private String chatId = null;
|
private String chatId = null;
|
||||||
|
|
||||||
@ -235,118 +227,41 @@ public class FlowiseActionService {
|
|||||||
|
|
||||||
public String actionStart() {
|
public String actionStart() {
|
||||||
|
|
||||||
// 防止重复启动
|
EdgeCommonVO speakVO = getEdgeCommonVO();
|
||||||
if (!actionRunning.compareAndSet(false, true)) {
|
try {
|
||||||
log.warn("action 已在运行中");
|
// 张嘴
|
||||||
return "already running";
|
String speakStart = edgeBioHeadService.speakStart(speakVO);
|
||||||
|
log.info("张嘴动作触发完成: {}", speakStart);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new GlobalException("张嘴执行异常", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "ok";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static EdgeCommonVO getEdgeCommonVO() {
|
||||||
String terminalId = "4ed1246c465b97975f96c9ef8371a3bd";
|
String terminalId = "4ed1246c465b97975f96c9ef8371a3bd";
|
||||||
String robotId = "hc01";
|
|
||||||
String bioId = "bio_head";
|
String bioId = "bio_head";
|
||||||
|
|
||||||
executor.execute(() -> {
|
EdgeCommonVO speakVO = new EdgeCommonVO();
|
||||||
EdgeCommonVO speakVO = new EdgeCommonVO();
|
speakVO.setTerminalId(terminalId);
|
||||||
speakVO.setTerminalId(terminalId);
|
speakVO.setDeviceId(bioId);
|
||||||
speakVO.setDeviceId(bioId);
|
return speakVO;
|
||||||
try {
|
|
||||||
// 张嘴
|
|
||||||
String speakStart = edgeBioHeadService.speakStart(speakVO);
|
|
||||||
log.info("张嘴动作触发完成: {}", speakStart);
|
|
||||||
|
|
||||||
// // 摆头循环
|
|
||||||
// boolean toRight = true;
|
|
||||||
//
|
|
||||||
// while (actionRunning.get()) {
|
|
||||||
//
|
|
||||||
// double rad = toRight ? 0.1d : -0.1d;
|
|
||||||
//
|
|
||||||
// EdgeMoveJVO moveJVO = buildHeadMoveJVO(
|
|
||||||
// terminalId,
|
|
||||||
// robotId,
|
|
||||||
// rad
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// long t0 = System.currentTimeMillis();
|
|
||||||
// log.info(">>> moveJ start, rad={},time={}", rad, t0);
|
|
||||||
// String res = edgeHumanoidRobotService.moveJ(moveJVO);
|
|
||||||
//
|
|
||||||
// long t1 = System.currentTimeMillis();
|
|
||||||
// log.info(">>> moveJ end, rad={}, cost={}", rad, t1 - t0);
|
|
||||||
//
|
|
||||||
// // 判断返回
|
|
||||||
// try {
|
|
||||||
// JSONObject resJson = JSON.parseObject(res);
|
|
||||||
// if (!resJson.getBooleanValue("success")) {
|
|
||||||
// log.warn("moveJ 返回失败,res={}", res);
|
|
||||||
// }
|
|
||||||
// } catch (Exception ignore) {
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// toRight = !toRight;
|
|
||||||
// }
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("action 执行异常", e);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
// 回正
|
|
||||||
// try {
|
|
||||||
// EdgeMoveJVO resetVO = buildHeadMoveJVO(
|
|
||||||
// terminalId,
|
|
||||||
// robotId,
|
|
||||||
// 0d
|
|
||||||
// );
|
|
||||||
// log.info("结束动作,头部回正 rad=0");
|
|
||||||
// edgeHumanoidRobotService.moveJ(resetVO);
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error("头部回正异常", e);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 停止张嘴
|
|
||||||
try {
|
|
||||||
edgeBioHeadService.speakStop(speakVO);
|
|
||||||
log.info("speakStop 已调用");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("speakStop 调用失败", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
actionRunning.set(false);
|
|
||||||
log.info("action 线程结束");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return "ok";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String actionStop() {
|
public String actionStop() {
|
||||||
if (!actionRunning.get()) {
|
EdgeCommonVO speakVO = getEdgeCommonVO();
|
||||||
return "not running";
|
// 停止张嘴
|
||||||
|
try {
|
||||||
|
edgeBioHeadService.speakStop(speakVO);
|
||||||
|
log.info("停止张嘴成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new GlobalException("停止张嘴失败", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("actionStop 调用,准备停止所有动作");
|
|
||||||
actionRunning.set(false);
|
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
private EdgeMoveJVO buildHeadMoveJVO(String terminalId,
|
|
||||||
String deviceId,
|
|
||||||
double rad) {
|
|
||||||
|
|
||||||
EdgeMoveJVO vo = new EdgeMoveJVO();
|
|
||||||
vo.setTerminalId(terminalId);
|
|
||||||
vo.setDeviceId(deviceId);
|
|
||||||
vo.setAcc(1d);
|
|
||||||
vo.setVel(1d);
|
|
||||||
|
|
||||||
EdgeMoveJVO.JointCmd headCmd = new EdgeMoveJVO.JointCmd();
|
|
||||||
headCmd.setJointName("HEAD_R");
|
|
||||||
headCmd.setRad(rad);
|
|
||||||
|
|
||||||
vo.setCmds(Collections.singletonList(headCmd));
|
|
||||||
return vo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void speakStatus(String text) {
|
private void speakStatus(String text) {
|
||||||
Map<String, String> body = new HashMap<>();
|
Map<String, String> body = new HashMap<>();
|
||||||
body.put("text", text);
|
body.put("text", text);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user