1 #include <yarp/os/all.h> 6 yarp::os::Bottle &sub=b.addList();
7 sub.addString(
"cartesian");
8 for (
size_t i=0; i<t.length(); i++)
15 for (
unsigned int i=0; i<options.size(); i++)
17 yarp::os::Value val=options.get(i);
20 std::string item=val.asString();
21 if ((item==
"left") || (item==
"right"))
32 if (handToUse.empty())
34 hand=(target[1]>0.0?
"right":
"left");
35 options.addString(hand.c_str());
44 yarp::os::Bottle cmd,reply;
45 cmd.addString(
"get_location");
47 cmd.addString(objName);
48 cmd.addString(
"iol-"+hand);
50 target[0]=reply.get(1).asDouble();
51 target[1]=reply.get(2).asDouble();
52 target[2]=reply.get(3).asDouble();
55 opt.addString(
"fixate");
66 yDebug() <<
"Send to ARE: " << cmd.toString();
67 yarp::os::Bottle bReply;
68 if (
portCmd.write(const_cast<yarp::os::Bottle&>(cmd),bReply))
69 ret=(bReply.get(0).asVocab()==yarp::os::Vocab::encode(
"ack"));
71 yDebug() <<
"Reply from ARE: " << bReply.toString();
78 if (!yarp::os::Network::isConnected(
portCalib.getName(),
"/iolReachingCalibration/rpc")) {
79 if (yarp::os::Network::connect(
portCalib.getName(),
"/iolReachingCalibration/rpc")) {
80 yInfo()<<
"ARE connected to calibrator";
82 yWarning()<<
"ARE didn't connect to calibrator";
87 if(!yarp::os::Network::isConnected(
portCmd.getName(),
"/actionsRenderingEngine/cmd:io")) {
88 ret&=yarp::os::Network::connect(
portCmd.getName(),
"/actionsRenderingEngine/cmd:io");
90 if(!yarp::os::Network::isConnected(
portRPC.getName(),
"/actionsRenderingEngine/rpc")) {
91 ret&=yarp::os::Network::connect(
portRPC.getName(),
"/actionsRenderingEngine/rpc");
93 if(!yarp::os::Network::isConnected(
portGet.getName(),
"/actionsRenderingEngine/get:io")) {
94 ret&=yarp::os::Network::connect(
portGet.getName(),
"/actionsRenderingEngine/get:io");
132 yarp::os::Bottle bCmd, bReply;
133 bCmd.addVocab(yarp::os::Vocab::encode(
"get"));
134 bCmd.addVocab(yarp::os::Vocab::encode(
"table"));
137 yarp::os::Value vHeight = bReply.find(
"table_height");
138 if (vHeight.isNull()) {
139 yError(
"No table height specified in ARE!");
143 height = vHeight.asDouble();
150 yarp::sig::VectorOf<double> out=in;
151 out[0]=std::min(out[0],-0.1);
155 out[2]=std::max(out[2],height);
162 yDebug() <<
"ARE::home start";
163 yarp::os::Bottle bCmd;
164 bCmd.addVocab(yarp::os::Vocab::encode(
"home"));
165 bCmd.addString(part.c_str());
169 bReturn ? status =
"success" : status =
"failed";
170 yDebug() <<
"ARE::home stop";
177 yDebug() <<
"ARE::take start";
182 o =
dynamic_cast<Object*
>(e);
185 yError() << sName <<
" is not an Entity";
189 yError() <<
"Could not cast" << e->
name() <<
"to Object";
193 yarp::os::Bottle bCmd;
194 bCmd.addVocab(yarp::os::Vocab::encode(
"take"));
197 yarp::os::Bottle opt=options;
205 bReturn ? status =
"success" : status =
"failed";
206 yDebug() <<
"ARE::take stop";
213 yDebug() <<
"ARE::push start";
218 o =
dynamic_cast<Object*
>(e);
221 yError() << sName <<
" is not an Entity";
225 yError() <<
"Could not cast" << e->
name() <<
"to Object";
229 yarp::os::Bottle bCmd;
230 bCmd.addVocab(yarp::os::Vocab::encode(
"push"));
233 yarp::os::Bottle opt=options;
241 bReturn ? status =
"success" : status =
"failed";
243 yDebug() <<
"ARE::push stop";
250 yDebug() <<
"ARE::point start";
253 yarp::os::Bottle bCmd;
254 if(target[0]<-0.31) {
255 yDebug() <<
"Use ARE::pfar for pointing";
256 bCmd.addVocab(yarp::os::Vocab::encode(
"pfar"));
258 yDebug() <<
"Use ARE::point for pointing";
259 bCmd.addVocab(yarp::os::Vocab::encode(
"point"));
263 bCmd.append(options);
267 bReturn ? status =
"success" : status =
"failed";
269 yDebug() <<
"ARE::point stop";
275 yDebug() <<
"ARE::drop start";
280 yarp::os::Bottle bCmd;
281 bCmd.addVocab(yarp::os::Vocab::encode(
"drop"));
282 bCmd.append(options);
285 bReturn ? status =
"success" : status =
"failed";
287 yDebug() <<
"ARE::drop stop";
293 yDebug() <<
"ARE::dropOn start";
295 yarp::os::Bottle bCmd;
296 bCmd.addVocab(yarp::os::Vocab::encode(
"drop"));
297 bCmd.addString(
"over");
299 yarp::sig::VectorOf<double> target=targetUnsafe;
300 yarp::os::Bottle opt=options;
308 bReturn ? status =
"success" : status =
"failed";
310 yDebug() <<
"ARE::dropOn stop";
316 yDebug() <<
"ARE::observe start";
318 yarp::os::Bottle bCmd;
319 bCmd.addVocab(yarp::os::Vocab::encode(
"observe"));
320 bCmd.append(options);
323 bReturn ? status =
"success" : status =
"failed";
325 yDebug() <<
"ARE::observe stop";
332 yDebug() <<
"ARE::expect start";
334 yarp::os::Bottle bCmd;
335 bCmd.addVocab(yarp::os::Vocab::encode(
"expect"));
336 bCmd.append(options);
339 bReturn ? status =
"success" : status =
"failed";
341 yDebug() <<
"ARE::expect stop";
348 yDebug() <<
"ARE::give start";
350 yarp::os::Bottle bCmd;
351 bCmd.addVocab(yarp::os::Vocab::encode(
"give"));
352 bCmd.append(options);
355 bReturn ? status =
"success" : status =
"failed";
357 yDebug() <<
"ARE::give stop";
363 yDebug() <<
"ARE::waving start";
365 yarp::os::Bottle bCmd;
366 bCmd.addVocab(yarp::os::Vocab::encode(
"waveing"));
367 bCmd.addString(sw ?
"on" :
"off");
368 bool bReturn =
portRPC.asPort().write(bCmd);
370 bReturn ? status =
"success" : status =
"failed";
372 yDebug() <<
"ARE::waving stop";
378 yDebug() <<
"ARE::look start";
380 yarp::os::Bottle bCmd;
381 bCmd.addVocab(yarp::os::Vocab::encode(
"look"));
383 bCmd.append(options);
386 bReturn ? status =
"success" : status =
"failed";
388 yarp::os::Time::delay(0.1);
390 yDebug() <<
"ARE::look stop";
397 yarp::os::Bottle bCmd;
398 bCmd.addVocab(yarp::os::Vocab::encode(
"track"));
400 bCmd.append(options);
406 yarp::os::Bottle bCmd;
407 bCmd.addVocab(yarp::os::Vocab::encode(
"impedance"));
408 bCmd.addString(sw ?
"on" :
"off");
409 return portRPC.asPort().write(bCmd);
414 yarp::os::Bottle bCmd;
415 bCmd.addVocab(yarp::os::Vocab::encode(
"time"));
416 bCmd.addDouble(execTime);
417 return portRPC.asPort().write(bCmd);
bool sendCmd(const yarp::os::Bottle &cmd)
Sends a command to ARE's cmdPort.
yarp::os::RpcClient portRPC
Port to /ARE/rpc.
std::string lastlyUsedHand
The hand which was used for the last action.
Represent any entity that can be stored within the OPC.
yarp::os::RpcClient portCalib
Port to iolReachingCalibration.
void close()
Close the client ports.
bool push(const std::string &sName, const yarp::os::Bottle &options=yarp::os::Bottle())
Reach the specified [target] from one side and then push it laterally.
bool look(const yarp::sig::VectorOf< double > &target, const yarp::os::Bottle &options=yarp::os::Bottle())
Look at the specified [target].
~SubSystem_ARE()
Destructor.
SubSystem_ARE(const std::string &masterName)
Default constructor.
bool expect(const yarp::os::Bottle &options=yarp::os::Bottle())
Put one hand forward with the palm facing up and wait for an object.
bool connect(const std::string &opcName)
Try to connect the client to an OPC server.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
yarp::sig::VectorOf< double > m_ego_position
Position of the Object, in the initial ego-centered reference frame of the agent mainting the OPC (in...
bool impedance(const bool sw)
Enable/disable impedance control.
bool point(const yarp::sig::VectorOf< double > &targetUnsafe, const yarp::os::Bottle &options=yarp::os::Bottle())
Point at the specified [target] with the index finger.
yarp::os::RpcClient portGet
Port to /ARE/get:io.
bool home(const std::string &part="all")
Put the specified part ih home position.
bool getTableHeight(double &height)
Gets the table height from ARE.
yarp::os::RpcClient portCmd
Port to /ARE/cmd:io.
Entity * getEntity(const std::string &name, bool forceUpdate=false)
Gets an entity based on its name, but do no create it if it doesn't exist yet.
Abstract class to handle sub-systems of the icub-client.
void Close()
Clean up resources.
bool track(const yarp::sig::VectorOf< double > &target, const yarp::os::Bottle &options=yarp::os::Bottle())
Track the specified [target].
An OPC client using the datastructures defined within the icub-client library.
bool observe(const yarp::os::Bottle &options=yarp::os::Bottle())
Bring the hand in the visual field and move it with the purpose of visual exploration.
bool take(const std::string &sName, const yarp::os::Bottle &options=yarp::os::Bottle())
Reach the specified [target] and grasp it.
yarp::sig::VectorOf< double > applySafetyMargins(const yarp::sig::VectorOf< double > &in)
Applies safety margins, i.e.
std::string name() const
Return the name of an entity (which has to be unique within the OPC)
void interrupt()
Interrupt communications of the client ports.
void appendCartesianTarget(yarp::os::Bottle &b, const yarp::sig::VectorOf< double > &t)
Appends a target vector t to the Bottle b
void selectHandCorrectTarget(yarp::os::Bottle &options, yarp::sig::VectorOf< double > &target, const std::string &objName, const std::string handToUse="")
bool dropOn(const yarp::sig::VectorOf< double > &targetUnsafe, const yarp::os::Bottle &options=yarp::os::Bottle())
Drop the object on a given target.
bool drop(const yarp::os::Bottle &options=yarp::os::Bottle())
If an object is held, bring it over the table and drop it on a random position.
bool give(const yarp::os::Bottle &options=yarp::os::Bottle())
Put one hand forward with the palm facing up and open the fingers so that the object held in the hand...
bool waving(const bool sw)
Enable/disable arms waving.
bool setExecTime(const double execTime)
Change default arm movement execution time.