footstep_state.h
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 
37 #ifndef JSK_FOOTSTEP_PLANNER_FOOTSTEP_STATE_H_
38 #define JSK_FOOTSTEP_PLANNER_FOOTSTEP_STATE_H_
39 
40 #include <jsk_footstep_msgs/Footstep.h>
41 
42 #include <pcl/kdtree/kdtree_flann.h>
43 #include <pcl/filters/crop_box.h>
44 #include <pcl/sample_consensus/method_types.h>
45 #include <pcl/sample_consensus/model_types.h>
46 #include <pcl/segmentation/sac_segmentation.h>
47 #include <pcl/segmentation/sac_segmentation.h>
48 #include <pcl/filters/project_inliers.h>
49 #include <pcl/search/octree.h>
50 
54 
55 namespace jsk_footstep_planner
56 {
57 
58  namespace projection_state
59  {
60  const unsigned int success = 1;
61  const unsigned int no_pointcloud = 2;
62  const unsigned int no_enough_support = 4;
63  const unsigned int no_plane = 8;
64  const unsigned int no_enough_inliers = 16;
65  const unsigned int close_to_success = 32;
66  const unsigned int transition_limit = 64;
67  const unsigned int vertical_footstep = 128;
68  const unsigned int no_enough_inliers_ratio = 256;
69  }
70 
71  std::string projectStateToString(unsigned int state);
72 
74  {
76  SUPPORTED,
78  };
79 
80  class FootstepState
81  {
82  public:
84  FootstepState(int leg,
85  const Eigen::Affine3f& pose,
86  const Eigen::Vector3f& dimensions,
87  const Eigen::Vector3f& resolution):
88  leg_(leg), pose_(pose), dimensions_(dimensions), resolution_(resolution)
89  {
90  debug_print_ = false;
91  float x = pose_.translation()[0];
92  float y = pose_.translation()[1];
93  float roll, pitch, yaw;
94  pcl::getEulerAngles(pose_, roll, pitch, yaw);
95  index_x_ = x / resolution_[0];
96  index_y_ = y / resolution_[1];
97  index_yaw_ = yaw / resolution_[2];
98  }
99 
100  FootstepState(int leg,
101  const Eigen::Affine3f& pose,
102  const Eigen::Vector3f& dimensions,
103  const Eigen::Vector3f& resolution,
104  int index_x,
105  int index_y,
106  int index_yaw):
108  index_x_(index_x), index_y_(index_y), index_yaw_(index_yaw)
109  {
110  debug_print_ = false;
111  }
112 
113  static
114  FootstepState::Ptr fromROSMsg(const jsk_footstep_msgs::Footstep& f,
115  const Eigen::Vector3f& size,
116  const Eigen::Vector3f& resolution);
117 
118  inline float cross2d(const Eigen::Vector2f& a, const Eigen::Vector2f& b) const
119  {
120  return a[0] * b[1] - a[1] * b[0];
121  }
122  virtual jsk_footstep_msgs::Footstep::Ptr toROSMsg();
123  virtual jsk_footstep_msgs::Footstep::Ptr toROSMsg(const Eigen::Vector3f& ioffset);
124 #if 0
126  projectToCloud(pcl::KdTreeFLANN<pcl::PointNormal>& tree,
127  pcl::PointCloud<pcl::PointNormal>::Ptr cloud,
129  pcl::search::Octree<pcl::PointNormal>& tree_2d,
130  pcl::PointCloud<pcl::PointNormal>::Ptr cloud_2d,
131  const Eigen::Vector3f& z,
132  unsigned int& error_state,
133  double outlier_threshold,
134  int max_iterations,
135  int min_inliers,
136  int foot_x_sampling_num = 3,
137  int foot_y_sampling_num = 3,
138  double vertex_threshold = 0.02,
139  const bool skip_cropping = true,
140  const bool use_normal = false,
141  double normal_distance_weight = 0.2,
142  double normal_opening_angle = 0.2,
143  double min_ratio_of_inliers = 0.8);
144 #endif
145  virtual FootstepState::Ptr
146  projectToCloud(pcl::KdTreeFLANN<pcl::PointNormal>& tree,
147  pcl::PointCloud<pcl::PointNormal>::Ptr cloud,
149  pcl::search::Octree<pcl::PointNormal>& tree_2d,
150  pcl::PointCloud<pcl::PointNormal>::Ptr cloud_2d,
151  const Eigen::Vector3f& z,
152  unsigned int& error_state,
154 
155 #if 0
156  pcl::PointIndices::Ptr
157  cropPointCloud(pcl::PointCloud<pcl::PointNormal>::Ptr cloud,
158  pcl::search::Octree<pcl::PointNormal>& tree);
159 #endif
160  pcl::PointIndices::Ptr
161  cropPointCloud(pcl::PointCloud<pcl::PointNormal>::Ptr cloud,
163  double padding_x = 0.0, double padding_y = 0.0);
164 
165  pcl::PointIndices::Ptr
166  cropPointCloudExact(pcl::PointCloud<pcl::PointNormal>::Ptr cloud,
167  pcl::PointIndices::Ptr near_indices,
168  double padding_x = 0.0, double padding_y = 0.0);
169 
170  template <class PointT>
171  PointT toPoint()
172  {
173  PointT p;
174  p.getVector3fMap() = Eigen::Vector3f(pose_.translation());
175  return p;
176  }
177 
178  inline void vertices(Eigen::Vector3f& a,
179  Eigen::Vector3f& b,
180  Eigen::Vector3f& c,
181  Eigen::Vector3f& d,
182  double collision_padding = 0)
183  {
184  const Eigen::Vector3f ux = Eigen::Vector3f::UnitX();
185  const Eigen::Vector3f uy = Eigen::Vector3f::UnitY();
186  double dim0 = dimensions_[0] + collision_padding;
187  double dim1 = dimensions_[1] + collision_padding;
188  a = Eigen::Vector3f((pose_ * Eigen::Translation3f( ux * dim0 / 2 + uy * dim1 / 2)).translation());
189  b = Eigen::Vector3f((pose_ * Eigen::Translation3f(- ux * dim0 / 2 + uy * dim1 / 2)).translation());
190  c = Eigen::Vector3f((pose_ * Eigen::Translation3f(- ux * dim0 / 2 - uy * dim1 / 2)).translation());
191  d = Eigen::Vector3f((pose_ * Eigen::Translation3f( ux * dim0 / 2 - uy * dim1 / 2)).translation());
192  }
193 
198  virtual bool crossCheck(FootstepState::Ptr other, float collision_padding = 0);
199 
200  virtual Eigen::Affine3f getPose() const { return pose_; }
201  virtual void setPose(const Eigen::Affine3f& pose)
202  {
204  }
205 
206  virtual int getLeg() const { return leg_; }
207  virtual Eigen::Vector3f getDimensions() const { return dimensions_; }
208  bool operator==(FootstepState& other)
209  {
210  return ((index_x_ == other.index_x_) &&
211  (index_y_ == other.index_y_) &&
212  (index_yaw_ == other.index_yaw_));
213  }
214 
215  virtual Eigen::Vector3f getResolution() const { return resolution_; }
216 
217 
218  inline virtual int indexX() { return index_x_; }
219  inline virtual int indexY() { return index_y_; }
220  inline virtual int indexT() { return index_yaw_; }
221 
222 
223  virtual FootstepSupportState
224  isSupportedByPointCloud(const Eigen::Affine3f& pose,
225  pcl::PointCloud<pcl::PointNormal>::Ptr cloud,
226  pcl::KdTreeFLANN<pcl::PointNormal>& tree,
227  pcl::PointIndices::Ptr inliers,
228  const int foot_x_sampling_num,
229  const int foot_y_sampling_num,
230  const double vertex_threshold);
231  virtual FootstepSupportState
232  isSupportedByPointCloudWithoutCropping(const Eigen::Affine3f& pose,
233  pcl::PointCloud<pcl::PointNormal>::Ptr cloud,
234  pcl::KdTreeFLANN<pcl::PointNormal>& tree,
235  pcl::PointIndices::Ptr inliers,
236  const int foot_x_sampling_num,
237  const int foot_y_sampling_num,
238  const double vertex_threshold);
239 
240  virtual Eigen::Affine3f midcoords(const FootstepState& other);
241  protected:
242  Eigen::Affine3f pose_;
243  const Eigen::Vector3f dimensions_;
244  const Eigen::Vector3f resolution_; // not memory efficient?
245  const int leg_;
246  int index_x_;
247  int index_y_;
248  int index_yaw_;
249  bool debug_print_;
250  private:
251 
252  };
253 
254  inline size_t hash_value(const FootstepState::Ptr& s)
255  {
256  return std::abs(s->indexX()) << (25 + 14) + std::abs(s->indexY()) << 14
257  + std::abs(s->indexT());
258  }
259 
260 }
261 
262 #endif
jsk_footstep_planner::FootstepParameters
Definition: footstep_parameters.h:74
jsk_footstep_planner::FootstepState::toPoint
PointT toPoint()
Definition: footstep_state.h:203
jsk_footstep_planner::FootstepState::pose_
Eigen::Affine3f pose_
Definition: footstep_state.h:274
boost::shared_ptr< FootstepState >
jsk_footstep_planner::FootstepState::indexT
virtual int indexT()
Definition: footstep_state.h:252
jsk_footstep_planner::FootstepState::cropPointCloud
pcl::PointIndices::Ptr cropPointCloud(pcl::PointCloud< pcl::PointNormal >::Ptr cloud, ANNGrid::Ptr grid_search, double padding_x=0.0, double padding_y=0.0)
Definition: footstep_state.cpp:155
jsk_footstep_planner::SUPPORTED
@ SUPPORTED
Definition: footstep_state.h:108
footstep_parameters.h
jsk_footstep_planner::FootstepState::toROSMsg
virtual jsk_footstep_msgs::Footstep::Ptr toROSMsg()
Definition: footstep_state.cpp:85
cloud
pcl::PointCloud< pcl::PointNormal >::Ptr cloud
Definition: footstep_projection_demo.cpp:49
jsk_footstep_planner::FootstepState::setPose
virtual void setPose(const Eigen::Affine3f &pose)
Definition: footstep_state.h:233
jsk_footstep_planner::FootstepSupportState
FootstepSupportState
Definition: footstep_state.h:105
jsk_footstep_planner::FootstepState::isSupportedByPointCloudWithoutCropping
virtual FootstepSupportState isSupportedByPointCloudWithoutCropping(const Eigen::Affine3f &pose, pcl::PointCloud< pcl::PointNormal >::Ptr cloud, pcl::KdTreeFLANN< pcl::PointNormal > &tree, pcl::PointIndices::Ptr inliers, const int foot_x_sampling_num, const int foot_y_sampling_num, const double vertex_threshold)
Definition: footstep_state.cpp:539
jsk_footstep_planner::FootstepState::isSupportedByPointCloud
virtual FootstepSupportState isSupportedByPointCloud(const Eigen::Affine3f &pose, pcl::PointCloud< pcl::PointNormal >::Ptr cloud, pcl::KdTreeFLANN< pcl::PointNormal > &tree, pcl::PointIndices::Ptr inliers, const int foot_x_sampling_num, const int foot_y_sampling_num, const double vertex_threshold)
Definition: footstep_state.cpp:467
resolution
const Eigen::Vector3f resolution(0.05, 0.05, 0.08)
jsk_footstep_planner::FootstepState::indexY
virtual int indexY()
Definition: footstep_state.h:251
c
c
jsk_footstep_planner::FootstepState::dimensions_
const Eigen::Vector3f dimensions_
Definition: footstep_state.h:275
jsk_footstep_planner::FootstepState::cross2d
float cross2d(const Eigen::Vector2f &a, const Eigen::Vector2f &b) const
Definition: footstep_state.h:150
pose
pose
jsk_footstep_planner::FootstepState::Ptr
boost::shared_ptr< FootstepState > Ptr
Definition: footstep_state.h:115
jsk_footstep_planner::FootstepState::indexX
virtual int indexX()
Definition: footstep_state.h:250
jsk_footstep_planner
Definition: ann_grid.h:50
jsk_footstep_planner::FootstepState
Definition: footstep_state.h:112
grid_search
ANNGrid::Ptr grid_search
Definition: footstep_projection_demo.cpp:53
jsk_footstep_planner::projection_state::no_enough_support
const unsigned int no_enough_support
Definition: footstep_state.h:126
jsk_footstep_planner::FootstepState::FootstepState
FootstepState(int leg, const Eigen::Affine3f &pose, const Eigen::Vector3f &dimensions, const Eigen::Vector3f &resolution)
Definition: footstep_state.h:116
jsk_footstep_planner::FootstepState::midcoords
virtual Eigen::Affine3f midcoords(const FootstepState &other)
Definition: footstep_state.cpp:605
y
double y
jsk_footstep_planner::projection_state::no_pointcloud
const unsigned int no_pointcloud
Definition: footstep_state.h:125
jsk_footstep_planner::CLOSE_TO_SUPPORTED
@ CLOSE_TO_SUPPORTED
Definition: footstep_state.h:109
PointT
pcl::PointXYZRGB PointT
jsk_footstep_planner::FootstepState::index_x_
int index_x_
Definition: footstep_state.h:278
pose_array.p
p
Definition: pose_array.py:21
jsk_footstep_planner::FootstepState::index_y_
int index_y_
Definition: footstep_state.h:279
jsk_footstep_planner::FootstepState::getLeg
virtual int getLeg() const
Definition: footstep_state.h:238
jsk_footstep_planner::FootstepState::vertices
void vertices(Eigen::Vector3f &a, Eigen::Vector3f &b, Eigen::Vector3f &c, Eigen::Vector3f &d, double collision_padding=0)
Definition: footstep_state.h:210
jsk_footstep_planner::FootstepState::fromROSMsg
static FootstepState::Ptr fromROSMsg(const jsk_footstep_msgs::Footstep &f, const Eigen::Vector3f &size, const Eigen::Vector3f &resolution)
Definition: footstep_state.cpp:592
jsk_footstep_planner::FootstepState::getPose
virtual Eigen::Affine3f getPose() const
Definition: footstep_state.h:232
d
d
jsk_footstep_planner::FootstepState::getDimensions
virtual Eigen::Vector3f getDimensions() const
Definition: footstep_state.h:239
jsk_footstep_planner::projection_state::no_enough_inliers
const unsigned int no_enough_inliers
Definition: footstep_state.h:128
jsk_footstep_planner::projection_state::success
const unsigned int success
Definition: footstep_state.h:124
jsk_footstep_planner::FootstepState::cropPointCloudExact
pcl::PointIndices::Ptr cropPointCloudExact(pcl::PointCloud< pcl::PointNormal >::Ptr cloud, pcl::PointIndices::Ptr near_indices, double padding_x=0.0, double padding_y=0.0)
Definition: footstep_state.cpp:112
tree
pcl::KdTreeFLANN< pcl::PointNormal > tree
Definition: footstep_projection_demo.cpp:50
jsk_footstep_planner::NOT_SUPPORTED
@ NOT_SUPPORTED
Definition: footstep_state.h:107
jsk_footstep_planner::FootstepState::projectToCloud
virtual FootstepState::Ptr projectToCloud(pcl::KdTreeFLANN< pcl::PointNormal > &tree, pcl::PointCloud< pcl::PointNormal >::Ptr cloud, ANNGrid::Ptr grid_search, pcl::search::Octree< pcl::PointNormal > &tree_2d, pcl::PointCloud< pcl::PointNormal >::Ptr cloud_2d, const Eigen::Vector3f &z, unsigned int &error_state, FootstepParameters &parameters)
Definition: footstep_state.cpp:210
parameters
FootstepParameters parameters
Definition: footstep_projection_demo.cpp:54
jsk_footstep_planner::FootstepState::getResolution
virtual Eigen::Vector3f getResolution() const
Definition: footstep_state.h:247
jsk_footstep_planner::projection_state::vertical_footstep
const unsigned int vertical_footstep
Definition: footstep_state.h:131
pose_array.s
s
Definition: pose_array.py:22
jsk_footstep_planner::FootstepState::resolution_
const Eigen::Vector3f resolution_
Definition: footstep_state.h:276
x
double x
jsk_footstep_planner::hash_value
size_t hash_value(const FootstepState::Ptr &s)
Definition: footstep_state.h:286
jsk_footstep_planner::FootstepState::index_yaw_
int index_yaw_
Definition: footstep_state.h:280
jsk_footstep_planner::FootstepState::crossCheck
virtual bool crossCheck(FootstepState::Ptr other, float collision_padding=0)
return true if this and other are collision free.
Definition: footstep_state.cpp:183
jsk_footstep_planner::projection_state::no_plane
const unsigned int no_plane
Definition: footstep_state.h:127
a
char a[26]
jsk_footstep_planner::projection_state::transition_limit
const unsigned int transition_limit
Definition: footstep_state.h:130
jsk_footstep_planner::FootstepState::debug_print_
bool debug_print_
Definition: footstep_state.h:281
util.h
jsk_footstep_planner::FootstepState::operator==
bool operator==(FootstepState &other)
Definition: footstep_state.h:240
jsk_footstep_planner::projection_state::close_to_success
const unsigned int close_to_success
Definition: footstep_state.h:129
jsk_footstep_planner::projectStateToString
std::string projectStateToString(unsigned int state)
Definition: footstep_state.cpp:59
jsk_footstep_planner::FootstepState::leg_
const int leg_
Definition: footstep_state.h:277
ann_grid.h
jsk_footstep_planner::projection_state::no_enough_inliers_ratio
const unsigned int no_enough_inliers_ratio
Definition: footstep_state.h:132


jsk_footstep_planner
Author(s): Ryohei Ueda
autogenerated on Wed Jan 24 2024 04:05:30