convert.h
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) 2017, Alexander W. Winkler, ETH Zurich. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright notice,
7  this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright notice,
9  this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of ETH ZURICH nor the names of its contributors may be
12  used to endorse or promote products derived from this software without
13  specific prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL ETH ZURICH BE LIABLE FOR ANY DIRECT, INDIRECT,
19 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ******************************************************************************/
26 
27 #ifndef XPP_ROS_CONVERSIONS_H_
28 #define XPP_ROS_CONVERSIONS_H_
29 
30 #include <vector>
31 
32 #include <xpp_msgs/StateLin3d.h>
33 #include <xpp_msgs/State6d.h>
34 #include <xpp_msgs/RobotStateCartesian.h>
35 #include <xpp_msgs/RobotStateCartesianTrajectory.h>
36 
37 #include <xpp_states/state.h>
39 
40 namespace xpp {
41 
48 struct Convert {
49 
50 static StateLin3d
51 ToXpp(const xpp_msgs::StateLin3d& ros)
52 {
53  StateLin3d point;
54  point.p_.x() = ros.pos.x;
55  point.p_.y() = ros.pos.y;
56  point.p_.z() = ros.pos.z;
57 
58  point.v_.x() = ros.vel.x;
59  point.v_.y() = ros.vel.y;
60  point.v_.z() = ros.vel.z;
61 
62  point.a_.x() = ros.acc.x;
63  point.a_.y() = ros.acc.y;
64  point.a_.z() = ros.acc.z;
65 
66  return point;
67 }
68 
69 static xpp_msgs::StateLin3d
71 {
72  xpp_msgs::StateLin3d ros;
73  ros.pos.x = xpp.p_.x();
74  ros.pos.y = xpp.p_.y();
75  ros.pos.z = xpp.p_.z();
76 
77  ros.vel.x = xpp.v_.x();
78  ros.vel.y = xpp.v_.y();
79  ros.vel.z = xpp.v_.z();
80 
81  ros.acc.x = xpp.a_.x();
82  ros.acc.y = xpp.a_.y();
83  ros.acc.z = xpp.a_.z();
84 
85  return ros;
86 }
87 
88 template<typename T>
89 static Vector3d
90 ToXpp(const T& ros)
91 {
92  Vector3d vec;
93  vec << ros.x, ros.y, ros.z;
94  return vec;
95 }
96 
97 template<typename T>
98 static T
100 {
101  T ros;
102  ros.x = xpp.x();
103  ros.y = xpp.y();
104  ros.z = xpp.z();
105 
106  return ros;
107 }
108 
109 template<typename T>
111 ToXpp(const std::vector<T>& ros)
112 {
113  Endeffectors<Vector3d> xpp(ros.size());
114 
115  for (auto ee : xpp.GetEEsOrdered())
116  xpp.at(ee) = ToXpp(ros.at(ee));
117 
118  return xpp;
119 }
120 
121 static Eigen::Quaterniond
122 ToXpp(const geometry_msgs::Quaternion ros)
123 {
124  Eigen::Quaterniond xpp;
125  xpp.w() = ros.w;
126  xpp.x() = ros.x;
127  xpp.y() = ros.y;
128  xpp.z() = ros.z;
129 
130  return xpp;
131 }
132 
133 static geometry_msgs::Quaternion
134 ToRos(const Eigen::Quaterniond xpp)
135 {
136  geometry_msgs::Quaternion ros;
137  ros.w = xpp.w();
138  ros.x = xpp.x();
139  ros.y = xpp.y();
140  ros.z = xpp.z();
141 
142  return ros;
143 }
144 
145 static xpp_msgs::State6d
147 {
148  xpp_msgs::State6d msg;
149 
150  msg.pose.position = ToRos<geometry_msgs::Point>(xpp.lin.p_);
151  msg.twist.linear = ToRos<geometry_msgs::Vector3>(xpp.lin.v_);
152  msg.accel.linear = ToRos<geometry_msgs::Vector3>(xpp.lin.a_);
153 
154  msg.pose.orientation = ToRos(xpp.ang.q);
155  msg.twist.angular = ToRos<geometry_msgs::Vector3>(xpp.ang.w);
156  msg.accel.angular = ToRos<geometry_msgs::Vector3>(xpp.ang.wd);
157 
158  return msg;
159 }
160 
161 static State3d
162 ToXpp(const xpp_msgs::State6d& ros)
163 {
164  State3d xpp;
165 
166  xpp.lin.p_ = ToXpp(ros.pose.position);
167  xpp.lin.v_ = ToXpp(ros.twist.linear);
168  xpp.lin.a_ = ToXpp(ros.accel.linear);
169 
170  xpp.ang.q = ToXpp(ros.pose.orientation);
171  xpp.ang.w = ToXpp(ros.twist.angular);
172  xpp.ang.wd = ToXpp(ros.accel.angular);
173 
174  return xpp;
175 }
176 
177 static xpp_msgs::RobotStateCartesian
179 {
180  xpp_msgs::RobotStateCartesian ros;
181 
182  ros.base = ToRos(xpp.base_);
183  ros.time_from_start = ros::Duration(xpp.t_global_);
184 
185  for (auto ee : xpp.ee_contact_.GetEEsOrdered()) {
186  ros.ee_motion. push_back(ToRos(xpp.ee_motion_.at(ee)));
187  ros.ee_contact.push_back(xpp.ee_contact_.at(ee));
188  ros.ee_forces. push_back(ToRos<geometry_msgs::Vector3>(xpp.ee_forces_.at(ee)));
189  }
190 
191  return ros;
192 }
193 
194 static RobotStateCartesian
195 ToXpp(const xpp_msgs::RobotStateCartesian& ros)
196 {
197 
198  int n_ee = ros.ee_motion.size();
199  RobotStateCartesian xpp(n_ee);
200 
201  xpp.base_ = ToXpp(ros.base);
202  xpp.t_global_ = ros.time_from_start.toSec();
203 
204  for (auto ee : xpp.ee_contact_.GetEEsOrdered()) {
205  xpp.ee_motion_.at(ee) = ToXpp(ros.ee_motion.at(ee));
206  xpp.ee_contact_.at(ee) = ros.ee_contact.at(ee);
207  xpp.ee_forces_.at(ee) = ToXpp(ros.ee_forces.at(ee));
208  }
209 
210  return xpp;
211 }
212 
213 static xpp_msgs::RobotStateCartesianTrajectory
214 ToRos(const std::vector<RobotStateCartesian>& xpp)
215 {
216  xpp_msgs::RobotStateCartesianTrajectory msg;
217 
218  for (const auto state : xpp) {
219  auto state_msg = ToRos(state);
220  msg.points.push_back(state_msg);
221  }
222 
223  return msg;
224 }
225 
226 static std::vector<RobotStateCartesian>
227 ToXpp(const xpp_msgs::RobotStateCartesianTrajectory& ros)
228 {
229  std::vector<RobotStateCartesian> xpp_vec;
230 
231  for (const auto ros_state : ros.points) {
232  auto xpp = ToXpp(ros_state);
233  xpp_vec.push_back(xpp);
234  }
235 
236  return xpp_vec;
237 }
238 
239 };
240 
241 } // namespace xpp
242 
243 #endif /* XPP_ROS_CONVERSIONS_H_ */
Quaterniond q
static geometry_msgs::Quaternion ToRos(const Eigen::Quaterniond xpp)
Definition: convert.h:134
static xpp_msgs::StateLin3d ToRos(const StateLin3d &xpp)
Definition: convert.h:70
StateLin3d & at(EndeffectorID ee)
static T ToRos(const Vector3d &xpp)
Definition: convert.h:99
static std::vector< RobotStateCartesian > ToXpp(const xpp_msgs::RobotStateCartesianTrajectory &ros)
Definition: convert.h:227
static xpp_msgs::RobotStateCartesianTrajectory ToRos(const std::vector< RobotStateCartesian > &xpp)
Definition: convert.h:214
EndeffectorsMotion ee_motion_
static xpp_msgs::RobotStateCartesian ToRos(const RobotStateCartesian &xpp)
Definition: convert.h:178
Eigen::Vector3d Vector3d
StateAng3d ang
StateLin3d lin
static State3d ToXpp(const xpp_msgs::State6d &ros)
Definition: convert.h:162
Converts between xpp-states types and xpp-messages.
Definition: convert.h:48
static RobotStateCartesian ToXpp(const xpp_msgs::RobotStateCartesian &ros)
Definition: convert.h:195
static xpp_msgs::State6d ToRos(const State3d &xpp)
Definition: convert.h:146
std::vector< EndeffectorID > GetEEsOrdered() const
static Endeffectors< Vector3d > ToXpp(const std::vector< T > &ros)
Definition: convert.h:111
static Eigen::Quaterniond ToXpp(const geometry_msgs::Quaternion ros)
Definition: convert.h:122
Endeffectors< Vector3d > ee_forces_
EndeffectorsContact ee_contact_
static Vector3d ToXpp(const T &ros)
Definition: convert.h:90
static StateLin3d ToXpp(const xpp_msgs::StateLin3d &ros)
Definition: convert.h:51


xpp_ros_conversions
Author(s): Alexander W. Winkler
autogenerated on Thu Nov 2 2017 02:22:54