Code taken from Lorenzo's tutorial on head control with the iCub.
This code demonstrates usage of RFModule, in particular to catch termination signals and properly unblock threads waiting on Port.read() so that the process has the chance to stop the head, park it and unitialize the device for controlling the head.
git clone url
cd case-study
mkdir build
cmake ../
make
Make sure you are running yarpserver.
In two separate terminals run:
./target/target
./headTracker/headTracker
Now connect:
yarp connect /detector/target /headTracker/target
Now you can try the following:
Send ctrl-c to headTracker, then to target.
This is fine.
Send ctrl-c to target and then to headTracker.
This is not fine. headTracker hangs.
Now un-comment the call to tracker.interrupt();
bool TrackerModule:: interruptModule()
{
// tracker.interrupt();
return true;
}
Send ctrl-c to target and then to headTracker.
Now this is also fine, because the signal handler calls tracker.interrupt() which in turns calls targetPort.interrupt(). This has the effect to unblock all pending read on the port.