/* * given the current state of the robot, find a good trajectory */ base_local_planner::Trajectory DWAPlanner::findBestPath( tf::Stamped<tf::Pose> global_pose, tf::Stamped<tf::Pose> global_vel, tf::Stamped<tf::Pose>& drive_velocities, std::vector<geometry_msgs::Point> footprint_spec) { obstacle_costs_.setFootprint(footprint_spec); //make sure that our configuration doesn't change mid-run boost::mutex::scoped_lock l(configuration_mutex_); Eigen::Vector3f pos(global_pose.getOrigin().getX(), global_pose.getOrigin().getY(), tf::getYaw(global_pose.getRotation())); Eigen::Vector3f vel(global_vel.getOrigin().getX(), global_vel.getOrigin().getY(), tf::getYaw(global_vel.getRotation())); geometry_msgs::PoseStamped goal_pose = global_plan_.back(); Eigen::Vector3f goal(goal_pose.pose.position.x, goal_pose.pose.position.y, tf::getYaw(goal_pose.pose.orientation)); base_local_planner::LocalPlannerLimits limits = planner_util_->getCurrentLimits(); // prepare cost functions and generators for this run generator_.initialise(pos, vel, goal, &limits, vsamples_); result_traj_.cost_ = -7; // find best trajectory by sampling and scoring the samples scored_sampling_planner_.findBestTrajectory(result_traj_, NULL); // verbose publishing of point clouds if (publish_cost_grid_pc_) { //we'll publish the visualization of the costs to rviz before returning our best trajectory map_viz_.publishCostCloud(*(planner_util_->getCostmap())); } // debrief stateful scoring functions oscillation_costs_.updateOscillationFlags(pos, &result_traj_, planner_util_->getCurrentLimits().min_trans_vel); //if we don't have a legal trajectory, we'll just command zero if (result_traj_.cost_ < 0) { drive_velocities.setIdentity(); } else { tf::Vector3 start(result_traj_.xv_, result_traj_.yv_, 0); drive_velocities.setOrigin(start); tf::Matrix3x3 matrix; matrix.setRotation(tf::createQuaternionFromYaw(result_traj_.thetav_)); drive_velocities.setBasis(matrix); } return result_traj_; }
//given the current state of the robot, find a good trajectory base_local_planner::Trajectory DWAPlanner::findBestPath(tf::Stamped<tf::Pose> global_pose, tf::Stamped<tf::Pose> global_vel, tf::Stamped<tf::Pose>& drive_velocities){ //make sure that our configuration doesn't change mid-run boost::mutex::scoped_lock l(configuration_mutex_); //make sure to get an updated copy of the costmap before computing trajectories costmap_ros_->getCostmapCopy(costmap_); Eigen::Vector3f pos(global_pose.getOrigin().getX(), global_pose.getOrigin().getY(), tf::getYaw(global_pose.getRotation())); Eigen::Vector3f vel(global_vel.getOrigin().getX(), global_vel.getOrigin().getY(), tf::getYaw(global_vel.getRotation())); //reset the map for new operations map_.resetPathDist(); front_map_.resetPathDist(); //make sure that we update our path based on the global plan and compute costs map_.setPathCells(costmap_, global_plan_); std::vector<geometry_msgs::PoseStamped> front_global_plan = global_plan_; front_global_plan.back().pose.position.x = front_global_plan.back().pose.position.x + forward_point_distance_ * cos(tf::getYaw(front_global_plan.back().pose.orientation)); front_global_plan.back().pose.position.y = front_global_plan.back().pose.position.y + forward_point_distance_ * sin(tf::getYaw(front_global_plan.back().pose.orientation)); front_map_.setPathCells(costmap_, front_global_plan); ROS_DEBUG_NAMED("dwa_local_planner", "Path/Goal distance computed"); //rollout trajectories and find the minimum cost one base_local_planner::Trajectory best = computeTrajectories(pos, vel); ROS_DEBUG_NAMED("dwa_local_planner", "Trajectories created"); //if we don't have a legal trajectory, we'll just command zero if(best.cost_ < 0){ drive_velocities.setIdentity(); } else{ tf::Vector3 start(best.xv_, best.yv_, 0); drive_velocities.setOrigin(start); tf::Matrix3x3 matrix; matrix.setRotation(tf::createQuaternionFromYaw(best.thetav_)); drive_velocities.setBasis(matrix); } //we'll publish the visualization of the costs to rviz before returning our best trajectory map_viz_.publishCostCloud(); return best; }
int main(int argc, char** argv) { // init node ros::init(argc, argv, "planner_simple"); ros::NodeHandle nh; // set up subscribers, publishers and listeners ros::Subscriber goal_sub = nh.subscribe("/goal", 1000, goalCallback); ros::Subscriber map_sub = nh.subscribe("/map", 1000, mapCallback); //ros::Subscriber obstacle_map_sub = nh.subscribe("/obstacle_map", 1000, mapCallback); marker_pub = nh.advertise<visualization_msgs::Marker>( "visualization_marker", 0 ); map_pub = nh.advertise<assn2::NavGrid>( "nav_grid", 0 ); tf::TransformListener listener; listener.waitForTransform("/map", "/base_link", ros::Time(), ros::Duration(1.5)); // set initial goal to be the robot's pose try { tf::StampedTransform map_base_link_transform; //lookup transform only works for this type listener.lookupTransform("/map", "/base_link", ros::Time(0), map_base_link_transform); goal_pose.setOrigin(map_base_link_transform.getOrigin()); goal_pose.setRotation(map_base_link_transform.getRotation()); } catch (tf::TransformException ex) { ROS_ERROR("%s",ex.what()); } ros::Rate rate(10); while (ros::ok()) { // populates the goal_pose and global_map if a new message has been published ros::spinOnce(); double cost_map[MAP_CELLS]; getCostFn(cost_map); visualizeHeatMap(cost_map,"intrinsic_cost_map"); double nav_fn[MAP_CELLS]; tf::StampedTransform robot_to_map_transform; // the pose of the robot in the map frame tf_util::getTransform(listener,"/base_link","/map",robot_to_map_transform); getNavFn(cost_map,robot_to_map_transform, nav_fn); visualizeHeatMap(nav_fn,"nav_fn"); publishMap(nav_fn); rate.sleep(); } }
/* * given the current state of the robot, find a good trajectory */ base_local_planner::Trajectory EDWAPlanner::findBestPath( tf::Stamped<tf::Pose> global_pose, tf::Stamped<tf::Pose> global_vel, tf::Stamped<tf::Pose>& drive_velocities, std::vector<geometry_msgs::Point> footprint_spec) { obstacle_costs_.setFootprint(footprint_spec); //make sure that our configuration doesn't change mid-run boost::mutex::scoped_lock l(configuration_mutex_); Eigen::Vector3f pos(global_pose.getOrigin().getX(), global_pose.getOrigin().getY(), tf::getYaw(global_pose.getRotation())); Eigen::Vector3f vel(global_vel.getOrigin().getX(), global_vel.getOrigin().getY(), tf::getYaw(global_vel.getRotation())); geometry_msgs::PoseStamped goal_pose = global_plan_.back(); Eigen::Vector3f goal(goal_pose.pose.position.x, goal_pose.pose.position.y, tf::getYaw(goal_pose.pose.orientation)); base_local_planner::LocalPlannerLimits limits = planner_util_->getCurrentLimits(); // prepare cost functions and generators for this run generator_.initialise(pos, vel, goal, &limits, vsamples_); energy_costs_.setLastSpeeds(global_vel.getOrigin().getX(), global_vel.getOrigin().getY(), tf::getYaw(global_vel.getRotation())); result_traj_.cost_ = -7; // find best trajectory by sampling and scoring the samples std::vector<base_local_planner::Trajectory> all_explored; scored_sampling_planner_.findBestTrajectory(result_traj_, &all_explored); if(publish_traj_pc_) { base_local_planner::MapGridCostPoint pt; traj_cloud_->points.clear(); traj_cloud_->width = 0; traj_cloud_->height = 0; std_msgs::Header header; pcl_conversions::fromPCL(traj_cloud_->header, header); header.stamp = ros::Time::now(); traj_cloud_->header = pcl_conversions::toPCL(header); for(std::vector<base_local_planner::Trajectory>::iterator t=all_explored.begin(); t != all_explored.end(); ++t) { if(t->cost_<0) continue; // Fill out the plan for(unsigned int i = 0; i < t->getPointsSize(); ++i) { double p_x, p_y, p_th; t->getPoint(i, p_x, p_y, p_th); pt.x=p_x; pt.y=p_y; pt.z=0; pt.path_cost=p_th; pt.total_cost=t->cost_; traj_cloud_->push_back(pt); } } traj_cloud_pub_.publish(*traj_cloud_); } // verbose publishing of point clouds if (publish_cost_grid_pc_) { //we'll publish the visualization of the costs to rviz before returning our best trajectory map_viz_.publishCostCloud(planner_util_->getCostmap()); } // debrief stateful scoring functions oscillation_costs_.updateOscillationFlags(pos, &result_traj_, planner_util_->getCurrentLimits().min_trans_vel); //if we don't have a legal trajectory, we'll just command zero if (result_traj_.cost_ < 0) { drive_velocities.setIdentity(); } else { tf::Vector3 start(result_traj_.xv_, result_traj_.yv_, 0); drive_velocities.setOrigin(start); tf::Matrix3x3 matrix; matrix.setRotation(tf::createQuaternionFromYaw(result_traj_.thetav_)); drive_velocities.setBasis(matrix); } return result_traj_; }
//given the current state of the robot, find a good trajectory Trajectory TrajectoryPlanner::findBestPath(tf::Stamped<tf::Pose> global_pose, tf::Stamped<tf::Pose> global_vel, tf::Stamped<tf::Pose>& drive_velocities){ Eigen::Vector3f pos(global_pose.getOrigin().getX(), global_pose.getOrigin().getY(), tf::getYaw(global_pose.getRotation())); Eigen::Vector3f vel(global_vel.getOrigin().getX(), global_vel.getOrigin().getY(), tf::getYaw(global_vel.getRotation())); //reset the map for new operations path_map_.resetPathDist(); goal_map_.resetPathDist(); //temporarily remove obstacles that are within the footprint of the robot std::vector<base_local_planner::Position2DInt> footprint_list = footprint_helper_.getFootprintCells( pos, footprint_spec_, costmap_, true); //mark cells within the initial footprint of the robot for (unsigned int i = 0; i < footprint_list.size(); ++i) { path_map_(footprint_list[i].x, footprint_list[i].y).within_robot = true; } //make sure that we update our path based on the global plan and compute costs path_map_.setTargetCells(costmap_, global_plan_); goal_map_.setLocalGoal(costmap_, global_plan_); ROS_DEBUG("Path/Goal distance computed"); //rollout trajectories and find the minimum cost one Trajectory best = createTrajectories(pos[0], pos[1], pos[2], vel[0], vel[1], vel[2], acc_lim_x_, acc_lim_y_, acc_lim_theta_); ROS_DEBUG("Trajectories created"); /* //If we want to print a ppm file to draw goal dist char buf[4096]; sprintf(buf, "base_local_planner.ppm"); FILE *fp = fopen(buf, "w"); if(fp){ fprintf(fp, "P3\n"); fprintf(fp, "%d %d\n", map_.size_x_, map_.size_y_); fprintf(fp, "255\n"); for(int j = map_.size_y_ - 1; j >= 0; --j){ for(unsigned int i = 0; i < map_.size_x_; ++i){ int g_dist = 255 - int(map_(i, j).goal_dist); int p_dist = 255 - int(map_(i, j).path_dist); if(g_dist < 0) g_dist = 0; if(p_dist < 0) p_dist = 0; fprintf(fp, "%d 0 %d ", g_dist, 0); } fprintf(fp, "\n"); } fclose(fp); } */ if(best.cost_ < 0){ drive_velocities.setIdentity(); } else{ tf::Vector3 start(best.xv_, best.yv_, 0); drive_velocities.setOrigin(start); tf::Matrix3x3 matrix; matrix.setRotation(tf::createQuaternionFromYaw(best.thetav_)); drive_velocities.setBasis(matrix); } return best; }