SyncCoordination.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 Jianfeng Gao ( jianfeng dot gao at kit dot edu )
17 * @date 2025
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <atomic>
25#include <map>
26#include <mutex>
27#include <string>
28
30
32#include <RobotAPI/interface/aron/Aron.h>
33
34#include <armarx/control/common/common.aron.generated.h>
36#include <armarx/control/common/coordination/aron/CoordinationConfig.aron.generated.h>
37
39{
40 /* experimental codee for sync mode
41 * */
43 {
44 public:
45 using Config = arondto::SyncModeConfig;
46 // using PoseFrameMode = armarx::control::common::arondto::pose_frame_mode_details::Enum;
47
48 SyncCoordination(const ::armarx::aron::data::dto::DictPtr& dto);
49 ~SyncCoordination() override = default;
50
51 struct Data
52 {
53 /// Note: all positions in matrix4f poses are in milli-meter
54 /// but in grasp matrix, it must be in meter
55 double deltaT = 0.0;
58 Eigen::Matrix4f virtualPose;
59
60 Eigen::Matrix4f targetPose;
61 Eigen::Matrix4f currentPose;
63 Eigen::VectorXf bimanualVel; // 12-d vec
64
66 Eigen::VectorXf bimanualFT;
67 // Eigen::VectorXf wrenchTarget;
68 Eigen::Vector6f deltaPosForWrenchControlL; // should be in milli-meter
70
71 /// Temporal variables to avoid memory allocation
72 Eigen::Vector3f rvec;
74 Eigen::Matrix3f oriError;
78
79 /// vectors represented in the object local frame
82
83 Eigen::MatrixXf graspMatrix; // should be (6, 12), position in meter
84 Eigen::MatrixXf pinvGraspMatrixT;
85
86 // Eigen::Matrix3f fixedLeftRightRotOffset;
87 Eigen::Matrix3f dOriInObjL; // the {obj}^T_{left}
88 Eigen::Matrix3f dOriInObjR; // the {obj}^T_{right}
89 Eigen::Matrix3f dOriInTCPL; // the {obj}^T_{left}
90 Eigen::Matrix3f dOriInTCPR; // the {obj}^T_{right}
91
92 void updateGraspMatrix(const bool leftAsLeader,
93 const bool rightAsLeader,
94 const bool followerIsolation);
95 void reset(const Eigen::Matrix4f& desiredPose,
96 Eigen::Matrix4f& leftPose,
97 Eigen::Matrix4f& rightPose,
98 PoseFrameMode leftPoseMode,
99 PoseFrameMode rightPoseMode);
100 void resetGraspVariableLeft(const Eigen::Matrix4f& desiredPose,
101 Eigen::Matrix4f& leftPose,
102 PoseFrameMode leftPoseMode);
103 void resetGraspVariableRight(const Eigen::Matrix4f& desiredPose,
104 Eigen::Matrix4f& rightPose,
105 PoseFrameMode rightPoseMode);
106 };
107
108 void rtPreActivate() final;
109 void reset(std::map<std::string, Eigen::Matrix4f>& initPose) override;
110 void runRT(std::map<std::string, InputData>& input, double deltaT) override;
111 void updateNonRt() override;
112 void commitNonRt() override;
113
115
116 void updateConfig(const ::armarx::aron::data::dto::DictPtr& dto,
117 bool flagResetRt = false) override;
118 void updateTargetPose(const Eigen::Matrix4f& targetPose);
119
120 // bool isInitialized() override;
121 // const std::vector<std::string>& getNodesetList();
122 // std::string& getLeftNodesetName();
123 // std::string& getRightNodesetName();
124
125 /// TODO private?
126 mutable std::recursive_mutex mtx_data_non_rt;
130
131 Config cfgInNonRt; /// for non rt
132
133 private:
134 Data dataRt_;
135 TripleBuffer<Data> bufferDataRtToNonRt_;
136
137 Config cfg_; /// for user
138 Config cfgInRT_; /// for rt
139 TripleBuffer<Config> bufferNonRtCfgToRt_;
140 TripleBuffer<Config> bufferUserCfgToNonRt_;
141 std::atomic_bool cfgBufferInitialized_{false};
142
143 static void computeWrenchControl(Eigen::Vector6f& deltaPos,
144 const Eigen::Vector6f& wrenchTarget,
145 const Eigen::Vector6f& stiffness);
146 static void setObjPoseFromHandPoses(Eigen::Matrix4f& objPose,
147 const Eigen::Matrix4f& poseL,
148 const Eigen::Matrix4f& poseR);
149
150 void updateCurrentPose(Eigen::Matrix4f& leftPose, Eigen::Matrix4f& rightPose);
151 // static void averageSE3(const Eigen::Matrix4f& pose1, const Eigen::Matrix4f& pose2, Eigen::Matrix4f& pose_avg);
152 };
153
154} // namespace armarx::control::common::coordination
A simple triple buffer for lockfree comunication between a single writer and a single reader.
void reset(std::map< std::string, Eigen::Matrix4f > &initPose) override
SyncCoordination(const ::armarx::aron::data::dto::DictPtr &dto)
void runRT(std::map< std::string, InputData > &input, double deltaT) override
void updateTargetPose(const Eigen::Matrix4f &targetPose)
void updateConfig(const ::armarx::aron::data::dto::DictPtr &dto, bool flagResetRt=false) override
Matrix< float, 6, 1 > Vector6f
armarx::control::common::arondto::PoseFrameMode PoseFrameMode
This file offers overloads of toIce() and fromIce() functions for STL container types.
void updateGraspMatrix(const bool leftAsLeader, const bool rightAsLeader, const bool followerIsolation)
void resetGraspVariableLeft(const Eigen::Matrix4f &desiredPose, Eigen::Matrix4f &leftPose, PoseFrameMode leftPoseMode)
double deltaT
Note: all positions in matrix4f poses are in milli-meter but in grasp matrix, it must be in meter.
Eigen::Vector3f rvec
Temporal variables to avoid memory allocation.
void resetGraspVariableRight(const Eigen::Matrix4f &desiredPose, Eigen::Matrix4f &rightPose, PoseFrameMode rightPoseMode)
Eigen::Vector3f obj2TcpInMeterL
vectors represented in the object local frame