00001 #include "force_navigation_alg_node.h"
00002
00003 ForceNavigationAlgNode::ForceNavigationAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<ForceNavigationAlgorithm>(),
00005 move_robot_client_("move_robot", true),
00006 robot_sim_(false), robot_stop_(false)
00007 {
00008
00009 this->loop_rate_ = 5;
00010 this->public_node_handle_.getParam("reference_frame", target_frame_);
00011 this->public_node_handle_.getParam("robot_frame", robot_frame_);
00012 this->public_node_handle_.getParam("robot_sim", robot_sim_);
00013 this->public_node_handle_.getParam("robot_x_ini", robot_x_ini_);
00014 this->public_node_handle_.getParam("robot_y_ini", robot_y_ini_);
00015 this->public_node_handle_.getParam("force_map_path", force_map_path_);
00016 this->public_node_handle_.getParam("destination_map_path", destination_map_path_);
00017
00018
00019
00020 this->navigation_work_publisher_ = this->public_node_handle_.advertise<std_msgs::Float64MultiArray>("navigation_work", 100);
00021 this->velocity_publisher_ = this->public_node_handle_.advertise<geometry_msgs::Twist>("velocity_no_col", 100);
00022 this->robot_simulated_pose_publisher_ = this->public_node_handle_.advertise<geometry_msgs::PoseStamped>("robot_simulated_pose", 100);
00023 this->trajectories_publisher_ = this->public_node_handle_.advertise<visualization_msgs::MarkerArray>("vis/trajectories", 100);
00024 this->forces_publisher_ = this->public_node_handle_.advertise<visualization_msgs::MarkerArray>("vis/forces", 100);
00025 this->destinations_publisher_ = this->public_node_handle_.advertise<visualization_msgs::MarkerArray>("vis/destinations", 100);
00026
00027
00028 this->tracks_subscriber_ = this->public_node_handle_.subscribe("tracks", 100, &ForceNavigationAlgNode::tracks_callback, this);
00029
00030
00031
00032
00033
00034
00035
00036
00037 init_node();
00038 }
00039
00040 ForceNavigationAlgNode::~ForceNavigationAlgNode(void)
00041 {
00042
00043 }
00044
00045 void ForceNavigationAlgNode::mainNodeThread(void)
00046 {
00047
00048 this->alg_.lock();
00049
00050
00051
00052
00053
00054 robot_desired_position_ = force_navigation_.robot_local_nav();
00055 vis_trajectories();
00056 vis_destinations();
00057
00058 ros::Time now = ros::Time::now();
00059
00060 if ( robot_sim_ )
00061 {
00062 PoseStamped_msg_.pose.position.x = robot_desired_position_.x;
00063 PoseStamped_msg_.pose.position.y = robot_desired_position_.y;
00064 PoseStamped_msg_.header.stamp = ros::Time::now();
00065 force_navigation_.update_robot( SdetectionObservation( 0, now.toSec(),
00066 robot_desired_position_.x, robot_desired_position_.y ,
00067 0.0, 0.0 ) );
00068 this->robot_simulated_pose_publisher_.publish(this->PoseStamped_msg_);
00069
00070
00071 }
00072 else
00073 {
00074
00075 try{
00076 bool tf_exists = tf_main_.waitForTransform(target_frame_,
00077 robot_frame_,
00078 now,
00079 ros::Duration(1), ros::Duration(0.01));
00080
00081 if(tf_exists)
00082 {
00083 geometry_msgs::PointStamped observation_point, target_point;
00084 observation_point.header.stamp = now;
00085 observation_point.header.frame_id=robot_frame_;
00086 observation_point.point.z = 0.0;
00087 observation_point.point.x = 0.0;
00088 observation_point.point.y = 0.0;
00089
00090 tf_listener_.transformPoint( target_frame_, observation_point, target_point);
00091
00092 force_navigation_.update_robot( SdetectionObservation( 0, now.toSec(),
00093 target_point.point.x , target_point.point.y , 0.0 , 0.0 ) );
00094 }
00095 else
00096 {
00097 ROS_ERROR("ForceNavigationAlgNode::No transform in main function");
00098 }
00099 }
00100 catch (tf::TransformException &ex)
00101 {
00102 ROS_ERROR("ForceNavigationAlgNode:: %s",ex.what());
00103 }
00104
00105
00106 if( !move_base_mode_ )
00107 {
00108
00109 Twist_msg_.linear.x = 0.0;
00110 }
00111 else
00112 {
00113 if( robot_stop_ || force_navigation_.get_robot_state() == Cforce_navigation::IDLE )
00114 {
00115
00116 ROS_INFO( "Stop mode, sending robot invalid commands");
00117 force_navigation_.stop_navigation();
00118 robot_desired_position_.x = 1.0/0.0;
00119 robot_desired_position_.y = 1.0/0.0;
00120 move_robotMakeActionRequest();
00121 Twist_msg_.linear.x = 0.0;
00122 robot_stop_ = false;
00123
00124 }
00125 else
00126 {
00127
00128 ROS_INFO( "Sending robot commands");
00129 move_robotMakeActionRequest();
00130 Twist_msg_.linear.x = robot_desired_position_.v;
00131 }
00132 }
00133
00134 }
00135
00136
00137 Float64_msg_.data.clear();
00138 Float64_msg_.data = force_navigation_.get_robot_inst_work();
00139 Float64_msg_.data.push_back( (double) force_navigation_.get_robot_state() );
00140
00141
00142
00143
00144
00145
00146
00147
00148 this->alg_.unlock();
00149
00150 this->navigation_work_publisher_.publish(this->Float64_msg_);
00151 this->trajectories_publisher_.publish(this->MarkerArray_trajectories_msg_);
00152 this->forces_publisher_.publish(this->MarkerArray_forces_msg_);
00153 this->destinations_publisher_.publish(this->MarkerArray_destinations_msg_);
00154 }
00155
00156
00157 void ForceNavigationAlgNode::init_node(void)
00158 {
00159
00160 if ( !force_navigation_.read_force_map( force_map_path_.c_str() ) )
00161 {
00162 ROS_ERROR("Could not read map force file !!!");
00163 }
00164 else{
00165 ROS_WARN("read map force file : SUCCESS!!!");
00166 }
00167
00168
00169
00170
00171 if ( !force_navigation_.read_destination_map( destination_map_path_.c_str() ) )
00172 {
00173 ROS_ERROR("Could not read map destinations file !!!");
00174 }
00175 else{
00176 ROS_WARN("read map destinations force file : SUCCESS!!!");
00177 }
00178
00179
00180 force_navigation_.set_dt( 1.0 / 5.0 );
00181 if( robot_sim_ )
00182 {
00183 ros::Time now = ros::Time::now();
00184 Spose robot_current_position( robot_x_ini_,robot_y_ini_, 0.0, now.toSec() );
00185 force_navigation_.update_robot( SdetectionObservation( 0, robot_current_position.time_stamp,
00186 robot_current_position.x, robot_current_position.y ,
00187 0.0, 0.0 ) );
00188 }
00189
00190
00191 force_navigation_.stop_navigation();
00192 force_navigation_.robot_global_planning( );
00193
00194
00195 Twist_msg_.angular.z = 100.0;
00196
00197 move_robot_goal_.target_pose.header.frame_id = target_frame_;
00198 move_robot_goal_.target_pose.pose.orientation.y = 1.0;
00199
00200
00201
00202 traj_marker_.ns = "trajectories";
00203 traj_marker_.header.frame_id = target_frame_;
00204 traj_marker_.type = visualization_msgs::Marker::LINE_STRIP;
00205 traj_marker_.action = visualization_msgs::Marker::ADD;
00206 traj_marker_.lifetime = ros::Duration(1.0f);
00207 traj_marker_.scale.x = 0.1;
00208 traj_marker_.color.a = 0.5;
00209 traj_marker_.color.r = 1.0;
00210 traj_marker_.color.g = 0.4;
00211 traj_marker_.color.b = 0.0;
00212
00213
00214 traj_robot_marker_.ns = "trajectories";
00215 traj_robot_marker_.header.frame_id = target_frame_;
00216 traj_robot_marker_.type = visualization_msgs::Marker::LINE_STRIP;
00217 traj_robot_marker_.action = visualization_msgs::Marker::ADD;
00218 traj_robot_marker_.lifetime = ros::Duration(1.0f);
00219 traj_robot_marker_.scale.x = 0.1;
00220 traj_robot_marker_.color.a = 0.6;
00221 traj_robot_marker_.color.r = 0.26;
00222 traj_robot_marker_.color.g = 0.0;
00223 traj_robot_marker_.color.b = 0.5;
00224
00225
00226 robot_marker_.ns = "trajectories";
00227 robot_marker_.header.frame_id = target_frame_;
00228 robot_marker_.type = visualization_msgs::Marker::MESH_RESOURCE;
00229 robot_marker_.mesh_resource = "package://tibi_dabo_base/model/meshes/tibi.stl";
00230 robot_marker_.action = visualization_msgs::Marker::ADD;
00231 robot_marker_.lifetime = ros::Duration(1.0f);
00232 robot_marker_.scale.x = 1.0;
00233 robot_marker_.scale.y = 0.6;
00234 robot_marker_.scale.z = 1.0;
00235 robot_marker_.color.a = 1.0;
00236 robot_marker_.color.r = 0.7;
00237 robot_marker_.color.g = 0.5;
00238 robot_marker_.color.b = 1.0;
00239
00240
00241
00242 target_marker_.ns = "trajectories";
00243 target_marker_.header.frame_id = target_frame_;
00244 target_marker_.type = visualization_msgs::Marker::CYLINDER;
00245 target_marker_.action = visualization_msgs::Marker::ADD;
00246 target_marker_.lifetime = ros::Duration(1.0f);
00247 target_marker_.scale.x = 0.5;
00248 target_marker_.scale.y = 0.5;
00249 target_marker_.scale.z = 0.6;
00250 target_marker_.color.a = 0.4;
00251 target_marker_.color.r = 0.0;
00252 target_marker_.color.g = 0.8;
00253 target_marker_.color.b = 0.0;
00254
00255
00256
00257 text_marker_.ns = "trajectories";
00258 text_marker_.header.frame_id = target_frame_;
00259 text_marker_.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
00260 text_marker_.action = visualization_msgs::Marker::ADD;
00261 text_marker_.lifetime = ros::Duration(1.0f);
00262 text_marker_.scale.z = 0.5;
00263 text_marker_.pose.position.z = 1.5;
00264 text_marker_.color.a = 0.5;
00265 text_marker_.color.r = 0.0;
00266 text_marker_.color.g = 0.0;
00267 text_marker_.color.b = 0.0;
00268
00269
00270 force_marker_.ns = "trajectories";
00271 force_marker_.header.frame_id = target_frame_;
00272 force_marker_.type = visualization_msgs::Marker::ARROW;
00273 force_marker_.action = visualization_msgs::Marker::ADD;
00274 force_marker_.lifetime = ros::Duration(1.0f);
00275 force_marker_.scale.x = 0.2;
00276 force_marker_.scale.y = 0.25;
00277 force_marker_.color.a = 0.8;
00278 force_marker_.color.r = 1.0;
00279 force_marker_.color.g = 0.0;
00280 force_marker_.color.b = 0.0;
00281
00282
00283 force_goal_marker_ = force_marker_;
00284 force_goal_marker_.color.r = 0.0;
00285 force_goal_marker_.color.g = 0.4;
00286 force_goal_marker_.color.b = 1.0;
00287
00288
00289 force_int_person_marker_ = force_marker_;
00290 force_int_person_marker_.color.r = 0.2;
00291 force_int_person_marker_.color.g = 0.85;
00292 force_int_person_marker_.color.b = 0.2;
00293
00294
00295 force_int_robot_marker_ = force_marker_;
00296 force_int_robot_marker_.color.r = 0.26;
00297 force_int_robot_marker_.color.g = 0.0;
00298 force_int_robot_marker_.color.b = 0.66;
00299
00300
00301 force_obstacle_map_marker_ = force_marker_;
00302 force_obstacle_map_marker_.color.r = 0.0;
00303 force_obstacle_map_marker_.color.g = 0.0;
00304 force_obstacle_map_marker_.color.b = 0.0;
00305
00306
00307 dest_marker_.ns = "destinations";
00308 dest_marker_.header.frame_id = target_frame_;
00309 dest_marker_.type = visualization_msgs::Marker::CYLINDER;
00310 dest_marker_.action = visualization_msgs::Marker::ADD;
00311 dest_marker_.lifetime = ros::Duration(1.0f);
00312 dest_marker_.color.a = 0.8;
00313
00314
00315 PoseStamped_msg_.header.frame_id = target_frame_;
00316
00317 }
00318
00319 void ForceNavigationAlgNode::vis_trajectories()
00320 {
00321 list<Cperson>& scene = force_navigation_.get_scene();
00322 int cont = 0, cont_f = 0;
00323 geometry_msgs::Point ros_point, ros_point_ini;
00324
00325
00326 traj_marker_.header.stamp = ros::Time::now();
00327 traj_robot_marker_.header.stamp = traj_marker_.header.stamp;
00328 robot_marker_.header.stamp = traj_marker_.header.stamp;
00329 target_marker_.header.stamp = traj_marker_.header.stamp;
00330 text_marker_.header.stamp = traj_marker_.header.stamp;
00331 force_marker_.header.stamp = traj_marker_.header.stamp;
00332 force_goal_marker_.header.stamp = force_marker_.header.stamp;
00333 force_goal2_marker_.header.stamp = force_marker_.header.stamp;
00334 force_int_person_marker_.header.stamp = force_marker_.header.stamp;
00335 force_int_robot_marker_.header.stamp = force_marker_.header.stamp;
00336 force_obstacle_map_marker_.header.stamp = force_marker_.header.stamp;
00337 force_obstacle_laser_marker_.header.stamp = force_marker_.header.stamp;
00338
00339 MarkerArray_trajectories_msg_.markers.clear();
00340 MarkerArray_forces_msg_.markers.clear();
00341
00342
00343
00344 clear_force_markers();
00345 Sforce force_to_goal, force_int_person , force_int_robot, force_obstacle, force_total;
00346 force_total = force_navigation_.get_robot().get_forces_person( force_to_goal, force_int_person , force_int_robot, force_obstacle );
00347
00348
00349
00350 ros_point_ini.x = force_navigation_.get_robot().get_current_pose().x;
00351 ros_point_ini.y = force_navigation_.get_robot().get_current_pose().y;
00352
00353
00354 if ( traj_robot_marker_.points.size() > 120)
00355 {
00356 vector<geometry_msgs::Point> temp_poses;
00357 temp_poses.reserve(100);
00358 for( unsigned int i = 21; i <= 100; ++i)
00359 temp_poses.push_back(traj_robot_marker_.points[i]);
00360 traj_robot_marker_.points = temp_poses;
00361 }
00362 traj_robot_marker_.points.push_back( ros_point_ini );
00363 traj_robot_marker_.id = cont;
00364 ++cont;
00365 MarkerArray_trajectories_msg_.markers.push_back( traj_robot_marker_ );
00366
00367
00368
00369 force_goal_marker_.points.push_back( ros_point_ini );
00370 ros_point.x = ros_point_ini.x + force_to_goal.fx;
00371 ros_point.y = ros_point_ini.y + force_to_goal.fy;
00372 force_goal_marker_.points.push_back( ros_point );
00373 force_goal_marker_.id = cont;
00374 ++cont;
00375 MarkerArray_trajectories_msg_.markers.push_back( force_goal_marker_ );
00376
00377
00378 force_int_person_marker_.points.push_back( ros_point_ini );
00379 ros_point.x = ros_point_ini.x + force_int_person.fx;
00380 ros_point.y = ros_point_ini.y + force_int_person.fy;
00381 force_int_person_marker_.points.push_back( ros_point);
00382 force_int_person_marker_.id = cont;
00383 ++cont;
00384 MarkerArray_trajectories_msg_.markers.push_back( force_int_person_marker_ );
00385
00386
00387 force_obstacle_map_marker_.points.push_back( ros_point_ini );
00388 ros_point.x = ros_point_ini.x + force_obstacle.fx;
00389 ros_point.y = ros_point_ini.y + force_obstacle.fy;
00390 force_obstacle_map_marker_.points.push_back( ros_point);
00391 force_obstacle_map_marker_.id = cont;
00392 ++cont;
00393 MarkerArray_trajectories_msg_.markers.push_back( force_obstacle_map_marker_ );
00394
00395
00396 force_marker_.points.push_back( ros_point_ini );
00397 ros_point.x = ros_point_ini.x + force_total.fx;
00398 ros_point.y = ros_point_ini.y + force_total.fy;
00399 force_marker_.points.push_back( ros_point);
00400 force_marker_.id = cont;
00401 ++cont;
00402 MarkerArray_trajectories_msg_.markers.push_back( force_marker_ );
00403
00404
00405 double robot_orientation = force_navigation_.get_robot().get_current_pose().theta - PI/2.0;
00406 robot_marker_.pose.position.x = ros_point_ini.x + 0.3*cos(robot_orientation);
00407 robot_marker_.pose.position.y = ros_point_ini.y + 0.3*sin(robot_orientation);
00408 robot_marker_.pose.position.z = 0.4;
00409
00410 robot_marker_.pose.orientation = tf::createQuaternionMsgFromRollPitchYaw(PI/2.0,0.0, robot_orientation );
00411 robot_marker_.id = cont;
00412 ++cont;
00413 MarkerArray_trajectories_msg_.markers.push_back( robot_marker_ );
00414
00415
00416
00417
00418
00419 for( list<Cperson>::iterator iit = scene.begin() ; iit != scene.end() ; iit++)
00420 {
00421 Spose target_pose = iit->get_current_pose();
00422
00423
00424 clear_force_markers();
00425 force_total = iit->get_forces_person( force_to_goal, force_int_person , force_int_robot, force_obstacle );
00426
00427
00428 ros_point_ini.x = target_pose.x;
00429 ros_point_ini.y = target_pose.y;
00430
00431
00432 force_goal_marker_.points.push_back( ros_point_ini );
00433 ros_point.x = ros_point_ini.x + force_to_goal.fx;
00434 ros_point.y = ros_point_ini.y + force_to_goal.fy;
00435 force_goal_marker_.points.push_back( ros_point );
00436 force_goal_marker_.id = cont_f;
00437 ++cont_f;
00438 MarkerArray_forces_msg_.markers.push_back( force_goal_marker_ );
00439
00440
00441 force_int_person_marker_.points.push_back( ros_point_ini );
00442 ros_point.x = ros_point_ini.x + force_int_person.fx;
00443 ros_point.y = ros_point_ini.y + force_int_person.fy;
00444 force_int_person_marker_.points.push_back( ros_point);
00445 force_int_person_marker_.id = cont_f;
00446 ++cont_f;
00447 MarkerArray_forces_msg_.markers.push_back( force_int_person_marker_ );
00448
00449
00450 force_int_robot_marker_.points.push_back( ros_point_ini );
00451 ros_point.x = ros_point_ini.x + force_int_robot.fx;
00452 ros_point.y = ros_point_ini.y + force_int_robot.fy;
00453 force_int_robot_marker_.points.push_back( ros_point);
00454 force_int_robot_marker_.id = cont_f;
00455 ++cont_f;
00456 MarkerArray_forces_msg_.markers.push_back( force_int_robot_marker_ );
00457
00458
00459 force_obstacle_map_marker_.points.push_back( ros_point_ini );
00460 ros_point.x = ros_point_ini.x + force_obstacle.fx;
00461 ros_point.y = ros_point_ini.y + force_obstacle.fy;
00462 force_obstacle_map_marker_.points.push_back( ros_point);
00463 force_obstacle_map_marker_.id = cont_f;
00464 ++cont_f;
00465 MarkerArray_forces_msg_.markers.push_back( force_obstacle_map_marker_ );
00466
00467
00468 force_marker_.points.push_back( ros_point_ini );
00469 ros_point.x = ros_point_ini.x + force_total.fx;
00470 ros_point.y = ros_point_ini.y + force_total.fy;
00471 force_marker_.points.push_back( ros_point);
00472 force_marker_.id = cont_f;
00473 ++cont_f;
00474 MarkerArray_forces_msg_.markers.push_back( force_marker_ );
00475
00476
00477 target_marker_.pose.position.x = target_pose.x;
00478 target_marker_.pose.position.y = target_pose.y;
00479 target_marker_.pose.position.z = 0.3;
00480 target_marker_.id = cont;
00481 ++cont;
00482 MarkerArray_trajectories_msg_.markers.push_back( target_marker_ );
00483
00484
00485 text_marker_.pose.position.x = target_pose.x;
00486 text_marker_.pose.position.y = target_pose.y;
00487 text_marker_.id = cont_f;
00488 ++cont_f;
00489 std::ostringstream target_id;
00490 target_id << iit->get_id();
00491 text_marker_.text = target_id.str();
00492 MarkerArray_forces_msg_.markers.push_back( text_marker_ );
00493 ++cont;
00494 }
00495
00496 }
00497
00498 void ForceNavigationAlgNode::clear_force_markers()
00499 {
00500 force_marker_.points.clear();
00501 force_goal_marker_.points.clear();
00502 force_goal2_marker_.points.clear();
00503 force_int_person_marker_.points.clear();
00504 force_int_robot_marker_.points.clear();
00505 force_obstacle_map_marker_.points.clear();
00506 force_obstacle_laser_marker_.points.clear();
00507 }
00508
00509 void ForceNavigationAlgNode::vis_destinations()
00510 {
00511 MarkerArray_destinations_msg_.markers.clear();
00512 int cont = 0;
00513
00514
00515 dest_marker_.color.r = 0.0;
00516 dest_marker_.color.g = 0.4;
00517 dest_marker_.color.b = 1.0;
00518 dest_marker_.scale.x = 1;
00519 dest_marker_.scale.y = 1;
00520 dest_marker_.scale.z = 0.2;
00521 dest_marker_.pose.position.z = 0.1;
00522 for ( unsigned int i = 0; i < force_navigation_.get_destinations().size(); ++i)
00523 {
00524 dest_marker_.pose.position.x = force_navigation_.get_destinations()[i].x;
00525 dest_marker_.pose.position.y = force_navigation_.get_destinations()[i].y;
00526 dest_marker_.id = cont;
00527 ++cont;
00528 MarkerArray_destinations_msg_.markers.push_back( dest_marker_ );
00529
00530 text_marker_.pose = dest_marker_.pose;
00531 text_marker_.id = cont;
00532 ++cont;
00533 std::ostringstream target_id;
00534 target_id << force_navigation_.get_destinations()[i].id;
00535 text_marker_.text = target_id.str();
00536 MarkerArray_destinations_msg_.markers.push_back( text_marker_ );
00537 }
00538
00539
00540 dest_marker_.color.r = 1.0;
00541 dest_marker_.color.g = 0.6;
00542 dest_marker_.color.b = 0.0;
00543 dest_marker_.scale.x = 0.8;
00544 dest_marker_.scale.y = 0.8;
00545 dest_marker_.scale.z = 0.2;
00546 dest_marker_.pose.position.z = 0.3;
00547 for ( unsigned int i = 0; i < force_navigation_.get_global_planning_destinations().size(); ++i)
00548 {
00549 dest_marker_.pose.position.x = force_navigation_.get_global_planning_destinations()[i].x;
00550 dest_marker_.pose.position.y = force_navigation_.get_global_planning_destinations()[i].y;
00551 dest_marker_.id = cont;
00552 ++cont;
00553 MarkerArray_destinations_msg_.markers.push_back( dest_marker_ );
00554 }
00555
00556
00557 if( !robot_stop_ && force_navigation_.get_robot_state() != Cforce_navigation::IDLE )
00558 {
00559
00560 dest_marker_.color.r = 0.0;
00561 dest_marker_.color.g = 0.9;
00562 dest_marker_.color.b = 0.9;
00563 dest_marker_.scale.x = 0.5;
00564 dest_marker_.scale.y = 0.5;
00565 dest_marker_.scale.z = 1.0;
00566 dest_marker_.pose.position.z = 0.5*dest_marker_.scale.z;
00567 dest_marker_.pose.position.x = force_navigation_.get_global_planning_destinations().back().x;
00568 dest_marker_.pose.position.y = force_navigation_.get_global_planning_destinations().back().y;
00569 dest_marker_.id = cont;
00570 ++cont;
00571 MarkerArray_destinations_msg_.markers.push_back( dest_marker_ );
00572
00573
00574
00575 dest_marker_.color.r = 0.8;
00576 dest_marker_.color.g = 0.26;
00577 dest_marker_.color.b = 0.0;
00578 dest_marker_.scale.x = 0.2;
00579 dest_marker_.scale.y = 0.2;
00580 dest_marker_.scale.z = 0.1;
00581 dest_marker_.pose.position.x = robot_desired_position_.x;
00582 dest_marker_.pose.position.y = robot_desired_position_.y;
00583 dest_marker_.id = cont;
00584 ++cont;
00585 MarkerArray_destinations_msg_.markers.push_back( dest_marker_ );
00586 }
00587
00588 }
00589
00590
00591 void ForceNavigationAlgNode::tracks_callback(const iri_perception_msgs::peopleTrackingArray::ConstPtr& msg)
00592 {
00593
00594
00595
00596
00597
00598 try
00599 {
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609 bool tf_exists = tf_listener_.waitForTransform(target_frame_,
00610 msg->header.frame_id,
00611 msg->header.stamp,
00612 ros::Duration(1), ros::Duration(0.01));
00613
00614 if(tf_exists)
00615 {
00616
00617 vector<SdetectionObservation> obs;
00618 geometry_msgs::PointStamped observation_point, target_point;
00619 observation_point.header = msg->header;
00620 observation_point.point.z = 0.0;
00621 for(unsigned int i = 0; i < msg->peopleSet.size() ; ++i)
00622 {
00623 observation_point.point.x = msg->peopleSet[i].x;
00624 observation_point.point.y = msg->peopleSet[i].y;
00625
00626
00627
00628
00629
00630
00631 tf_listener_.transformPoint( target_frame_, observation_point, target_point);
00632
00633 obs.push_back( SdetectionObservation( msg->peopleSet[i].targetId ,
00634 msg->header.stamp.toSec() , target_point.point.x ,
00635 target_point.point.y , 0.0 , 0.0 ) );
00636 }
00637
00638 this->alg_.lock();
00639 force_navigation_.update_scene( obs );
00640 this->alg_.unlock();
00641 }
00642 else
00643 {
00644 ROS_ERROR("ForceNavigationAlgNode::No transform in tracks callback function");
00645 }
00646 }
00647 catch (tf::TransformException &ex)
00648 {
00649 ROS_ERROR("ForceNavigationAlgNode:: %s",ex.what());
00650 }
00651
00652
00653
00654 }
00655
00656
00657
00658
00659 void ForceNavigationAlgNode::move_robotDone(const actionlib::SimpleClientGoalState& state, const move_base_msgs::MoveBaseResultConstPtr& result)
00660 {
00661 if( state.toString().compare("SUCCEEDED") == 0 )
00662 ROS_INFO("ForceNavigationAlgNode::move_robotDone: Goal Achieved!");
00663 else
00664 ROS_INFO("ForceNavigationAlgNode::move_robotDone: %s", state.toString().c_str());
00665
00666
00667 }
00668
00669 void ForceNavigationAlgNode::move_robotActive()
00670 {
00671
00672 }
00673
00674 void ForceNavigationAlgNode::move_robotFeedback(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback)
00675 {
00676
00677
00678 bool feedback_is_ok = true;
00679
00680
00681
00682
00683
00684 if( !feedback_is_ok )
00685 {
00686 move_robot_client_.cancelGoal();
00687
00688 }
00689 }
00690
00691
00692 void ForceNavigationAlgNode::move_robotMakeActionRequest()
00693 {
00694 ROS_INFO("ForceNavigationAlgNode::move_robotMakeActionRequest: Starting New Request!");
00695
00696
00697
00698 move_robot_client_.waitForServer();
00699 ROS_INFO("ForceNavigationAlgNode::move_robotMakeActionRequest: Server is Available!");
00700
00701
00702
00703 move_robot_goal_.target_pose.header.frame_id = target_frame_;
00704 move_robot_goal_.target_pose.header.stamp = ros::Time::now();
00705 move_robot_goal_.target_pose.pose.position.x = robot_desired_position_.x;
00706 move_robot_goal_.target_pose.pose.position.y = robot_desired_position_.y;
00707
00708 move_robot_client_.sendGoal(move_robot_goal_,
00709 boost::bind(&ForceNavigationAlgNode::move_robotDone, this, _1, _2),
00710 boost::bind(&ForceNavigationAlgNode::move_robotActive, this),
00711 boost::bind(&ForceNavigationAlgNode::move_robotFeedback, this, _1));
00712 ROS_INFO("ForceNavigationAlgNode::move_robotMakeActionRequest: Goal Sent. Wait for Result!");
00713 }
00714
00715 void ForceNavigationAlgNode::node_config_update(Config &config, uint32_t level)
00716 {
00717 this->alg_.lock();
00718 ROS_INFO(" ******* algorithm config update *******");
00719 move_base_mode_ = config.move_base;
00720
00721
00722 robot_stop_ = config.stop_robot;
00723
00724
00725 if( config.set_planning )
00726 {
00727 stringstream lineStream( config.manual_planning );
00728 vector<int> path,path_reversed;
00729 int num;
00730 while (lineStream >> num) path.push_back(num);
00731 for(unsigned int i = path.size(); i>0; --i) path_reversed.push_back( path[i-1] );
00732 force_navigation_.robot_global_planning( path_reversed );
00733 }
00734
00735 force_navigation_.set_v_max( config.v_max );
00736 force_navigation_.set_v_cruise( config.v_cruise );
00737 force_navigation_.set_time_horizon( config.time_horizon );
00738
00739
00740 vector<double> param;
00741 param.push_back(config.force_goal);
00742 param.push_back(config.force_interaction);
00743 param.push_back(config.force_map);
00744 force_navigation_.set_force_nav_params( param);
00745
00746
00747 robot_sim_ = config.robot_sim;
00748 if (robot_sim_)
00749 {
00750 robot_x_ini_ = config.robot_x_ini;
00751 robot_y_ini_ = config.robot_y_ini;
00752 }
00753
00754
00755 this->alg_.unlock();
00756 }
00757
00758 void ForceNavigationAlgNode::addNodeDiagnostics(void)
00759 {
00760 }
00761
00762
00763 int main(int argc,char *argv[])
00764 {
00765 return algorithm_base::main<ForceNavigationAlgNode>(argc, argv, "force_navigation_alg_node");
00766 }