Motor.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # -*- Python -*-
00004 
00005 import sys
00006 import time
00007 sys.path.append(".")
00008 
00009 # Import RTM module
00010 import RTC
00011 import OpenRTM_aist
00012 
00013 motor_spec = ["implementation_id", "Motor", 
00014               "type_name",         "Motor", 
00015               "description",       "Motor component", 
00016               "version",           "1.0", 
00017               "vendor",            "Noriaki Ando, AIST", 
00018               "category",          "example", 
00019               "activity_type",     "DataFlowComponent", 
00020               "max_instance",      "10", 
00021               "language",          "Python", 
00022               "lang_type",         "SCRIPT",
00023               "conf.default.motor_id", "0",
00024               ""]
00025 
00026 class Motor(OpenRTM_aist.DataFlowComponentBase):
00027   def __init__(self, manager):
00028     OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
00029     return
00030 
00031   def onInitialize(self):
00032     self._d_in = RTC.TimedFloat(RTC.Time(0,0),0)
00033     self._inIn = OpenRTM_aist.InPort("in", self._d_in)
00034     self._d_out = RTC.TimedLong(RTC.Time(0,0),0)
00035     self._outOut = OpenRTM_aist.OutPort("out", self._d_out)
00036 
00037     # Set InPort buffers
00038     self.addInPort("in",self._inIn)
00039     
00040     # Set OutPort buffers
00041     self.addOutPort("out",self._outOut)
00042 
00043     self._motor_id = [0]
00044     
00045     # Bind variables and configuration variable
00046     self.bindParameter("motor_id", self._motor_id, "0")
00047     self._configsets.update("default")
00048     return RTC.RTC_OK
00049 
00050 
00051   def onExecute(self, ec_id):
00052     if self._inIn.isNew():
00053       data = self._inIn.read()
00054       print "Motor Received data: ", data.data
00055       self._d_out.data = long(data.data *2)
00056       self._outOut.write()
00057     return RTC.RTC_OK
00058   
00059 
00060 
00061 
00062 def MotorInit(manager):
00063   profile = OpenRTM_aist.Properties(defaults_str=motor_spec)
00064   manager.registerFactory(profile,
00065                           Motor,
00066                           OpenRTM_aist.Delete)
00067 
00068 def MyModuleInit(manager):
00069   MotorInit(manager)
00070 
00071   # Create a component
00072   comp = manager.createComponent("Motor")
00073 
00074 
00075 
00076 def main():
00077   mgr = OpenRTM_aist.Manager.init(sys.argv)
00078   mgr.setModuleInitProc(MyModuleInit)
00079   mgr.activateManager()
00080   mgr.runManager()
00081 
00082 if __name__ == "__main__":
00083   main()
00084 


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28