342#include <yarp/os/all.h>
343#include <yarp/sig/Vector.h>
347#include <iCub/utils.h>
352#define ACK yarp::os::createVocab32('a','c','k')
353#define NACK yarp::os::createVocab32('n','a','c','k')
355#define RPC_HELP yarp::os::createVocab32('h','e','l','p')
356#define RPC_GET yarp::os::createVocab32('g','e','t')
357#define RPC_GET_STATUS yarp::os::createVocab32('s','t','a','t')
358#define RPC_IMPEDANCE yarp::os::createVocab32('i','m','p','e')
359#define RPC_S2C_MODE yarp::os::createVocab32('m','o','d','e')
360#define RPC_INTERRUPT yarp::os::createVocab32('i','n','t','e')
361#define RPC_REINSTATE yarp::os::createVocab32('r','e','i','n')
362#define RPC_WAVEING yarp::os::createVocab32('w','a','v','e')
363#define RPC_ELBOW yarp::os::createVocab32('e','l','b','o')
364#define RPC_EXECTIME yarp::os::createVocab32('t','i','m','e')
366#define CMD_IDLE yarp::os::createVocab32('i','d','l','e')
367#define CMD_HOME yarp::os::createVocab32('h','o','m','e')
368#define CMD_CALIBRATE yarp::os::createVocab32('c','a','l','i')
369#define CMD_EXPLORE yarp::os::createVocab32('e','x','p','l')
371#define CMD_OBSERVE yarp::os::createVocab32('o','b','s','e')
372#define CMD_DROP yarp::os::createVocab32('d','r','o','p')
374#define CMD_HOLD yarp::os::createVocab32('h','o','l','d')
376#define CMD_LEARN_MIL yarp::os::createVocab32('l','e','a','r')
378#define CMD_GET yarp::os::createVocab32('g','e','t')
379#define CMD_TAKE yarp::os::createVocab32('t','a','k','e')
380#define CMD_GRASP yarp::os::createVocab32('g','r','a','s')
381#define CMD_TOUCH yarp::os::createVocab32('t','o','u','c')
382#define CMD_PICK yarp::os::createVocab32('p','i','c','k')
383#define CMD_PUSH yarp::os::createVocab32('p','u','s','h')
384#define CMD_POINT yarp::os::createVocab32('p','o','i','n')
385#define CMD_POINT_FAR yarp::os::createVocab32('p','f','a','r')
386#define CMD_LOOK yarp::os::createVocab32('l','o','o','k')
387#define CMD_TRACK yarp::os::createVocab32('t','r','a','c')
388#define CMD_EXPECT yarp::os::createVocab32('e','x','p','e')
389#define CMD_GIVE yarp::os::createVocab32('g','i','v','e')
390#define CMD_HAND yarp::os::createVocab32('h','a','n','d')
391#define CMD_GAZE yarp::os::createVocab32('r','e','l','e')
394#define CMD_TAKE_TOOL yarp::os::createVocab32('t','a','t','o')
396#define CMD_ACTION_TEACH yarp::os::createVocab32('t','e','a','c')
397#define CMD_ACTION_IMITATE yarp::os::createVocab32('i','m','i','t')
400#define GET_S2C yarp::os::createVocab32('s','2','c')
401#define GET_TABLE yarp::os::createVocab32('t','a','b','l')
402#define GET_HOLDING yarp::os::createVocab32('h','o','l','d')
403#define GET_HAND yarp::os::createVocab32('h','a','n','d')
404#define GET_IMAGE yarp::os::createVocab32('i','m','a','g')
405#define GET_IDLE yarp::os::createVocab32('i','d','l','e')
408#define CALIB_TABLE yarp::os::createVocab32('t','a','b','l')
409#define CALIB_FINGERS yarp::os::createVocab32('f','i','n','g')
410#define CALIB_KIN_OFFSET yarp::os::createVocab32('k','i','n','e')
413#define EXPLORE_TORSO yarp::os::createVocab32('t','o','r','s')
414#define EXPLORE_HAND yarp::os::createVocab32('h','a','n','d')
417#define PORT_TAG_CMD 0
418#define PORT_TAG_GET 1
421 #pragma warning(disable:4996)
425using namespace yarp::os;
426using namespace yarp::sig;
428using namespace yarp::math;
445 bool check(Bottle &bot,
const string &name)
448 for(
int i=0; i<bot.size(); i++)
450 if(bot.get(i).asString()==name)
468 string name=rf.check(
"name",Value(
"actionsRenderingEngine")).asString();
527 bool respond(
const Bottle &command, Bottle &reply)
529 if(command.size()==0)
531 reply.addString(
"No command received.");
535 switch(command.get(0).asVocab32())
539 string rep=
"Commands:\n";
540 rep+=
"\"interrupt\"\t\t\tinterrupts all the actions untill a 'reinstate' command is issued\n";
541 rep+=
"\"reinstate\"\t\t\treinstates the system (usually called after an 'interrupt' command\n";
542 rep+=
"\"impedance on/off\"\\off\t\t\tset the impedance control on or off\n";
543 rep+=
"\"mode homography\"\\disparity\\network\t\t\tset the 'stereo to cartesian' mode";
544 rep+=
"\"status\"\t\t\tget the module current status\n";
545 reply.addString(rep);
553 switch(command.get(1).asVocab32())
568 if(command.get(1).asString()==
"on")
571 done?reply.addString(
"Impedance turned on"):reply.addString(
"Unable to set impedance on");
573 else if(command.get(1).asString()==
"off")
576 reply.addString(
"Impedance turned off");
580 reply.addString(
"What do you want? Impedance on or off?");
588 if(command.get(1).asString()==
"on")
591 reply.addString(
"Waveing turned on");
593 else if(command.get(1).asString()==
"off")
596 reply.addString(
"Waveing turned off");
600 reply.addString(
"What do you want? Waveing on or off?");
618 reply.addString(
"interrupted");
627 reply.addString(
"reinstated");
633 if (command.size()>=4)
635 string arm=command.get(1).asString();
636 double height=command.get(2).asFloat64();
637 double weight=command.get(3).asFloat64();
639 if ((arm==
"both") || (arm==
"left"))
642 if ((arm==
"both") || (arm==
"right"))
645 reply.addString(
"elbow parameters updated");
648 reply.addString(
"missing elbow parameters");
655 if (command.size()>1)
657 double execTime=command.get(1).asFloat64();
660 reply.addString(
"execution time updated");
663 reply.addString(
"missing execution time");
670 reply.addString(
"command not recognized");
677 bool process(
int &port_tag, Bottle &command, Bottle &reply)
681 reply.addVocab32(
NACK);
682 reply.addString(
"Sorry. Module closing.");
686 if(command.size()==0)
688 reply.addVocab32(
NACK);
689 reply.addString(
"No command received.");
693 reply.addVocab32(
NACK);
694 reply.addString(
"Module currently interrupted. Reinstate for action.");
700 if(command.get(0).asVocab32()!=
CMD_GET)
702 reply.addVocab32(
NACK);
703 reply.addString(
"This port can only process [get] commands");
705 else if(command.size()>1)
707 switch(command.get(1).asVocab32())
713 for(
int target_idx=2; target_idx<command.size(); target_idx++)
719 Bottle &tmp_reply=reply.addList();
722 for(
size_t i=0; i<xd.size(); i++)
723 tmp_reply.addFloat64(xd[i]);
726 tmp_reply.addVocab32(
NACK);
736 reply.addVocab32(
ACK);
738 reply.addVocab32(
NACK);
749 Bottle &tmp_reply=reply.addList();
750 tmp_reply.addString(
"table_height");
751 tmp_reply.addFloat64(table_height);
754 reply.addVocab32(
NACK);
763 reply.addVocab32(
ACK);
765 reply.addVocab32(
NACK);
772 if(command.get(2).asVocab32()==
GET_IMAGE)
776 reply.addVocab32(
NACK);
779 reply.addVocab32(
NACK);
787 reply.addVocab32(
NACK);
793 reply.addVocab32(
NACK);
797 switch(command.get(0).asVocab32())
802 reply.addVocab32(
ACK);
809 reply.addVocab32(
ACK);
818 reply.addVocab32(
ACK);
819 reply.addInt32(holding?1:0);
822 reply.addVocab32(
NACK);
829 reply.addVocab32(
ACK);
839 switch(command.get(1).asVocab32())
850 for(
size_t i=0; i<xd.size(); i++)
851 reply.addFloat64(xd[i]);
854 reply.addVocab32(
NACK);
872 switch(command.get(1).asVocab32())
877 reply.addVocab32(
ACK);
879 reply.addVocab32(
NACK);
887 reply.addVocab32(
ACK);
889 reply.addVocab32(
NACK);
896 string rep=command.get(1).asString();
897 reply.addVocab32(
NACK);
898 reply.addString(
"parameter '"+rep+
"' not supported by 'explore' command.");
905 reply.addVocab32(
NACK);
906 reply.addString(
"explore command needs further parameter (e.g. 'torso')");
913 switch(command.get(1).asVocab32())
919 reply.addVocab32(
ACK);
921 reply.addVocab32(
NACK);
929 reply.addVocab32(
ACK);
931 reply.addVocab32(
NACK);
938 if(command.get(2).asString()==
"start")
940 if (command.size()>=4)
941 if (command.get(3).isList())
945 reply.addVocab32(
ACK);
946 reply.addString(
"learn kinematic offset mode: on");
949 reply.addVocab32(
NACK);
951 else if(command.get(2).asString()==
"stop")
955 reply.addVocab32(
ACK);
956 reply.addString(
"learn kinematic offset mode: off");
959 reply.addVocab32(
NACK);
972 if(
check(command,
"start"))
974 string action_name=command.get(1).asString();
976 Bottle &action=command.addList();
977 action.addString(
"action_name");
978 action.addString(action_name);
982 reply.addVocab32(
NACK);
983 reply.addString(
"action "+action_name+
" already known");
989 reply.addVocab32(
ACK);
990 reply.addString(
"start teaching");
994 if(
check(command,
"stop"))
999 reply.addVocab32(
ACK);
1000 reply.addString(
"stop teaching");
1003 reply.addVocab32(
NACK);
1011 string action_name=command.get(1).asString();
1013 Bottle &action=command.addList();
1014 action.addString(
"action_name");
1015 action.addString(action_name);
1021 reply.addVocab32(
NACK);
1022 reply.addString(
"action "+action_name+
" unknown");
1026 reply.addVocab32(
ACK);
1027 reply.addString(
"action "+action_name+
" done");
1038 string obj_name=command.get(1).asString();
1054 reply.addString(obj_name +
" learned");
1062 reply.addVocab32(
NACK);
1063 reply.addString(
"Nothing to observe. Not holding anything");
1072 reply.addVocab32(
ACK);
1084 reply.addVocab32(
NACK);
1092 if (
check(command,
"near"))
1098 b.addString(
"head");
1099 b.addString(
"arms");
1103 reply.addVocab32(
ACK);
1110 reply.addVocab32(
NACK);
1120 reply.addVocab32(
NACK);
1121 reply.addString(
"Nothing to give. Not holding anything");
1132 reply.addVocab32(
NACK);
1140 if(
check(command,
"over") && command.size()>2)
1152 reply.addVocab32(
ACK);
1160 if(command.size()<2)
1162 reply.addVocab32(
NACK);
1168 command.addString(
"pretake_hand");
1171 reply.addVocab32(
NACK);
1180 if (
check(command,
"near"))
1187 if (!
check(command,
"still"))
1190 b.addString(
"head");
1191 b.addString(
"arms");
1196 reply.addVocab32(
ACK);
1203 if (!
check(command,
"still"))
1209 reply.addVocab32(
NACK);
1219 if (command.size()<2)
1221 reply.addVocab32(
NACK);
1231 if (!
check(command,
"still"))
1234 b.addString(
"head");
1235 b.addString(
"arms");
1239 reply.addVocab32(
ACK);
1245 if (!
check(command,
"still"))
1248 reply.addVocab32(
NACK);
1257 if(command.size()<2)
1259 reply.addVocab32(
NACK);
1265 command.addString(
"touch");
1268 reply.addVocab32(
NACK);
1272 if(!
check(command,
"still"))
1279 reply.addVocab32(
ACK);
1285 if(command.size()<2)
1287 reply.addVocab32(
NACK);
1295 reply.addVocab32(
NACK);
1299 if (!
check(command,
"still"))
1306 reply.addVocab32(
ACK);
1312 if(command.size()<2)
1314 reply.addVocab32(
NACK);
1322 reply.addVocab32(
NACK);
1326 if(!
check(command,
"still"))
1332 reply.addVocab32(
ACK);
1337 if(command.size()<2)
1339 reply.addVocab32(
NACK);
1347 reply.addVocab32(
NACK);
1351 if(!
check(command,
"still"))
1357 reply.addVocab32(
ACK);
1362 if(command.size()<2)
1364 reply.addVocab32(
NACK);
1368 if(!
check(command,
"hand"))
1373 reply.addVocab32(
NACK);
1377 reply.addVocab32(
ACK);
1383 if (command.get(1).asVocab32()!=Vocab32::encode(
"motion"))
1389 reply.addVocab32(
ACK);
1394 if (command.size()<2)
1396 reply.addVocab32(
NACK);
1401 reply.addVocab32(
ACK);
1407 reply.addVocab32(
NACK);
1415 if(reply.isNull() || reply.size()==0)
1417 reply.addVocab32(
NACK);
1418 reply.addString(
"Random Error");
1439 bool read(ConnectionReader &connection)
1441 Bottle command, reply;
1442 if (!command.read(connection))
1449 if (ConnectionWriter *writer=connection.getWriter())
1450 reply.write(*writer);
1483 string name=rf.check(
"name",Value(
"actionsRenderingEngine")).asString();
1484 setName(name.c_str());
1490 yError(
"ARE could not be initialized!");
1546 virtual bool respond(
const Bottle &command, Bottle &reply)
1551 return RFModule::respond(command,reply);
1560 if (!
yarp.checkNetwork())
1564 rf.setDefaultContext(
"actionsRenderingEngine");
1565 rf.setDefaultConfigFile(
"config.ini");
1566 rf.setDefault(
"name",
"actionsRenderingEngine");
1567 rf.configure(argc,argv);
1571 return mod.runModule(rf);
ARE_PortReader(ActionsRenderingEngine *_are, int _port_tag)
ActionsRenderingEngine * are
bool read(ConnectionReader &connection)
virtual bool configure(ResourceFinder &rf)
virtual double getPeriod()
ARE_PortReader * port_reader_get
ActionsRenderingEngineModule()
virtual bool interruptModule()
virtual bool updateModule()
virtual bool respond(const Bottle &command, Bottle &reply)
ActionsRenderingEngine * are
ARE_PortReader * port_reader_cmd
Initializer * initializer
bool check(Bottle &bot, const string &name)
bool respond(const Bottle &command, Bottle &reply)
bool initialize(ResourceFinder &rf)
bool process(int &port_tag, Bottle &command, Bottle &reply)
bool push(Bottle &options)
bool targetToCartesian(Bottle *target, Vector &xd)
bool calibTable(Bottle &options)
bool powerGrasp(Bottle &options)
void keepFixation(Bottle &options)
bool startLearningModeAction(Bottle &options)
bool reach(Bottle &options)
bool grasp(const Bottle &options)
bool drawNear(Bottle &options)
bool isHolding(const Bottle &options)
void track(Bottle &options)
bool clearIt(Bottle &options)
bool getTableHeight(double *_table_height)
void getStatus(Bottle &status)
bool point(Bottle &options)
bool startLearningModeKinOffset(Bottle &options)
bool hand(const Bottle &options, const string &type="", bool *holding=NULL)
bool give(Bottle &options)
void lookAtHand(Bottle &options)
bool point_far(Bottle &options)
bool imitateAction(Bottle &options)
bool exploreHand(Bottle &options)
bool look(Bottle &options)
bool deploy(Bottle &options)
bool suspendLearningModeKinOffset(Bottle &options)
bool exploreTorso(Bottle &options)
bool changeElbowHeight(const int arm, const double height, const double weight)
bool suspendLearningModeAction(Bottle &options)
bool setImpedance(bool turn_on)
bool changeExecTime(const int arm, const double execTime)
bool release(const Bottle &options)
bool takeTool(Bottle &options)
bool calibFingers(Bottle &options)
bool setWaveing(bool _waveing)
bool shiftAndGrasp(Bottle &options)
bool getHandImagePosition(Bottle &hand_image_pos)
bool goHome(Bottle &options)
int setStereoToCartesianMode(const int mode, Bottle &reply)
bool goUp(Bottle &options, const double h=std::numeric_limits< double >::quiet_NaN())
bool expect(Bottle &options)
bool startLearningMIL(const string &obj_name)
bool getTarget(Value &type, Bottle &target)
#define CMD_ACTION_IMITATE
Copyright (C) 2008 RobotCub Consortium.