my_map_checker_alg_node.cpp
Go to the documentation of this file.
00001 #include "my_map_checker_alg_node.h"
00002 
00003 
00004 MyMapCheckerAlgNode::MyMapCheckerAlgNode(void) :
00005   algorithm_base::IriBaseAlgorithm<MyMapCheckerAlgorithm>()
00006 {
00007   //init class attributes if necessary
00008   this->loop_rate_ = 0.1;//in [Hz]
00009         this->public_node_handle_.getParam("force_map_path", force_map_path_);
00010         cout << "path = " << force_map_path_ << endl;
00011         if ( !pred_.read_force_map(  force_map_path_.c_str() ) )
00012         {
00013                 ROS_WARN("Could not read map force file !!!");
00014         }
00015         pred_.get_map_params( min_x_, max_x_, min_y_, max_y_, resolution_, map_number_x_, map_number_y_);
00016 
00017   // [init publishers]
00018   this->force_map_publisher_ = this->public_node_handle_.advertise<visualization_msgs::MarkerArray>("force_map", 100);
00019   
00020   // [init subscribers]
00021   
00022   // [init services]
00023   
00024   // [init clients]
00025   
00026   // [init action servers]
00027   
00028   // [init action clients]
00029         force_marker_.ns =  "force_map";
00030         force_marker_.type = visualization_msgs::Marker::ARROW;
00031         force_marker_.action = visualization_msgs::Marker::ADD;
00032         force_marker_.lifetime = ros::Duration(10.0f);
00033         force_marker_.scale.x = 0.1;
00034         force_marker_.scale.y = 0.15;
00035         force_marker_.color.a = 1.0;
00036         force_marker_.color.r = 0.0;
00037         force_marker_.color.g = 0.0;
00038         force_marker_.color.b = 1.0;
00039         force_marker_.header.frame_id = "/map";
00040 
00041         obstacle_marker_.ns =  "force_map";
00042         obstacle_marker_.type = visualization_msgs::Marker::CUBE;
00043         obstacle_marker_.action = visualization_msgs::Marker::ADD;
00044         obstacle_marker_.lifetime = ros::Duration(10.0f);
00045         obstacle_marker_.scale.x = 0.2;
00046         obstacle_marker_.scale.y = 0.2;
00047         obstacle_marker_.scale.z = 0.2;
00048         obstacle_marker_.color.a = 1.0;
00049         obstacle_marker_.color.r = 1.0;
00050         obstacle_marker_.color.g = 0.0;
00051         obstacle_marker_.color.b = 0.0;
00052         obstacle_marker_.header.frame_id = "/map";
00053 
00054 }
00055 
00056 MyMapCheckerAlgNode::~MyMapCheckerAlgNode(void)
00057 {
00058   // [free dynamic memory]
00059 }
00060 
00061 void MyMapCheckerAlgNode::mainNodeThread(void)
00062 {
00063   // [fill msg structures]
00064   //this->MarkerArray_msg_.data = my_var;
00065 
00066         geometry_msgs::Point ros_point;
00067         Sforce map_force;
00068         force_marker_.header.stamp = ros::Time::now();
00069         MarkerArray_msg_.markers.clear();
00070 
00071 
00072         for(unsigned int i = 0; i< map_number_x_; i+=3)
00073         {
00074                 for(unsigned int j = 0; j< map_number_y_; j+=3)
00075                 {
00076                         
00077                         force_marker_.points.clear();
00078                         force_marker_.id = i * map_number_x_ + j;
00079                         ros_point.x = min_x_ + i * resolution_;
00080                         ros_point.y = min_y_ + j * resolution_;
00081                         force_marker_.points.push_back(  ros_point  );
00082                         map_force = pred_.get_force_map(ros_point.x , ros_point.y);
00083                         ros_point.x += 0.1*map_force.fx;
00084                         ros_point.y += 0.1*map_force.fy;
00085                         force_marker_.points.push_back(  ros_point  );
00086                         MarkerArray_msg_.markers.push_back(  force_marker_  );
00087                         
00088                         /*obstacle_marker_.points.clear();
00089                         obstacle_marker_.id = i * map_number_x_ + j;
00090                         ros_point.x = min_x_ + i * resolution_;
00091                         ros_point.y = min_y_ + j * resolution_;
00092                         //ROS_INFO( "%d" , (int)pred_.is_cell_clear_map(ros_point.x , ros_point.y) );
00093                         if( !pred_.is_cell_clear_map(ros_point.x , ros_point.y) )
00094                         {
00095                                 obstacle_marker_.pose.position =  ros_point;
00096                                 MarkerArray_msg_.markers.push_back(  obstacle_marker_  );
00097                         }*/
00098                 }
00099         }
00100 /*      for (unsigned int i = 0; i<map_number_x_*map_number_y_; i+=5)
00101         {
00102                 if( !pred_.get_map_obstacle( i ) )
00103                 {
00104                         ros_point.y = min_y_ + i/map_number_x_*resolution_;
00105                         ros_point.x = min_x_ + (i - i/map_number_x_ * map_number_x_ ) * resolution_;
00106                         obstacle_marker_.id = i;
00107                         obstacle_marker_.pose.position =  ros_point;
00108                         MarkerArray_msg_.markers.push_back(  obstacle_marker_  );
00109                 }
00110         }
00111   */
00112   // [fill srv structure and make request to the server]
00113   
00114   // [fill action structure and make request to the action server]
00115 
00116   // [publish messages]
00117   this->force_map_publisher_.publish(this->MarkerArray_msg_);
00118 
00119 }
00120 
00121 /*  [subscriber callbacks] */
00122 
00123 /*  [service callbacks] */
00124 
00125 /*  [action callbacks] */
00126 
00127 /*  [action requests] */
00128 
00129 void MyMapCheckerAlgNode::node_config_update(Config &config, uint32_t level)
00130 {
00131   this->alg_.lock();
00132         force_map_path_ = config.force_map_path;
00133   this->alg_.unlock();
00134 }
00135 
00136 void MyMapCheckerAlgNode::addNodeDiagnostics(void)
00137 {
00138 }
00139 
00140 /* main function */
00141 int main(int argc,char *argv[])
00142 {
00143   return algorithm_base::main<MyMapCheckerAlgNode>(argc, argv, "my_map_checker_alg_node");
00144 }


my_map_checker
Author(s): gferrer
autogenerated on Fri Dec 6 2013 21:59:14