5 #include <yarp/os/all.h> 17 yarp::os::BufferedPort<yarp::os::Bottle> behavior_start_stop_port;
21 yarp::os::ResourceFinder&
rf;
22 virtual void run(
const yarp::os::Bottle &
args) = 0;
30 Behavior(yarp::os::Mutex* _mut, yarp::os::ResourceFinder &_rf,
icubclient::ICubClient* _iCub, std::string _behaviorName) : mut(_mut), iCub(_iCub), rf(_rf), behaviorName(_behaviorName){
31 from_sensation_port_name =
"None";
32 external_port_name =
"None";
44 if (from_sensation_port_name !=
"None") {
45 sensation_port_in.open(
"/" + port_name_prefix +
"/" + behaviorName +
"/sensation:i");
47 if (external_port_name !=
"None") {
48 rpc_out_port.open(
"/" + port_name_prefix +
"/" + behaviorName +
"/to_external_module");
50 behavior_start_stop_port.open(
"/" + port_name_prefix +
"/" + behaviorName +
"/start_stop:o");
59 yDebug() << behaviorName <<
"::trigger starts";
60 if (mut->try_lock()) {
61 yDebug() << behaviorName <<
"::trigger mutex locked";
62 yarp::os::Bottle & msg = behavior_start_stop_port.prepare();
64 msg.addString(
"start");
65 behavior_start_stop_port.write();
69 msg = behavior_start_stop_port.prepare();
71 msg.addString(
"stop");
72 behavior_start_stop_port.write();
74 yDebug() << behaviorName <<
"::trigger mutex unlocked";
75 yDebug() << behaviorName <<
"::trigger ends";
78 yDebug() << behaviorName <<
" not executed, mutex was closed";
79 yDebug() << behaviorName <<
"::trigger ends";
89 sensation_port_in.interrupt();
90 rpc_out_port.interrupt();
91 behavior_start_stop_port.interrupt();
99 sensation_port_in.interrupt();
100 sensation_port_in.close();
101 rpc_out_port.interrupt();
102 rpc_out_port.close();
103 behavior_start_stop_port.interrupt();
104 behavior_start_stop_port.close();
icubclient::ICubClient * iCub
Grants access to high level motor commands (grasp, touch, look, goto, etc) of the robot as well as it...
bool trigger(const yarp::os::Bottle &args)
trigger triggers this behavior and blocks the mutex
Behavior()=delete
No default constructor!
virtual void close_extra_ports()=0
yarp::os::BufferedPort< yarp::os::Bottle > sensation_port_in
Input port from sensationManager.
yarp::os::Port rpc_out_port
Port to external module.
virtual void configure()=0
virtual void run(const yarp::os::Bottle &args)=0
void openPorts(std::string port_name_prefix)
openPorts open ports defined for a behavior
Behavior(yarp::os::Mutex *_mut, yarp::os::ResourceFinder &_rf, icubclient::ICubClient *_iCub, std::string _behaviorName)
void close_ports()
close_ports close ports defined for a behavior
std::string from_sensation_port_name
yarp::os::ResourceFinder & rf
void interrupt_ports()
interrupt_ports interrupt ports defined for a behavior
std::string external_port_name