00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <rtt/Command.hpp>
00018 #include <rtt/Event.hpp>
00019
00020 #include <ocl/OCL.hpp>
00021
00022 namespace OCL
00023 {
00035 class EmergencyStop
00036 {
00037 public:
00043 EmergencyStop(RTT::TaskContext* axes)
00044 : _axes(axes),fired(false)
00045 {
00046 _stop = axes->methods()->getMethod<bool(void)>("stopAllAxes");
00047 _lock = axes->methods()->getMethod<bool(void)>("lockAllAxes");
00048 if(!_stop.ready()||!_lock.ready()){
00049 log(Error)<<"(EmergencyStop) Stop and Lock Method are not ready"<<endlog();
00050 }
00051 };
00052 ~EmergencyStop(){};
00061 bool addEvent(RTT::TaskContext* task,const std::string& eventname)
00062 {
00063 Handle handle;
00064 try{
00065 log(Debug)<<"Creating Handler"<<endlog();
00066 handle = task->events()->setupConnection(eventname).callback(this,&EmergencyStop::callback).handle();
00067 }catch(...){
00068 log(Error)<<"Could not create Handler for event "<<eventname<<endlog();
00069 }
00070 bool retval = false;
00071 try{
00072 log(Debug)<<"Connecting Event"<<endlog();
00073 retval = handle.connect();
00074 _handlers.push_back(handle);
00075 }catch(...){
00076 log(Error)<<"Could not connect event"<<eventname<<" to handler"<<endlog();
00077 }
00078 return retval;
00079 };
00087 void callback(std::string message) {
00088 if(!fired){
00089 _stop();
00090 _lock();
00091 log(Error) << message <<endlog();
00092 log(Error) << "---------------------------------------------" << endlog();
00093 log(Error) << "--------- EMERGENCY STOP --------------------" << endlog();
00094 log(Error) << "---------------------------------------------" << endlog();
00095 fired=true;
00096 }
00097 };
00098 private:
00099 RTT::TaskContext *_axes;
00100 RTT::Method<bool(void)> _stop;
00101 RTT::Method<bool(void)> _lock;
00102 std::vector<RTT::Handle> _handlers;
00103 bool fired;
00104 };
00105 }