Go to the documentation of this file.00001
00010 #include "CaptureController.h"
00011
00012
00013
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
00027 "conf.default.frameRate", "1",
00028 "conf.default.initialMode", "sleep",
00029
00030 ""
00031 };
00032
00033
00034 CaptureController::CaptureController(RTC::Manager* manager)
00035 : RTC::DataFlowComponentBase(manager),
00036
00037 m_imageIn("imageIn", m_image),
00038 m_imageOut("imageOut", m_image),
00039 m_CameraCaptureServicePort("CameraCaptureService"),
00040 m_CameraCaptureService(this),
00041
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
00056
00057 bindParameter("frameRate", m_frameRate, "1");
00058 bindParameter("initialMode", m_initialMode, "sleep");
00059
00060
00061
00062
00063
00064
00065 addInPort("imageIn", m_imageIn);
00066
00067
00068 addOutPort("imageOut", m_imageOut);
00069
00070
00071 m_CameraCaptureServicePort.registerProvider("service0", "CameraCaptureService", m_CameraCaptureService);
00072
00073
00074
00075
00076 addPort(m_CameraCaptureServicePort);
00077
00078
00079
00080 RTC::Properties& prop = getProperties();
00081
00082 return RTC::RTC_OK;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
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
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
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
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