19 #include <yarp/os/Network.h>
20 #include <yarp/os/Time.h>
21 #include <yarp/os/Log.h>
22 #include <yarp/os/LogStream.h>
23 #include <yarp/os/BufferedPort.h>
24 #include <yarp/sig/Vector.h>
25 #include <yarp/math/Math.h>
27 #include <yarp/dev/ControlBoardInterfaces.h>
28 #include <yarp/dev/PolyDriver.h>
29 #include <yarp/os/PeriodicThread.h>
30 #include <yarp/os/Thread.h>
40 using namespace yarp::os;
41 using namespace yarp::sig;
43 using namespace yarp::math;
57 q_joints =
new double [N_JOINTS];
58 for (
int i=0; i<N_JOINTS; i++) q_joints[i]=0.0;
64 N_JOINTS = as.N_JOINTS;
68 q_joints =
new double [N_JOINTS];
69 for (
int i=0; i< N_JOINTS; i++)
79 N_JOINTS = as.N_JOINTS;
83 q_joints =
new double [N_JOINTS];
84 for (
int i=0; i< N_JOINTS; i++)
105 action_vector.clear();
115 for (action_it=action_vector.begin(); action_it<action_vector.end(); action_it++)
117 yInfo (
"%d %f ",action_it->counter,action_it->time);
118 for (
int i=0; i< action_it->get_n_joints(); i++)
119 yInfo(
"%f ", action_it->q_joints[i]);
128 data_file = fopen(filename.c_str(),
"r");
135 char command_line[1024];
136 bb = fgets (command_line, 1024, data_file);
140 if(!parseCommandLineFixTime(command_line, line++, 1.0/50.0, n_joints))
142 yError (
"error parsing file, line %d\n", line);
153 yError(
"unable to find file\n");
161 static int count = 0;
162 static double time =0.0;
165 tmp_action.
counter = count; count = count + 1;
169 size_t ss = strlen(command_line);
170 char* cline =
new char [ss];
171 strcpy(cline,command_line);
172 tok = strtok (cline,
" ");
174 int joints_count = 0;
175 while (tok != 0 && joints_count < n_joints)
177 sscanf(tok,
"%lf", &tmp_action.
q_joints[i++]);
178 tok = strtok (NULL,
" ");
189 if (action_vector.size()==0)
191 action_vector.push_back(tmp_action);
195 for (action_it=action_vector.end()-1; action_it>=action_vector.begin(); action_it--)
197 if (tmp_action.
time > action_it->time)
break;
199 action_vector.insert(action_it+1,tmp_action);
207 char command_line_format [1000];
208 sprintf(command_line_format,
"%%d %%lf ");
209 for (
int i = 0; i < n_joints; i++)
211 size_t off = strlen(command_line_format);
212 sprintf(command_line_format+off,
"%%lf ");
215 int ret = sscanf(command_line,
"%d %lf %lf %lf %lf %lf %lf %lf",
227 if (ret == n_joints+2)
230 for (action_it=action_vector.begin(); action_it<action_vector.end(); action_it++)
231 if (tmp_action.
time > action_it->time)
break;
232 action_vector.insert(action_it,tmp_action);
243 drvOptions_ll.clear();
259 Property &options=
const_cast<Property &
> (copt);
261 drvOptions_ll.put(
"device",
"remote_controlboard");
263 if (!options.check(
"robot")) { yError() <<
"Missing robot parameter";
return false; }
264 if (!options.check(
"part")) { yError() <<
"Missing part parameter";
return false; }
268 remote_ll = string(
"/") + string(options.find(
"robot").asString()) + string(
"/") +string(options.find(
"part").asString());
269 local_ll = string(
"/") + string(
"trajectoryPlayer") + string(
"/") + string(options.find(
"part").asString());
270 drvOptions_ll.put(
"remote",remote_ll.c_str());
271 drvOptions_ll.put(
"local",local_ll.c_str());
275 yDebug() <<
"driver options:\n" << drvOptions_ll.toString().c_str();
283 drv_ll=
new PolyDriver(drvOptions_ll);
285 if (drv_ll->isValid())
286 drv_connected = drv_ll->view(ipos_ll) && drv_ll->view(iposdir_ll) && drv_ll->view(ienc_ll) && drv_ll->view(ipid_ll) && drv_ll->view(imotenc_ll) && drv_ll->view(icmd_ll);
301 ienc_ll->getAxes(&n_joints);
304 double* speeds =
new double [n_joints];
305 for (
int i=0; i<n_joints; i++) speeds[i] = 20.0;
306 ipos_ll->setRefSpeeds(speeds);
309 return drv_connected;
323 if (!icmd_ll)
return false;
324 return icmd_ll->setControlMode(joints_map[j], mode);
329 if (!iposdir_ll)
return false;
330 return iposdir_ll->setPosition(joints_map[j], ref);
335 if (!ienc_ll)
return false;
336 return ienc_ll->getEncoder(joints_map[j], v);
341 if (!ipos_ll)
return false;
342 return ipos_ll->positionMove(joints_map[j], v);
bool parseCommandLineFixTime(const char *command_line, int line, double fixTime, int n_joints)
bool parseCommandLine(const char *command_line, int line, int n_joints)
bool openFile(string filename, int n_joints)
action_struct & operator=(const action_struct &as)
bool setPosition(int j, double ref)
bool setControlMode(const int j, const int mode)
bool getEncoder(int j, double *v)
bool configure(const Property &copt)
bool positionMove(int j, double ref)