37 taskRpcServerName(taskRpcPortName),
38 controlThreadPeriod(period),
74 yarp::os::Bottle message, reply;
75 message.addString(
"closeControlPorts");
77 double closeDelay = 0.5;
78 double closeDelayTotal = 0.0;
83 yarp::os::Time::delay(closeDelay);
84 closeDelayTotal += closeDelay;
86 if (reply.get(0).asInt()) {
89 std::cout <<
"[WARNING](ControlThread::threadRelease): Couldn't close task control ports." << std::endl;
91 std::cout <<
"Done.\n";
107 bool portsOpened =
yarp.checkNetwork();
111 std::string portNameBase =
"/CT/" +
getThreadType() +
"/id_";
112 std::stringstream portNameStream;
114 portNameBase += portNameStream.str();
135 std::cout <<
"[ERROR](ControlThread::openControlPorts): Yarp network not running." << std::endl;
143 bool portsConnected =
yarp.checkNetwork();
149 yarp::os::Bottle message, reply;
150 message.addString(
"openControlPorts");
152 if (reply.get(0).asInt())
154 std::string taskOutputPortName, taskInputPortName;
158 message.addString(
"getControlPortNames");
161 taskInputPortName = reply.get(1).asString();
162 taskOutputPortName = reply.get(2).asString();
164 portsConnected = portsConnected &&
yarp.connect(taskOutputPortName.c_str(),
inputPortName.c_str());
165 portsConnected = portsConnected &&
yarp.connect(
outputPortName.c_str(), taskInputPortName.c_str());
170 portsConnected =
false;
174 std::cout <<
"[ERROR](ControlThread::connectControlPorts): Yarp network not running." << std::endl;
177 return portsConnected;
187 for(
int i=0; i<input->size(); i++)
205 yarp::os::Bottle input;
206 if (input.read(connection)){
224 yarp::os::Bottle message;
225 message.addString(
"updateCurrentStateAndSend");
231 yarp::os::Bottle message, reply;
232 message.addString(
"deactivate");
234 if (reply.get(0).asString()==
"deactivated")
244 yarp::os::Bottle message, reply;
245 message.addString(
"activate");
247 if (reply.get(0).asString()==
"activated")
257 yarp::os::Bottle message, reply;
258 message.addString(
"getWeight");
260 if (reply.size()>1) {
263 std::cout <<
"[ERROR](ControlThread::getTaskDimensions): Did not get a valid response from the task for its weight dimension." << std::endl;
269 message.addString(
"getDesired");
271 if (reply.size()>1) {
274 std::cout <<
"[ERROR](ControlThread::getTaskDimensions): Did not get a valid response from the task for its state dimension." << std::endl;
287 yarp::os::Bottle message, reply;
288 message.addString(
"getStiffness");
289 message.addString(
"getDamping");
290 message.addString(
"getDimension");
291 message.addString(
"getWeight");
292 message.addString(
"getDesired");
293 message.addString(
"getCurrentState");
294 message.addString(
"getType");
295 message.addString(
"getName");
296 message.addString(
"getActivityStatus");
298 int maxCount = message.size();
302 for(
int i=0; i<reply.size(); i++)
304 if (reply.get(i).asString()==
"Kp:"){
306 TP.
kp = reply.get(i).asDouble();
309 else if (reply.get(i).asString()==
"Kd:"){
311 TP.
kd = reply.get(i).asDouble();
314 else if (reply.get(i).asString()==
"Dimension:"){
319 else if (reply.get(i).asString()==
"Weight:"){
323 TP.
weight(j) = reply.get(i).asDouble();
327 else if (reply.get(i).asString()==
"Desired:"){
331 TP.
desired(j) = reply.get(i).asDouble();
335 else if (reply.get(i).asString()==
"currentState:"){
343 else if (reply.get(i).asString()==
"Type:"){
345 TP.
type = reply.get(i).asString();
348 else if (reply.get(i).asString()==
"Name:"){
350 TP.
name = reply.get(i).asString();
353 else if (reply.get(i).asString()==
"activated"){
355 TP.
isActive = reply.get(i).asBool();
360 return count==maxCount;
bool connectControlPorts()
ControlThread(int period, const std::string &taskRpcPortName)
Eigen::VectorXd currentStateVector
yarp::os::RpcClient threadRpcClient
virtual bool threadInit()
A class for launching generic control threads.
inputCallback * inpCallback
Eigen::VectorXd getCurrentState()
virtual void ct_threadRelease()=0
std::string getThreadType()
Eigen::VectorXd currentState
std::string inputPortName
TaskParameters currentTaskParams
static int CONTROL_THREAD_COUNT
std::string outputPortName
std::string taskRpcServerName
std::string threadRpcClientName
virtual bool ct_threadInit()=0
double controlThreadPeriod
yarp::os::Port outputPort
TaskParameters originalTaskParams
bool getTaskParameters(TaskParameters &TP)
void sendGetStateMessage()
bool waitingForFirstStateMessage
bool parseInput(yarp::os::Bottle *input)
virtual void threadRelease()