00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <footstep_planner/Footstep.h>
00028
00029
00030 namespace footstep_planner
00031 {
00032 Footstep::Footstep(double x, double y, double theta, double cell_size,
00033 int num_angle_bins, int max_hash_size)
00034 : ivTheta(angle_state_2_cell(theta, num_angle_bins)),
00035 ivCellSize(cell_size),
00036 ivNumAngleBins(num_angle_bins),
00037 ivMaxHashSize(max_hash_size),
00038 ivDiscSuccessorLeft(num_angle_bins),
00039 ivDiscSuccessorRight(num_angle_bins),
00040 ivDiscPredecessorLeft(num_angle_bins),
00041 ivDiscPredecessorRight(num_angle_bins)
00042 {
00043 init(x, y);
00044 }
00045
00046
00047 Footstep::~Footstep()
00048 {}
00049
00050
00051 void
00052 Footstep::init(double x, double y)
00053 {
00054 int backward_angle;
00055 int footstep_x;
00056 int footstep_y;
00057
00058 for (int a = 0; a < ivNumAngleBins; ++a)
00059 {
00060 backward_angle = calculateForwardStep(RIGHT, a, x, y,
00061 &footstep_x, &footstep_y);
00062 ivDiscSuccessorRight[a] = footstep_xy(footstep_x, footstep_y);
00063 ivDiscPredecessorLeft[backward_angle] = footstep_xy(-footstep_x,
00064 -footstep_y);
00065 backward_angle = calculateForwardStep(LEFT, a, x, y,
00066 &footstep_x, &footstep_y);
00067 ivDiscSuccessorLeft[a] = footstep_xy(footstep_x, footstep_y);
00068 ivDiscPredecessorRight[backward_angle] = footstep_xy(-footstep_x,
00069 -footstep_y);
00070 }
00071 }
00072
00073
00074 PlanningState
00075 Footstep::performMeOnThisState(const PlanningState& current)
00076 const
00077 {
00078 Leg leg;
00079
00080 int x = current.getX();
00081 int y = current.getY();
00082 int theta = current.getTheta();
00083
00084 if (current.getLeg() == RIGHT)
00085 {
00086 footstep_xy xy = ivDiscSuccessorRight[theta];
00087 x += xy.first;
00088 y += xy.second;
00089 theta += ivTheta;
00090 leg = LEFT;
00091 }
00092 else
00093 {
00094 footstep_xy xy = ivDiscSuccessorLeft[theta];
00095 x += xy.first;
00096 y += xy.second;
00097 theta -= ivTheta;
00098 leg = RIGHT;
00099 }
00100
00101
00102 if (theta < 0)
00103 theta += ivNumAngleBins;
00104 else if (theta >= ivNumAngleBins)
00105 theta -= ivNumAngleBins;
00106
00107 return PlanningState(x, y, theta, leg, ivMaxHashSize);
00108 }
00109
00110
00111 PlanningState
00112 Footstep::reverseMeOnThisState(const PlanningState& current)
00113 const
00114 {
00115 Leg leg;
00116
00117 int x = current.getX();
00118 int y = current.getY();
00119 int theta = current.getTheta();
00120
00121 if (current.getLeg() == LEFT)
00122 {
00123 footstep_xy xy = ivDiscPredecessorLeft[theta];
00124 x += xy.first;
00125 y += xy.second;
00126 theta -= ivTheta;
00127 leg = RIGHT;
00128 }
00129 else
00130 {
00131 footstep_xy xy = ivDiscPredecessorRight[theta];
00132 x += xy.first;
00133 y += xy.second;
00134 theta += ivTheta;
00135 leg = LEFT;
00136 }
00137
00138 if (theta < 0)
00139 theta += ivNumAngleBins;
00140 else if (theta >= ivNumAngleBins)
00141 theta -= ivNumAngleBins;
00142
00143 return PlanningState(x, y, theta, leg, ivMaxHashSize);
00144 }
00145
00146
00147 int
00148 Footstep::calculateForwardStep(Leg leg, int global_theta,
00149 double x, double y,
00150 int* footstep_x, int* footstep_y)
00151 const
00152 {
00153 double cont_footstep_x, cont_footstep_y;
00154 double cont_global_theta = angle_cell_2_state(global_theta,
00155 ivNumAngleBins);
00156 double theta_cos = cos(cont_global_theta);
00157 double theta_sin = sin(cont_global_theta);
00158 if (leg == RIGHT)
00159 {
00160 cont_footstep_x = theta_cos * x - theta_sin * y;
00161 cont_footstep_y = theta_sin * x + theta_cos * y;
00162
00163 global_theta += ivTheta;
00164 }
00165 else
00166 {
00167 cont_footstep_x = theta_cos * x + theta_sin * y;
00168 cont_footstep_y = theta_sin * x - theta_cos * y;
00169
00170 global_theta -= ivTheta;
00171 }
00172 *footstep_x = disc_val(cont_footstep_x, ivCellSize);
00173 *footstep_y = disc_val(cont_footstep_y, ivCellSize);
00174
00175
00176 if (global_theta < 0)
00177 global_theta += ivNumAngleBins;
00178 else if (global_theta >= ivNumAngleBins)
00179 global_theta -= ivNumAngleBins;
00180 return global_theta;
00181 }
00182 }