00001 #include "force_robot_companion_learning_alg_node.h"
00002 #include <deque>
00003 #include <stdio.h>
00004
00005
00006 ForceRobotCompanionLearningAlgNode::ForceRobotCompanionLearningAlgNode(void) :
00007 algorithm_base::IriBaseAlgorithm<ForceRobotCompanionLearningAlgorithm>() ,
00008 tf_listener_(ros::Duration(30.f)),
00009 nearest_target_(0),
00010 simulation_state_(ForceRobotCompanionLearningAlgNode::Init_Sim),
00011 number_of_virtual_people_(0),
00012 num_experiment_(0),
00013 results_file_is_open_(false),
00014 learning_mode_( ForceRobotCompanionLearningAlgNode::Density )
00015 {
00016
00017
00018 this->loop_rate_ = 5;
00019
00020
00021 this->angle_robot_person_publisher_ = this->public_node_handle_.advertise<std_msgs::Float64>("angle_robot_person", 100);
00022 this->person_robot_dist_publisher_ = this->public_node_handle_.advertise<std_msgs::Float64>("person_robot_dist", 100);
00023
00024 this->target_person_position_publisher_ = this->public_node_handle_.advertise<geometry_msgs::PointStamped>("target_position", 100);
00025 this->robot_position_publisher_ = this->public_node_handle_.advertise<geometry_msgs::PoseStamped>("robot_position", 100);
00026 this->force_param_publisher_ = this->public_node_handle_.advertise<geometry_msgs::PointStamped>("force_param", 100);
00027 this->trajectories_publisher_ = this->public_node_handle_.advertise<visualization_msgs::MarkerArray>("vis/trajectories", 100);
00028 this->forces_publisher_ = this->public_node_handle_.advertise<visualization_msgs::MarkerArray>("vis/forces", 100);
00029 this->destinations_publisher_ = this->public_node_handle_.advertise<visualization_msgs::MarkerArray>("vis/destinations", 100);
00030 this->predictions_publisher_ = this->public_node_handle_.advertise<visualization_msgs::MarkerArray>("vis/predictions", 100);
00031 init_node();
00032
00033
00034 this->dest_subscriber_ = this->public_node_handle_.subscribe("dest", 100, &ForceRobotCompanionLearningAlgNode::dest_callback, this);
00035 this->tracks_subscriber_ = this->public_node_handle_.subscribe("tracks", 100, &ForceRobotCompanionLearningAlgNode::tracks_callback, this);
00036
00037
00038
00039
00040
00041
00042 reset_client_ = this->public_node_handle_.serviceClient<std_srvs::Empty>("reset");
00043
00044
00045
00046
00047 }
00048
00049 ForceRobotCompanionLearningAlgNode::~ForceRobotCompanionLearningAlgNode(void)
00050 {
00051
00052 if ( results_file_is_open_ )
00053 fclose( file_results_out_ );
00054 }
00055
00056 void ForceRobotCompanionLearningAlgNode::mainNodeThread(void)
00057 {
00058
00059
00060
00061
00062 this->alg_.lock();
00063 pred_.scene_intentionality_prediction_bhmip();
00064
00065 now_ = ros::Time::now();
00066 vis_trajectories();
00067 vis_destinations();
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 angle_robot_person_msg_.data = target_followed_pose_.angle_heading_point( pred_.get_robot()->get_current_pointV() );
00080 switch( learning_mode_ )
00081 {
00082
00083 case ForceRobotCompanionLearningAlgNode::Density:
00084 growing_density_test();
00085 break;
00086
00087
00088
00089 case ForceRobotCompanionLearningAlgNode::Initial_paramters :
00090 default:
00091 initial_params_learning();
00092 break;
00093 }
00094
00095
00096 this->alg_.unlock();
00097
00098
00099
00100 this->angle_robot_person_publisher_.publish(this->angle_robot_person_msg_);
00101 this->person_robot_dist_publisher_.publish(this->person_robot_dist_msg_);
00102 force_param_msg_.header.stamp = now_;
00103 this->target_person_position_publisher_.publish(this->target_person_position_msg_);
00104 this->robot_position_publisher_.publish(this->robot_position_msg_);
00105 this->force_param_publisher_.publish(this->force_param_msg_);
00106 this->trajectories_publisher_.publish(this->MarkerArray_trajectories_msg_);
00107 this->forces_publisher_.publish(this->MarkerArray_forces_msg_);
00108 this->destinations_publisher_.publish(this->MarkerArray_destinations_msg_);
00109 this->predictions_publisher_.publish(this->MarkerArray_predictions_msg_);
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 void ForceRobotCompanionLearningAlgNode::init_node()
00129 {
00130 pred_.set_dt( 1.0 / 5.0 );
00131 this->public_node_handle_.getParam("reference_frame", target_frame_);
00132 this->public_node_handle_.getParam("force_map_path", force_map_path_);
00133 this->public_node_handle_.getParam("destination_map_path", destination_map_path_);
00134 if ( !pred_.read_force_map( force_map_path_.c_str() ) )
00135 {
00136 ROS_WARN("Could not read map force file !!!");
00137 }
00138 this->public_node_handle_.getParam("robot_x_ini", robot_x_ini_);
00139 this->public_node_handle_.getParam("robot_y_ini", robot_y_ini_);
00140
00141
00142 if ( !pred_.read_destination_map( destination_map_path_.c_str() ) )
00143 {
00144 ROS_ERROR("Could not read map destinations file !!!");
00145 }
00146 else{
00147 ROS_WARN("read destinations map file : SUCCESS!!!");
00148 }
00149
00150
00151 if ( !pred_.read_force_map( force_map_path_.c_str() ) )
00152 {
00153 ROS_ERROR("Could not read map force file !!!");
00154 }
00155 else{
00156 ROS_WARN("read map force file : SUCCESS!!!");
00157 }
00158
00159
00160
00161 force_param_msg_.header.frame_id = target_frame_;
00162 now_ = ros::Time::now();
00163 Spose robot_current_position( robot_x_ini_,robot_y_ini_, 0.0, now_.toSec() );
00164 pred_.update_robot( SdetectionObservation( 0, robot_current_position.time_stamp,
00165 robot_current_position.x, robot_current_position.y ,
00166 0.0, 0.0 ) );
00167 robot_position_msg_.header.stamp = now_;
00168 robot_position_msg_.header.frame_id = target_frame_;
00169 robot_position_msg_.pose.position.x = robot_x_ini_;
00170 robot_position_msg_.pose.position.y = robot_y_ini_;
00171
00172
00173
00174 traj_marker_.ns = "trajectories";
00175 traj_marker_.type = visualization_msgs::Marker::LINE_STRIP;
00176 traj_marker_.action = visualization_msgs::Marker::ADD;
00177 traj_marker_.lifetime = ros::Duration(1.0f);
00178 traj_marker_.scale.x = 0.1;
00179 traj_marker_.color.a = 0.5;
00180 traj_marker_.color.r = 1.0;
00181 traj_marker_.color.g = 0.4;
00182 traj_marker_.color.b = 0.0;
00183
00184
00185 traj_robot_marker_.ns = "trajectories";
00186 traj_robot_marker_.type = visualization_msgs::Marker::LINE_STRIP;
00187 traj_robot_marker_.action = visualization_msgs::Marker::ADD;
00188 traj_robot_marker_.lifetime = ros::Duration(1.0f);
00189 traj_robot_marker_.scale.x = 0.1;
00190 traj_robot_marker_.color.a = 0.6;
00191 traj_robot_marker_.color.r = 0.26;
00192 traj_robot_marker_.color.g = 0.0;
00193 traj_robot_marker_.color.b = 0.5;
00194
00195
00196 robot_marker_.ns = "trajectories";
00197 robot_marker_.type = visualization_msgs::Marker::MESH_RESOURCE;
00198 robot_marker_.mesh_resource = "package://tibi_dabo_base/model/meshes/tibi.stl";
00199 robot_marker_.action = visualization_msgs::Marker::ADD;
00200 robot_marker_.lifetime = ros::Duration(1.0f);
00201 robot_marker_.scale.x = 1.0;
00202 robot_marker_.scale.y = 0.6;
00203 robot_marker_.scale.z = 1.0;
00204 robot_marker_.color.a = 1.0;
00205 robot_marker_.color.r = 0.7;
00206 robot_marker_.color.g = 0.5;
00207 robot_marker_.color.b = 1.0;
00208
00209
00210
00211 target_marker_.ns = "trajectories";
00212 target_marker_.type = visualization_msgs::Marker::CYLINDER;
00213 target_marker_.action = visualization_msgs::Marker::ADD;
00214 target_marker_.lifetime = ros::Duration(1.0f);
00215 target_marker_.scale.x = 0.5;
00216 target_marker_.scale.y = 0.5;
00217
00218
00219
00220 text_marker_.ns = "trajectories";
00221 text_marker_.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
00222 text_marker_.action = visualization_msgs::Marker::ADD;
00223 text_marker_.lifetime = ros::Duration(1.0f);
00224 text_marker_.scale.z = 0.5;
00225 text_marker_.pose.position.z = 1.5;
00226 text_marker_.color.a = 0.5;
00227 text_marker_.color.r = 0.0;
00228 text_marker_.color.g = 0.0;
00229 text_marker_.color.b = 0.0;
00230
00231
00232 force_marker_.ns = "trajectories";
00233 force_marker_.type = visualization_msgs::Marker::ARROW;
00234 force_marker_.action = visualization_msgs::Marker::ADD;
00235 force_marker_.lifetime = ros::Duration(1.0f);
00236 force_marker_.scale.x = 0.2;
00237 force_marker_.scale.y = 0.25;
00238 force_marker_.color.a = 0.8;
00239 force_marker_.color.r = 1.0;
00240 force_marker_.color.g = 0.0;
00241 force_marker_.color.b = 0.0;
00242
00243
00244 force_goal_marker_ = force_marker_;
00245 force_goal_marker_.color.r = 0.0;
00246 force_goal_marker_.color.g = 0.4;
00247 force_goal_marker_.color.b = 1.0;
00248
00249
00250 force_goal2_marker_ = force_marker_;
00251 force_goal2_marker_.color.r = 1.0;
00252 force_goal2_marker_.color.g = 0.4;
00253 force_goal2_marker_.color.b = 0.0;
00254
00255
00256 force_int_person_marker_ = force_marker_;
00257 force_int_person_marker_.color.r = 0.2;
00258 force_int_person_marker_.color.g = 0.85;
00259 force_int_person_marker_.color.b = 0.2;
00260
00261
00262 force_int_robot_marker_ = force_marker_;
00263 force_int_robot_marker_.color.r = 0.26;
00264 force_int_robot_marker_.color.g = 0.0;
00265 force_int_robot_marker_.color.b = 0.66;
00266
00267
00268 force_obstacle_laser_marker_ = force_marker_;
00269 force_obstacle_laser_marker_.color.r = 0.0;
00270 force_obstacle_laser_marker_.color.g = 1.0;
00271 force_obstacle_laser_marker_.color.b = 1.0;
00272
00273
00274 force_obstacle_map_marker_ = force_marker_;
00275 force_obstacle_map_marker_.color.r = 0.0;
00276 force_obstacle_map_marker_.color.g = 0.0;
00277 force_obstacle_map_marker_.color.b = 0.0;
00278
00279
00280 dest_marker_.ns = "destinations";
00281 dest_marker_.type = visualization_msgs::Marker::CYLINDER;
00282 dest_marker_.action = visualization_msgs::Marker::ADD;
00283 dest_marker_.lifetime = ros::Duration(1.0f);
00284 dest_marker_.color.a = 0.8;
00285
00286
00287 pred_marker_.ns = "predictions";
00288 pred_marker_.type = visualization_msgs::Marker::LINE_STRIP;
00289 pred_marker_.action = visualization_msgs::Marker::ADD;
00290 pred_marker_.scale.x = 0.1;
00291 pred_marker_.lifetime = ros::Duration(1.0f);
00292 pred_marker_.color.a = 0.5;
00293 pred_marker_.color.r = 0.0;
00294 pred_marker_.color.g = 0.0;
00295 pred_marker_.color.b = 0.0;
00296
00297
00298 }
00299
00300
00301 void ForceRobotCompanionLearningAlgNode::growing_density_test()
00302 {
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 }
00386
00387 void ForceRobotCompanionLearningAlgNode::initial_params_learning()
00388 {
00389
00390 std::stringstream experimentString;
00391 vector<double> params;
00392 switch(simulation_state_)
00393 {
00394 case ForceRobotCompanionLearningAlgNode::Init_Sim:
00395
00396
00397 timer_ = 0;
00398 ++num_experiment_;
00399 ROS_INFO( "experiment number %d", num_experiment_ );
00400 experimentString << num_experiment_;
00401
00402 file_results_out_ = fopen ( (results_folder_ + experimentString.str() ).c_str() , "w");
00403 if (file_results_out_ == NULL)
00404 {
00405 results_file_is_open_ = false;
00406 break;
00407 }
00408 else{
00409 results_file_is_open_ = true;
00410 fprintf (file_results_out_, "%%distance_robot-person, robot_angle_position_wrt_personheading, distance_to_nearest_person, v_robot, v_person, time\n");
00411 }
00412
00413
00414
00415
00416 params = pred_.learning_force_companion_params_alphabeta( );
00417 if( results_file_is_open_ )
00418 {
00419 simulation_state_ = ForceRobotCompanionLearningAlgNode::Find_Nearest;
00420 fprintf (file_results_out_, "%% alpha, beta, gamma, delta(laser), delta(map)\n");
00421 fprintf (file_results_out_, "%f %f %f %f %f 0.0\n", params[0],params[1],params[2],params[3],params[4]);
00422 }
00423 break;
00424
00425 case ForceRobotCompanionLearningAlgNode::Find_Nearest:
00426
00427
00428 if( pred_.set_nearest_target_person() )
00429 simulation_state_ = ForceRobotCompanionLearningAlgNode::Test_Sim;
00430 break;
00431
00432 case ForceRobotCompanionLearningAlgNode::Test_Sim:
00433
00434 robot_desired_position_ = pred_.robot_approach_pose( f1_, f2_, f3_, f4_,f5_, f_ );
00435
00436 pred_.update_robot( SdetectionObservation( 0, now_.toSec(),
00437 robot_desired_position_.x, robot_desired_position_.y ,
00438 0.0, 0.0 ) );
00439 robot_position_msg_.pose.position.x = robot_desired_position_.x;
00440 robot_position_msg_.pose.position.y = robot_desired_position_.y;
00441 robot_position_msg_.header.stamp = now_;
00442
00443
00444 if ( results_file_is_open_ )
00445 {
00446 fprintf (file_results_out_, "%f %f %f %f %f %f\n" ,
00447 person_robot_dist_msg_.data,
00448 target_followed_pose_.angle_heading_point( pred_.get_robot()->get_current_pointV() ),
00449 pred_.distance_to_nearest_person( pred_.get_robot() ),
00450 pred_.get_robot()->get_current_pointV().v() ,
00451 target_followed_pose_.v() ,
00452 now_.toSec());
00453 }
00454
00455 if( !pred_.find_person( pred_.get_target_person() ) )
00456 simulation_state_ = End_Sim;
00457
00458 if( timer_ > 5*60*5 ){
00459 simulation_state_ = ForceRobotCompanionLearningAlgNode::End_Sim;
00460 --num_experiment_;
00461 }
00462 else
00463 ++timer_;
00464 break;
00465
00466 case ForceRobotCompanionLearningAlgNode::End_Sim:
00467 default:
00468
00469 if ( results_file_is_open_ ){
00470 fclose( file_results_out_ );
00471 results_file_is_open_ = false;
00472 }
00473
00474 pred_.clear_scene();
00475 pred_.get_robot()->reset();
00476 pred_.update_robot( SdetectionObservation( 0, now_.toSec(),
00477 robot_x_ini_, robot_y_ini_ ,
00478 0.0, 0.0 ) );
00479 target_followed_pose_ = SpointV_cov();
00480 traj_marker_.points.clear();
00481 traj_robot_marker_.points.clear();
00482
00483 ROS_INFO("ForceRobotCompanionLearningAlgNode:: Sending New Request!");
00484 if (reset_client_.call(reset_srv_))
00485 {
00486 ROS_INFO("ForceRobotCompanionLearningAlgNode:: Response: ");
00487 simulation_state_ = ForceRobotCompanionLearningAlgNode::Init_Sim;
00488 }
00489 else
00490 {
00491 ROS_INFO("ForceRobotCompanionLearningAlgNode:: Failed to Call Server on topic reset ");
00492 }
00493 break;
00494 }
00495
00496 }
00497
00498 void ForceRobotCompanionLearningAlgNode::vis_trajectories()
00499 {
00500 std::vector<SpointV_cov> scene_targets_pointV;
00501 std::vector<unsigned int> scene_targets_ids;
00502 pred_.get_scene_observation(scene_targets_pointV,scene_targets_ids);
00503
00504 int cont = 0;
00505 geometry_msgs::Point ros_point, ros_point_ini;
00506
00507
00508 traj_marker_.header.stamp = now_;
00509 traj_marker_.header.frame_id = target_frame_;
00510 traj_robot_marker_.header.stamp = traj_marker_.header.stamp;
00511 traj_robot_marker_.header.frame_id = target_frame_;
00512 robot_marker_.header.stamp = traj_marker_.header.stamp;
00513 robot_marker_.header.frame_id = target_frame_;
00514 target_marker_.header.stamp = traj_marker_.header.stamp;
00515 target_marker_.header.frame_id = target_frame_;
00516 text_marker_.header.stamp = traj_marker_.header.stamp;
00517 text_marker_.header.frame_id = target_frame_;
00518 force_marker_.header.stamp = traj_marker_.header.stamp;
00519 force_marker_.header.frame_id = target_frame_;
00520 force_goal_marker_.header.stamp = force_marker_.header.stamp;
00521 force_goal_marker_.header.frame_id = force_marker_.header.frame_id;
00522 force_goal2_marker_.header.stamp = force_marker_.header.stamp;
00523 force_goal2_marker_.header.frame_id = force_marker_.header.frame_id;
00524 force_int_person_marker_.header.stamp = force_marker_.header.stamp;
00525 force_int_person_marker_.header.frame_id = force_marker_.header.frame_id;
00526 force_int_robot_marker_.header.stamp = force_marker_.header.stamp;
00527 force_int_robot_marker_.header.frame_id = force_marker_.header.frame_id;
00528 force_obstacle_map_marker_.header.stamp = force_marker_.header.stamp;
00529 force_obstacle_map_marker_.header.frame_id = force_marker_.header.frame_id;
00530 force_obstacle_laser_marker_.header.stamp = force_marker_.header.stamp;
00531 force_obstacle_laser_marker_.header.frame_id = force_marker_.header.frame_id;
00532
00533 MarkerArray_trajectories_msg_.markers.clear();
00534 MarkerArray_forces_msg_.markers.clear();
00535
00536
00537
00538 clear_force_markers();
00539
00540
00541
00542
00543 ros_point_ini.x = pred_.get_robot()->get_current_pointV().x;
00544 ros_point_ini.y = pred_.get_robot()->get_current_pointV().y;
00545
00546
00547 if ( traj_robot_marker_.points.size() > 500)
00548 {
00549 vector<geometry_msgs::Point> temp_poses;
00550 temp_poses.reserve(250);
00551 for( unsigned int i = 251; i <= 500; ++i)
00552 temp_poses.push_back(traj_robot_marker_.points[i]);
00553 traj_robot_marker_.points = temp_poses;
00554 }
00555 traj_robot_marker_.points.push_back( ros_point_ini );
00556 traj_robot_marker_.id = cont;
00557 ++cont;
00558 MarkerArray_trajectories_msg_.markers.push_back( traj_robot_marker_ );
00559
00560
00561
00562 force_goal_marker_.points.push_back( ros_point_ini );
00563 ros_point.x = ros_point_ini.x + f1_.fx;
00564 ros_point.y = ros_point_ini.y + f1_.fy;
00565 force_goal_marker_.points.push_back( ros_point );
00566 force_goal_marker_.id = cont;
00567 ++cont;
00568 MarkerArray_trajectories_msg_.markers.push_back( force_goal_marker_ );
00569
00570
00571 force_goal2_marker_.points.push_back( ros_point_ini );
00572 ros_point.x = ros_point_ini.x + f2_.fx;
00573 ros_point.y = ros_point_ini.y + f2_.fy;
00574 force_goal2_marker_.points.push_back( ros_point );
00575 force_goal2_marker_.id = cont;
00576 ++cont;
00577 MarkerArray_trajectories_msg_.markers.push_back( force_goal2_marker_ );
00578
00579
00580 force_int_person_marker_.points.push_back( ros_point_ini );
00581 ros_point.x = ros_point_ini.x + f3_.fx;
00582 ros_point.y = ros_point_ini.y + f3_.fy;
00583 force_int_person_marker_.points.push_back( ros_point);
00584 force_int_person_marker_.id = cont;
00585 ++cont;
00586 MarkerArray_trajectories_msg_.markers.push_back( force_int_person_marker_ );
00587
00588
00589 force_obstacle_laser_marker_.points.push_back( ros_point_ini );
00590 ros_point.x = ros_point_ini.x + f4_.fx;
00591 ros_point.y = ros_point_ini.y + f4_.fy;
00592 force_obstacle_laser_marker_.points.push_back( ros_point);
00593 force_obstacle_laser_marker_.id = cont;
00594 ++cont;
00595 MarkerArray_trajectories_msg_.markers.push_back( force_obstacle_laser_marker_ );
00596
00597
00598 force_obstacle_map_marker_.points.push_back( ros_point_ini );
00599 ros_point.x = ros_point_ini.x + f5_.fx;
00600 ros_point.y = ros_point_ini.y + f5_.fy;
00601 force_obstacle_map_marker_.points.push_back( ros_point);
00602 force_obstacle_map_marker_.id = cont;
00603 ++cont;
00604 MarkerArray_trajectories_msg_.markers.push_back( force_obstacle_map_marker_ );
00605
00606
00607 force_marker_.points.push_back( ros_point_ini );
00608 ros_point.x = ros_point_ini.x + f_.fx;
00609 ros_point.y = ros_point_ini.y + f_.fy;
00610 force_marker_.points.push_back( ros_point);
00611 force_marker_.id = cont;
00612 ++cont;
00613 MarkerArray_trajectories_msg_.markers.push_back( force_marker_ );
00614
00615
00616 double robot_orientation = pred_.get_robot()->get_current_pointV().orientation() - PI/2.0;
00617 robot_marker_.pose.position.x = ros_point_ini.x + 0.3*cos(robot_orientation);
00618 robot_marker_.pose.position.y = ros_point_ini.y + 0.3*sin(robot_orientation);
00619 robot_marker_.pose.position.z = 0.4;
00620
00621 robot_marker_.pose.orientation = tf::createQuaternionMsgFromRollPitchYaw(PI/2.0,0.0, robot_orientation );
00622 robot_position_msg_.pose.orientation = robot_marker_.pose.orientation;
00623 robot_marker_.id = cont;
00624 ++cont;
00625 MarkerArray_trajectories_msg_.markers.push_back( robot_marker_ );
00626
00627
00628
00629
00630 Sforce force_to_goal, force_int_person , force_int_robot, force_obstacle;
00631 for( unsigned int i = 0; i < (unsigned int)scene_targets_pointV.size() ; i++)
00632 {
00633 SpointV_cov target_pose = scene_targets_pointV[i];
00634
00635
00636
00637 if ( scene_targets_ids[i] == (unsigned int)pred_.get_target_person())
00638 {
00639
00640 target_followed_pose_ = target_pose;
00641
00642 ros_point.x = target_pose.x;
00643 ros_point.y = target_pose.y;
00644 if ( traj_marker_.points.size() > 500)
00645 {
00646 vector<geometry_msgs::Point> temp_poses;
00647 temp_poses.reserve(250);
00648 for( unsigned int i = 251; i <= 500; ++i)
00649 temp_poses.push_back(traj_marker_.points[i]);
00650 traj_marker_.points = temp_poses;
00651 }
00652 traj_marker_.points.push_back( ros_point );
00653 traj_marker_.id = cont;
00654 ++cont;
00655 MarkerArray_trajectories_msg_.markers.push_back( traj_marker_ );
00656
00657
00658 target_marker_.scale.z = 0.8;
00659 target_marker_.color.a = 0.8;
00660 target_marker_.color.r = 1.0;
00661 target_marker_.color.g = 0.4;
00662 target_marker_.color.b = 0.0;
00663
00664 target_marker_.pose.position.x = target_pose.x;
00665 target_marker_.pose.position.y = target_pose.y;
00666 target_marker_.pose.position.z = 0.4;
00667 ++cont;
00668 target_marker_.id = cont;
00669 MarkerArray_trajectories_msg_.markers.push_back( target_marker_ );
00670
00671
00672
00673 target_person_position_msg_.point.x = target_pose.x;
00674 target_person_position_msg_.point.y = target_pose.y;
00675 target_person_position_msg_.point.z = target_pose.v();
00676 target_person_position_msg_.header = traj_marker_.header;
00677
00678
00679
00680 person_robot_dist_msg_.data = target_pose.distance( pred_.get_robot()->get_current_pointV() );
00681 }
00682 else
00683 {
00684 target_marker_.scale.z = 0.6;
00685 target_marker_.color.a = 0.4;
00686 target_marker_.color.r = 0.0;
00687 target_marker_.color.g = 0.8;
00688 target_marker_.color.b = 0.0;
00689
00690 target_marker_.pose.position.x = target_pose.x;
00691 target_marker_.pose.position.y = target_pose.y;
00692 target_marker_.pose.position.z = 0.3;
00693 ++cont;
00694 target_marker_.id = cont;
00695 MarkerArray_trajectories_msg_.markers.push_back( target_marker_ );
00696 }
00697
00698
00699 text_marker_.pose.position.x = target_pose.x;
00700 text_marker_.pose.position.y = target_pose.y;
00701 ++cont;
00702 text_marker_.id = cont;
00703 std::ostringstream target_id;
00704 target_id << scene_targets_ids[i];
00705 text_marker_.text = target_id.str();
00706
00707 ++cont;
00708 }
00709
00710 }
00711
00712 void ForceRobotCompanionLearningAlgNode::clear_force_markers()
00713 {
00714 force_marker_.points.clear();
00715 force_goal_marker_.points.clear();
00716 force_goal2_marker_.points.clear();
00717 force_int_person_marker_.points.clear();
00718 force_int_robot_marker_.points.clear();
00719 force_obstacle_map_marker_.points.clear();
00720 force_obstacle_laser_marker_.points.clear();
00721 }
00722
00723 void ForceRobotCompanionLearningAlgNode::vis_intentionality_prediction()
00724 {
00725
00726 vector<vector<Sdestination> >& intentionality_pred = pred_.get_scene_intentionality_prediction_bhmip( );
00727
00728 dest_marker_.header.frame_id = target_frame_;
00729 MarkerArray_destinations_msg_.markers.clear();
00730 dest_marker_.color.r = 1.0;
00731 dest_marker_.color.g = 0.0;
00732 dest_marker_.color.b = 0.0;
00733 dest_marker_.scale.x = 0.5;
00734 dest_marker_.scale.y = 0.5;
00735 for (unsigned int i = 0; i < intentionality_pred.size() ; ++i)
00736 {
00737 for (unsigned int j = 0; j < intentionality_pred[i].size() ; ++j)
00738 {
00739 dest_marker_.scale.z = intentionality_pred[i][j].prob;
00740 dest_marker_.pose.position.z = 0.5*intentionality_pred[i][j].prob;
00741
00742
00743 dest_marker_.pose.position.x = intentionality_pred[i][j].x;
00744 dest_marker_.pose.position.y = intentionality_pred[i][j].y;
00745 dest_marker_.id = i*intentionality_pred[i].size() + j;
00746 MarkerArray_destinations_msg_.markers.push_back( dest_marker_ );
00747 }
00748 }
00749 }
00750
00751
00752 void ForceRobotCompanionLearningAlgNode::vis_destinations()
00753 {
00754
00755 dest_marker_.header.frame_id = target_frame_;
00756 MarkerArray_destinations_msg_.markers.clear();
00757 int cont = 0;
00758
00759
00760
00761 dest_marker_.color.r = 0.0;
00762 dest_marker_.color.g = 0.4;
00763 dest_marker_.color.b = 1.0;
00764 dest_marker_.scale.x = 1;
00765 dest_marker_.scale.y = 1;
00766 dest_marker_.scale.z = 0.01;
00767 dest_marker_.pose.position.z = 0.0;
00768 for ( unsigned int i = 0; i < pred_.get_destinations().size(); ++i)
00769 {
00770 dest_marker_.pose.position.x = pred_.get_destinations()[i].x;
00771 dest_marker_.pose.position.y = pred_.get_destinations()[i].y;
00772 dest_marker_.id = cont;
00773 ++cont;
00774 MarkerArray_destinations_msg_.markers.push_back( dest_marker_ );
00775 }
00776
00777
00778 dest_marker_.color.r = 1.0;
00779 dest_marker_.color.g = 1.0;
00780 dest_marker_.color.b = 1.0;
00781 dest_marker_.scale.x = 0.8;
00782 dest_marker_.scale.y = 0.8;
00783 dest_marker_.scale.z = 0.1;
00784 for ( unsigned int i = 0; i < pred_.get_robot()->get_destinations()->size(); ++i)
00785 {
00786 dest_marker_.pose.position.x = pred_.get_robot()->get_destinations()->at(i).x;
00787 dest_marker_.pose.position.y = pred_.get_robot()->get_destinations()->at(i).y;
00788 dest_marker_.id = cont;
00789 ++cont;
00790 MarkerArray_destinations_msg_.markers.push_back( dest_marker_ );
00791 }
00792
00793
00794 Cperson_abstract* iit;
00795 if( pred_.find_person( pred_.get_target_person() , &iit ) )
00796 {
00797 dest_marker_.color.r = 0.0;
00798 dest_marker_.color.g = 0.9;
00799 dest_marker_.color.b = 0.9;
00800 dest_marker_.scale.x = 0.5;
00801 dest_marker_.scale.y = 0.5;
00802 dest_marker_.scale.z = 0;
00803
00804 dest_marker_.scale.z = iit->get_best_dest().prob;
00805 dest_marker_.pose.position.z = 0.5*dest_marker_.scale.z;
00806 dest_marker_.pose.position.x = iit->get_best_dest().x;
00807 dest_marker_.pose.position.y = iit->get_best_dest().y;
00808 dest_marker_.id = cont;
00809 ++cont;
00810 MarkerArray_destinations_msg_.markers.push_back( dest_marker_ );
00811
00812 }
00813
00814
00815 dest_marker_.color.r = 0.8;
00816 dest_marker_.color.g = 0.26;
00817 dest_marker_.color.b = 0.0;
00818 dest_marker_.scale.x = 0.2;
00819 dest_marker_.scale.y = 0.2;
00820 dest_marker_.scale.z = 0.1;
00821 dest_marker_.pose.position.x = robot_desired_position_.x;
00822 dest_marker_.pose.position.y = robot_desired_position_.y;
00823 dest_marker_.id = cont;
00824 ++cont;
00825 MarkerArray_destinations_msg_.markers.push_back( dest_marker_ );
00826
00827
00828 }
00829
00830 void ForceRobotCompanionLearningAlgNode::vis_predictions()
00831 {
00832
00833 vector< vector<vector<Spose> >* > scene_pred = pred_.get_scene_motion_prediction();
00834 int cont = 0;
00835
00836
00837 pred_marker_.header.frame_id = target_frame_;
00838 pred_marker_.header.stamp = now_;
00839 MarkerArray_predictions_msg_.markers.clear();
00840
00841
00842 for( unsigned int i = 0; i < scene_pred.size(); ++i )
00843 {
00844 for( unsigned int j = 0; j < scene_pred[i]->size() ; ++j )
00845 {
00846
00847 pred_marker_.points.clear();
00848 for( unsigned int t = 0; t < scene_pred[i]->at(j).size() ; ++t )
00849 {
00850 geometry_msgs::Point ros_point;
00851 ros_point.x = scene_pred.at(i)->at(j).at(t).x;
00852 ros_point.y = scene_pred.at(i)->at(j).at(t).y;
00853 pred_marker_.points.push_back( ros_point );
00854 }
00855 pred_marker_.id = cont;
00856 ++cont;
00857 MarkerArray_predictions_msg_.markers.push_back( pred_marker_ );
00858 }
00859 }
00860 }
00861
00862
00863
00864
00865 void ForceRobotCompanionLearningAlgNode::dest_callback(const geometry_msgs::PoseStamped::ConstPtr& msg)
00866 {
00867
00868
00869
00870 this->alg_.lock();
00871
00872
00873
00874
00875 this->alg_.unlock();
00876
00877 }
00878
00879 void ForceRobotCompanionLearningAlgNode::tracks_callback(const iri_perception_msgs::peopleTrackingArray::ConstPtr& msg)
00880 {
00881
00882
00883
00884
00885 this->tracks_mutex_.enter();
00886
00887 try
00888 {
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898 bool tf_exists = tf_listener_.waitForTransform(target_frame_,
00899 msg->header.frame_id,
00900 msg->header.stamp,
00901 ros::Duration(1), ros::Duration(0.01));
00902
00903 if(tf_exists)
00904 {
00905
00906 vector<SdetectionObservation> obs;
00907 geometry_msgs::PointStamped observation_point, target_point;
00908 observation_point.header = msg->header;
00909 observation_point.point.z = 0.0;
00910 for(unsigned int i = 0; i < msg->peopleSet.size() ; ++i)
00911 {
00912 observation_point.point.x = msg->peopleSet[i].x;
00913 observation_point.point.y = msg->peopleSet[i].y;
00914
00915
00916
00917
00918
00919
00920 tf_listener_.transformPoint( target_frame_, observation_point, target_point);
00921
00922 obs.push_back( SdetectionObservation( msg->peopleSet[i].targetId ,
00923 msg->header.stamp.toSec() , target_point.point.x ,
00924 target_point.point.y , 0.0 , 0.0 ) );
00925 }
00926
00927 this->alg_.lock();
00928 pred_.update_scene( obs );
00929 this->alg_.unlock();
00930
00931 }
00932 else
00933 {
00934 ROS_ERROR("ForceRobotCompanionLearningAlgNode::No transform in tracks callback function");
00935 }
00936 }
00937 catch (tf::TransformException &ex)
00938 {
00939 ROS_ERROR("ForceRobotCompanionTracks:: %s",ex.what());
00940 }
00941
00942
00943 this->tracks_mutex_.exit();
00944 }
00945
00946
00947
00948
00949
00950
00951 void ForceRobotCompanionLearningAlgNode::node_config_update(Config &config, uint32_t level)
00952 {
00953 this->alg_.lock();
00954
00955 ROS_INFO(" ******* algorithm config update *******\n\n");
00956 using_prediction_ = config.using_prediction;
00957 learning_mode_ = (ForceRobotCompanionLearningAlgNode::learning_mode) config.learning_mode;
00958 results_folder_ = config.results_folder;
00959 target_frame_ = config.reference_frame;
00960 robot_frame_ = config.robot_frame;
00961 if( config.target_person_id != pred_.get_target_person() )
00962 traj_marker_.points.clear();
00963 pred_.set_target_person( config.target_person_id );
00964 pred_.set_v_max( config.v_max );
00965 pred_.set_v_cruise( config.v_cruise );
00966 pred_.set_time_horizon( config.time_horizon );
00967 if( config.force_parameters )
00968 {
00969 pred_.set_force_params( config.force_goal, config.force_toperson, config.force_interaction ,
00970 config.force_laser, config.force_map);
00971 force_param_msg_.point.x = config.force_goal;
00972 force_param_msg_.point.y = config.force_toperson;
00973 force_param_msg_.point.z = config.force_interaction;
00974 }
00975 laser_radi_ = config.laser_radi;
00976 pred_.set_companion_position(config.r , config.theta/180*3.14);
00977 if(config.follow_nearest)
00978 {
00979 ROS_INFO("Following nearest target (id: %d)", nearest_target_);
00980 pred_.set_target_person( nearest_target_ );
00981 config.target_person_id = nearest_target_;
00982 }
00983 force_map_path_ = config.force_map_path;
00984
00985 vector<double> param;
00986 param.push_back(config.K_rob_per);
00987 param.push_back(config.lambda_rob_per);
00988 param.push_back(config.A_rob_per);
00989 param.push_back(config.B_rob_per);
00990 param.push_back(config.d_rob_per);
00991 pred_.get_robot()->set_social_force_parameters_person_robot( param );
00992
00993 param.clear();
00994 param.push_back(config.K_obstacle);
00995 param.push_back(config.lambda_obs);
00996 param.push_back(config.A_obstacle);
00997 param.push_back(config.B_obstacle);
00998 param.push_back(config.d_obstacle);
00999 pred_.get_robot()->set_social_force_parameters_obstacle( param );
01000 if( config.clear_target_traj )
01001 traj_marker_.points.clear();
01002 traj_robot_marker_.points.clear();
01003 robot_x_ini_ = config.robot_x_ini;
01004 robot_y_ini_ = config.robot_y_ini;
01005 this->alg_.unlock();
01006 }
01007
01008
01009 void ForceRobotCompanionLearningAlgNode::addNodeDiagnostics(void)
01010 {
01011 }
01012
01013
01014 int main(int argc,char *argv[])
01015 {
01016 return algorithm_base::main<ForceRobotCompanionLearningAlgNode>(argc, argv, "force_robot_companion_learning_alg_node");
01017 }