PathPlanning.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include "PathPlanning.h"
00011 #include "planner.h"
00012 #include <math.h>
00013 #include "PathType.h"
00014 
00015 void path2pathseq(PathMapPtr a_path, IIS::TimedPath2DSeq *out_path);
00016 
00017 // Module specification
00018 // <rtc-template block="module_spec">
00019 static const char* pathplanning_spec[] =
00020   {
00021     "implementation_id", "PathPlanning",
00022     "type_name",         "PathPlanning",
00023     "description",       "compornent",
00024     "version",           "1.0",
00025     "vendor",            "MyName",
00026     "category",          "example",
00027     "activity_type",     "DataFlowComponent",
00028     "max_instance",      "10",
00029     "language",          "C++",
00030     "lang_type",         "compile",
00031     // Configuration variables
00032     "conf.default.map_file", "route_map",
00033 
00034     ""
00035   };
00036 // </rtc-template>
00037 
00038 PathPlanning::PathPlanning(RTC::Manager* manager)
00039   : RTC::DataFlowComponentBase(manager),
00040     // <rtc-template block="initializer">
00041     m_current_positionIn("current_position", m_current_position),
00042     m_goalIn("goal", m_goal),
00043     m_min_pathOut("min_path", m_min_path)
00044     
00045 {
00046   registerInPort("current_position", m_current_positionIn);
00047   registerInPort("goal", m_goalIn);
00048 
00049   registerOutPort("min_path", m_min_pathOut);
00050 
00051   map_loaded = 0;
00052 }
00053 
00054 PathPlanning::~PathPlanning()
00055 {
00056 }
00057 
00058 
00059 RTC::ReturnCode_t PathPlanning::onInitialize()
00060 {
00061   bindParameter("map_file", m_map_file, "route_map");
00062  
00063   return RTC::RTC_OK;
00064 }
00065 
00066 
00067 RTC::ReturnCode_t PathPlanning::onActivated(RTC::UniqueId ec_id)
00068 {
00069   all_path = make_path(); 
00070   if(load_path_file((const char*)m_map_file.c_str(), all_path)) 
00071     map_loaded = 1;
00072   return RTC::RTC_OK;
00073 }
00074 
00075 
00076 
00077 RTC::ReturnCode_t PathPlanning::onDeactivated(RTC::UniqueId ec_id)
00078 {
00079   printf("deactivate\n");
00080   if(map_loaded)delete_path(all_path);
00081   map_loaded = 0;
00082 
00083   return RTC::RTC_OK;
00084 }
00085 
00086 
00087 
00088 RTC::ReturnCode_t PathPlanning::onExecute(RTC::UniqueId ec_id)
00089 {
00090   while(!m_current_positionIn.isEmpty())m_current_positionIn.read();
00091 
00092   if(map_loaded){
00093     if(!m_goalIn.isEmpty()){
00094     
00095       while(!m_goalIn.isEmpty())m_goalIn.read();
00096 
00097       /*input current position*/
00098       set_start_position(all_path, m_current_position.data.position.x, m_current_position.data.position.y);
00099       printf("%f %f\n",m_current_position.data.position.x, m_current_position.data.position.y);
00100 
00101       /*input target  position*/
00102       set_goal_position(all_path, m_goal.data.position.x, m_goal.data.position.y);
00103       printf("%f %f\n",m_goal.data.position.x, m_goal.data.position.y);
00104 
00105       /*solve*/
00106       minimum_path=solve_minimum_path(all_path);
00107       draw_path(all_path,minimum_path);
00108   
00109       
00110       path2pathseq(minimum_path,&m_min_path);
00111       if(minimum_path)delete_path(minimum_path);
00112                         int pointnum = m_min_path.pose.length();
00113 
00114                   m_min_path.id.length(pointnum+1);
00115                   m_min_path.pose.length(pointnum+1);
00116                 m_min_path.velocity.length(pointnum+1);
00117                 m_min_path.error.length(pointnum+1);
00118 
00119                         m_min_path.pose[pointnum].position.x = m_goal.data.position.x;
00120                         m_min_path.pose[pointnum].position.y = m_goal.data.position.y;
00121                         m_min_path.pose[pointnum].heading = m_goal.data.heading;
00122 
00123       m_min_pathOut.write();
00124     } 
00125   }
00126   return RTC::RTC_OK;
00127 }
00128 
00129 
00130 extern "C"
00131 {
00132  
00133   void PathPlanningInit(RTC::Manager* manager)
00134   {
00135     RTC::Properties profile(pathplanning_spec);
00136     manager->registerFactory(profile,
00137                              RTC::Create<PathPlanning>,
00138                              RTC::Delete<PathPlanning>);
00139   }
00140   
00141 };
00142 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


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