Go to the documentation of this file.00001 #include <vigir_footstep_planning_default_plugins/state_generator/reachability_state_generator.h>
00002
00003 #include <vigir_footstep_planning_lib/math.h>
00004
00005 #include <vigir_footstep_planning_plugins/plugin_aggregators/robot_model.h>
00006 #include <vigir_footstep_planning_plugins/plugin_aggregators/world_model.h>
00007
00008
00009
00010 namespace vigir_footstep_planning
00011 {
00012 ReachabilityStateGenerator::ReachabilityStateGenerator()
00013 : StateGeneratorPlugin("reachability_state_generator")
00014 {
00015 }
00016
00017 bool ReachabilityStateGenerator::loadParams(const vigir_generic_params::ParameterSet& params)
00018 {
00019 if (!StateGeneratorPlugin::loadParams(params))
00020 return false;
00021
00022 bool result = true;
00023
00024 int threads;
00025 unsigned int jobs_per_thread;
00026 result &= params.getParam("threads", threads);
00027 result &= params.getParam("jobs_per_thread", jobs_per_thread);
00028
00029 int hash_table_size;
00030 double cell_size;
00031 int num_angle_bins;
00032 result &= params.getParam("max_hash_size", hash_table_size);
00033 result &= params.getParam("collision_check/cell_size", cell_size);
00034 result &= params.getParam("collision_check/num_angle_bins", num_angle_bins);
00035 double angle_bin_size = 2.0*M_PI / static_cast<double>(num_angle_bins);
00036
00037 int ivMaxStepRangeX, ivMaxStepRangeY, ivMaxStepRangeTheta;
00038 int ivMaxInvStepRangeX, ivMaxInvStepRangeY, ivMaxInvStepRangeTheta;
00039
00041 std::vector<std::pair<int, int> > step_range;
00042
00043
00044 XmlRpc::XmlRpcValue step_range_x;
00045 XmlRpc::XmlRpcValue step_range_y;
00046 if (params.getParam("step_range/x", step_range_x) && params.getParam("step_range/y", step_range_y))
00047 {
00048
00049 step_range.clear();
00050 step_range.reserve(step_range_x.size());
00051 double max_x = (double)step_range_x[0];
00052 double max_y = (double)step_range_y[0];
00053 double max_inv_x = (double)step_range_x[0];
00054 double max_inv_y = (double)step_range_y[0];
00055 for (int i=0; i < step_range_x.size(); ++i)
00056 {
00057 double x = (double)step_range_x[i];
00058 double y = (double)step_range_y[i];
00059
00060 max_x = std::max(max_x, x);
00061 max_y = std::max(max_y, y);
00062 max_inv_x = std::min(max_inv_x, x);
00063 max_inv_y = std::min(max_inv_y, y);
00064
00065 step_range.push_back(std::pair<int, int>(disc_val(x, cell_size), disc_val(y, cell_size)));
00066 }
00067
00068 double max_step_range_theta;
00069 double max_inverse_step_range_theta;
00070 result &= params.getParam("foot/max/step/theta", max_step_range_theta);
00071 result &= params.getParam("foot/max/inverse/step/theta", max_inverse_step_range_theta);
00072
00073 ivMaxStepRangeX = disc_val(max_x, cell_size);
00074 ivMaxStepRangeY = disc_val(max_y, cell_size);
00075 ivMaxStepRangeTheta = angle_state_2_cell(max_step_range_theta, angle_bin_size);
00076 ivMaxInvStepRangeX = disc_val(max_inv_x, cell_size);
00077 ivMaxInvStepRangeY = disc_val(max_inv_y, cell_size);
00078 ivMaxInvStepRangeTheta = angle_state_2_cell(max_inverse_step_range_theta, angle_bin_size);
00079 }
00080
00081
00082
00083 if (!result)
00084 return false;
00085
00086
00087 expand_states_manager.reset(new threading::ThreadingManager<threading::ExpandStateJob>(threads, jobs_per_thread));
00088
00089
00090
00091 for (int y = ivMaxInvStepRangeY; y <= ivMaxStepRangeY; y++)
00092 {
00093 for (int x = ivMaxInvStepRangeX; x <= ivMaxStepRangeX; x++)
00094 {
00095 bool in_step_range = pointWithinPolygon(x, y, step_range);
00096
00097 if (!in_step_range)
00098 continue;
00099
00100
00101 for (int theta = ivMaxInvStepRangeTheta; theta <= ivMaxStepRangeTheta; theta++)
00102 {
00103 Footstep f(cont_val(x, cell_size), cont_val(y, cell_size), angle_cell_2_state(theta, angle_bin_size), 0.0, cell_size, num_angle_bins, hash_table_size);
00104 ivContFootstepSet.push_back(f);
00105 }
00106 }
00107 }
00108
00109 return result;
00110 }
00111
00112 std::list<PlanningState::Ptr> ReachabilityStateGenerator::generatePredecessors(const PlanningState& state) const
00113 {
00114 std::list<PlanningState::Ptr> result;
00115
00116 ROS_ERROR("[ReachabilityStateGenerator] generatePredecessor not implemented yet!");
00117
00118 return result;
00119 }
00120
00121 std::list<PlanningState::Ptr> ReachabilityStateGenerator::generateSuccessors(const PlanningState& state) const
00122 {
00123 std::list<PlanningState::Ptr> result;
00124
00125
00126 std::list<threading::ExpandStateJob::Ptr> jobs;
00127 for (const Footstep& footstep : ivContFootstepSet)
00128 jobs.push_back(threading::ExpandStateJob::Ptr(new threading::ExpandStateJob(footstep, state)));
00129
00130 expand_states_manager->addJobs(jobs);
00131 expand_states_manager->waitUntilJobsFinished();
00132
00133 for (std::list<threading::ExpandStateJob::Ptr>::iterator itr = jobs.begin(); itr != jobs.end(); itr++)
00134 {
00135 threading::ExpandStateJob::Ptr& job = *itr;
00136 if (job->successful)
00137 result.push_back(job->next);
00138 }
00139
00140 return result;
00141 }
00142 }
00143
00144 #include <pluginlib/class_list_macros.h>
00145 PLUGINLIB_EXPORT_CLASS(vigir_footstep_planning::ReachabilityStateGenerator, vigir_footstep_planning::StateGeneratorPlugin)