RTSample.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
7 #include "RTSample.h"
8 
9 // Module specification
10 // <rtc-template block="module_spec">
11 static const char* rtsample_spec[] =
12  {
13  "implementation_id", "RTSample",
14  "type_name", "RTSample",
15  "description", "Realtime periodic execution example component",
16  "version", "1.0",
17  "vendor", "Noriaki Ando, AIST",
18  "category", "example",
19  "activity_type", "PERIODIC",
20  "kind", "DataFlowComponent",
21  "max_instance", "10",
22  "language", "C++",
23  "lang_type", "compile",
24  // Configuration variables
25  ""
26  };
27 // </rtc-template>
28 
30  // <rtc-template block="initializer">
31  : RTC::DataFlowComponentBase(manager)
32  // </rtc-template>
33 {
34 }
35 
37 {
38 }
39 
40 
42 {
43  // Registration: InPort/OutPort/Service
44  // <rtc-template block="registration">
45  // Set InPort buffers
46 
47  // Set OutPort buffer
48 
49  // Set service provider to Ports
50 
51  // Set service consumers to Ports
52 
53  // Set CORBA Service Ports
54 
55  // </rtc-template>
56 
57  // <rtc-template block="bind_config">
58  // Bind variables and configuration variable
59 
60  // </rtc-template>
61  return RTC::RTC_OK;
62 }
63 
64 
65 /*
66 RTC::ReturnCode_t RTSample::onFinalize()
67 {
68  return RTC::RTC_OK;
69 }
70 */
71 /*
72 RTC::ReturnCode_t RTSample::onStartup(RTC::UniqueId ec_id)
73 {
74  return RTC::RTC_OK;
75 }
76 */
77 /*
78 RTC::ReturnCode_t RTSample::onShutdown(RTC::UniqueId ec_id)
79 {
80  return RTC::RTC_OK;
81 }
82 */
83 
85 {
86  m_tm.tick();
87  return RTC::RTC_OK;
88 }
89 
90 
92 {
93  double tm_max, tm_min, tm_mean, tm_stddev;
94  m_tm.getStatistics(tm_max, tm_min, tm_mean, tm_stddev);
95  std::cout << "max: " << tm_max * 1000 << " [ms]" << std::endl;
96  std::cout << "min: " << tm_min * 1000 << " [ms]" << std::endl;
97  std::cout << "mean: " << tm_mean * 1000 << " [ms]" << std::endl;
98  std::cout << "stddev: " << tm_stddev * 1000 << " [ms]" << std::endl;
99  return RTC::RTC_OK;
100 }
101 
102 
104 {
105  static int count;
106  m_tm.tack();
107  m_tm.tick();
108 
109  if (count > 1000)
110  {
111  count = 0;
112  double tm_max, tm_min, tm_mean, tm_stddev;
113  m_tm.getStatistics(tm_max, tm_min, tm_mean, tm_stddev);
114  std::cout << "max: " << tm_max * 1000 << " [ms]" << std::endl;
115  std::cout << "min: " << tm_min * 1000 << " [ms]" << std::endl;
116  std::cout << "mean: " << tm_mean * 1000 << " [ms]" << std::endl;
117  std::cout << "stddev: " << tm_stddev * 1000 << " [ms]" << std::endl;
118  }
119 
120  ++count;
121  return RTC::RTC_OK;
122 }
123 
124 /*
125 RTC::ReturnCode_t RTSample::onAborting(RTC::UniqueId ec_id)
126 {
127  return RTC::RTC_OK;
128 }
129 */
130 /*
131 RTC::ReturnCode_t RTSample::onError(RTC::UniqueId ec_id)
132 {
133  return RTC::RTC_OK;
134 }
135 */
136 /*
137 RTC::ReturnCode_t RTSample::onReset(RTC::UniqueId ec_id)
138 {
139  return RTC::RTC_OK;
140 }
141 */
142 /*
143 RTC::ReturnCode_t RTSample::onStateUpdate(RTC::UniqueId ec_id)
144 {
145  return RTC::RTC_OK;
146 }
147 */
148 /*
149 RTC::ReturnCode_t RTSample::onRateChanged(RTC::UniqueId ec_id)
150 {
151  return RTC::RTC_OK;
152 }
153 */
154 
155 
156 extern "C"
157 {
158 
160  {
162  manager->registerFactory(profile,
163  RTC::Create<RTSample>,
164  RTC::Delete<RTSample>);
165  }
166 
167 };
168 
169 
170 
RT-Component.
bool getStatistics(double &max_interval, double &min_interval, double &mean_interval, double &stddev)
Get total statistics.
DataFlowComponentBase class.
Realtime periodic execution example component *.
ReturnCode_t
Definition: doil.h:53
Manager class.
Definition: Manager.h:80
coil::TimeMeasure m_tm
Definition: RTSample.h:118
~RTSample()
Definition: RTSample.cpp:36
RTSample(RTC::Manager *manager)
Definition: RTSample.cpp:29
void tack()
Finish time measurement for time statistics.
Definition: TimeMeasure.cpp:72
virtual RTC::ReturnCode_t onInitialize()
Callback function to initialize.
Definition: RTSample.cpp:41
void RTSampleInit(RTC::Manager *manager)
Definition: RTSample.cpp:159
ExecutionContextHandle_t UniqueId
static const char * rtsample_spec[]
Definition: RTSample.cpp:11
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Callback function to execute periodically.
Definition: RTSample.cpp:103
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
Callback function to deactivate.
Definition: RTSample.cpp:91
Class represents a set of properties.
Definition: Properties.h:101
void tick()
Begin time measurement for time statistics.
Definition: TimeMeasure.cpp:60
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Register RT-Component Factory.
Definition: Manager.cpp:433
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Callback function to activate.
Definition: RTSample.cpp:84


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:00