21 from omniORB
import CORBA, PortableServer
27 DEFAULT_PERIOD = 0.000001
83 self.
_sm.setListener(self)
84 self.
_sm.setEntryAction (RTC.ACTIVE_STATE,
86 self.
_sm.setDoAction (RTC.ACTIVE_STATE,
88 self.
_sm.setPostDoAction(RTC.ACTIVE_STATE,
90 self.
_sm.setExitAction (RTC.ACTIVE_STATE,
92 self.
_sm.setEntryAction (RTC.ERROR_STATE,
94 self.
_sm.setDoAction (RTC.ERROR_STATE,
96 self.
_sm.setExitAction (RTC.ERROR_STATE,
99 st.prev = RTC.INACTIVE_STATE
100 st.curr = RTC.INACTIVE_STATE
101 st.next = RTC.INACTIVE_STATE
102 self.
_sm.setStartState(st)
103 self.
_sm.goTo(RTC.INACTIVE_STATE)
157 self.
_sm.goTo(RTC.ERROR_STATE)
233 self.
_sm.goTo(RTC.ERROR_STATE)
256 self.
_sm.goTo(RTC.ERROR_STATE)
279 self.
_sm.goTo(RTC.ERROR_STATE)
335 return self.
_sm.getState()
352 def __init__(self, owner=None, rate=None):
353 self.
_rtcout = OpenRTM_aist.Manager.instance().getLogbuf(
"rtobject.periodic_ec")
354 self.
_rtcout.RTC_TRACE(
"PeriodicExecutionContext()")
356 OpenRTM_aist.Task.__init__(self)
363 global DEFAULT_PERIOD
369 rate = 1.0 / DEFAULT_PERIOD
375 self.
_rtcout.RTC_DEBUG(
"Actual rate: %d [sec], %d [usec]",
379 self.
_profile = RTC.ExecutionContextProfile(RTC.PERIODIC, (1.0/self.
_period.toDouble()),
None, [], [])
385 def __del__(self, Task=OpenRTM_aist.Task):
386 self.
_rtcout.RTC_TRACE(
"~PeriodicExecutionContext()")
442 while not self.
_worker._running:
456 exctm_ = (t1_ - t0_).getTime().toDouble()
457 slptm_ = self.
_period.toDouble() - exctm_
458 self.
_rtcout.RTC_PARANOID(
"Period: %f [s]", self.
_period.toDouble())
459 self.
_rtcout.RTC_PARANOID(
"Execution: %f [s]", exctm_)
460 self.
_rtcout.RTC_PARANOID(
"Sleep: %f [s]", slptm_)
464 if not self.
_nowait and self.
_period.toDouble() > ((t1_ - t0_).getTime().toDouble()):
466 self.
_rtcout.RTC_PARANOID(
"sleeping...")
467 slptm_ = self.
_period.toDouble() - (t1_ - t0_).getTime().toDouble()
472 self.
_rtcout.RTC_PARANOID(
"Slept: %f [s]", (t3_ - t2_).getTime().toDouble())
502 def close(self, flags):
565 return RTC.PRECONDITION_NOT_MET
568 comp._sm.on_startup()
586 self.
_rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
620 return RTC.PRECONDITION_NOT_MET
628 comp._sm.on_shutdown()
686 self.
_period.set_time(1.0/rate)
687 if self.
_period.toDouble() == 0.0:
691 comp._sm.on_rate_changed()
693 return RTC.BAD_PARAMETER
726 self.
_rtcout.RTC_TRACE(
"activate_component()")
727 for compIn
in self.
_comps:
728 if compIn._ref._is_equivalent(comp):
729 if not compIn._sm._sm.isIn(RTC.INACTIVE_STATE):
730 return RTC.PRECONDITION_NOT_MET
731 compIn._sm._sm.goTo(RTC.ACTIVE_STATE)
734 return RTC.BAD_PARAMETER
767 self.
_rtcout.RTC_TRACE(
"deactivate_component()")
768 for compIn
in self.
_comps:
769 if compIn._ref._is_equivalent(comp):
770 if not compIn._sm._sm.isIn(RTC.ACTIVE_STATE):
771 return RTC.PRECONDITION_NOT_MET
772 compIn._sm._sm.goTo(RTC.INACTIVE_STATE)
774 usec_per_sec_ = 1.0e6
775 sleeptime_ = 10.0 * usec_per_sec_ / float(self.
get_rate())
776 self.
_rtcout.RTC_PARANOID(
"Sleep time is %f [us]", sleeptime_)
777 while compIn._sm._sm.isIn(RTC.ACTIVE_STATE):
778 self.
_rtcout.RTC_TRACE(
"Waiting to be the INACTIVE state %d %f", (count_, float(time.time())))
779 time.sleep(sleeptime_/usec_per_sec_)
781 self.
_rtcout.RTC_ERROR(
"The component is not responding.")
784 if compIn._sm._sm.isIn(RTC.INACTIVE_STATE):
785 self.
_rtcout.RTC_TRACE(
"The component has been properly deactivated.")
787 self.
_rtcout.RTC_ERROR(
"The component could not be deactivated.")
790 return RTC.BAD_PARAMETER
823 for compIn
in self.
_comps:
824 if compIn._ref._is_equivalent(comp):
825 if not compIn._sm._sm.isIn(RTC.ERROR_STATE):
826 return RTC.PRECONDITION_NOT_MET
827 compIn._sm._sm.goTo(RTC.INACTIVE_STATE)
830 return RTC.BAD_PARAMETER
855 self.
_rtcout.RTC_TRACE(
"get_component_state()")
856 for compIn
in self.
_comps:
857 if compIn._ref._is_equivalent(comp):
858 return compIn._sm._sm.getState()
860 return RTC.CREATED_STATE
913 if CORBA.is_nil(comp):
914 return RTC.BAD_PARAMETER
916 dfp_ = comp._narrow(OpenRTM.DataFlowComponent)
917 rtc_ = comp._narrow(RTC.RTObject)
918 if CORBA.is_nil(dfp_)
or CORBA.is_nil(rtc_):
919 return RTC.BAD_PARAMETER
921 id_ = dfp_.attach_context(self.
_ref)
922 comp_ = self.
Comp(ref=comp, dfp=dfp_, id=id_)
924 self.
_profile.participants.append(rtc_)
926 except CORBA.Exception:
927 self.
_rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
928 return RTC.BAD_PARAMETER
936 return RTC.BAD_PARAMETER
938 comp_ = rtc.getObjRef()
939 dfp_ = comp_._narrow(OpenRTM.DataFlowComponent)
940 id_ = rtc.bindContext(self.
_ref)
941 if id_ < 0
or id_ > OpenRTM_aist.ECOTHER_OFFSET:
942 self.
_rtcout.RTC_ERROR(
"bindContext returns invalid id: %d", id_)
945 self.
_rtcout.RTC_DEBUG(
"bindContext returns id = %d", id_)
979 for i
in range(len_):
981 if self.
_comps[idx]._ref._is_equivalent(comp):
982 self.
_comps[idx]._ref.detach_context(self.
_comps[idx]._sm.ec_id)
984 rtcomp = comp._narrow(RTC.RTObject)
985 if CORBA.is_nil(rtcomp):
986 self.
_rtcout.RTC_ERROR(
"Invalid object reference.")
992 return RTC.BAD_PARAMETER
1034 def __init__(self, ref=None, dfp=None, id=None, comp=None):
1039 self.
_ref = comp._ref
1084 manager.registerECFactory(
"PeriodicExecutionContext",
1086 OpenRTM_aist.ECDelete)
1087 def deactivate_component(self, comp)
Deactivate a RT-component.
def get_profile(self)
Get the ExecutionContextProfile.
def start(self)
Start ExecutionContext.
def set_rate(self, rate)
Set ExecutionRate.
def get_rate(self)
Get ExecutionRate.
def on_activated(self, st)
def add_component(self, comp)
Add a RT-component.
def PeriodicExecutionContextInit(manager)
PeriodicExecutionContext class.
def on_state_update(self, st)
def __init__(self, ref=None, dfp=None, id=None, comp=None)
def svc(self)
Create internal activity thread.
def remove_component(self, comp)
Remove the RT-component from participant list.
def close(self, flags)
Close activity thread.
def __init__(self)
Constructor.
def get_component_state(self, comp)
Get RT-component's state.
def on_deactivated(self, st)
def is_running(self)
Check for ExecutionContext running state.
def on_aborting(self, st)
def __del__(self, Task=OpenRTM_aist.Task)
def activate_component(self, comp)
Activate a RT-component.
def stop(self)
Stop ExecutionContext.
def get_kind(self)
Get the ExecutionKind.
def __init__(self, obj, id_)
Constructor.
def bindComponent(self, rtc)
def on_rate_changed(self)
def reset_component(self, comp)
Reset a RT-component.