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",
|
|
|
|
|
|
"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"))
|
|
|
|
|
|
{
|
2025-11-06 17:27:37 +08:00
|
|
|
|
const Json::Value& params = json["params"];
|
2025-11-06 15:58:32 +08:00
|
|
|
|
if (params.isMember("canGroupId"))
|
|
|
|
|
|
canGroupId = params["canGroupId"].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-11-06 17:27:37 +08:00
|
|
|
|
//最后计算好了通过下面的接口调用电机通信
|
|
|
|
|
|
std::string joint_name ="";
|
|
|
|
|
|
auto motorInfo = HardWareManager::getInstance().getCanGroup(canGroupId)->getMotorInfo(joint_name);
|
|
|
|
|
|
motorInfo.motorProtocol->setQ(motorInfo.node_id,0.1);
|
2025-10-29 16:26:15 +08:00
|
|
|
|
|
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
|
|
|
|
}
|