ImpedanceController.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 2021
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/Robot.h>
26 
30 
34 #include <armarx/control/njoint_controller/task_space/ControllerInterface.h>
35 
37 {
39 
40  /**
41  * @defgroup Library-NJointTaskspaceImpedanceController NJointTaskspaceImpedanceController
42  * @ingroup Library-RobotUnit-NJointControllers
43  * A description of the library NJointTaskspaceImpedanceController.
44  *
45  * @class NJointTaskspaceImpedanceController
46  * @ingroup Library-NJointTaskspaceImpedanceController
47  * @brief Brief description of class NJointTaskspaceImpedanceController.
48  *
49  * Detailed description of class NJointTaskspaceImpedanceController.
50  */
52  virtual public NJointController,
54  {
55  public:
56  using ConfigPtrT = ConfigurableNJointControllerConfigPtr;
59  using RtStatus = law::TaskspaceImpedanceController::RtStatus;
60 
61  struct ArmData
62  {
63  /// devices
65  std::vector<ControlTarget1DoFActuatorTorque*> targets;
66 
67  /// names
68  std::string kinematicChainName;
69  std::vector<std::string> jointNames;
70 
71  /// controller (maths)
73 
74  /// set data containers and buffers
81 
87 
88  /// flags
89  std::atomic_bool rtFirstRun{true};
90  std::atomic_bool rtReady{false};
91  std::atomic_bool reInitPreActivate{false};
92 
93  /// robot
95  };
96 
97  using ArmPtr = std::unique_ptr<ArmData>;
98 
100  const NJointControllerConfigPtr& config,
101  const VirtualRobot::RobotPtr&);
102 
103  std::string getClassName(const Ice::Current& = Ice::emptyCurrent) const override;
104 
105  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
106  const IceUtil::Time& timeSinceLastIteration) override;
107 
108  /// NJointController interface
110  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
111  bool updateTargetPose(const TargetPoseMap& targetPoseMap,
112  const TargetNullspaceMap& targetNullspaceMap,
113  const Ice::Current& = Ice::emptyCurrent) override;
115  getConfig(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
116 
117  Ice::FloatSeq getTCPVel(const std::string& rns,
118  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
119 
120  /// ft sensor
121  void calibrateFTSensor(const Ice::Current&) override;
122  void
123  enableSafeGuardForceTorque(const std::string& nodeSetName,
124  const bool forceGuard,
125  const bool torqueGuard,
126  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
127  bool isSafeForceTorque(const std::string& nodeSetName,
128  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
129 
130  public:
133  const std::map<std::string, ConstControlDevicePtr>&,
134  const std::map<std::string, ConstSensorDevicePtr>&);
135 
137 
138  protected:
139  virtual void additionalTask();
142  void validateConfigData(Config& config, ArmPtr& arm);
143  void onPublish(const SensorAndControl&,
145  const DebugObserverInterfacePrx&) override;
146 
147  void limbInit(const std::string nodeSetName,
148  ArmPtr& arm,
149  Config& cfg,
150  VirtualRobot::RobotPtr& nonRtRobotPtr);
151  void limbNonRT(ArmPtr& arm);
152  void limbRT(ArmPtr& arm, const double deltaT);
153  void limbRTUpdateStatus(ArmPtr& arm, const double deltaT);
154  void limbRTSetTarget(ArmPtr& arm, const Eigen::VectorXf& targetTorque);
155  void limbPublish(ArmPtr& arm, const DebugObserverInterfacePrx& debugObs);
156  void limbReInit(ArmPtr& arm);
157  void handleRTNotSafeInNonRT();
158 
159  protected:
160  std::map<std::string, ArmPtr> limb;
162  RobotUnitPtr robotUnit;
165  std::map<std::string, VirtualRobot::RobotNodeSetPtr> controllableNodeSets;
166 
167  protected:
168  /// NJointControllerBase interface
169  void onInitNJointController() override;
170  void rtPreActivateController() override;
171  void rtPostDeactivateController() override;
172  };
173 } // namespace armarx::control::njoint_controller::task_space
HandControlBase.h
armarx::control::NJointTaskspaceImpedanceControllerInterface
Definition: ControllerInterface.ice:48
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::bufferConfigRtToOnPublish
TripleBuffer< Config > bufferConfigRtToOnPublish
Definition: ImpedanceController.h:79
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::bufferConfigNonRtToRt
TripleBuffer< Config > bufferConfigNonRtToRt
Definition: ImpedanceController.h:78
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController
Brief description of class NJointTaskspaceImpedanceController.
Definition: ImpedanceController.h:51
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::bufferConfigUserToNonRt
TripleBuffer< Config > bufferConfigUserToNonRt
Definition: ImpedanceController.h:77
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::bufferRtStatusToUser
TripleBuffer< RtStatus > bufferRtStatusToUser
Definition: ImpedanceController.h:85
armarx::control::njoint_controller::core::HandControlPtr
std::shared_ptr< HandControlBase > HandControlPtr
Definition: HandControlBase.h:121
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::limbRT
void limbRT(ArmPtr &arm, const double deltaT)
Definition: ImpedanceController.cpp:278
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::GenerateConfigFromVariants
static ConfigPtrT GenerateConfigFromVariants(const StringVariantBaseMap &values)
Definition: ImpedanceController.cpp:654
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::handleRTNotSafeInNonRT
void handleRTNotSafeInNonRT()
Definition: ImpedanceController.cpp:210
RobotUnit.h
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::GenerateConfigDescription
static WidgetDescription::WidgetPtr GenerateConfigDescription(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &, const std::map< std::string, ConstSensorDevicePtr > &)
--------------------------------— GUI Widget ------------------------------------------—
Definition: ImpedanceController.cpp:621
TaskspaceImpedanceController.h
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData
Definition: ImpedanceController.h:61
armarx::SynchronousNJointController
Definition: NJointControllerBase.h:1145
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::rtStatus
RtStatus rtStatus
Definition: ImpedanceController.h:83
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::RtStatus
law::TaskspaceImpedanceController::RtStatus RtStatus
Definition: ImpedanceController.h:59
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::hands
core::HandControlPtr hands
Definition: ImpedanceController.h:164
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::onInitNJointController
void onInitNJointController() override
NJointControllerBase interface.
Definition: ImpedanceController.cpp:134
armarx::control::NJointTaskspaceImpedanceControllerInterface::calibrateFTSensor
void calibrateFTSensor()
ft sensor
armarx::control::njoint_controller::task_space
Definition: AdmittanceController.cpp:37
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::sensorDevices
common::SensorDevicesForNJointTorqueController sensorDevices
devices
Definition: ImpedanceController.h:64
armarx::control::common::SensorDevicesForNJointTorqueController
Definition: device.h:12
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::limbInit
void limbInit(const std::string nodeSetName, ArmPtr &arm, Config &cfg, VirtualRobot::RobotPtr &nonRtRobotPtr)
Definition: ImpedanceController.cpp:44
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::limbPublish
void limbPublish(ArmPtr &arm, const DebugObserverInterfacePrx &debugObs)
Definition: ImpedanceController.cpp:502
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::rtFirstRun
std::atomic_bool rtFirstRun
flags
Definition: ImpedanceController.h:89
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::jointNames
std::vector< std::string > jointNames
Definition: ImpedanceController.h:69
armarx::control::common::control_law::TaskspaceImpedanceController::ConfigDict
common::control_law::arondto::TaskspaceImpedanceControllerConfigDict ConfigDict
Definition: TaskspaceImpedanceController.h:45
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::bufferRtStatusToOnPublish
TripleBuffer< RtStatus > bufferRtStatusToOnPublish
Definition: ImpedanceController.h:84
device.h
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::bufferConfigRtToUser
TripleBuffer< Config > bufferConfigRtToUser
Definition: ImpedanceController.h:80
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: ImpedanceController.cpp:607
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::reInitPreActivate
std::atomic_bool reInitPreActivate
Definition: ImpedanceController.h:91
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::enableSafeGuardForceTorque
void enableSafeGuardForceTorque(const std::string &nodeSetName, const bool forceGuard, const bool torqueGuard, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: ImpedanceController.cpp:369
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: ImpedanceController.cpp:308
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::updateConfig
void updateConfig(const ::armarx::aron::data::dto::DictPtr &dto, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
NJointController interface.
Definition: ImpedanceController.cpp:325
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::rtReady
std::atomic_bool rtReady
Definition: ImpedanceController.h:90
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::control::TargetNullspaceMap
dictionary< string, Ice::FloatSeq > TargetNullspaceMap
Definition: ControllerInterface.ice:40
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmPtr
std::unique_ptr< ArmData > ArmPtr
Definition: ImpedanceController.h:97
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::onPublish
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: ImpedanceController.cpp:526
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::NJointTaskspaceImpedanceController
NJointTaskspaceImpedanceController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: ImpedanceController.cpp:85
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::getTCPVel
Ice::FloatSeq getTCPVel(const std::string &rns, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: ImpedanceController.cpp:412
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::rtStatusInNonRT
RtStatus rtStatusInNonRT
Definition: ImpedanceController.h:82
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::nonRtConfig
Config nonRtConfig
set data containers and buffers
Definition: ImpedanceController.h:75
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::limbRTSetTarget
void limbRTSetTarget(ArmPtr &arm, const Eigen::VectorXf &targetTorque)
Definition: ImpedanceController.cpp:250
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::rtConfig
Config rtConfig
Definition: ImpedanceController.h:76
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ConfigDict
law::TaskspaceImpedanceController::ConfigDict ConfigDict
Definition: ImpedanceController.h:58
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::validateConfigData
void validateConfigData(Config &config, ArmPtr &arm)
Definition: ImpedanceController.cpp:458
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::nonRtRobot
VirtualRobot::RobotPtr nonRtRobot
Definition: ImpedanceController.h:161
ControlTarget1DoFActuator.h
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::isSafeForceTorque
bool isSafeForceTorque(const std::string &nodeSetName, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
-----------------------------— Other interaces ----------------------------------------—
Definition: ImpedanceController.cpp:395
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::kinematicChainName
std::string kinematicChainName
names
Definition: ImpedanceController.h:68
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: ImpedanceController.cpp:592
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::getConfig
::armarx::aron::data::dto::DictPtr getConfig(const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: ImpedanceController.cpp:354
NJointController.h
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::additionalTask
virtual void additionalTask()
Definition: ImpedanceController.cpp:167
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::controller
law::TaskspaceImpedanceController controller
controller (maths)
Definition: ImpedanceController.h:72
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::nonRtRobot
VirtualRobot::RobotPtr nonRtRobot
robot
Definition: ImpedanceController.h:94
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::controllableNodeSets
std::map< std::string, VirtualRobot::RobotNodeSetPtr > controllableNodeSets
Definition: ImpedanceController.h:165
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::bufferRtStatusToNonRt
TripleBuffer< RtStatus > bufferRtStatusToNonRt
Definition: ImpedanceController.h:86
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::getClassName
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: ImpedanceController.cpp:128
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::ArmData::targets
std::vector< ControlTarget1DoFActuatorTorque * > targets
Definition: ImpedanceController.h:65
armarx::control::common::control_law::TaskspaceImpedanceController
Definition: TaskspaceImpedanceController.h:40
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::additionalTaskSetTarget
void additionalTaskSetTarget()
Definition: ImpedanceController.cpp:197
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::limb
std::map< std::string, ArmPtr > limb
Definition: ImpedanceController.h:160
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::TargetPoseMap
dictionary< string, FloatSeqSeq > TargetPoseMap
Definition: ControllerInterface.ice:39
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::Config
law::TaskspaceImpedanceController::Config Config
Definition: ImpedanceController.h:57
armarx::control::common::control_law::TaskspaceImpedanceController::Config
common::control_law::arondto::TaskspaceImpedanceControllerConfig Config
Definition: TaskspaceImpedanceController.h:44
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::limbRTUpdateStatus
void limbRTUpdateStatus(ArmPtr &arm, const double deltaT)
-----------------------------— Real time cotnrol --------------------------------------—
Definition: ImpedanceController.cpp:231
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::limbReInit
void limbReInit(ArmPtr &arm)
Definition: ImpedanceController.cpp:548
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::limbNonRT
void limbNonRT(ArmPtr &arm)
Definition: ImpedanceController.cpp:160
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::updateTargetPose
bool updateTargetPose(const TargetPoseMap &targetPoseMap, const TargetNullspaceMap &targetNullspaceMap, const Ice::Current &=Ice::emptyCurrent) override
Definition: ImpedanceController.cpp:426
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::additionalTaskUpdateStatus
bool additionalTaskUpdateStatus()
Definition: ImpedanceController.cpp:178
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::userConfig
ConfigDict userConfig
Definition: ImpedanceController.h:163
armarx::control::njoint_controller::task_space::NJointTaskspaceImpedanceController::robotUnit
RobotUnitPtr robotUnit
Definition: ImpedanceController.h:162
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::TripleBuffer< Config >