param_parser.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
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 
18 #ifndef COB_TRICYCLE_CONTROLLER_PARAM_PARSER_H
19 #define COB_TRICYCLE_CONTROLLER_PARAM_PARSER_H
20 
21 #include <urdf/model.h>
22 
25 #include <tf2/LinearMath/Vector3.h>
26 
27 inline bool parseWheelTransform(const std::string& joint_name, const std::string& parent_link_name,
28  tf2::Transform &transform, urdf::Model* model)
29 {
30  tf2::Transform transform_inc; transform_inc.setIdentity();
31  if(model)
32  {
33  urdf::JointConstSharedPtr joint(model->getJoint(joint_name));
34  if (!joint)
35  {
36  ROS_ERROR_STREAM(joint_name
37  << " couldn't be retrieved from model description");
38  return false;
39  }
40 
41  transform_inc = tf2::Transform(tf2::Quaternion(joint->parent_to_joint_origin_transform.rotation.x,
42  joint->parent_to_joint_origin_transform.rotation.y,
43  joint->parent_to_joint_origin_transform.rotation.z,
44  joint->parent_to_joint_origin_transform.rotation.w),
45  tf2::Vector3(joint->parent_to_joint_origin_transform.position.x,
46  joint->parent_to_joint_origin_transform.position.y,
47  joint->parent_to_joint_origin_transform.position.z));
48  ROS_DEBUG_STREAM("transform_inc first");
49  ROS_DEBUG_STREAM("Tx: "<<transform_inc.getOrigin().x()<<", Ty: "<<transform_inc.getOrigin().y()<<", Tz: "<<transform_inc.getOrigin().z());
50  ROS_DEBUG_STREAM("Ax: "<<transform_inc.getRotation().getAxis().x()<<", Ay: "<<transform_inc.getRotation().getAxis().y()<<", Az: "<<transform_inc.getRotation().getAxis().z());
51  ROS_DEBUG_STREAM("a: "<<transform_inc.getRotation().getAngle());
52  while(joint->parent_link_name != parent_link_name)
53  {
54  urdf::LinkConstSharedPtr link_parent(model->getLink(joint->parent_link_name));
55  ROS_DEBUG_STREAM("joint: "<<joint->name<<", parent_link_name: "<<joint->parent_link_name);
56  if (!link_parent || !link_parent->parent_joint)
57  {
58  ROS_ERROR_STREAM(joint->parent_link_name
59  << " couldn't be retrieved from model description or his parent joint");
60  return false;
61  }
62  joint = link_parent->parent_joint;
63  transform = tf2::Transform(tf2::Quaternion(joint->parent_to_joint_origin_transform.rotation.x,
64  joint->parent_to_joint_origin_transform.rotation.y,
65  joint->parent_to_joint_origin_transform.rotation.z,
66  joint->parent_to_joint_origin_transform.rotation.w),
67  tf2::Vector3(joint->parent_to_joint_origin_transform.position.x,
68  joint->parent_to_joint_origin_transform.position.y,
69  joint->parent_to_joint_origin_transform.position.z));
70  transform_inc *= transform;
71  ROS_DEBUG_STREAM("transform");
72  ROS_DEBUG_STREAM("Tx: "<<transform.getOrigin().x()<<", Ty: "<<transform.getOrigin().y()<<", Tz: "<<transform.getOrigin().z());
73  ROS_DEBUG_STREAM("Ax: "<<transform.getRotation().getAxis().x()<<", Ay: "<<transform.getRotation().getAxis().y()<<", Az: "<<transform.getRotation().getAxis().z());
74  ROS_DEBUG_STREAM("a: "<<transform.getRotation().getAngle());
75  ROS_DEBUG_STREAM("transform_inc");
76  ROS_DEBUG_STREAM("Tx: "<<transform_inc.getOrigin().x()<<", Ty: "<<transform_inc.getOrigin().y()<<", Tz: "<<transform_inc.getOrigin().z());
77  ROS_DEBUG_STREAM("Ax: "<<transform_inc.getRotation().getAxis().x()<<", Ay: "<<transform_inc.getRotation().getAxis().y()<<", Az: "<<transform_inc.getRotation().getAxis().z());
78  ROS_DEBUG_STREAM("a: "<<transform_inc.getRotation().getAngle());
79  }
80 
81  transform.setIdentity();
82  transform = transform_inc;
83  ROS_DEBUG_STREAM("final");
84  ROS_DEBUG_STREAM("Tx: "<<transform.getOrigin().x()<<", Ty: "<<transform.getOrigin().y()<<", Tz: "<<transform.getOrigin().z());
85  ROS_DEBUG_STREAM("Ax: "<<transform.getRotation().getAxis().x()<<", Ay: "<<transform.getRotation().getAxis().y()<<", Az: "<<transform.getRotation().getAxis().z());
86  ROS_DEBUG_STREAM("a: "<<transform.getRotation().getAngle());
87  return true;
88  }
89  else
90  return false;
91 }
92 
93 #endif // COB_TRICYCLE_CONTROLLER_PARAM_PARSER_H
Quaternion getRotation() const
void setIdentity()
tf2Scalar getAngle() const
TF2SIMD_FORCE_INLINE Vector3 & getOrigin()
bool parseWheelTransform(const std::string &joint_name, const std::string &parent_link_name, tf2::Transform &transform, urdf::Model *model)
Definition: param_parser.h:27
#define ROS_DEBUG_STREAM(args)
Vector3 getAxis() const
#define ROS_ERROR_STREAM(args)


cob_tricycle_controller
Author(s): Felix Messmer
autogenerated on Thu Apr 8 2021 02:39:57