2025-10-24 14:37:17 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Created by linbo on 2025/10/24.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "jointpositioncontroller.h"
|
2025-10-29 16:26:15 +08:00
|
|
|
|
#include "hardware/can/can_manager.h"
|
|
|
|
|
|
#include "hardware_manager/hardware_manager.h"
|
2025-10-24 14:37:17 +08:00
|
|
|
|
using namespace std;
|
|
|
|
|
|
using namespace cmvr::device;
|
2025-10-29 16:26:15 +08:00
|
|
|
|
using namespace cmvr::hardware;
|
|
|
|
|
|
|
2025-10-24 14:37:17 +08:00
|
|
|
|
JointPositionController::JointPositionController(const XmlNode& cfg):AbstractController(cfg)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-24 17:06:17 +08:00
|
|
|
|
void JointPositionController::call(const Json::Value& json)
|
2025-10-24 14:37:17 +08:00
|
|
|
|
{
|
2025-10-24 14:44:45 +08:00
|
|
|
|
if (state_ != ControllerState_Idle)
|
|
|
|
|
|
return;
|
2025-10-29 16:26:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//解析jason,执行算法
|
2025-11-06 15:58:32 +08:00
|
|
|
|
/*
|
|
|
|
|
|
"params":{
|
|
|
|
|
|
“canGroupId”:"leftArm",
|
|
|
|
|
|
"protocolType":"Ti5MotorProtocol",
|
|
|
|
|
|
"motors":[{"joint_name":""},{"joint_name":""}]
|
|
|
|
|
|
},
|
|
|
|
|
|
"operate":{}
|
2025-10-29 16:26:15 +08:00
|
|
|
|
|
2025-11-06 15:58:32 +08:00
|
|
|
|
**/
|
|
|
|
|
|
std::string canGroupId;
|
|
|
|
|
|
std::string protocolType;
|
|
|
|
|
|
if (json.isMember("params"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Json::Value params = json["params"];
|
|
|
|
|
|
if (params.isMember("canGroupId"))
|
|
|
|
|
|
canGroupId = params["canGroupId"].asString();
|
|
|
|
|
|
if (params.isMember("protocolType"))
|
|
|
|
|
|
protocolType = params["protocolType"].asString();
|
|
|
|
|
|
if (params.isMember("motors"))
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < params["motors"].size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::string joint_name = params["motors"][i]["joint_name"].asString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-29 16:26:15 +08:00
|
|
|
|
|
2025-11-06 15:58:32 +08:00
|
|
|
|
if (json.isMember("operate"))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-10-29 16:26:15 +08:00
|
|
|
|
|
|
|
|
|
|
//调用canmanager执行电机指令
|
2025-11-06 15:58:32 +08:00
|
|
|
|
auto protocol = HardWareManager::getInstance().getCanGroup(canGroupId)->getMotorProtocol(protocolType);
|
|
|
|
|
|
//这里通过joint_name获取node_id?
|
2025-10-24 14:37:17 +08:00
|
|
|
|
}
|
2025-10-29 16:26:15 +08:00
|
|
|
|
|
|
|
|
|
|
void JointPositionController::interrupt()
|
2025-10-24 14:37:17 +08:00
|
|
|
|
{
|
2025-10-29 16:26:15 +08:00
|
|
|
|
state_ = ControllerState_Switching;
|
2025-10-24 14:37:17 +08:00
|
|
|
|
|
2025-10-29 16:26:15 +08:00
|
|
|
|
|
|
|
|
|
|
state_ = ControllerState_Idle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JointPositionController::stop()
|
|
|
|
|
|
{
|
|
|
|
|
|
state_ = ControllerState_Idle;
|
2025-10-24 14:37:17 +08:00
|
|
|
|
}
|