37 double t_start = yarp::os::Time::now();
39 if (getIterations()>100)
41 yDebug(
"Thread ran %d times, est period %lf[ms], used %lf[ms]\n",
43 1000.0*getEstimatedPeriod(),
44 1000.0*getEstimatedUsed());
47 std::lock_guard<std::mutex> lck(_mutex);
51 yarp::os::Bottle *bot = command_port.read(
false);
56 int size = bot->size()/2;
57 for(
int i=0;i<size;i++)
59 int ind = bot->get(2*i).asInt32();
62 targets(ind) = bot->get(2*i+1).asFloat64();
72 if(nb_void_loops > 5) {
78 yarp::os::Bottle *vec = command_port2.read(
false);
81 for(
int k=0;k<nJoints;k++)
82 targets(k)=vec->get(k).asFloat64();
88 ienc->getEncoders(encoders.data());
93 for(
int i=0;i<nJoints;i++)
94 fprintf(currentSpeedFile,
"%f ",encoders(i));
95 fprintf(currentSpeedFile,
"%f\n",t_start-time_watch);
100 for(
int k=0;k<nJoints;k++)
103 double current_err = targets(k)-encoders(k);
104 error_d(k) = (current_err - error(k))/((
double)control_rate)*1000.0;
105 error(k) = current_err;
108 command(k) = Kp(k)*error(k) + Kd(k)*error_d(k) + ffVelocities(k);
120 for(
int i=0;i<nJoints;i++)
121 fprintf(targetSpeedFile,
"%f ",command(i));
122 fprintf(targetSpeedFile,
"%f\n",t_start-time_watch);
132 for(
int i=0;i<nJoints;i++)
134 if (fabs(targets(i)-encoders(i))>6.0)
135 ipos->positionMove(i,targets(i));
137 ipid->setPidReference(yarp::dev::VOCAB_PIDTYPE_POSITION,i,targets(i));
143 while(!ivel->velocityMove(command.data()))
146 yError(
"velcontrol ERROR>> velocity move sent false\n");
149 yError(
"velcontrol ERROR>> tried 10 times to velocityMove, halting...\n");
198 sprintf(tmp,
"/%s/vc/%s/fastCommand", robotName.c_str(), partName.c_str());
199 yInfo(
"opening port for part %s\n",tmp);
200 command_port.open(tmp);
204 tmp2+=robotName.c_str();
206 tmp2+=partName.c_str();
208 command_port2.open(tmp2.c_str());
221 if ( (ivel==0)||(ienc==0) || (imod==0) || (ipid==0) || (ipos==0))
224 ivel->getAxes(&nJoints);
225 yInfo(
"controlling %d DOFs\n",nJoints);
228 accs.resize(nJoints);
230 speeds.resize(nJoints);
231 ivel->getRefAccelerations(accs.data());
233 ivel->setRefAccelerations(accs.data());
235 ipos->setRefSpeeds(speeds.data());
237 encoders.resize(nJoints);
238 encoders_speed.resize(nJoints);
239 command.resize(nJoints);
240 targets.resize(nJoints);
241 ffVelocities.resize(nJoints);
249 error.resize(nJoints);
251 error_d.resize(nJoints);
254 maxVel.resize(nJoints);
258 sprintf(tmp,
"%s_target_speed.dat",partName.c_str());
259 targetSpeedFile = fopen(tmp,
"w");
260 sprintf(tmp,
"%s_current_speed.dat",partName.c_str());
261 currentSpeedFile = fopen(tmp,
"w");