14 rpc_in_port.interrupt();
16 for(
auto& beh : behaviors) {
17 beh->interrupt_ports();
24 rpc_in_port.interrupt();
28 for(
auto& beh : behaviors) {
29 beh->interrupt_ports();
42 moduleName = rf.check(
"name",Value(
"BehaviorManager")).asString();
43 setName(moduleName.c_str());
44 yInfo()<<moduleName<<
": finding configuration files...";
45 period = rf.check(
"period",Value(1.0)).asDouble();
47 Bottle grp = rf.findGroup(
"BEHAVIORS");
48 Bottle behaviorList = *grp.find(
"behaviors").asList();
50 rpc_in_port.open(
"/" + moduleName +
"/trigger:i");
51 yInfo() <<
"RPC_IN : " << rpc_in_port.getName();
54 bool isRFVerbose =
false;
59 yInfo() <<
"iCubClient : Some dependencies are not running...";
63 for (
unsigned int i = 0; i<behaviorList.size(); i++)
65 std::string behavior_name = behaviorList.get(i).asString();
66 if (behavior_name ==
"tagging") {
67 behaviors.push_back(
new Tagging(&mut, rf, iCub,
"tagging"));
68 }
else if (behavior_name ==
"pointing") {
69 behaviors.push_back(
new Pointing(&mut, rf, iCub,
"pointing"));
70 }
else if (behavior_name ==
"dummy") {
71 behaviors.push_back(
new Dummy(&mut, rf, iCub,
"dummy"));
72 }
else if (behavior_name ==
"dummy2") {
73 behaviors.push_back(
new Dummy(&mut, rf, iCub,
"dummy2"));
74 }
else if (behavior_name ==
"recognitionOrder") {
75 behaviors.push_back(
new RecognitionOrder(&mut, rf, iCub,
"recognitionOrder"));
76 }
else if (behavior_name ==
"moveObject") {
77 behaviors.push_back(
new MoveObject(&mut, rf, iCub,
"moveObject"));
80 yDebug() <<
"Behavior " + behavior_name +
" not implemented";
85 while (!Network::connect(
"/ears/behavior:o", rpc_in_port.getName())) {
86 yWarning() <<
"Ears is not reachable";
87 yarp::os::Time::delay(0.5);
90 for(
auto& beh : behaviors) {
92 beh->openPorts(moduleName);
94 if (beh->from_sensation_port_name !=
"None") {
95 while (!Network::connect(beh->from_sensation_port_name, beh->sensation_port_in.getName())) {
96 yInfo()<<
"Connecting "<< beh->from_sensation_port_name <<
" to " << beh->sensation_port_in.getName();
97 yarp::os::Time::delay(0.5);
100 if (beh->external_port_name !=
"None") {
101 while (!Network::connect(beh->rpc_out_port.getName(), beh->external_port_name)) {
102 yInfo()<<
"Connecting "<< beh->rpc_out_port.getName() <<
" to " << beh->external_port_name;
103 yarp::os::Time::delay(0.5);
124 yDebug() <<
"RPC received in BM";
125 yDebug() << cmd.toString();
129 if (cmd.get(0).asString() ==
"help" )
130 {
string help =
"\n";
131 help +=
" ['behavior_name'] : Triggers corresponding behavior \n";
132 reply.addString(help);
134 else if (cmd.get(0).asString() ==
"names" ) {
136 for(
auto& beh : behaviors) {
137 names.addString(beh->behaviorName);
139 reply.addList() = names;
140 }
else if (cmd.get(0).asString() ==
"is_available" ) {
141 if (mut.try_lock()) {
150 bool behavior_triggered =
false;
151 for(
auto& beh : behaviors) {
152 if (cmd.get(0).asString() == beh->behaviorName) {
154 if (beh->from_sensation_port_name !=
"None") {
155 if (!Network::isConnected(beh->from_sensation_port_name, beh->sensation_port_in.getName())) {
156 aux =Network::connect(beh->from_sensation_port_name, beh->sensation_port_in.getName());
157 yInfo()<<
"The sensations port for "<< beh->behaviorName <<
" was not connected. \nReconnection status: " << aux;
160 if (beh->external_port_name !=
"None") {
161 if (!Network::isConnected(beh->rpc_out_port.getName(), beh->external_port_name)) {
162 aux = Network::connect(beh->rpc_out_port.getName(), beh->external_port_name);
163 yInfo()<<
"The external port for "<< beh->behaviorName <<
" was not connected. \nReconnection status: " << aux;
171 yDebug() <<
"arguments are " << args.toString().c_str();
172 behavior_triggered = beh->trigger(args);
175 if (behavior_triggered) {
176 reply.addString(
"ack");
178 reply.addString(
"nack");
179 yDebug()<<
"Behavior ' " << cmd.get(0).asString() <<
" ' cant be triggered. \nSend 'names' to see a list of available behaviors. ";
182 yDebug() <<
"End of BehaviorManager::respond";
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &reply)
Grants access to high level motor commands (grasp, touch, look, goto, etc) of the robot as well as it...
bool configure(yarp::os::ResourceFinder &rf)