MixedImpedanceVelocityController.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 Jianfeng Gao ( jianfeng dot gao 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 <VirtualRobot/VirtualRobot.h>
26
30
31#include <armarx/control/common/common.aron.generated.h>
36#include <armarx/control/njoint_controller/task_space/ControllerInterface.h>
37
39{
40 namespace law = armarx::control::common::control_law;
41
42 /**
43 * @defgroup Library-NJointTaskspaceMixedImpedanceVelocityController NJointTaskspaceMixedImpedanceVelocityController
44 * @ingroup Library-RobotUnit-NJointControllers
45 * A description of the library NJointTaskspaceMixedImpedanceVelocityController.
46 *
47 * @class NJointTaskspaceMixedImpedanceVelocityController
48 * @ingroup Library-NJointTaskspaceMixedImpedanceVelocityController
49 * @brief Brief description of class NJointTaskspaceMixedImpedanceVelocityController.
50 *
51 * Detailed description of class NJointTaskspaceMixedImpedanceVelocityController.
52 */
54 virtual public NJointController,
57 {
58 public:
59 using ConfigPtrT = ConfigurableNJointControllerConfigPtr;
60 using Config = law::TaskspaceMixedImpedanceVelocityController::Config;
61 using ConfigDict = law::TaskspaceMixedImpedanceVelocityController::ConfigDict;
62
64 using PoseFrameMode = armarx::control::common::arondto::PoseFrameMode;
65
66 // using UserRTStatus = law::TaskspaceMixedImpedanceVelocityController::
67
68 struct ArmData
69 {
70 /// devices
72 std::vector<ControlTarget1DoFActuatorTorque*> targetsTorque;
73 std::vector<ControlTarget1DoFActuatorVelocity*> targetsVel;
74
75 std::vector<size_t> torqueControlledIndex;
76 std::vector<size_t> velocityControlledIndex;
77
78 /// names
79 std::string kinematicChainName;
80 std::vector<std::string> jointNames;
81
82 /// controller (maths)
83 law::TaskspaceMixedImpedanceVelocityController controller;
84
85 /// set data containers and buffers
86 double nonRTAccumulateTime = 0.0;
87 double nonRTDeltaT = 0.0;
88
95
101
102 /// flags
103 std::atomic_bool rtFirstRun{true};
104 std::atomic_bool rtReady{false};
105 std::atomic_bool reInitPreActivate{false};
106
107 /// robot
109 };
110
111 using ArmPtr = std::unique_ptr<ArmData>;
112
114 const NJointControllerConfigPtr& config,
116
117 std::string getClassName(const Ice::Current& = Ice::emptyCurrent) const override;
118
119 void rtRun(const IceUtil::Time& sensorValuesTimestamp,
120 const IceUtil::Time& timeSinceLastIteration) override;
121
122 /// NJointController interface
123 void updateConfig(const ::armarx::aron::data::dto::DictPtr& dto,
124 const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
125 bool updateTargetPose(const TargetPoseMap& targetPoseMap,
126 const TargetNullspaceMap& targetNullspaceMap,
127 const Ice::Current& = Ice::emptyCurrent) override;
129 getConfig(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
131 getRTStatus(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
132
133 Ice::FloatSeq getTCPVel(const std::string& rns,
134 const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
135
136 Ice::DoubleSeq
137 getCurrentTCPPose(const std::string& nodeSetName,
138 const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
139
140 /// ft sensor
141 void calibrateFTSensor(const Ice::Current&) override;
142 void
143 enableSafeGuardForceTorque(const std::string& nodeSetName,
144 const bool forceGuard,
145 const bool torqueGuard,
146 const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
147 bool isSafeForceTorque(const std::string& nodeSetName,
148 const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
149 void useCoordinator(const std::string& type,
150 const ::armarx::aron::data::dto::DictPtr& dto,
151 const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
152 void disableCoordinator(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
153
154 public:
157 const std::map<std::string, ConstControlDevicePtr>&,
158 const std::map<std::string, ConstSensorDevicePtr>&);
159
161
162 protected:
163 virtual void additionalTask();
164 std::tuple<bool, bool> additionalTaskUpdateStatus();
166 void validateConfigData(Config& config, ArmPtr& arm);
167 void onPublish(const SensorAndControl&,
169 const DebugObserverInterfacePrx&) override;
171
172 void limbInit(const std::string nodeSetName,
173 ArmPtr& arm,
174 Config& cfg,
175 VirtualRobot::RobotPtr& nonRtRobotPtr);
176 void limbNonRT(ArmPtr& arm);
177 void limbRT(ArmPtr& arm, const double deltaT);
178 void limbRTUpdateStatus(ArmPtr& arm, const double deltaT);
179 void limbRTSetTarget(ArmPtr& arm,
180 const size_t nDoFTorque,
181 const size_t nDoFVelocity,
182 const Eigen::VectorXf& targetTorque,
183 const Eigen::VectorXf& targetVelocity);
184 void limbPublish(ArmPtr& arm, const DebugObserverInterfacePrx& debugObs);
185 void limbReInit(ArmPtr& arm);
187
188 /// coordinator
189 void rtRunCoordinator(double deltaT);
190 void updateInputData(const std::string& key,
191 const Eigen::Matrix4f& targetPose,
192 const PoseFrameMode& targetPoseMode,
193 const Eigen::Matrix4f& pose,
194 const Eigen::Vector6f& vel,
195 const Eigen::Vector6f& ft,
196 const Eigen::Vector6f& stiffness);
197
198 protected:
199 std::map<std::string, ArmPtr> limb;
204 std::map<std::string, VirtualRobot::RobotNodeSetPtr> controllableNodeSets;
205
206 /// coordinator
207 std::atomic_bool coordinatorEnabled = false;
208 std::shared_ptr<common::coordination::SyncCoordination> coordinator = nullptr;
209 std::map<std::string, common::coordination::InputData> coordinatorInputData;
210
211 protected:
212 /// NJointControllerBase interface
213 void onInitNJointController() override;
214 void rtPreActivateController() override;
215 void rtPostDeactivateController() override;
216 };
217} // namespace armarx::control::njoint_controller::task_space
Provides a ready-to-use ArViz client arviz as member variable.
A simple triple buffer for lockfree comunication between a single writer and a single reader.
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
static WidgetDescription::WidgetPtr GenerateConfigDescription(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &, const std::map< std::string, ConstSensorDevicePtr > &)
--------------------------------— GUI Widget ------------------------------------------—
Ice::DoubleSeq getCurrentTCPPose(const std::string &nodeSetName, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
::armarx::aron::data::dto::DictPtr getConfig(const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Ice::FloatSeq getTCPVel(const std::string &rns, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
void useCoordinator(const std::string &type, const ::armarx::aron::data::dto::DictPtr &dto, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
bool isSafeForceTorque(const std::string &nodeSetName, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
-----------------------------— Other interaces ----------------------------------------—
void limbRTSetTarget(ArmPtr &arm, const size_t nDoFTorque, const size_t nDoFVelocity, const Eigen::VectorXf &targetTorque, const Eigen::VectorXf &targetVelocity)
void enableSafeGuardForceTorque(const std::string &nodeSetName, const bool forceGuard, const bool torqueGuard, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
void updateInputData(const std::string &key, const Eigen::Matrix4f &targetPose, const PoseFrameMode &targetPoseMode, const Eigen::Matrix4f &pose, const Eigen::Vector6f &vel, const Eigen::Vector6f &ft, const Eigen::Vector6f &stiffness)
some method for coordinator
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
void limbInit(const std::string nodeSetName, ArmPtr &arm, Config &cfg, VirtualRobot::RobotPtr &nonRtRobotPtr)
void updateConfig(const ::armarx::aron::data::dto::DictPtr &dto, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
NJointController interface.
bool updateTargetPose(const TargetPoseMap &targetPoseMap, const TargetNullspaceMap &targetNullspaceMap, const Ice::Current &=Ice::emptyCurrent) override
NJointTaskspaceMixedImpedanceVelocityController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
void rtPreActivateController() override
This function is called before the controller is activated.
void limbRTUpdateStatus(ArmPtr &arm, const double deltaT)
-----------------------------— Real time cotnrol --------------------------------------—
Matrix< float, 6, 1 > Vector6f
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
::IceInternal::Handle< Dict > DictPtr
std::shared_ptr< HandControlBase > HandControlPtr
dictionary< string, Ice::FloatSeq > TargetNullspaceMap
dictionary< string, FloatSeqSeq > TargetPoseMap
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::map< std::string, VariantBasePtr > StringVariantBaseMap
SynchronousNJointController NJointController
IceUtil::Handle< class RobotUnit > RobotUnitPtr
Definition FTSensor.h:34
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl