147 #include <yarp/os/Network.h>
148 #include <yarp/os/RFModule.h>
149 #include <yarp/os/Bottle.h>
150 #include <yarp/os/BufferedPort.h>
151 #include <yarp/sig/Vector.h>
152 #include <yarp/math/Math.h>
153 #include <yarp/dev/Drivers.h>
161 #define AFFACTIONPRIMITIVESLAYER ActionPrimitivesLayer1
164 using namespace yarp::os;
165 using namespace yarp::sig;
167 using namespace yarp::math;
192 graspOrien.resize(4);
199 graspOrien[0]=-0.171542;
200 graspOrien[1]= 0.124396;
201 graspOrien[2]=-0.977292;
202 graspOrien[3]= 3.058211;
226 Vector &_dOffs, Vector &_dLift, Vector &_home_x)
228 if (Bottle *pB=b.find(
"grasp_orientation").asList())
230 int sz=(int)pB->size();
231 int len=(int)_gOrien.length();
234 for (
int i=0; i<l; i++)
235 _gOrien[i]=pB->get(i).asFloat64();
238 if (Bottle *pB=b.find(
"grasp_displacement").asList())
240 int sz=(int)pB->size();
241 int len=(int)_gDisp.length();
244 for (
int i=0; i<l; i++)
245 _gDisp[i]=pB->get(i).asFloat64();
248 if (Bottle *pB=b.find(
"systematic_error_displacement").asList())
250 int sz=(int)pB->size();
251 int len=(int)_dOffs.length();
254 for (
int i=0; i<l; i++)
255 _dOffs[i]=pB->get(i).asFloat64();
258 if (Bottle *pB=b.find(
"lifting_displacement").asList())
260 int sz=(int)pB->size();
261 int len=(int)_dLift.length();
264 for (
int i=0; i<l; i++)
265 _dLift[i]=pB->get(i).asFloat64();
268 if (Bottle *pB=b.find(
"home_position").asList())
270 int sz=(int)pB->size();
271 int len=(int)_home_x.length();
274 for (
int i=0; i<l; i++)
275 _home_x[i]=pB->get(i).asFloat64();
282 string name=rf.find(
"name").asString();
283 setName(name.c_str());
285 Property config; config.fromConfigFile(rf.findFile(
"from"));
286 Bottle &bGeneral=config.findGroup(
"general");
287 if (bGeneral.isNull())
289 cout<<
"Error: group general is missing!"<<endl;
294 Property option(bGeneral.toString().c_str());
295 option.put(
"local",name);
296 option.put(
"part",
"left_arm");
297 option.put(
"grasp_model_type",rf.find(
"grasp_model_type").asString());
298 option.put(
"grasp_model_file",rf.findFile(
"grasp_model_file"));
299 option.put(
"hand_sequences_file",rf.findFile(
"hand_sequences_file"));
302 Bottle &bArm=config.findGroup(
"arm_dependent");
303 getArmDependentOptions(bArm,graspOrien,graspDisp,dOffs,dLift,home_x);
305 cout<<
"***** Instantiating primitives for left arm"<<endl;
307 if (!action->isValid())
313 deque<string> q=action->getHandSeqList();
314 cout<<
"***** List of available hand sequence keys:"<<endl;
315 for (
size_t i=0; i<q.size(); i++)
319 inPort.open(fwslash+name+
"/in");
320 rpcPort.open(fwslash+name+
"/rpc");
325 Model *model; action->getGraspModel(model);
331 prop.put(
"finger",
"all");
362 action->pushAction(home_x,
"open_hand");
363 action->checkActionsDone(
f,
true);
364 action->enableArmWaving(home_x);
387 xd[0]=b->get(0).asFloat64();
388 xd[1]=b->get(1).asFloat64();
389 xd[2]=b->get(2).asFloat64();
396 xd[0]=xd[0]>-0.1?-0.1:xd[0];
399 action->grasp(xd,graspOrien,graspDisp);
400 action->checkActionsDone(
f,
true);
401 action->areFingersInPosition(
f);
408 cout<<
"Wow, got something!"<<endl;
411 action->pushAction(xd+dLift,graspOrien);
412 action->checkActionsDone(
f,
true);
415 cout<<
"Sorry :( ... nothing to grasp"<<endl;
419 action->pushAction(
"open_hand");
420 action->checkActionsDone(
f,
true);
424 action->pushAction(home_x);
425 action->checkActionsDone(
f,
true);
430 action->enableArmWaving(home_x);
442 action->syncCheckInterrupt(
true);
456 if (!
yarp.checkNetwork())
458 cout<<
"YARP server not available!"<<endl;
463 rf.setDefaultConfigFile(
"config.ini");
464 rf.setDefault(
"grasp_model_type",
"tactile");
465 rf.setDefault(
"grasp_model_file",
"grasp_model.ini");
466 rf.setDefault(
"hand_sequences_file",
"hand_sequences.ini");
467 rf.setDefault(
"name",
"actionPrimitivesMod");
468 rf.configure(
argc,argv);
471 return mod.runModule(rf);
BufferedPort< Bottle > inPort
void getArmDependentOptions(Bottle &b, Vector &_gOrien, Vector &_gDisp, Vector &_dOffs, Vector &_dLift, Vector &_home_x)
AFFACTIONPRIMITIVESLAYER * action
bool configure(ResourceFinder &rf)
An abstract class that provides basic methods for interfacing with the data acquisition.
virtual bool isCalibrated() const =0
Return the internal status of the calibration.
virtual bool calibrate(const yarp::os::Property &options)=0
Some kinds of models need to be calibrated to properly operate.
Copyright (C) 2008 RobotCub Consortium.
int main(int argc, char *argv[])
#define AFFACTIONPRIMITIVESLAYER