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#include <fstream>
26
27#include <SimoxUtility/json/json.hpp>
28
31
32// #include <armarx/control/common/control_law/KeypointsImpedanceController.h>
33// #include <armarx/control/common/control_law/SafetyTaskspaceImpedanceController.h>
34// #include <armarx/control/common/control_law/TaskspaceAdmittanceController.h>
35// #include <armarx/control/common/control_law/TaskspaceImpedanceController.h>
36// #include <armarx/control/common/control_law/TaskspaceMixedImpedanceVelocityController.h>
37// #include <armarx/control/common/control_law/aron/KeypointControllerConfig.aron.generated.h>
38// #include <armarx/control/common/control_law/aron/SafetyTaskspaceImpedanceControllerConfig.aron.generated.h>
39// #include <armarx/control/common/control_law/aron/TaskspaceAdmittanceControllerConfig.aron.generated.h>
40// #include <armarx/control/common/control_law/aron/TaskspaceImpedanceControllerConfig.aron.generated.h>
41// #include <armarx/control/common/control_law/aron/TaskspaceMixedImpedanceVelocityControllerConfig.aron.generated.h>
42// #include <armarx/control/common/ft/FTSensor.h>
43// #include <armarx/control/common/ft/aron/FTConfig.aron.generated.h>
44// #include <armarx/control/common/mp/MP.h>
45// #include <armarx/control/common/mp/aron/MPConfig.aron.generated.h>
46
47namespace armarx
48{
49 template <typename AronType, typename T>
50 T
51 fromAronDict(const ::armarx::aron::data::dto::DictPtr& dto)
52 {
53 static_assert(
54 std::is_base_of_v<armarx::aron::codegenerator::cpp::AronGeneratedClass, AronType>,
55 "AronType must be an ARON generated type");
56
57 const auto dtoConfig = AronType::FromAron(dto);
58
59 T config;
60 fromAron(dtoConfig, config);
61
62 return config;
63 }
64
65 template <typename T, typename BOType>
67 toAronDict(const BOType& bo)
68 {
69 T aronDTO;
70 toAron(aronDTO, bo);
71
72 return aronDTO.toAronDTO();
73 }
74
75 template <typename AronDTO>
76 AronDTO
77 readFromJson(const std::filesystem::path& filename)
78 {
79 ARMARX_CHECK(std::filesystem::is_regular_file(filename)) << filename;
80
81 // ARMARX_INFO << "Loading config from file `" << filename << "`.";
82 std::ifstream ifs{filename};
83
84 nlohmann::json jsonConfig;
85 ifs >> jsonConfig;
86 auto dto = AronDTO();
87
89 dto.read(reader, jsonConfig);
90 return dto;
91 }
92
93 template <typename AronDTO, typename BO>
94 BO
95 readFromJson(const std::filesystem::path& filename)
96 {
97 auto dto = readFromJson<AronDTO>(filename);
98 BO bo;
99 fromAron(dto, bo);
100 return bo;
101 }
102} // namespace armarx
103
105{
106 // void fromAron(const arondto::FTConfig& dto, FTSensor::FTConfig& bo);
107 // void toAron(arondto::FTConfig& dto, const FTSensor::FTConfig& bo);
108} // namespace armarx::control::common::ft
109
111{
112
113 /// TaskspaceImpedanceController
114 // /// dto: data transfer object; bo: business object
115 // void fromAron(const arondto::TaskspaceImpedanceControllerConfig& dto,
116 // TaskspaceImpedanceController::Config& bo);
117 // void toAron(arondto::TaskspaceImpedanceControllerConfig& dto,
118 // const TaskspaceImpedanceController::Config& bo);
119
120 // void fromAron(const arondto::TaskspaceImpedanceControllerConfigDict& dto,
121 // TaskspaceImpedanceController::ConfigDict& bo);
122 // void toAron(arondto::TaskspaceImpedanceControllerConfigDict& dto,
123 // const TaskspaceImpedanceController::ConfigDict& bo);
124
125 // /// TaskspaceMixedImpedanceVelocityController
126 // void fromAron(const arondto::TaskspaceMixedImpedanceVelocityControllerConfig& dto,
127 // TaskspaceMixedImpedanceVelocityController::Config& bo);
128 // void toAron(arondto::TaskspaceMixedImpedanceVelocityControllerConfig& dto,
129 // const TaskspaceMixedImpedanceVelocityController::Config& bo);
130 //
131 // void fromAron(const arondto::TaskspaceMixedImpedanceVelocityControllerConfigDict& dto,
132 // TaskspaceMixedImpedanceVelocityController::ConfigDict& bo);
133 // void toAron(arondto::TaskspaceMixedImpedanceVelocityControllerConfigDict& dto,
134 // const TaskspaceMixedImpedanceVelocityController::ConfigDict& bo);
135 //
136 // /// TaskspaceAdmittanceController
137 // void fromAron(const arondto::TaskspaceAdmittanceControllerConfig& dto,
138 // TaskspaceAdmittanceController::Config& bo);
139 // void toAron(arondto::TaskspaceAdmittanceControllerConfig& dto,
140 // const TaskspaceAdmittanceController::Config& bo);
141 //
142 // void fromAron(const arondto::TaskspaceAdmittanceControllerConfigDict& dto,
143 // TaskspaceAdmittanceController::ConfigDict& bo);
144 // void toAron(arondto::TaskspaceAdmittanceControllerConfigDict& dto,
145 // const TaskspaceAdmittanceController::ConfigDict& bo);
146 //
147 // void fromAron(const arondto::KeypointControllerConfig& dto,
148 // KeypointsImpedanceController::Config& bo);
149 // void toAron(arondto::KeypointControllerConfig& dto,
150 // const KeypointsImpedanceController::Config& bo);
151
152} // namespace armarx::control::common::control_law
153
155{
156 // /// ListViaPoint
157 // void fromAron(const arondto::ListViaPoint& dto, MP::ListViaPoint& bo);
158 // void toAron(arondto::ListViaPoint& dto, const MP::ListViaPoint& bo);
159 // void fromAron(const arondto::DictViaPoint& dto, MP::DictViaPoint& bo);
160
161 // /// MPConfig
162 // void fromAron(const arondto::MPConfig& dto, MP::MPConfig& bo);
163 // void toAron(arondto::MPConfig& dto, const MP::MPConfig& bo);
164
165 // /// MPTraj
166 // void fromAron(const arondto::MPTraj& dto, MPTraj& bo);
167 // void toAron(arondto::MPTraj& dto, const MPTraj& bo);
168
169 // // void fromAron(const arondto::MPTrajs& dto, MPTrajs& bo);
170 // // void toAron(arondto::MPTrajs& dto, const MPTrajs& bo);
171
172 // // void fromAron(const arondto::MultiMPTrajs& dto, MultiMPTrajs& bo);
173 // // void toAron(arondto::MultiMPTrajs& dto, const MultiMPTrajs& bo);
174
175 // /// MPListConfig
176 // void fromAron(const arondto::MPListConfig& dto, MP::MPListConfig& bo);
177 // void toAron(arondto::MPListConfig& dto, const MP::MPListConfig& bo);
178} // namespace armarx::control::common::mp
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
::IceInternal::Handle< Dict > DictPtr
This file is part of ArmarX.
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
AronDTO readFromJson(const std::filesystem::path &filename)
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)
::armarx::aron::data::dto::DictPtr toAronDict(const BOType &bo)
void fromAron(const arondto::PackagePath &dto, PackageFileLocation &bo)
T fromAronDict(const ::armarx::aron::data::dto::DictPtr &dto)