planner.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <vector>
00003 #include <ros/ros.h>
00004 #include <riskrrt/Trajectory.h>
00005 #include "riskrrt/riskrrt.hpp"
00006 
00007 using namespace std;
00008 
00009 int main(int argc, char **argv){
00010  
00011   //Initializing ROS node
00012   ros::init(argc, argv, "rrt");
00013   ros::NodeHandle n;
00014  
00015   //Reading parameters from yaml file (description in yaml file)
00016   Params params;
00017   n.param("timeStep", params.timeStep, 0.5);
00018   n.param("maxDepth", params.maxDepth, 10);
00019   n.param("nv", params.nv, 10);
00020   n.param("nphi", params.nphi, 10);
00021   n.param("threshold", params.threshold, 0.9);
00022   n.param("socialWeight", params.socialWeight, 10.0);
00023   n.param("rotationWeight", params.rotationWeight, 5.0);
00024   n.param("growTime", params.growTime, 0.1);
00025   n.param("bias", params.bias, 0.02);
00026   n.param("goalTh", params.goalTh, 0.5);
00027   n.param("windowSize", params.windowSize, 10.0);
00028   n.param("robotLength", params.robotLength, 1.5);
00029   n.param("robotWidth", params.robotWidth, 0.7);
00030   n.param("vMin", params.vMin, 0.0);
00031   n.param("vMax", params.vMax, 0.5);
00032   n.param("accMax", params.accMax, 0.5);
00033   n.param("omegaMax", params.omegaMax, 1.0);
00034   n.param("accOmegaMax", params.accOmegaMax, 1.0);
00035   
00036   //maxdepth is the maximum depth a node can have to grow, thus this node can have a son for which we will compute the risk and try to access an inexistent grid layer
00037   params.maxDepth = params.maxDepth - 1;
00038   
00039   //creating rrt 
00040   RRT* rrt;
00041   rrt = new RRT(params);
00042   
00043   //publishers
00044   ros::Publisher traj_pub = n.advertise<riskrrt::Trajectory>("traj", 10);
00045   ros::Publisher node_markers_pub = n.advertise<visualization_msgs::MarkerArray>("node_markers", 10);
00046   ros::Publisher path_markers_pub = n.advertise<visualization_msgs::MarkerArray>("path_markers", 10);
00047   
00048   ros::Publisher robot_marker_pub = n.advertise<visualization_msgs::Marker>( "robot_marker", 0 );
00049   visualization_msgs::Marker marker;
00050   ros::Publisher goal_marker_pub = n.advertise<visualization_msgs::Marker>( "goal_marker", 0 );
00051   visualization_msgs::Marker gmarker;
00052   
00053   //subscribers
00054   rrt->initOgArraySub();
00055   rrt->initOdomSub();
00056   rrt->initPoseSub();
00057   rrt->initGoalSub();
00058   rrt->initcontrollerFeedbackSub();
00059   
00060   //timers
00061   ros::WallTime growing_start_time;
00062   ros::WallTime present;
00063   ros::WallDuration time_spent_growing;
00064   ros::WallDuration total_time_to_grow(params.growTime);
00065   
00066   //constants & variables
00067   double distance_to_goal_th = params.goalTh;
00068   int i;
00069   
00070   //goal flag to start rrt
00071   rrt->goal_received = false;
00072   while (ros::ok())
00073   {
00074     
00075     if(rrt->goal_received)//TODO: always on rrt
00076     {
00077       
00078       //initializing rrt
00079       rrt->init();
00080       ROS_INFO("GOAL RECEIVED");
00081       
00082       while(!(rrt->isGoalReached()) && ros::ok())//while goal not reached
00083       {
00084       
00085         gmarker.header.frame_id = "/map";
00086         gmarker.header.stamp = ros::Time();
00087         gmarker.ns = "goal";
00088         gmarker.id = 1;
00089         gmarker.type = visualization_msgs::Marker::SPHERE;
00090         gmarker.action = visualization_msgs::Marker::ADD;
00091         gmarker.pose.position.x = rrt->final_goal.x;
00092         gmarker.pose.position.y = rrt->final_goal.y;
00093         gmarker.pose.position.z = 0.15;
00094         gmarker.scale.x = 0.3;
00095         gmarker.scale.y = 0.3;
00096         gmarker.scale.z = 0.3;
00097         gmarker.color.a = 1.0; // Don't forget to set the alpha!
00098         gmarker.color.r = 0.0;
00099         gmarker.color.g = 0.0;
00100         gmarker.color.b = 1.0;
00101         goal_marker_pub.publish( gmarker );
00102         
00103         
00104         marker.header.frame_id = "/map";
00105         marker.header.stamp = ros::Time();
00106         marker.ns = "robot";
00107         marker.id = 0;
00108         marker.type = visualization_msgs::Marker::MESH_RESOURCE;
00109         marker.action = visualization_msgs::Marker::ADD;
00110         marker.pose.position.x = rrt->robot_pose.x;
00111         marker.pose.position.y = rrt->robot_pose.y;
00112         marker.pose.position.z = 0;
00113         marker.pose.orientation = tf::createQuaternionMsgFromYaw(rrt->robot_pose.theta);
00114         marker.scale.x = 1.0;
00115         marker.scale.y = 1.0;
00116         marker.scale.z = 1.0;
00117         //marker.color.a = 1.0; // Don't forget to set the alpha!
00118         //marker.color.r = 1.0;
00119         //marker.color.g = 1.0;
00120         //marker.color.b = 1.0;
00121         marker.mesh_use_embedded_materials = true;
00122         marker.mesh_resource = "package://riskrrt/meshes/wheelchair/Wheelchair1.dae";
00123         robot_marker_pub.publish( marker );
00124         
00125         
00126         growing_start_time = ros::WallTime::now();
00127         time_spent_growing = ros::WallTime::now() - growing_start_time;
00128         i=0;
00129         
00130         while(time_spent_growing < total_time_to_grow && ros::ok())//while there is still some time left
00131         {
00132           //make the tree grow
00133           rrt->grow();
00134           i++;
00135           //update the timer to know how much time we have left to grow
00136           time_spent_growing = ros::WallTime::now() - growing_start_time;
00137           
00138         }//time is up, end of growing part
00139         
00141         //rrt->findPath();
00142         
00143         //robot is at the right place at the right time
00144         if(rrt->robot_on_traj){
00145           //update the tree with the latest map
00146           rrt->update();
00147         }
00148         else{
00149           //robot failed to follow the trajectory, start over from current location
00150           rrt->init();
00151           ROS_INFO("REINIT");
00152         }
00153         
00154         //find the best partial path toward the final goal
00155         rrt->findPath();
00156         
00157         //publish the trajectory and markers
00158         traj_pub.publish(rrt->traj_msg);
00159         node_markers_pub.publish(rrt->node_markers);
00160         path_markers_pub.publish(rrt->path_markers);
00161         rrt->node_markers.markers.clear();
00162         rrt->path_markers.markers.clear();
00163         
00164         ros::spinOnce();
00165         
00166       }//goal reached
00167       
00168       //set the trajectory flag to false and publish it to stop controller
00169       rrt->traj_msg.exists.data = false;
00170       traj_pub.publish(rrt->traj_msg);
00171       ROS_INFO("GOAL REACHED");
00172       rrt->goal_received = false;
00173     }
00174     ros::spinOnce();
00175     
00176   }//end ros::ok()
00177 
00178   return 0;
00179 }


riskrrt
Author(s): Gregoire Vignon
autogenerated on Thu Jun 6 2019 18:42:06