CaptureController.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include "CaptureController.h"
00011 
00012 // Module specification
00013 // <rtc-template block="module_spec">
00014 static const char* capturecontroller_spec[] =
00015   {
00016     "implementation_id", "CaptureController",
00017     "type_name",         "CaptureController",
00018     "description",       "capture controller",
00019     "version",           HRPSYS_PACKAGE_VERSION,
00020     "vendor",            "AIST",
00021     "category",          "example",
00022     "activity_type",     "DataFlowComponent",
00023     "max_instance",      "10",
00024     "language",          "C++",
00025     "lang_type",         "compile",
00026     // Configuration variables
00027     "conf.default.frameRate",  "1",
00028     "conf.default.initialMode", "sleep",
00029 
00030     ""
00031   };
00032 // </rtc-template>
00033 
00034 CaptureController::CaptureController(RTC::Manager* manager)
00035   : RTC::DataFlowComponentBase(manager),
00036     // <rtc-template block="initializer">
00037     m_imageIn("imageIn", m_image),
00038     m_imageOut("imageOut", m_image),
00039     m_CameraCaptureServicePort("CameraCaptureService"),
00040     m_CameraCaptureService(this),
00041     // </rtc-template>
00042     dummy(0)
00043 {
00044 }
00045 
00046 CaptureController::~CaptureController()
00047 {
00048 }
00049 
00050 
00051 
00052 RTC::ReturnCode_t CaptureController::onInitialize()
00053 {
00054   std::cout << m_profile.instance_name << ": onInitialize()" << std::endl;
00055   // <rtc-template block="bind_config">
00056   // Bind variables and configuration variable
00057   bindParameter("frameRate", m_frameRate, "1");
00058   bindParameter("initialMode", m_initialMode, "sleep");
00059   
00060   // </rtc-template>
00061 
00062   // Registration: InPort/OutPort/Service
00063   // <rtc-template block="registration">
00064   // Set InPort buffers
00065   addInPort("imageIn", m_imageIn);
00066 
00067   // Set OutPort buffer
00068   addOutPort("imageOut", m_imageOut);
00069   
00070   // Set service provider to Ports
00071   m_CameraCaptureServicePort.registerProvider("service0", "CameraCaptureService", m_CameraCaptureService);
00072   
00073   // Set service consumers to Ports
00074   
00075   // Set CORBA Service Ports
00076   addPort(m_CameraCaptureServicePort);
00077   
00078   // </rtc-template>
00079 
00080   RTC::Properties& prop = getProperties();
00081 
00082   return RTC::RTC_OK;
00083 }
00084 
00085 
00086 
00087 /*
00088 RTC::ReturnCode_t CaptureController::onFinalize()
00089 {
00090   return RTC::RTC_OK;
00091 }
00092 */
00093 
00094 /*
00095 RTC::ReturnCode_t CaptureController::onStartup(RTC::UniqueId ec_id)
00096 {
00097   return RTC::RTC_OK;
00098 }
00099 */
00100 
00101 /*
00102 RTC::ReturnCode_t CaptureController::onShutdown(RTC::UniqueId ec_id)
00103 {
00104   return RTC::RTC_OK;
00105 }
00106 */
00107 
00108 RTC::ReturnCode_t CaptureController::onActivated(RTC::UniqueId ec_id)
00109 {
00110   std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
00111   m_tOld = (double)(coil::gettimeofday());
00112   if (m_initialMode == "continuous"){
00113     m_mode = CONTINUOUS;
00114   }else if(m_initialMode == "oneshot"){
00115     m_mode = ONESHOT;
00116   }else{
00117     m_mode = SLEEP;
00118   }
00119   return RTC::RTC_OK;
00120 }
00121 
00122 RTC::ReturnCode_t CaptureController::onDeactivated(RTC::UniqueId ec_id)
00123 {
00124   std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
00125   return RTC::RTC_OK;
00126 }
00127 
00128 RTC::ReturnCode_t CaptureController::onExecute(RTC::UniqueId ec_id)
00129 {
00130   //std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << m_data.data << std::endl;
00131   double tNew = (double)(coil::gettimeofday());
00132   double dt = (double)(tNew - m_tOld);
00133   if (m_mode != SLEEP && dt > 1.0/m_frameRate && m_imageIn.isNew()){
00134     m_imageIn.read();
00135     m_imageOut.write();
00136     if (m_mode == ONESHOT) m_mode = SLEEP;
00137     m_tOld = tNew;
00138   }
00139   
00140   return RTC::RTC_OK;
00141 }
00142 
00143 /*
00144 RTC::ReturnCode_t CaptureController::onAborting(RTC::UniqueId ec_id)
00145 {
00146   return RTC::RTC_OK;
00147 }
00148 */
00149 
00150 /*
00151 RTC::ReturnCode_t CaptureController::onError(RTC::UniqueId ec_id)
00152 {
00153   return RTC::RTC_OK;
00154 }
00155 */
00156 
00157 /*
00158 RTC::ReturnCode_t CaptureController::onReset(RTC::UniqueId ec_id)
00159 {
00160   return RTC::RTC_OK;
00161 }
00162 */
00163 
00164 /*
00165 RTC::ReturnCode_t CaptureController::onStateUpdate(RTC::UniqueId ec_id)
00166 {
00167   return RTC::RTC_OK;
00168 }
00169 */
00170 
00171 /*
00172 RTC::ReturnCode_t CaptureController::onRateChanged(RTC::UniqueId ec_id)
00173 {
00174   return RTC::RTC_OK;
00175 }
00176 */
00177 
00178 
00179 void CaptureController::take_one_frame()
00180 {
00181   m_mode = ONESHOT;
00182 }
00183 
00184 void CaptureController::start_continuous()
00185 {
00186   m_mode = CONTINUOUS;
00187 }
00188 
00189 void CaptureController::stop_continuous()
00190 {
00191   m_mode = SLEEP;
00192 }
00193 
00194 extern "C"
00195 {
00196 
00197   void CaptureControllerInit(RTC::Manager* manager)
00198   {
00199     RTC::Properties profile(capturecontroller_spec);
00200     manager->registerFactory(profile,
00201                              RTC::Create<CaptureController>,
00202                              RTC::Delete<CaptureController>);
00203   }
00204 
00205 };
00206 
00207 


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Sep 6 2017 02:35:54