state.cpp
Go to the documentation of this file.
2 
4 {
6  : ivLeg(NOLEG)
7  , ivRoll(0.0)
8  , ivPitch(0.0)
9  , ivYaw(0.0)
10  , ivSwingHeight(0.0)
11  , ivSwayDuration(0.0)
12  , ivStepDuration(0.0)
13  , ivGroundContactSupport(0.0)
14  , body_vel(geometry_msgs::Vector3())
15  , sway_distance(0.0)
16  , swing_distance(0.0)
17  , cost(0.0)
18  , risk(0.0)
19 {
20  ivPose = tf::Pose();
21 
22  ivNormal.x = 0.0;
23  ivNormal.y = 0.0;
24  ivNormal.z = 1.0;
25 }
26 
27 State::State(double x, double y, double z, double roll, double pitch, double yaw, Leg leg)
28  : ivLeg(leg)
29  , ivRoll(roll)
30  , ivPitch(pitch)
31  , ivYaw(yaw)
32  , ivSwingHeight(0.0)
33  , ivSwayDuration(0.0)
34  , ivStepDuration(0.0)
37  , sway_distance(0.0)
38  , swing_distance(0.0)
39  , cost(0.0)
40  , risk(0.0)
41 {
42  ivPose.setOrigin(tf::Vector3(x, y, z));
44 
46 }
47 
48 State::State(const geometry_msgs::Vector3& position, double roll, double pitch, double yaw, Leg leg)
49  : State(position.x, position.y, position.z, roll, pitch, yaw, leg)
50 {
51 }
52 
53 State::State(const geometry_msgs::Vector3& position, const geometry_msgs::Vector3& normal, double yaw, Leg leg)
54  : ivLeg(leg)
55  , ivYaw(yaw)
56  , ivSwingHeight(0.0)
57  , ivSwayDuration(0.0)
58  , ivStepDuration(0.0)
61  , sway_distance(0.0)
62  , swing_distance(0.0)
63  , cost(0.0)
64  , risk(0.0)
65 {
66  ivPose.setOrigin(tf::Vector3(position.x, position.y, position.z));
67 
68  setNormal(normal);
69 }
70 
71 State::State(const geometry_msgs::Pose& pose, Leg leg)
72  : ivLeg(leg)
73  , ivSwingHeight(0.0)
74  , ivSwayDuration(0.0)
75  , ivStepDuration(0.0)
78  , sway_distance(0.0)
79  , swing_distance(0.0)
80  , cost(0.0)
81  , risk(0.0)
82 {
83  tf::poseMsgToTF(pose, ivPose);
85 
87 }
88 
89 State::State(const tf::Transform& t, Leg leg)
90  : ivLeg(leg)
91  , ivSwingHeight(0.0)
92  , ivSwayDuration(0.0)
93  , ivStepDuration(0.0)
95  , body_vel(geometry_msgs::Vector3())
96  , sway_distance(0.0)
97  , swing_distance(0.0)
98  , cost(0.0)
99  , risk(0.0)
100 {
101  ivPose = t;
103 
104  recomputeNormal();
105 }
106 
107 State::State(const msgs::Foot foot)
108  : State(foot.pose, foot.foot_index == msgs::Foot::LEFT ? LEFT : RIGHT)
109 {
110 }
111 
112 State::State(const msgs::Step step)
113  : State(step.foot)
114 {
115  ivSwingHeight = step.swing_height;
116  ivSwayDuration = step.sway_duration;
117  ivStepDuration = step.step_duration;
118 }
119 
121 {}
122 
123 bool State::operator==(const State& s2) const
124 {
125  return (fabs(getX() - s2.getX()) < FLOAT_CMP_THR &&
126  fabs(getY() - s2.getY()) < FLOAT_CMP_THR &&
127  fabs(getZ() - s2.getZ()) < FLOAT_CMP_THR &&
131  ivLeg == s2.getLeg());
132 }
133 
134 bool State::operator!=(const State& s2) const
135 {
136  return not (*this == s2);
137 }
138 
139 void State::setPosition(const geometry_msgs::Point& position)
140 {
141  setX(position.x);
142  setY(position.y);
143  setZ(position.z);
144 }
145 
146 void State::setOrientation(const geometry_msgs::Quaternion& q)
147 {
148  double roll, pitch, yaw;
149  tf::Quaternion q_tf;
150  tf::quaternionMsgToTF(q, q_tf);
151  tf::Matrix3x3(q_tf).getRPY(roll, pitch, yaw);
152  setRPY(roll, pitch, yaw);
153 }
154 
155 void State::setRPY(double roll, double pitch, double yaw)
156 {
157  ivRoll = roll;
158  ivPitch = pitch;
159  ivYaw = yaw;
160 
162  recomputeNormal();
163 }
164 
165 void State::setNormal(const geometry_msgs::Vector3 &normal)
166 {
167  ivNormal = normal;
168 
169  if (ivNormal.z > 0.99)
170  {
171  ivNormal.x = 0.0;
172  ivNormal.y = 0.0;
173  ivNormal.z = 1.0;
174  ivRoll = 0.0;
175  ivPitch = 0.0;
176  }
177  else
178  {
179  // get roll and pitch
181  }
182 
184 }
185 
186 void State::setNormal(double x, double y, double z)
187 {
188  geometry_msgs::Vector3 n;
189  n.x = x;
190  n.y = y;
191  n.z = z;
192  setNormal(n);
193 }
194 
195 void State::getStep(msgs::Step &step) const
196 {
197  step.step_index = 0;
198  getFoot(step.foot);
199  step.sway_duration = ivSwayDuration;
200  step.step_duration = ivStepDuration;
201  step.swing_height = ivSwingHeight;
202  step.cost = cost;
203  step.risk = risk;
204 }
205 
206 void State::getFoot(msgs::Foot& foot) const
207 {
208  foot.foot_index = ivLeg == LEFT ? static_cast<uint8_t>(msgs::Foot::LEFT) : static_cast<uint8_t>(msgs::Foot::RIGHT);
209  foot.pose.position.x = getX();
210  foot.pose.position.y = getY();
211  foot.pose.position.z = getZ();
212  normalToQuaternion(ivNormal, ivYaw, foot.pose.orientation);
213 }
214 
216 {
217  if (std::abs(ivRoll) < 0.01 && std::abs(ivPitch) < 0.01)
218  {
219  ivNormal.x = 0.0;
220  ivNormal.y = 0.0;
221  ivNormal.z = 1.0;
222  }
223  else
224  {
225  // get normal
227  }
228 }
229 
230 } // end of namespace
static void poseMsgToTF(const geometry_msgs::Pose &msg, Pose &bt)
void getFoot(msgs::Foot &foot) const
Definition: state.cpp:206
geometry_msgs::Vector3 body_vel
Definition: state.h:144
void setOrientation(const geometry_msgs::Quaternion &q)
Definition: state.cpp:146
void getStep(msgs::Step &step) const
Definition: state.cpp:195
void setNormal(const geometry_msgs::Vector3 &normal)
Definition: state.cpp:165
void setPosition(const geometry_msgs::Point &position)
Definition: state.cpp:139
double getY() const
Definition: state.h:98
void normalToQuaternion(const geometry_msgs::Vector3 &n, double yaw, geometry_msgs::Quaternion &q)
Definition: math.cpp:84
TFSIMD_FORCE_INLINE Matrix3x3 & getBasis()
static const double FLOAT_CMP_THR
Definition: math.h:49
TFSIMD_FORCE_INLINE const tfScalar & y() const
void setY(double y)
Definition: state.h:76
void setRPY(double roll, double pitch, double yaw)
Definition: state.cpp:155
bool operator!=(const State &s2) const
Inequality operator for two states (negates the equality operator).
Definition: state.cpp:134
void setZ(double z)
Definition: state.h:77
tf::Transform Pose
A class representing the robot&#39;s pose (i.e. position and orientation) in the (continuous) world view...
Definition: state.h:49
void RPYToNormal(double r, double p, double y, geometry_msgs::Vector3 &n)
Definition: math.cpp:91
static void quaternionMsgToTF(const geometry_msgs::Quaternion &msg, Quaternion &bt)
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
void setRPY(tfScalar roll, tfScalar pitch, tfScalar yaw)
TFSIMD_FORCE_INLINE Vector3()
double ivRoll
The robot&#39;s orientation.
Definition: state.h:132
Leg ivLeg
The robot&#39;s supporting leg.
Definition: state.h:129
TFSIMD_FORCE_INLINE const tfScalar & x() const
void normalToRP(const geometry_msgs::Vector3 &n, double yaw, double &r, double &p)
Definition: math.cpp:104
double getX() const
Definition: state.h:97
TFSIMD_FORCE_INLINE const tfScalar & z() const
bool operator==(const State &s2) const
Compare two states on equality of x, y, theta, leg upon a certain degree of float precision...
Definition: state.cpp:123
geometry_msgs::Vector3 ivNormal
The normal of foot in world.
Definition: state.h:136
double getZ() const
Definition: state.h:99
double ivGroundContactSupport
percentage of ground contact support (0.0 - 1.0 = 100%)
Definition: state.h:142
TFSIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)
def shortest_angular_distance(from_angle, to_angle)
void setX(double x)
Definition: state.h:75


vigir_footstep_planning_lib
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:47:33