op3_localization.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
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 /* Author: SCH */
18 
20 
21 namespace robotis_op
22 {
23 
25  : ros_node_(),
26  transform_tolerance_(0.0),
27  err_tol_(0.2),
28  is_moving_walking_(false)
29 {
30  initialize();
31 
32  pelvis_pose_base_walking_.pose.position.x = 0.0;
33  pelvis_pose_base_walking_.pose.position.y = 0.0;
34  pelvis_pose_base_walking_.pose.position.z = 0.0;
35  pelvis_pose_base_walking_.pose.orientation.x = 0.0;
36  pelvis_pose_base_walking_.pose.orientation.y = 0.0;
37  pelvis_pose_base_walking_.pose.orientation.z = 0.0;
38  pelvis_pose_base_walking_.pose.orientation.w = 1.0;
39 
40  pelvis_pose_offset_.pose.position.x = 0.0;
41  pelvis_pose_offset_.pose.position.y = 0.0;
42  pelvis_pose_offset_.pose.position.z = 0.2495256; //0.3402256 - 0.0907;
43  pelvis_pose_offset_.pose.orientation.x = 0.0;
44  pelvis_pose_offset_.pose.orientation.y = 0.0;
45  pelvis_pose_offset_.pose.orientation.z = 0.0;
46  pelvis_pose_offset_.pose.orientation.w = 1.0;
47 
48  pelvis_pose_old_.pose.position.x = 0.0;
49  pelvis_pose_old_.pose.position.y = 0.0;
50  pelvis_pose_old_.pose.position.z = 0.0;
51  pelvis_pose_old_.pose.orientation.x = 0.0;
52  pelvis_pose_old_.pose.orientation.y = 0.0;
53  pelvis_pose_old_.pose.orientation.z = 0.0;
54  pelvis_pose_old_.pose.orientation.w = 1.0;
55 
56  update();
57 }
58 
60 {
61 
62 }
63 
65 {
66  // subscriber
67  pelvis_pose_msg_sub_ = ros_node_.subscribe("/robotis/pelvis_pose", 5,
69 // pelvis_base_walking_msg_sub_ = ros_node_.subscribe("/robotis/pelvis_pose_base_walking", 5,
70 // &OP3Localization::pelvisPoseBaseWalkingCallback, this);
71 
72  pelvis_reset_msg_sub_ = ros_node_.subscribe("/robotis/pelvis_pose_reset", 5,
74 
75 }
76 
77 void OP3Localization::pelvisPoseCallback(const geometry_msgs::PoseStamped::ConstPtr& msg)
78 {
79  mutex_.lock();
80 
81  pelvis_pose_offset_ = *msg;
82  pelvis_pose_.header.stamp = pelvis_pose_offset_.header.stamp;
83 
84  mutex_.unlock();
85 }
86 
87 //void OP3Localization::pelvisPoseBaseWalkingCallback(const geometry_msgs::PoseStamped::ConstPtr& msg)
88 //{
89 // mutex_.lock();
90 
91 // Eigen::Quaterniond msg_q;
92 // tf::quaternionMsgToEigen(msg->pose.orientation, msg_q);
93 
94 // Eigen::MatrixXd rpy = robotis_framework::convertQuaternionToRPY(msg_q);
95 // double yaw = rpy.coeff(2,0);
96 
97 // if ( fabs(msg->pose.position.x) <= 1e-3 &&
98 // fabs(msg->pose.position.y) <= 1e-3 &&
99 // fabs(yaw) <= 1e-3 )
100 // {
101 // if (is_moving_walking_ == true)
102 // {
103 // ROS_INFO("Walking Pelvis Pose Update");
104 // pelvis_pose_old_.pose.position.x += pelvis_pose_base_walking_new_.pose.position.x;
105 // pelvis_pose_old_.pose.position.y += pelvis_pose_base_walking_new_.pose.position.y;
106 
107 // Eigen::Quaterniond pose_old_quaternion(pelvis_pose_old_.pose.orientation.w,
108 // pelvis_pose_old_.pose.orientation.x,
109 // pelvis_pose_old_.pose.orientation.y,
110 // pelvis_pose_old_.pose.orientation.z);
111 
112 // Eigen::Quaterniond pose_base_quaternion(pelvis_pose_base_walking_.pose.orientation.w,
113 // pelvis_pose_base_walking_.pose.orientation.x,
114 // pelvis_pose_base_walking_.pose.orientation.y,
115 // pelvis_pose_base_walking_.pose.orientation.z);
116 
117 // Eigen::Quaterniond q = pose_old_quaternion * pose_base_quaternion;
118 // tf::quaternionEigenToMsg(q, pelvis_pose_old_.pose.orientation);
119 
120 // is_moving_walking_ = false;
121 // }
122 // }
123 // else
124 // {
125 // is_moving_walking_ = true;
126 // }
127 
128 // pelvis_pose_base_walking_ = *msg;
129 // pelvis_pose_.header.stamp = pelvis_pose_base_walking_.header.stamp;
130 
131 // mutex_.unlock();
132 //}
133 
134 void OP3Localization::pelvisPoseResetCallback(const std_msgs::String::ConstPtr& msg)
135 {
136  if (msg->data == "reset")
137  {
138  ROS_INFO("Pelvis Pose Reset");
139 
140  pelvis_pose_old_.pose.position.x = 0.0;
141  pelvis_pose_old_.pose.position.y = 0.0;
142  pelvis_pose_old_.pose.orientation.x = 0.0;
143  pelvis_pose_old_.pose.orientation.y = 0.0;
144  pelvis_pose_old_.pose.orientation.z = 0.0;
145  pelvis_pose_old_.pose.orientation.w = 1.0;
146  }
147 }
148 
150 {
151  update();
152 
154  pelvis_pose_.pose.position.y,
155  pelvis_pose_.pose.position.z)
156  );
157 
158  tf::Quaternion q(pelvis_pose_.pose.orientation.x,
159  pelvis_pose_.pose.orientation.y,
160  pelvis_pose_.pose.orientation.z,
161  pelvis_pose_.pose.orientation.w);
162 
164 
165  ros::Duration transform_tolerance(transform_tolerance_);
166  ros::Time transform_expiration = (pelvis_pose_.header.stamp + transform_tolerance);
167 
168  tf::StampedTransform tmp_tf_stamped(pelvis_trans_, transform_expiration, "world", "body_link");
169 
170  broadcaster_.sendTransform(tmp_tf_stamped);
171 }
172 
174 {
175  mutex_.lock();
176 
177  Eigen::Quaterniond pose_old_quaternion(pelvis_pose_old_.pose.orientation.w,
178  pelvis_pose_old_.pose.orientation.x,
179  pelvis_pose_old_.pose.orientation.y,
180  pelvis_pose_old_.pose.orientation.z);
181 
182 // Eigen::Quaterniond pose_base_walking_quaternion(pelvis_pose_base_walking_.pose.orientation.w,
183 // pelvis_pose_base_walking_.pose.orientation.x,
184 // pelvis_pose_base_walking_.pose.orientation.y,
185 // pelvis_pose_base_walking_.pose.orientation.z);
186 
187  Eigen::Quaterniond pose_offset_quaternion(pelvis_pose_offset_.pose.orientation.w,
188  pelvis_pose_offset_.pose.orientation.x,
189  pelvis_pose_offset_.pose.orientation.y,
190  pelvis_pose_offset_.pose.orientation.z);
191 
192  Eigen::Quaterniond pose_quaternion =
193  pose_old_quaternion *
194 // pose_base_walking_quaternion *
195  pose_offset_quaternion;
196 
197 // Eigen::MatrixXd position_walking = Eigen::MatrixXd::Zero(3,1);
198 // position_walking.coeffRef(0,0) =
199 // pelvis_pose_base_walking_.pose.position.x;
200 // position_walking.coeffRef(1,0) =
201 // pelvis_pose_base_walking_.pose.position.y;
202 
203  Eigen::MatrixXd position_offset = Eigen::MatrixXd::Zero(3,1);
204  position_offset.coeffRef(0,0) =
205  pelvis_pose_offset_.pose.position.x;
206  position_offset.coeffRef(1,0) =
207  pelvis_pose_offset_.pose.position.y;
208 
209  Eigen::MatrixXd orientation = robotis_framework::convertQuaternionToRotation(pose_old_quaternion);
210 // Eigen::MatrixXd position_walking_new = orientation * position_walking;
211  Eigen::MatrixXd position_offset_new = orientation * position_offset;
212 
213 // pelvis_pose_base_walking_new_.pose.position.x = position_walking_new.coeff(0,0);
214 // pelvis_pose_base_walking_new_.pose.position.y = position_walking_new.coeff(1,0);
215 
216  pelvis_pose_offset_new_.pose.position.x = position_offset_new.coeff(0,0);
217  pelvis_pose_offset_new_.pose.position.y = position_offset_new.coeff(1,0);
218 
219  pelvis_pose_.pose.position.x =
220  pelvis_pose_old_.pose.position.x +
221 // pelvis_pose_base_walking_new_.pose.position.x +
222  pelvis_pose_offset_new_.pose.position.x;
223 
224  pelvis_pose_.pose.position.y =
225  pelvis_pose_old_.pose.position.y +
226 // pelvis_pose_base_walking_new_.pose.position.y +
227  pelvis_pose_offset_new_.pose.position.y;
228 
229  pelvis_pose_.pose.position.z =
230  pelvis_pose_offset_.pose.position.z;
231 
232  tf::quaternionEigenToMsg(pose_quaternion, pelvis_pose_.pose.orientation);
233 
234  mutex_.unlock();
235 }
236 
237 } // namespace robotis_op
TFSIMD_FORCE_INLINE void setRotation(const Quaternion &q)
geometry_msgs::PoseStamped pelvis_pose_base_walking_
void quaternionEigenToMsg(const Eigen::Quaterniond &e, geometry_msgs::Quaternion &m)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
geometry_msgs::PoseStamped pelvis_pose_offset_new_
geometry_msgs::PoseStamped pelvis_pose_old_
tf::TransformBroadcaster broadcaster_
tf::StampedTransform pelvis_trans_
void pelvisPoseResetCallback(const std_msgs::String::ConstPtr &msg)
Eigen::Matrix3d convertQuaternionToRotation(const Eigen::Quaterniond &quaternion)
geometry_msgs::PoseStamped pelvis_pose_offset_
#define ROS_INFO(...)
geometry_msgs::PoseStamped pelvis_pose_
void sendTransform(const StampedTransform &transform)
void pelvisPoseCallback(const geometry_msgs::PoseStamped::ConstPtr &msg)
ros::Subscriber pelvis_pose_msg_sub_
ros::Subscriber pelvis_reset_msg_sub_
TFSIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)


op3_localization
Author(s): SCH
autogenerated on Mon Jun 10 2019 14:41:20