SharedMemoryController.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 * @package ...
17 * @author Andre Meixner ( andre dot meixner at kit dot edu )
18 * @date 2024
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <SimoxUtility/math/convert/mat4f_to_pos.h>
26#include <SimoxUtility/math/convert/mat4f_to_quat.h>
27#include <SimoxUtility/math/convert/pos_quat_to_mat4f.h>
28
29#include <ArmarXCore/interface/serialization/Eigen/Eigen_fdi.h>
30
32
33#include "SharedMemory.h"
34
35
36#define MAX_N 2 // Maximum number of nodesets
37#define TS6_DIM_N (MAX_N * 6)
38#define TS7_DIM_N (MAX_N * 7)
39#define MAX_JS_DIM 8 // Maximum allowed number of joint space size
40#define MAX_JS_DIM_N (MAX_N * MAX_JS_DIM)
41#define MAX_HC_DIM 4 // Maximum allowed number of joints for hand configuration
42#define MAX_HC_DIM_N (MAX_N * MAX_HC_DIM)
43
45{
47 {
48 int32_t n_limbs;
49 // x1, y1, z1, qx1, qy1, qz1, qw1, x2, ... (with position in mm)
51 // x1, y1, z1, roll1, pitch1, yaw1, x2, ...
53 // x1, y1, z1, qx1, qy1, qz1, qw1 (with position in mm)
55 // x1, y1, z1, qx1, qy1, qz1, qw1, x2, ... (with position in mm)
57
60
62
63 // In radian or mm
66
67 // In Radian
69
71 bool rtSafe;
72
73 inline static size_t
75 {
76 return sizeof(int32_t) + (sizeof(float) * TS7_DIM_N) + (sizeof(float) * TS6_DIM_N) +
77 (sizeof(float) * 7) + (sizeof(float) * TS7_DIM_N) + (sizeof(float) * TS6_DIM_N) +
78 (sizeof(float) * TS6_DIM_N) + (sizeof(float) * TS6_DIM_N) +
79 (sizeof(float) * MAX_JS_DIM_N) + (sizeof(float) * MAX_JS_DIM_N) +
80 (sizeof(float) * MAX_HC_DIM_N) + sizeof(float) + sizeof(bool);
81 }
82 };
83
85 {
86 // x1, y1, z1, qx1, qy1, qz1, qw1, x2, ... (with position in mm)
88 // x1, y1, z1, roll1, pitch1, yaw1, x2, ... (currently has no effect)
90 // x1, y1, z1, qx1, qy1, qz1, qw1 (with position in mm)
92
95
96 // In radian or mm
98
99 // In radian
101
102 bool useJointAngles = false;
103 bool initialized = false;
104
105 inline static size_t
107 {
108 return (sizeof(float) * TS7_DIM_N) + (sizeof(float) * TS6_DIM_N) + (sizeof(float) * 7) +
109 (sizeof(float) * TS6_DIM_N) + (sizeof(float) * TS6_DIM_N) +
110 (sizeof(float) * MAX_JS_DIM_N) + (sizeof(float) * MAX_HC_DIM_N) + sizeof(bool) +
111 sizeof(bool);
112 }
113 };
114
115 template <typename NJointTaskspaceController>
116 concept ContainsStiffness = requires {
118 { std::declval<typename NJointTaskspaceController::Config>().kpImpedance };
119 };
120
121 template <typename NJointTaskspaceController>
123 {
124 public:
126 const armarx::NJointControllerConfigPtr& config,
127 const VirtualRobot::RobotPtr& robot);
128
129 void init();
130
131 void writeConfig();
132
133 //overwritten for specific templates, see .cpp
134 std::string
135 getClassName(const Ice::Current&) const final
136 {
137 return "NJointSharedMemoryTaskspaceUnknownController";
138 }
139
140 void
142 const typename NJointTaskspaceController::Config& config,
143 unsigned int index) const
144 {
145 // Default do nothing
146 }
147
148 void
150 typename NJointTaskspaceController::Config& config,
151 unsigned int index) const
152 {
153 // Default do nothing
154 }
155
156 void
158 {
159 // Default do nothing
160 }
161
162 void
164 {
165 // Default do nothing
166 }
167
168 void
170 const typename NJointTaskspaceController::Config& config,
171 unsigned int index) const
173 {
174 std::memcpy(
175 writeData.kpImpedance + (index * 6), config.kpImpedance.data(), sizeof(float) * 6);
176 std::memcpy(
177 writeData.kdImpedance + (index * 6), config.kdImpedance.data(), sizeof(float) * 6);
178 }
179
180 void
182 typename NJointTaskspaceController::Config& config,
183 unsigned int index) const
185 {
186 std::memcpy(
187 config.kpImpedance.data(), readData.kpImpedance + (index * 6), sizeof(float) * 6);
188
189 std::memcpy(
190 config.kdImpedance.data(), readData.kdImpedance + (index * 6), sizeof(float) * 6);
191 }
192
193 void
196 {
197 // TODO: Add concept that checks if it contains coordinator
198
199 if (this->coordinator)
200 {
201 this->coordinator->updateNonRt();
202
203 Eigen::Matrix<float, 7, 1> currentCoordinatedPose;
204 currentCoordinatedPose.head(3) =
205 simox::math::mat4f_to_pos(this->coordinator->dataNonRt.currentPose);
206 currentCoordinatedPose.tail(4) =
207 simox::math::mat4f_to_quat(this->coordinator->dataNonRt.currentPose)
208 .coeffs(); // x,y,z,w
209 std::memcpy(writeData.currentCoordinatedPose,
210 currentCoordinatedPose.data(),
211 sizeof(float) * 7);
212 }
213 }
214
215 void
218 {
219 // TODO: Add concept that checks if it contains coordinator
220
221 if (this->coordinator)
222 {
223 Eigen::Map<const Eigen::Matrix<float, 7, 1>> desiredCoordinatedPose(
224 readData.desiredCoordinatedPose);
225 const Eigen::Vector3f& pos = desiredCoordinatedPose.head(3);
226 const Eigen::Vector4f& orientation = desiredCoordinatedPose.tail(4);
227 const Eigen::Matrix4f pose =
228 simox::math::pos_quat_to_mat4f(pos, Eigen::Quaternionf(orientation));
229 this->coordinator->cfgInNonRt.desiredPose = pose;
230
231 this->coordinator->commitNonRt();
232 }
233 }
234
235 void additionalTask() final;
236
237 protected:
240 };
241
242} // namespace armarx::control::njoint_controller::task_space
#define float
Definition 16_Level.h:22
uint8_t index
#define MAX_JS_DIM_N
#define TS6_DIM_N
#define TS7_DIM_N
#define MAX_HC_DIM_N
void writeAdditonalDataToSM(ToSharedMemory &writeData, const typename NJointTaskspaceController::Config &config, unsigned int index) const
void readAdditonalDataFromSM(const FromSharedMemory &readData, typename NJointTaskspaceController::Config &config, unsigned int index) const
void writeAdditonalDataToSM(ToSharedMemory &writeData, const typename NJointTaskspaceController::Config &config, unsigned int index) const
NJointSharedMemoryTaskspaceController(const armarx::RobotUnitPtr &robotUnit, const armarx::NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &robot)
void readAdditonalDataFromSM(const FromSharedMemory &readData, typename NJointTaskspaceController::Config &config, unsigned int index) const
std::shared_ptr< common::coordination::SyncCoordination > coordinator
Definition Base.h:224
NJointTaskspaceController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition Base.cpp:138
typename NJointTaskspaceControllerType::Config Config
Definition Base.h:63
Quaternion< float, 0 > Quaternionf
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
IceUtil::Handle< class RobotUnit > RobotUnitPtr
Definition FTSensor.h:34