SampleComponent.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include "SampleComponent.h"
11 
12 // Module specification
13 // <rtc-template block="module_spec">
14 static const char* nullcomponent_spec[] =
15  {
16  "implementation_id", "SampleComponent",
17  "type_name", "SampleComponent",
18  "description", "null component",
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.debugLevel", "0",
28  ""
29  };
30 // </rtc-template>
31 
33  : RTC::DataFlowComponentBase(manager),
34  // <rtc-template block="initializer">
35  m_qCurrentIn("qCurrent", m_qCurrent),
36  m_qOut("q", m_q),
37  m_SampleComponentPort("SampleComponentService"),
38  loop(0),
39  offset(0),
40  m_debugLevel(0),
41  dummy(0)
42 {
43  m_service0.sample(this);
44  std::cerr << "SampleComponent::SampleComponent()" << std::endl;
45 }
46 
48 {
49  std::cerr << "SampleComponent::~SampleComponent()" << std::endl;
50 }
51 
52 
53 
54 RTC::ReturnCode_t SampleComponent::onInitialize()
55 {
56  std::cerr << m_profile.instance_name << ": onInitialize()" << std::endl;
57  // <rtc-template block="bind_config">
58  // Bind variables and configuration variable
59 
60  // </rtc-template>
61 
62  // Registration: InPort/OutPort/Service
63  // <rtc-template block="registration">
64  // Set InPort buffers
65  addInPort("qCurrent", m_qCurrentIn);
66 
67  // Set OutPort buffer
68  addOutPort("q", m_qOut);
69 
70  // Set service provider to Ports
71  m_SampleComponentPort.registerProvider("service0", "SampleComponentService", m_service0);
72 
73  // Set service consumers to Ports
74 
75  // Set CORBA Service Ports
77 
78  // </rtc-template>
79 
80  return RTC::RTC_OK;
81 }
82 
83 
84 
85 /*
86 RTC::ReturnCode_t SampleComponent::onFinalize()
87 {
88  return RTC::RTC_OK;
89 }
90 */
91 
92 /*
93 RTC::ReturnCode_t SampleComponent::onStartup(RTC::UniqueId ec_id)
94 {
95  return RTC::RTC_OK;
96 }
97 */
98 
99 /*
100 RTC::ReturnCode_t SampleComponent::onShutdown(RTC::UniqueId ec_id)
101 {
102  return RTC::RTC_OK;
103 }
104 */
105 
107 {
108  std::cerr << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
109  return RTC::RTC_OK;
110 }
111 
113 {
114  std::cerr << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
115  return RTC::RTC_OK;
116 }
117 
119  loop = 0;
120  offset = dir;
121  return true;
122 }
123 
125 {
126  //std::cerr << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << std::endl;
127  loop ++;
128  static double output = 0;
129  if (m_qCurrentIn.isNew()) {
130  m_qCurrentIn.read();
131  }
132 
133  if ( m_qCurrent.data.length() != m_q.data.length() ) {
134  m_q.data.length(m_qCurrent.data.length());
135  }
136  for ( unsigned int i = 0; i < m_qCurrent.data.length(); i++ ){
137  m_q.data[i] = m_qCurrent.data[i];
138  }
139  if ( loop < 1000 ) {
140  output += offset;
141  }
142  if ( m_q.data.length() > 9 ) {
143  m_q.data[9] = output;
144  }
145  m_qOut.write();
146 
147  return RTC::RTC_OK;
148 }
149 
150 /*
151 RTC::ReturnCode_t SampleComponent::onAborting(RTC::UniqueId ec_id)
152 {
153  return RTC::RTC_OK;
154 }
155 */
156 
157 /*
158 RTC::ReturnCode_t SampleComponent::onError(RTC::UniqueId ec_id)
159 {
160  return RTC::RTC_OK;
161 }
162 */
163 
164 /*
165 RTC::ReturnCode_t SampleComponent::onReset(RTC::UniqueId ec_id)
166 {
167  return RTC::RTC_OK;
168 }
169 */
170 
171 /*
172 RTC::ReturnCode_t SampleComponent::onStateUpdate(RTC::UniqueId ec_id)
173 {
174  return RTC::RTC_OK;
175 }
176 */
177 
178 /*
179 RTC::ReturnCode_t SampleComponent::onRateChanged(RTC::UniqueId ec_id)
180 {
181  return RTC::RTC_OK;
182 }
183 */
184 
185 
186 
187 extern "C"
188 {
189 
191  {
193  manager->registerFactory(profile,
194  RTC::Create<SampleComponent>,
195  RTC::Delete<SampleComponent>);
196  }
197 
198 };
199 
200 
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
bool resetOffset(double dir)
TimedDoubleSeq m_q
void SampleComponentInit(RTC::Manager *manager)
SampleComponent_impl m_service0
png_uint_32 i
RTC::CorbaPort m_SampleComponentPort
bool addOutPort(const char *name, OutPortBase &outport)
null component
ExecutionContextHandle_t UniqueId
virtual ~SampleComponent()
Destructor.
virtual RTC::ReturnCode_t onInitialize()
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
TimedDoubleSeq m_qCurrent
virtual bool isNew()
bool addPort(PortBase &port)
virtual bool write(DataType &value)
OutPort< TimedDoubleSeq > m_qOut
InPort< TimedDoubleSeq > m_qCurrentIn
bool addInPort(const char *name, InPortBase &inport)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
SampleComponent(RTC::Manager *manager)
Constructor.
void sample(SampleComponent *i_sample)
output(gif_dest_ptr dinfo, int code)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
static const char * nullcomponent_spec[]


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