All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Pose.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /* Desc: External interfaces for Gazebo
18  * Author: Nate Koenig
19  * Date: 03 Apr 2007
20  */
21 
22 #ifndef POSE_HH
23 #define POSE_HH
24 
25 #include <iostream>
26 
27 #include "math/Vector3.hh"
28 #include "math/Quaternion.hh"
29 
30 namespace gazebo
31 {
32  namespace math
33  {
36 
38  class Pose
39  {
41  public: Pose();
42 
46  public: Pose(const Vector3 &_pos, const Quaternion &_rot);
47 
49  public: Pose(double _x, double _y, double _z,
50  double _roll, double _pitch, double _yaw);
51 
54  public: Pose(const Pose &_pose);
55 
57  public: virtual ~Pose();
58 
62  public: void Set(const Vector3 &_pos, const Quaternion &_rot);
63 
71  public: void Set(double _x, double _y, double _z,
72  double _roll, double _pitch, double _yaw);
73 
75  public: bool IsFinite() const;
76 
78  public: inline void Correct()
79  {
80  this->pos.Correct();
81  this->rot.Correct();
82  }
83 
86  public: Pose GetInverse() const;
87 
91  public: Pose operator+(const Pose &_pose) const;
92 
96  public: const Pose &operator+=(const Pose &_pose);
97 
101  public: inline Pose operator-(const Pose &_pose) const
102  {
103  return Pose(this->CoordPositionSub(_pose),
104  this->CoordRotationSub(_pose.rot));
105  }
106 
110  public: const Pose &operator-=(const Pose &_pose);
111 
115  public: bool operator ==(const Pose &_pose) const;
116 
120  public: bool operator!=(const Pose &_pose) const;
121 
125  public: Pose operator*(const Pose &_pose);
126 
130  public: Vector3 CoordPositionAdd(const Vector3 &_pos) const;
131 
135  public: Vector3 CoordPositionAdd(const Pose &_pose) const;
136 
140  public: inline Vector3 CoordPositionSub(const Pose &_pose) const
141  {
142  Quaternion tmp(0.0,
143  this->pos.x - _pose.pos.x,
144  this->pos.y - _pose.pos.y,
145  this->pos.z - _pose.pos.z);
146 
147  tmp = _pose.rot.GetInverse() * (tmp * _pose.rot);
148  return Vector3(tmp.x, tmp.y, tmp.z);
149  }
150 
154  public: Quaternion CoordRotationAdd(const Quaternion &_rot) const;
155 
159  public: inline Quaternion CoordRotationSub(const Quaternion &_rot) const
160  {
161  Quaternion result(_rot.GetInverse() * this->rot);
162  result.Normalize();
163  return result;
164  }
165 
166 
170  public: Pose CoordPoseSolve(const Pose &_b) const;
171 
173  public: void Reset();
174 
178  public: Pose RotatePositionAboutOrigin(const Quaternion &_rot) const;
179 
182  public: void Round(int _precision);
183 
185  public: Vector3 pos;
186 
188  public: Quaternion rot;
189 
194  public: friend std::ostream &operator<<(std::ostream &_out,
195  const gazebo::math::Pose &_pose)
196  {
197  _out << _pose.pos << " " << _pose.rot;
198  return _out;
199  }
200 
205  public: friend std::istream &operator>>(std::istream &_in,
206  gazebo::math::Pose &_pose)
207  {
208  // Skip white spaces
209  _in.setf(std::ios_base::skipws);
210  _in >> _pose.pos >> _pose.rot;
211  return _in;
212  }
213  };
215  }
216 }
217 #endif