angle_conversions.h
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #ifndef PSEN_SCAN_V2_STANDALONE_ANGLE_CONVERSIONS_H
17 #define PSEN_SCAN_V2_STANDALONE_ANGLE_CONVERSIONS_H
18 
19 #include <sstream>
20 #include <stdexcept>
21 
22 #include <boost/math/constants/constants.hpp>
23 
25 {
26 namespace data_conversion_layer
27 {
28 inline static constexpr double radianToDegree(const double& angle_in_rad)
29 {
30  return angle_in_rad * 180. / boost::math::double_constants::pi;
31 }
32 
33 inline static constexpr double degreeToRadian(const double& angle_in_degree)
34 {
35  return (angle_in_degree / 180.) * boost::math::double_constants::pi;
36 }
37 
38 inline static int16_t degreeToTenthDegree(const double& angle_in_degree)
39 {
40  const double tenth_degree_rounded{ std::round(10. * angle_in_degree) };
41  if (tenth_degree_rounded < std::numeric_limits<int16_t>::min() ||
42  tenth_degree_rounded > std::numeric_limits<int16_t>::max())
43  {
44  std::stringstream exception_msg;
45  exception_msg << "Angle " << tenth_degree_rounded << " (tenth of degree) is out of range.";
46  throw std::invalid_argument(exception_msg.str());
47  }
48  return static_cast<int16_t>(tenth_degree_rounded);
49 }
50 
51 inline static int16_t radToTenthDegree(const double& angle_in_rad)
52 {
53  return degreeToTenthDegree(radianToDegree(angle_in_rad));
54 }
55 
56 inline static double constexpr tenthDegreeToRad(const int16_t& angle_in_tenth_degree)
57 {
58  return data_conversion_layer::degreeToRadian(static_cast<double>(angle_in_tenth_degree) / 10.);
59 }
60 
61 } // namespace data_conversion_layer
62 } // namespace psen_scan_v2_standalone
63 
64 #endif // PSEN_SCAN_V2_STANDALONE_ANGLE_CONVERSIONS_H
psen_scan_v2_standalone::data_conversion_layer::radToTenthDegree
static int16_t radToTenthDegree(const double &angle_in_rad)
Definition: angle_conversions.h:51
psen_scan_v2_standalone::data_conversion_layer::degreeToRadian
static constexpr double degreeToRadian(const double &angle_in_degree)
Definition: angle_conversions.h:33
psen_scan_v2_standalone::data_conversion_layer::radianToDegree
static constexpr double radianToDegree(const double &angle_in_rad)
Definition: angle_conversions.h:28
psen_scan_v2_standalone::data_conversion_layer::degreeToTenthDegree
static int16_t degreeToTenthDegree(const double &angle_in_degree)
Definition: angle_conversions.h:38
psen_scan_v2_standalone
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
psen_scan_v2_standalone::data_conversion_layer::tenthDegreeToRad
static constexpr double tenthDegreeToRad(const int16_t &angle_in_tenth_degree)
Definition: angle_conversions.h:56


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Jun 22 2024 02:46:11