aron_conversions.h
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Fabian Reister ( fabian dot reister at kit dot edu )
17  * @date 2022
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 #include <type_traits>
25 
26 #include <SimoxUtility/json/json.hpp>
27 
29 
35 #include <armarx/control/common/control_law/aron/KeypointControllerConfig.aron.generated.h>
36 #include <armarx/control/common/control_law/aron/SafetyTaskspaceImpedanceControllerConfig.aron.generated.h>
37 #include <armarx/control/common/control_law/aron/TaskspaceAdmittanceControllerConfig.aron.generated.h>
38 #include <armarx/control/common/control_law/aron/TaskspaceImpedanceControllerConfig.aron.generated.h>
39 #include <armarx/control/common/control_law/aron/TaskspaceMixedImpedanceVelocityControllerConfig.aron.generated.h>
41 #include <armarx/control/common/ft/aron/FTConfig.aron.generated.h>
43 #include <armarx/control/common/mp/aron/MPConfig.aron.generated.h>
44 
45 namespace armarx
46 {
47  template <typename AronType, typename T>
48  T
50  {
51  static_assert(
53  "AronType must be an ARON generated type");
54 
55  const auto dtoConfig = AronType::FromAron(dto);
56 
57  T config;
58  fromAron(dtoConfig, config);
59 
60  return config;
61  }
62 
63  template <typename T, typename BOType>
65  toAronDict(const BOType& bo)
66  {
67  T aronDTO;
68  toAron(aronDTO, bo);
69 
70  return aronDTO.toAronDTO();
71  }
72 
73  template <typename AronDTO>
74  AronDTO
75  readFromJson(const std::filesystem::path& filename)
76  {
77  ARMARX_CHECK(std::filesystem::is_regular_file(filename)) << filename;
78 
79  ARMARX_INFO << "Loading config from file `" << filename << "`.";
80  std::ifstream ifs{filename};
81 
82  nlohmann::json jsonConfig;
83  ifs >> jsonConfig;
84  auto dto = AronDTO();
85 
87  dto.read(reader, jsonConfig);
88  return dto;
89  }
90 
91  template <typename AronDTO, typename BO>
92  BO
93  readFromJson(const std::filesystem::path& filename)
94  {
95  auto dto = readFromJson<AronDTO>(filename);
96  BO bo;
97  fromAron(dto, bo);
98  return bo;
99  }
100 } // namespace armarx
101 
103 {
104  // void fromAron(const arondto::FTConfig& dto, FTSensor::FTConfig& bo);
105  // void toAron(arondto::FTConfig& dto, const FTSensor::FTConfig& bo);
106 } // namespace armarx::control::common::ft
107 
109 {
110 
111  /// TaskspaceImpedanceController
112  // /// dto: data transfer object; bo: business object
113  // void fromAron(const arondto::TaskspaceImpedanceControllerConfig& dto,
114  // TaskspaceImpedanceController::Config& bo);
115  // void toAron(arondto::TaskspaceImpedanceControllerConfig& dto,
116  // const TaskspaceImpedanceController::Config& bo);
117 
118  // void fromAron(const arondto::TaskspaceImpedanceControllerConfigDict& dto,
119  // TaskspaceImpedanceController::ConfigDict& bo);
120  // void toAron(arondto::TaskspaceImpedanceControllerConfigDict& dto,
121  // const TaskspaceImpedanceController::ConfigDict& bo);
122 
123  // /// TaskspaceMixedImpedanceVelocityController
124  // void fromAron(const arondto::TaskspaceMixedImpedanceVelocityControllerConfig& dto,
125  // TaskspaceMixedImpedanceVelocityController::Config& bo);
126  // void toAron(arondto::TaskspaceMixedImpedanceVelocityControllerConfig& dto,
127  // const TaskspaceMixedImpedanceVelocityController::Config& bo);
128  //
129  // void fromAron(const arondto::TaskspaceMixedImpedanceVelocityControllerConfigDict& dto,
130  // TaskspaceMixedImpedanceVelocityController::ConfigDict& bo);
131  // void toAron(arondto::TaskspaceMixedImpedanceVelocityControllerConfigDict& dto,
132  // const TaskspaceMixedImpedanceVelocityController::ConfigDict& bo);
133  //
134  // /// TaskspaceAdmittanceController
135  // void fromAron(const arondto::TaskspaceAdmittanceControllerConfig& dto,
136  // TaskspaceAdmittanceController::Config& bo);
137  // void toAron(arondto::TaskspaceAdmittanceControllerConfig& dto,
138  // const TaskspaceAdmittanceController::Config& bo);
139  //
140  // void fromAron(const arondto::TaskspaceAdmittanceControllerConfigDict& dto,
141  // TaskspaceAdmittanceController::ConfigDict& bo);
142  // void toAron(arondto::TaskspaceAdmittanceControllerConfigDict& dto,
143  // const TaskspaceAdmittanceController::ConfigDict& bo);
144  //
145  // void fromAron(const arondto::KeypointControllerConfig& dto,
146  // KeypointsImpedanceController::Config& bo);
147  // void toAron(arondto::KeypointControllerConfig& dto,
148  // const KeypointsImpedanceController::Config& bo);
149 
150 } // namespace armarx::control::common::control_law
151 
153 {
154  // /// ListViaPoint
155  // void fromAron(const arondto::ListViaPoint& dto, MP::ListViaPoint& bo);
156  // void toAron(arondto::ListViaPoint& dto, const MP::ListViaPoint& bo);
157  // void fromAron(const arondto::DictViaPoint& dto, MP::DictViaPoint& bo);
158 
159  // /// MPConfig
160  // void fromAron(const arondto::MPConfig& dto, MP::MPConfig& bo);
161  // void toAron(arondto::MPConfig& dto, const MP::MPConfig& bo);
162 
163  // /// MPTraj
164  // void fromAron(const arondto::MPTraj& dto, MPTraj& bo);
165  // void toAron(arondto::MPTraj& dto, const MPTraj& bo);
166 
167  // // void fromAron(const arondto::MPTrajs& dto, MPTrajs& bo);
168  // // void toAron(arondto::MPTrajs& dto, const MPTrajs& bo);
169 
170  // // void fromAron(const arondto::MultiMPTrajs& dto, MultiMPTrajs& bo);
171  // // void toAron(arondto::MultiMPTrajs& dto, const MultiMPTrajs& bo);
172 
173  // /// MPListConfig
174  // void fromAron(const arondto::MPListConfig& dto, MP::MPListConfig& bo);
175  // void toAron(arondto::MPListConfig& dto, const MP::MPListConfig& bo);
176 } // namespace armarx::control::common::mp
TaskspaceMixedImpedanceVelocityController.h
TaskspaceImpedanceController.h
NlohmannJSONReaderWithoutTypeCheck.h
FTSensor.h
armarx::control::common::ft
This file is part of ArmarX.
Definition: aron_conversions.cpp:29
armarx::control::common::mp
This file is part of ArmarX.
Definition: aron_conversions.cpp:331
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
MP.h
armarx::readFromJson
AronDTO readFromJson(const std::filesystem::path &filename)
Definition: aron_conversions.h:75
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::aron::data::reader::NlohmannJSONReaderWithoutTypeCheck
Definition: NlohmannJSONReaderWithoutTypeCheck.h:35
KeypointsImpedanceController.h
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
filename
std::string filename
Definition: VisualizationRobot.cpp:83
TaskspaceAdmittanceController.h
armarx::fromAronDict
T fromAronDict(const ::armarx::aron::data::dto::DictPtr &dto)
Definition: aron_conversions.h:49
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
SafetyTaskspaceImpedanceController.h
armarx::fromAron
void fromAron(const arondto::PackagePath &dto, PackageFileLocation &bo)
armarx::toAron
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::toAronDict
::armarx::aron::data::dto::DictPtr toAronDict(const BOType &bo)
Definition: aron_conversions.h:65
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::aron::bo
const std::optional< BoT > & bo
Definition: aron_conversions.h:168