CaptureController.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include "CaptureController.h"
11 
12 // Module specification
13 // <rtc-template block="module_spec">
14 static const char* capturecontroller_spec[] =
15  {
16  "implementation_id", "CaptureController",
17  "type_name", "CaptureController",
18  "description", "capture controller",
19  "version", HRPSYS_PACKAGE_VERSION,
20  "vendor", "AIST",
21  "category", "example",
22  "activity_type", "DataFlowComponent",
23  "max_instance", "10",
24  "language", "C++",
25  "lang_type", "compile",
26  // Configuration variables
27  "conf.default.frameRate", "1",
28  "conf.default.initialMode", "sleep",
29 
30  ""
31  };
32 // </rtc-template>
33 
35  : RTC::DataFlowComponentBase(manager),
36  // <rtc-template block="initializer">
37  m_imageIn("imageIn", m_image),
38  m_imageOut("imageOut", m_image),
39  m_CameraCaptureServicePort("CameraCaptureService"),
40  m_CameraCaptureService(this),
41  // </rtc-template>
42  dummy(0)
43 {
44 }
45 
47 {
48 }
49 
50 
51 
53 {
54  std::cout << m_profile.instance_name << ": onInitialize()" << std::endl;
55  // <rtc-template block="bind_config">
56  // Bind variables and configuration variable
57  bindParameter("frameRate", m_frameRate, "1");
58  bindParameter("initialMode", m_initialMode, "sleep");
59 
60  // </rtc-template>
61 
62  // Registration: InPort/OutPort/Service
63  // <rtc-template block="registration">
64  // Set InPort buffers
65  addInPort("imageIn", m_imageIn);
66 
67  // Set OutPort buffer
68  addOutPort("imageOut", m_imageOut);
69 
70  // Set service provider to Ports
71  m_CameraCaptureServicePort.registerProvider("service0", "CameraCaptureService", m_CameraCaptureService);
72 
73  // Set service consumers to Ports
74 
75  // Set CORBA Service Ports
77 
78  // </rtc-template>
79 
81 
82  return RTC::RTC_OK;
83 }
84 
85 
86 
87 /*
88 RTC::ReturnCode_t CaptureController::onFinalize()
89 {
90  return RTC::RTC_OK;
91 }
92 */
93 
94 /*
95 RTC::ReturnCode_t CaptureController::onStartup(RTC::UniqueId ec_id)
96 {
97  return RTC::RTC_OK;
98 }
99 */
100 
101 /*
102 RTC::ReturnCode_t CaptureController::onShutdown(RTC::UniqueId ec_id)
103 {
104  return RTC::RTC_OK;
105 }
106 */
107 
109 {
110  std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
111  m_tOld = (double)(coil::gettimeofday());
112  if (m_initialMode == "continuous"){
113  m_mode = CONTINUOUS;
114  }else if(m_initialMode == "oneshot"){
115  m_mode = ONESHOT;
116  }else{
117  m_mode = SLEEP;
118  }
119  return RTC::RTC_OK;
120 }
121 
123 {
124  std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
125  return RTC::RTC_OK;
126 }
127 
129 {
130  //std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << m_data.data << std::endl;
131  double tNew = (double)(coil::gettimeofday());
132  double dt = (double)(tNew - m_tOld);
133  if (m_mode != SLEEP && dt > 1.0/m_frameRate && m_imageIn.isNew()){
134  m_imageIn.read();
135  m_imageOut.write();
136  if (m_mode == ONESHOT) m_mode = SLEEP;
137  m_tOld = tNew;
138  }
139 
140  return RTC::RTC_OK;
141 }
142 
143 /*
144 RTC::ReturnCode_t CaptureController::onAborting(RTC::UniqueId ec_id)
145 {
146  return RTC::RTC_OK;
147 }
148 */
149 
150 /*
151 RTC::ReturnCode_t CaptureController::onError(RTC::UniqueId ec_id)
152 {
153  return RTC::RTC_OK;
154 }
155 */
156 
157 /*
158 RTC::ReturnCode_t CaptureController::onReset(RTC::UniqueId ec_id)
159 {
160  return RTC::RTC_OK;
161 }
162 */
163 
164 /*
165 RTC::ReturnCode_t CaptureController::onStateUpdate(RTC::UniqueId ec_id)
166 {
167  return RTC::RTC_OK;
168 }
169 */
170 
171 /*
172 RTC::ReturnCode_t CaptureController::onRateChanged(RTC::UniqueId ec_id)
173 {
174  return RTC::RTC_OK;
175 }
176 */
177 
178 
180 {
181  m_mode = ONESHOT;
182 }
183 
185 {
186  m_mode = CONTINUOUS;
187 }
188 
190 {
191  m_mode = SLEEP;
192 }
193 
194 extern "C"
195 {
196 
198  {
200  manager->registerFactory(profile,
201  RTC::Create<CaptureController>,
202  RTC::Delete<CaptureController>);
203  }
204 
205 };
206 
207 
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
InPort< Img::TimedCameraImage > m_imageIn
void CaptureControllerInit(RTC::Manager *manager)
CameraCaptureService_impl m_CameraCaptureService
static const char * capturecontroller_spec[]
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
RTC::CorbaPort m_CameraCaptureServicePort
coil::Properties & getProperties()
bool addOutPort(const char *name, OutPortBase &outport)
capture controller
int gettimeofday(struct timeval *tv, struct timezone *tz)
std::string m_initialMode
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
OutPort< Img::TimedCameraImage > m_imageOut
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
CaptureController(RTC::Manager *manager)
Constructor.
prop
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
virtual bool isNew()
virtual RTC::ReturnCode_t onInitialize()
bool addPort(PortBase &port)
virtual bool write(DataType &value)
virtual ~CaptureController()
Destructor.
bool addInPort(const char *name, InPortBase &inport)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:49