SampleComponent.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include "SampleComponent.h"
00011 
00012 // Module specification
00013 // <rtc-template block="module_spec">
00014 static const char* nullcomponent_spec[] =
00015   {
00016     "implementation_id", "SampleComponent",
00017     "type_name",         "SampleComponent",
00018     "description",       "null component",
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.debugLevel", "0",
00028     ""
00029   };
00030 // </rtc-template>
00031 
00032 SampleComponent::SampleComponent(RTC::Manager* manager)
00033   : RTC::DataFlowComponentBase(manager),
00034     // <rtc-template block="initializer">
00035     m_qCurrentIn("qCurrent", m_qCurrent),
00036     m_qOut("q", m_q),
00037     m_SampleComponentPort("SampleComponentService"),
00038     loop(0),
00039     offset(0),
00040     m_debugLevel(0),
00041     dummy(0)
00042 {
00043   m_service0.sample(this);
00044   std::cerr << "SampleComponent::SampleComponent()" << std::endl;
00045 }
00046 
00047 SampleComponent::~SampleComponent()
00048 {
00049   std::cerr << "SampleComponent::~SampleComponent()" << std::endl;
00050 }
00051 
00052 
00053 
00054 RTC::ReturnCode_t SampleComponent::onInitialize()
00055 {
00056   std::cerr << m_profile.instance_name << ": onInitialize()" << std::endl;
00057   // <rtc-template block="bind_config">
00058   // Bind variables and configuration variable
00059   
00060   // </rtc-template>
00061 
00062   // Registration: InPort/OutPort/Service
00063   // <rtc-template block="registration">
00064   // Set InPort buffers
00065   addInPort("qCurrent", m_qCurrentIn);
00066 
00067   // Set OutPort buffer
00068   addOutPort("q", m_qOut);
00069   
00070   // Set service provider to Ports
00071   m_SampleComponentPort.registerProvider("service0", "SampleComponentService", m_service0);
00072   
00073   // Set service consumers to Ports
00074   
00075   // Set CORBA Service Ports
00076   addPort(m_SampleComponentPort);
00077   
00078   // </rtc-template>
00079 
00080   return RTC::RTC_OK;
00081 }
00082 
00083 
00084 
00085 /*
00086 RTC::ReturnCode_t SampleComponent::onFinalize()
00087 {
00088   return RTC::RTC_OK;
00089 }
00090 */
00091 
00092 /*
00093 RTC::ReturnCode_t SampleComponent::onStartup(RTC::UniqueId ec_id)
00094 {
00095   return RTC::RTC_OK;
00096 }
00097 */
00098 
00099 /*
00100 RTC::ReturnCode_t SampleComponent::onShutdown(RTC::UniqueId ec_id)
00101 {
00102   return RTC::RTC_OK;
00103 }
00104 */
00105 
00106 RTC::ReturnCode_t SampleComponent::onActivated(RTC::UniqueId ec_id)
00107 {
00108   std::cerr << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
00109   return RTC::RTC_OK;
00110 }
00111 
00112 RTC::ReturnCode_t SampleComponent::onDeactivated(RTC::UniqueId ec_id)
00113 {
00114   std::cerr << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
00115   return RTC::RTC_OK;
00116 }
00117 
00118 bool SampleComponent::resetOffset(double dir) {
00119   loop = 0;
00120   offset = dir;
00121   return true;
00122 }
00123 
00124 RTC::ReturnCode_t SampleComponent::onExecute(RTC::UniqueId ec_id)
00125 {
00126  //std::cerr << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << std::endl;
00127   loop ++;
00128   static double output = 0;
00129   if (m_qCurrentIn.isNew()) {
00130     m_qCurrentIn.read();
00131   }
00132 
00133   if ( m_qCurrent.data.length() != m_q.data.length() ) {
00134       m_q.data.length(m_qCurrent.data.length());
00135   }
00136   for ( unsigned int i = 0; i < m_qCurrent.data.length(); i++ ){
00137       m_q.data[i] = m_qCurrent.data[i];
00138   }
00139   if ( loop < 1000 ) {
00140       output += offset;
00141   }
00142   if ( m_q.data.length() > 9 ) {
00143       m_q.data[9] = output;
00144   }
00145   m_qOut.write();
00146 
00147   return RTC::RTC_OK;
00148 }
00149 
00150 /*
00151 RTC::ReturnCode_t SampleComponent::onAborting(RTC::UniqueId ec_id)
00152 {
00153   return RTC::RTC_OK;
00154 }
00155 */
00156 
00157 /*
00158 RTC::ReturnCode_t SampleComponent::onError(RTC::UniqueId ec_id)
00159 {
00160   return RTC::RTC_OK;
00161 }
00162 */
00163 
00164 /*
00165 RTC::ReturnCode_t SampleComponent::onReset(RTC::UniqueId ec_id)
00166 {
00167   return RTC::RTC_OK;
00168 }
00169 */
00170 
00171 /*
00172 RTC::ReturnCode_t SampleComponent::onStateUpdate(RTC::UniqueId ec_id)
00173 {
00174   return RTC::RTC_OK;
00175 }
00176 */
00177 
00178 /*
00179 RTC::ReturnCode_t SampleComponent::onRateChanged(RTC::UniqueId ec_id)
00180 {
00181   return RTC::RTC_OK;
00182 }
00183 */
00184 
00185 
00186 
00187 extern "C"
00188 {
00189 
00190   void SampleComponentInit(RTC::Manager* manager)
00191   {
00192     RTC::Properties profile(nullcomponent_spec);
00193     manager->registerFactory(profile,
00194                              RTC::Create<SampleComponent>,
00195                              RTC::Delete<SampleComponent>);
00196   }
00197 
00198 };
00199 
00200 


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed May 15 2019 05:02:18