RangeDataViewer.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include "RangeDataViewer.h"
00011 
00012 // Module specification
00013 // <rtc-template block="module_spec">
00014 static const char* cameraimageviewercomponent_spec[] =
00015   {
00016     "implementation_id", "RangeDataViewer",
00017     "type_name",         "RangeDataViewer",
00018     "description",       "range data viewer 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.maxRange", "2.0",
00028     
00029 
00030     ""
00031   };
00032 // </rtc-template>
00033 
00034 RangeDataViewer::RangeDataViewer(RTC::Manager* manager)
00035   : RTC::DataFlowComponentBase(manager),
00036     // <rtc-template block="initializer">
00037     m_rangeIn("rangeIn", m_range),
00038     // </rtc-template>
00039     m_cvImage(NULL),
00040     dummy(0)
00041 {
00042 }
00043 
00044 RangeDataViewer::~RangeDataViewer()
00045 {
00046 }
00047 
00048 
00049 
00050 RTC::ReturnCode_t RangeDataViewer::onInitialize()
00051 {
00052   std::cout << m_profile.instance_name << ": onInitialize()" << std::endl;
00053   // <rtc-template block="bind_config">
00054   // Bind variables and configuration variable
00055   bindParameter("maxRange", m_maxRange, "2.0");
00056   
00057   // </rtc-template>
00058 
00059   // Registration: InPort/OutPort/Service
00060   // <rtc-template block="registration">
00061   // Set InPort buffers
00062   addInPort("rangeIn", m_rangeIn);
00063 
00064   // Set OutPort buffer
00065   
00066   // Set service provider to Ports
00067   
00068   // Set service consumers to Ports
00069   
00070   // Set CORBA Service Ports
00071   
00072   // </rtc-template>
00073 
00074   RTC::Properties& prop = getProperties();
00075 
00076   return RTC::RTC_OK;
00077 }
00078 
00079 
00080 
00081 /*
00082   RTC::ReturnCode_t RangeDataViewer::onFinalize()
00083   {
00084   return RTC::RTC_OK;
00085   }
00086 */
00087 
00088 /*
00089   RTC::ReturnCode_t RangeDataViewer::onStartup(RTC::UniqueId ec_id)
00090   {
00091   return RTC::RTC_OK;
00092   }
00093 */
00094 
00095 /*
00096   RTC::ReturnCode_t RangeDataViewer::onShutdown(RTC::UniqueId ec_id)
00097   {
00098   return RTC::RTC_OK;
00099   }
00100 */
00101 
00102 #define WSIZE 640
00103 RTC::ReturnCode_t RangeDataViewer::onActivated(RTC::UniqueId ec_id)
00104 {
00105   std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
00106   m_cvImage = cvCreateImage(cvSize(WSIZE, WSIZE), IPL_DEPTH_8U, 3);
00107   cvNamedWindow("Range",CV_WINDOW_AUTOSIZE);
00108   return RTC::RTC_OK;
00109 }
00110 
00111 RTC::ReturnCode_t RangeDataViewer::onDeactivated(RTC::UniqueId ec_id)
00112 {
00113   std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
00114   if (m_cvImage) {
00115     cvReleaseImage(&m_cvImage);
00116     m_cvImage = NULL;
00117   }
00118   cvDestroyWindow("Range");
00119   return RTC::RTC_OK;
00120 }
00121 
00122 RTC::ReturnCode_t RangeDataViewer::onExecute(RTC::UniqueId ec_id)
00123 {
00124   //std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")"  << std::endl;
00125 
00126   if (1/*m_rangeIn.isNew()*/){
00127     do {
00128       m_rangeIn.read();
00129     }while(m_rangeIn.isNew());
00130 
00131     cvSetZero(m_cvImage);
00132 
00133     CvPoint center = cvPoint(WSIZE/2,WSIZE/2);
00134     CvScalar green = cvScalar(0,255,0);
00135     double th,d,x,y;
00136 #if 0
00137     std::cout << "minAngle:" << m_range.config.minAngle << std::endl;
00138     std::cout << "maxAngle:" << m_range.config.maxAngle << std::endl;
00139     std::cout << "angularRes:" << m_range.config.angularRes << std::endl;
00140     std::cout << "minRange:" << m_range.config.minRange << std::endl;
00141     std::cout << "maxRange:" << m_range.config.maxRange << std::endl;
00142     std::cout << "rangeRes:" << m_range.config.rangeRes << std::endl;
00143     std::cout << "frequency:" << m_range.config.frequency << std::endl;
00144     std::cout << "ndata = " << m_range.ranges.length() << std::endl;
00145 #endif
00146     for (unsigned int i=0; i<m_range.ranges.length(); i++){
00147       d = m_range.ranges[i];
00148       if (isinf(d)) continue;
00149       th = m_range.config.minAngle + m_range.config.angularRes*i;
00150       x = -d*sin(th)/m_maxRange*WSIZE/2 + WSIZE/2;
00151       y = -d*cos(th)/m_maxRange*WSIZE/2 + WSIZE/2;
00152       cvLine(m_cvImage, center, cvPoint(x, y), green, 1, 8, 0);
00153     }
00154 
00155     cvShowImage("Range",m_cvImage);
00156     cvWaitKey(10);
00157   }
00158 
00159   return RTC::RTC_OK;
00160 }
00161 
00162 /*
00163   RTC::ReturnCode_t RangeDataViewer::onAborting(RTC::UniqueId ec_id)
00164   {
00165   return RTC::RTC_OK;
00166   }
00167 */
00168 
00169 /*
00170   RTC::ReturnCode_t RangeDataViewer::onError(RTC::UniqueId ec_id)
00171   {
00172   return RTC::RTC_OK;
00173   }
00174 */
00175 
00176 /*
00177   RTC::ReturnCode_t RangeDataViewer::onReset(RTC::UniqueId ec_id)
00178   {
00179   return RTC::RTC_OK;
00180   }
00181 */
00182 
00183 /*
00184   RTC::ReturnCode_t RangeDataViewer::onStateUpdate(RTC::UniqueId ec_id)
00185   {
00186   return RTC::RTC_OK;
00187   }
00188 */
00189 
00190 /*
00191   RTC::ReturnCode_t RangeDataViewer::onRateChanged(RTC::UniqueId ec_id)
00192   {
00193   return RTC::RTC_OK;
00194   }
00195 */
00196 
00197 
00198 
00199 extern "C"
00200 {
00201 
00202   void RangeDataViewerInit(RTC::Manager* manager)
00203   {
00204     RTC::Properties profile(cameraimageviewercomponent_spec);
00205     manager->registerFactory(profile,
00206                              RTC::Create<RangeDataViewer>,
00207                              RTC::Delete<RangeDataViewer>);
00208   }
00209 
00210 };
00211 
00212 


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Sep 6 2017 02:35:55