1 #include <yarp/os/all.h> 10 yarp::os::Bottle &sub=b;
11 for (
size_t i=0; i<t.length(); i++)
17 yarp::os::Bottle &sub=b;
22 yarp::sig::VectorOf<double> &target,
const std::string handToUse)
25 for (
unsigned int i=0; i<options.size(); i++)
27 yarp::os::Value val=options.get(i);
30 std::string item=val.asString();
31 if ((item==
"left") || (item==
"right"))
42 if (handToUse.empty())
44 hand=(target[1]>0.0?
"right":
"left");
53 if (portCalib.getOutputCount()>0 && targetName!=
"")
55 yarp::os::Bottle cmd,reply;
56 cmd.addString(
"get_location");
58 cmd.addString(targetName);
59 cmd.addString(
"iol-"+hand);
60 portCalib.write(cmd,reply);
61 target[0]=reply.get(1).asDouble();
62 target[1]=reply.get(2).asDouble();
63 target[2]=reply.get(3).asDouble();
66 opt.addString(
"fixate");
67 SubARE->look(target,opt);
75 yarp::os::Bottle bReply;
76 if (portRPC.write(cmd,bReply))
77 ret=(bReply.get(0).asVocab()==yarp::os::Vocab::encode(
"ack"));
84 AREconnected=SubARE->Connect();
86 yInfo()<<
"KARMA connected to ARE";
88 yWarning()<<
"KARMA didn't connect to ARE";
91 if(!yarp::os::Network::isConnected(portStop.getName(),
"/karmaMotor/stop:i")) {
92 ret&=yarp::os::Network::connect(portStop.getName(),
"/karmaMotor/stop:i");
94 if(!yarp::os::Network::isConnected(portRPC.getName(),
"/karmaMotor/rpc")) {
95 ret&=yarp::os::Network::connect(portRPC.getName(),
"/karmaMotor/rpc");
98 if(!yarp::os::Network::isConnected(portVision.getName(),
"/karmaMotor/vision:i")) {
99 if (yarp::os::Network::connect(portVision.getName(),
"/karmaMotor/vision:i"))
100 yInfo()<<
"KARMA connected to tool tip vision";
102 yWarning()<<
"KARMA didn't connect to tool tip vision";
105 if(!yarp::os::Network::isConnected(portCalib.getName(),
"/iolReachingCalibration/rpc")) {
106 if (yarp::os::Network::connect(portCalib.getName(),
"/iolReachingCalibration/rpc"))
107 yInfo()<<
"KARMA connected to calibrator";
109 yWarning()<<
"KARMA didn't connect to calibrator";
112 openCartesianClient();
116 hasTable = SubARE->getTableHeight(tableHeight);
118 yInfo(
"[SubSystem_KARMA] table height: %f",tableHeight);
120 yWarning(
"[SubSystem_KARMA] no table object");
126 yWarning(
"[SubSystem_KARMA] not connected to ARE");
174 yarp::sig::VectorOf<double> out=in;
175 out[0]=std::min(out[0],-0.1);
182 Vector xL(3,0.0), xR(3,0.0), xdL(3,0.0), xdR(3,0.0), odL(3,0.0), odR(3,0.0);
183 double travelTime = 2.0;
185 int contextL, contextR;
193 Bottle &straightOpt=options.addList();
194 straightOpt.addString(
"straightness");
195 straightOpt.addDouble(10.0);
202 if (armType ==
"selectable")
209 yInfo(
"[SubSystem_KARMA] return %s arm before home",armType.c_str());
210 if (armType ==
"left")
213 xdL[2] = std::min(0.05,xL[2] + 0.1);
214 yInfo(
"[SubSystem_KARMA] xdL = %s",xdL.toString().c_str());
221 else if (armType ==
"right")
224 xdR[2] = std::min(0.05,xR[2] + 0.1);
225 yInfo(
"[SubSystem_KARMA] xdR = %s",xdR.toString().c_str());
238 Vector dimTool(3,0.0);
239 yarp::os::Bottle bCmd;
240 bCmd.addVocab(yarp::os::Vocab::encode(
"tool"));
241 bCmd.addVocab(yarp::os::Vocab::encode(
"attach"));
242 bCmd.addString(armType);
250 yarp::os::Bottle bCmd;
251 bCmd.addVocab(yarp::os::Vocab::encode(
"tool"));
252 bCmd.addVocab(yarp::os::Vocab::encode(
"remove"));
256 yError() <<
"Could not communicate with Karma";
261 const yarp::sig::VectorOf<double> &objCenter,
const double &targetPosY,
263 const std::string &armType,
264 const yarp::os::Bottle &options)
267 Vector
object = objCenter;
268 Bottle opt = options;
269 double zOffset = 0.05;
270 double actionOffset = 0.1;
271 yInfo (
"[subSystem_KARMA] object center OPC : %s",
object.toString().c_str());
273 yInfo (
"[subSystem_KARMA] object center calib: %s",
object.toString().c_str());
274 double radius = fabs(
object[1] - targetPosY);
275 yInfo (
"objectY = %f",
object[1]);
276 yInfo (
"targetPosYRight = %f",targetPosY);
277 yInfo (
"radius = %f",radius);
278 Vector targetCenter = object;
279 targetCenter[1] = targetPosY;
284 yInfo (
"object height = %f",targetCenter[2]);
287 bool armChoose =
false;
288 if (armType ==
"right" || armType ==
"left")
292 bool pushSucceed =
push(targetCenter,theta,radius + actionOffset,options);
304 const yarp::sig::VectorOf<double> &objCenter,
const double &targetPosXFront,
305 const std::string &armType,
306 const yarp::os::Bottle &options)
309 Vector
object = objCenter;
310 Bottle opt = options;
311 double zOffset = 0.1;
312 double actionOffset = 0.1;
313 yInfo (
"[subSystem_KARMA] object center OPC : %s",
object.toString().c_str());
315 yInfo (
"[subSystem_KARMA] object center calib: %s",
object.toString().c_str());
316 double radius = fabs(
object[0] - targetPosXFront);
317 yInfo (
"objectX = %f",
object[0]);
318 yInfo (
"targetPosXFront = %f",targetPosXFront);
319 yInfo (
"radius = %f",radius);
320 Vector targetCenter = object;
321 targetCenter[0] = targetPosXFront;
326 yInfo (
"object height = %f",targetCenter[2]);
329 bool armChoose =
false;
330 if (armType ==
"right" || armType ==
"left")
334 bool pushSucceed =
push(targetCenter,-90,radius + actionOffset,options);
346 const double theta,
const double radius,
347 const yarp::os::Bottle &options)
349 yarp::os::Bottle bCmd;
350 bCmd.addVocab(yarp::os::Vocab::encode(
"push"));
352 yarp::sig::VectorOf<double> target=targetCenter;
353 yarp::os::Bottle opt=options;
366 const yarp::sig::VectorOf<double> &objCenter,
const double &targetPosXBack,
367 const std::string &armType,
368 const yarp::os::Bottle &options)
371 Vector
object = objCenter;
372 Bottle opt = options;
373 double zOffset = -0.04;
374 double actionOffset = 0.05;
375 yInfo (
"[subSystem_KARMA] object center OPC : %s",
object.toString().c_str());
377 yInfo (
"[subSystem_KARMA] object center calib: %s",
object.toString().c_str());
378 double dist = fabs(
object[0] - targetPosXBack);
379 yInfo (
"objectX = %f",
object[0]);
380 yInfo (
"targetPosXBack = %f",targetPosXBack);
381 yInfo (
"dist = %f",dist);
382 Vector targetCenter = object;
385 targetCenter[2] = std::max(
tableHeight,targetCenter[2]);
386 targetCenter[2] += zOffset;
388 yInfo (
"object height = %f",targetCenter[2]);
391 bool armChoose =
false;
392 if (armType ==
"right" || armType ==
"left")
396 bool drawSucceed =
draw(targetCenter,90,actionOffset,dist + actionOffset,options);
408 const double theta,
const double radius,
409 const double dist,
const yarp::os::Bottle &options)
411 yarp::os::Bottle bCmd;
412 bCmd.addVocab(yarp::os::Vocab::encode(
"draw"));
414 yarp::sig::VectorOf<double> target=targetCenter;
415 yarp::os::Bottle opt=options;
428 const yarp::sig::VectorOf<double> &targetCenter,
429 const double theta,
const double radius,
431 const yarp::os::Bottle &options)
433 yarp::os::Bottle bCmd;
434 bCmd.addVocab(yarp::os::Vocab::encode(
"vdraw"));
436 yarp::sig::VectorOf<double> target=targetCenter;
437 yarp::os::Bottle opt=options;
451 std::string name =
"KARMA";
453 Property optionL(
"(device cartesiancontrollerclient)");
454 optionL.put(
"remote",(
"/"+
robot+
"/cartesianController/left_arm").c_str());
455 optionL.put(
"local",(
"/"+name+
"/cart_ctrl/left_arm").c_str());
457 Property optionR(
"(device cartesiancontrollerclient)");
458 optionR.put(
"remote",(
"/"+
robot+
"/cartesianController/right_arm").c_str());
459 optionR.put(
"local",(
"/"+name+
"/cart_ctrl/right_arm").c_str());
461 Property optionHL(
"(device remote_controlboard)");
462 optionHL.put(
"remote",(
"/"+
robot+
"/left_arm").c_str());
463 optionHL.put(
"local",(
"/"+name+
"/hand_ctrl/left_arm").c_str());
465 Property optionHR(
"(device remote_controlboard)");
466 optionHR.put(
"remote",(
"/"+
robot+
"/right_arm").c_str());
467 optionHR.put(
"local",(
"/"+name+
"/hand_ctrl/right_arm").c_str());
bool chooseArm(const std::string &armType)
chooseArm (toolAttach in KARMA): wrapper for tool-attach of KARMA, can be used to choose the arm for ...
bool sendCmd(yarp::os::Bottle &cmd)
Sends a command to KARMA's RPC port.
~SubSystem_KARMA()
Destructor.
bool pullBack(const std::string &objName, const yarp::sig::VectorOf< double > &objCenter, const double &targetPosXBack, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pullBack (KARMA): pull an object to a certain location along x-axis of robot RoF
SubSystem to deal with the actionsRenderingEngine module (a.k.a.
yarp::dev::PolyDriver driverHR
yarp::dev::PolyDriver driverR
yarp::os::RpcClient portRPC
bool vdraw(const std::string &objName, const yarp::sig::VectorOf< double > &targetCenter, const double theta, const double radius, const double dist, const yarp::os::Bottle &options=yarp::os::Bottle())
vdraw (KARMA): virtual draw action, along the positive direction of the x-axis (in robot FoR) ...
yarp::os::RpcClient portFinder
yarp::sig::VectorOf< double > applySafetyMargins(const yarp::sig::VectorOf< double > &in)
Applies safety margins, i.e.
void appendTarget(yarp::os::Bottle &b, const yarp::sig::VectorOf< double > &tCenter)
Appends a target vector t to the Bottle
bool draw(const yarp::sig::VectorOf< double > &targetCenter, const double theta, const double radius, const double dist, const yarp::os::Bottle &options=yarp::os::Bottle())
draw (KARMA): draw action, along the positive direction of the x-axis (in robot FoR) ...
yarp::dev::PolyDriver driverHL
Abstract class to handle sub-systems of the icub-client.
void Close()
Clean up resources.
yarp::dev::PolyDriver driverL
SubSystem_KARMA(const std::string &masterName, const std::string &robot)
Default constructor.
bool openCartesianClient()
bool returnArmSafely(std::string armType)
yarp::os::RpcClient portCalib
void selectHandCorrectTarget(yarp::os::Bottle &options, const std::string &targetName, yarp::sig::VectorOf< double > &target, const std::string handToUse="")
void chooseArmAuto()
chooseArmAuto (toolRemove in KARMA): wrapper for tool-remove of Karma, use to clear the arm choise ...
yarp::os::RpcClient portStop
void appendDouble(yarp::os::Bottle &b, const double &v)
Appends a double value v to the Bottle
bool pushFront(const std::string &objName, const yarp::sig::VectorOf< double > &objCenter, const double &targetPosXFront, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pushFront (KARMA): push an object to a certain location along x-axis of robot RoF ...
bool push(const yarp::sig::VectorOf< double > &targetCenter, const double theta, const double radius, const yarp::os::Bottle &options=yarp::os::Bottle())
push (KARMA): push to certain position, along a defined direction
yarp::os::RpcClient portVision
bool pushAside(const std::string &objName, const yarp::sig::VectorOf< double > &objCenter, const double &targetPosY, const double &theta, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pushAside (KARMA): push an object to a certain location along y-axis of robot RoF ...
void Close()
Clean up resources.
yarp::dev::ICartesianControl * iCartCtrlL
yarp::dev::ICartesianControl * iCartCtrlR