Gazebo Sim

API Reference

7.7.0
TransformTypes.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Open Source Robotics Foundation
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 #ifndef GZ_ENVIRONMENTAL_SYSTEM_TRANFORM_TYPE_HH_
18 #define GZ_ENVIRONMENTAL_SYSTEM_TRANFORM_TYPE_HH_
19 
20 #include <string>
21 #include <optional>
22 
23 #include <gz/math/Vector3.hh>
24 #include <gz/math/Pose3.hh>
25 
26 namespace gz {
27 namespace sim {
43 };
44 
48 std::optional<TransformType> getTransformType(const std::string &_str)
49 {
50  if(_str == "ADD_VELOCITY_LOCAL")
52  if(_str == "ADD_VELOCITY_GLOBAL")
54  if(_str == "LOCAL")
55  return TransformType::LOCAL;
56  if(_str == "GLOBAL")
57  return TransformType::GLOBAL;
58  return std::nullopt;
59 }
60 
68  const TransformType _type, const math::Pose3d& _pose,
69  const math::Vector3d& _velocity, const math::Vector3d& _reading)
70 {
71  math::Vector3d result;
72  math::Vector3d offset{0, 0, 0};
73 
74  if (_type == ADD_VELOCITY_LOCAL || _type == ADD_VELOCITY_GLOBAL)
75  {
76  offset = -_velocity;
77  }
78 
79  switch (_type) {
80  case ADD_VELOCITY_LOCAL:
81  case LOCAL:
82  result = _pose.Rot().Inverse() * (_reading + offset);
83  break;
84  default:
85  result = (_reading + offset);
86  }
87 
88  return result;
89 }
90 }
91 }
92 #endif