tf2_bullet  master
Bullet binding for tf2.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
tf2_bullet.h
Go to the documentation of this file.
1 // Copyright (c) 2008, Willow Garage, Inc. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 //
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 //
13 // * Neither the name of the Willo Garage, Inc nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 
31 #ifndef TF2_BULLET__TF2_BULLET_H_
32 #define TF2_BULLET__TF2_BULLET_H_
33 
34 #include <tf2/convert.h>
35 #include <LinearMath/btTransform.h>
36 #include <geometry_msgs/msg/point_stamped.hpp>
38 
39 #include <iostream>
40 
41 namespace tf2
42 {
47  inline
48  btTransform transformToBullet(const geometry_msgs::msg::TransformStamped & t)
49  {
50  return btTransform(
51  btQuaternion(
52  static_cast < float > (t.transform.rotation.x),
53  static_cast < float > (t.transform.rotation.y),
54  static_cast < float > (t.transform.rotation.z),
55  static_cast < float > (t.transform.rotation.w)),
56  btVector3(
57  static_cast < float > (t.transform.translation.x),
58  static_cast < float > (t.transform.translation.y),
59  static_cast < float > (t.transform.translation.z)));
60  }
61 
62 
69  template < >
70  inline
73  const geometry_msgs::msg::TransformStamped & transform)
74  {
75  t_out =
77  transformToBullet(transform) * t_in,
78  tf2_ros::fromMsg(transform.header.stamp), transform.header.frame_id);
79  }
80 
86  inline
87  geometry_msgs::msg::PointStamped toMsg(const tf2::Stamped < btVector3 > & in)
88  {
89  geometry_msgs::msg::PointStamped msg;
90  msg.header.stamp = tf2_ros::toMsg(in.stamp_);
91  msg.header.frame_id = in.frame_id_;
92  msg.point.x = in[0];
93  msg.point.y = in[1];
94  msg.point.z = in[2];
95  return msg;
96  }
97 
103  inline
104  void fromMsg(const geometry_msgs::msg::PointStamped & msg, tf2::Stamped < btVector3 > & out)
105  {
106  out.stamp_ = tf2_ros::fromMsg(msg.header.stamp);
107  out.frame_id_ = msg.header.frame_id;
108  out[0] = static_cast < float > (msg.point.x);
109  out[1] = static_cast < float > (msg.point.y);
110  out[2] = static_cast < float > (msg.point.z);
111  }
112 
113 
120  template < >
121  inline
124  const geometry_msgs::msg::TransformStamped & transform)
125  {
126  t_out =
128  transformToBullet(transform) * t_in,
129  tf2_ros::fromMsg(transform.header.stamp), transform.header.frame_id);
130  }
131 
132 
133 } // namespace tf2
134 
135 #endif // TF2_BULLET__TF2_BULLET_H_
tf2::Stamped::stamp_
TimePoint stamp_
tf2::fromMsg
void fromMsg(const A &, B &b)
tf2::transformToBullet
btTransform transformToBullet(const geometry_msgs::msg::TransformStamped &t)
Convert a timestamped transform to the equivalent Bullet data type.
Definition: tf2_bullet.h:48
tf2::Stamped
tf2::Stamped::frame_id_
std::string frame_id_
tf2_ros::fromMsg
tf2::TimePoint fromMsg(const builtin_interfaces::msg::Time &time_msg)
tf2
tf2::toMsg
B toMsg(const A &a)
convert.h
tf2::doTransform
void doTransform(const T &data_in, T &data_out, const geometry_msgs::msg::TransformStamped &transform)
tf2_ros::toMsg
builtin_interfaces::msg::Time toMsg(const tf2::TimePoint &t)
buffer_interface.h