DispPosition.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include "DispPosition.h"
00011 
00012 // Module specification
00013 // <rtc-template block="module_spec">
00014 static const char* dispposition_spec[] =
00015   {
00016     "implementation_id", "DispPosition",
00017     "type_name",         "DispPosition",
00018     "description",       "${rtcParam.description}",
00019     "version",           "1.0.0",
00020     "vendor",            "AIST",
00021     "category",          "example",
00022     "activity_type",     "PERIODIC",
00023     "kind",              "DataFlowComponent",
00024     "max_instance",      "1",
00025     "language",          "C++",
00026     "lang_type",         "compile",
00027     ""
00028   };
00029 // </rtc-template>
00030 
00035 DispPosition::DispPosition(RTC::Manager* manager)
00036     // <rtc-template block="initializer">
00037   : RTC::DataFlowComponentBase(manager),
00038     m_posIn("position", m_pos)
00039 
00040     // </rtc-template>
00041 {
00042 }
00043 
00047 DispPosition::~DispPosition()
00048 {
00049 }
00050 
00051 
00052 
00053 RTC::ReturnCode_t DispPosition::onInitialize()
00054 {
00055   // Registration: InPort/OutPort/Service
00056   // <rtc-template block="registration">
00057   // Set InPort buffers
00058   addInPort("position", m_posIn);
00059   
00060         //地図画像の読み込み
00061         imOrgmap = cvLoadImage(ORG_MAP,CV_LOAD_IMAGE_COLOR);
00062   if (!imOrgmap)
00063   {
00064     fprintf(stderr, "%s: LOAD ERROR\n", ORG_MAP);
00065     return RTC::RTC_ERROR;
00066   }
00067         imTrjmap = cvCloneImage(imOrgmap);
00068         imRobmap = cvCloneImage(imOrgmap);
00069         cvNamedWindow("Display",CV_WINDOW_AUTOSIZE);
00070 
00071         //初期値
00072         rx = 100; ry = 50;
00073         rth = 1.0;
00074 
00075         mPerPix = 0.05;
00076         //m_BlockSize = 64;
00077         cnt=0;
00078 
00079         for(int i=0; i<5; i++)
00080                 robopt[i] = cvPoint(0.0,0.0);
00081 
00082   return RTC::RTC_OK;
00083 }
00084 
00085 
00086 RTC::ReturnCode_t DispPosition::onShutdown(RTC::UniqueId ec_id)
00087 {
00088         cvDestroyWindow("Display");
00089   return RTC::RTC_OK;
00090 }
00091 
00092 
00093 
00094 RTC::ReturnCode_t DispPosition::onExecute(RTC::UniqueId ec_id)
00095 {
00096         if(m_posIn.isNew())
00097         {
00098                 m_posIn.read();
00099                 rx = round(m_pos.data.position.x);
00100                 ry = round(m_pos.data.position.y);
00101                 rth = m_pos.data.heading + M_PI/2.0;
00102                 
00103                 if (rth > M_PI)         /* 180度を越えている場合、マイナスに変更する */
00104                         rth = -M_PI * 2 + rth;
00105                 else if (rth < -M_PI)   /* -180を下回る場合、プラスに変更する */
00106                         rth = M_PI * 2 + rth;
00107                 
00108                 rx = round( m_pos.data.position.x / mPerPix ) + 69;
00109                 ry = - round( m_pos.data.position.y / mPerPix ) + (333.0 - 63.0);
00110 
00111                 //ロボット位置の描画
00112                 //位置 (imTrjmapに軌跡として蓄積)
00113                 cvCircle ( imTrjmap, cvPoint(rx,ry), 1, CV_RGB(255,0,0), -1, 4, 0 );
00114                 cvCopy( imTrjmap, imRobmap );
00115 
00116                 //方向 (imRobmapで更新)
00117                 //cvCircle ( imRobmap, cvPoint(rx,ry), 3, CV_RGB(0,0,255), -1, 2, 0 );
00118                 cvLine( imRobmap, cvPoint( rx, ry ),cvPoint( rx + sin(rth)*15, ry + cos(rth)*15 ), CV_RGB(0,0,255), 2, 0, 0);
00119         
00120                 robopt[0] = cvPoint(rx + sin(rth+M_PI/4.0)*10, ry + cos(rth+M_PI/4.0)*10 );
00121                 robopt[1] = cvPoint(rx + sin(rth-M_PI/4.0)*10, ry + cos(rth-M_PI/4.0)*10 );
00122                 robopt[2] = cvPoint(rx - sin(rth+M_PI/4.0)*10, ry - cos(rth+M_PI/4.0)*10 );
00123                 robopt[3] = cvPoint(rx - sin(rth-M_PI/4.0)*10, ry - cos(rth-M_PI/4.0)*10 );
00124                 robopt[4] = cvPoint(rx + sin(rth)*15, ry + cos(rth)*15 );
00125 
00126                 cvLine( imRobmap, robopt[0], robopt[4], CV_RGB(0,0,255), 1, 0, 0);
00127                 cvLine( imRobmap, robopt[4], robopt[1], CV_RGB(0,0,255), 1, 0, 0);
00128                 cvLine( imRobmap, robopt[1], robopt[2], CV_RGB(0,0,255), 1, 0, 0);
00129                 cvLine( imRobmap, robopt[2], robopt[3], CV_RGB(0,0,255), 1, 0, 0);
00130                 cvLine( imRobmap, robopt[3], robopt[0], CV_RGB(0,0,255), 1, 0, 0);
00131                                 
00132                 cvShowImage("Display", imRobmap);
00133                 key = cvWaitKey(50) & 0xff;
00134                 cnt++;
00135         }               
00136         return RTC::RTC_OK;
00137 }
00138 
00139 
00140 extern "C"
00141 {
00142  
00143   void DispPositionInit(RTC::Manager* manager)
00144   {
00145     coil::Properties profile(dispposition_spec);
00146     manager->registerFactory(profile,
00147                              RTC::Create<DispPosition>,
00148                              RTC::Delete<DispPosition>);
00149   }
00150   
00151 };
00152 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


RS003
Author(s):
autogenerated on Thu Jun 27 2013 14:58:49