SafetyImpedanceController.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 
31 
34 #include <armarx/control/njoint_controller/task_space/ControllerInterface.h>
35 
36 #include <simox/control/environment/CollisionRobot.h>
37 #include <simox/control/geodesics/metric/inertia.h>
38 #include <simox/control/impl/simox/robot/Robot.h>
39 
41 {
43 
44  /**
45  * @defgroup Library-NJointTaskspaceImpedanceController NJointTaskspaceSafetyImpedanceController
46  * @ingroup Library-RobotUnit-NJointControllers
47  * A description of the library NJointTaskspaceSafetyImpedanceController.
48  *
49  * @class NJointTaskspaceSafetyImpedanceController
50  * @ingroup Library-NJointTaskspaceImpedanceController
51  * @brief Brief description of class NJointTaskspaceSafetyImpedanceController.
52  *
53  * Detailed description of class NJointTaskspaceSafetyImpedanceController.
54  */
56  virtual public NJointController,
59  {
60  public:
61  using ConfigPtrT = ConfigurableNJointControllerConfigPtr;
64  using RtStatus = law::SafetyTaskspaceImpedanceController::RtStatus;
65 
66  struct ArmData
67  {
68  /// devices
70  std::vector<ControlTarget1DoFActuatorTorque*> targets;
71 
72  /// names
73  std::string kinematicChainName;
74  std::vector<std::string> jointNames;
75  std::string tcpName;
76 
77  /// controller (maths)
79 
80  /// set data containers and buffers
87 
93 
94  /// flags
95  std::atomic_bool rtFirstRun{true};
96  std::atomic_bool rtReady{false};
97  std::atomic_bool reInitPreActivate{false};
98 
99  /// robot
101 
102  /// self-collision avoidance
103  std::shared_ptr<simox::control::geodesics::metric::Inertia> inertiaPtr;
104  std::shared_ptr<std::vector<simox::control::environment::DistanceResult>>
106  std::shared_ptr<std::vector<int>> pointsOnArm;
108  // reduced robot required to get node where contact point is located to compute Jacobian
109  std::shared_ptr<simox::control::simox::robot::Robot> simoxReducedRobotPtr;
110  };
111 
112  using ArmPtr = std::unique_ptr<ArmData>;
113 
115  const NJointControllerConfigPtr& config,
116  const VirtualRobot::RobotPtr&);
117 
118  std::string getClassName(const Ice::Current& = Ice::emptyCurrent) const override;
119 
120  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
121  const IceUtil::Time& timeSinceLastIteration) override;
122 
123  /// NJointController interface
125  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
126  bool updateTargetPose(const TargetPoseMap& targetPoseMap,
127  const TargetNullspaceMap& targetNullspaceMap,
128  const Ice::Current& = Ice::emptyCurrent) override;
130  getConfig(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
131 
132  Ice::FloatSeq getTCPVel(const std::string& rns,
133  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
134 
135  /// ft sensor
136  void calibrateFTSensor(const Ice::Current&) override;
137  void
138  enableSafeGuardForceTorque(const std::string& nodeSetName,
139  const bool forceGuard,
140  const bool torqueGuard,
141  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
142  bool isSafeForceTorque(const std::string& nodeSetName,
143  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
144 
145  protected:
146  virtual void additionalTask();
147  void validateConfigData(Config& config, ArmPtr& arm);
148  void onPublish(const SensorAndControl&,
150  const DebugObserverInterfacePrx&) override;
151 
152  void limbInit(const std::string nodeSetName,
153  ArmPtr& arm,
154  Config& cfg,
155  VirtualRobot::RobotPtr& nonRtRobotPtr,
156  std::shared_ptr<std::vector<::simox::control::environment::DistanceResult>>
158  void limbNonRT(ArmPtr& arm);
159  void limbRT(ArmPtr& arm, const double deltaT);
160  void limbPublish(ArmPtr& arm, const DebugObserverInterfacePrx& debugObs);
161  void limbReInit(ArmPtr& arm);
162 
163  protected:
164  std::map<std::string, ArmPtr> limb;
166  RobotUnitPtr robotUnit;
167  std::unique_ptr<::simox::control::environment::CollisionRobot<hpp::fcl::OBBRSS>>
169  std::shared_ptr<::simox::control::simox::robot::Robot> simoxControlRobotPtr;
170  std::shared_ptr<simox::control::simox::robot::Robot> simoxReducedRobotPtr;
172  /// store collision pairs in vector to be able to preallocate memory
173  std::shared_ptr<std::vector<::simox::control::environment::DistanceResult>> collisionPairs;
176  std::vector<std::string> actuatedJoints;
177  Eigen::VectorXd qposActuatedJoints;
178  //int qposActuatedJointsIndex;
179 
180  protected:
181  /// NJointControllerBase interface
182  void onInitNJointController() override;
183  void rtPreActivateController() override;
184  void rtPostDeactivateController() override;
185  };
186 } // namespace armarx::control::njoint_controller::task_space
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::additionalTask
virtual void additionalTask()
Definition: SafetyImpedanceController.cpp:233
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::collisionRobotPtr
std::unique_ptr<::simox::control::environment::CollisionRobot< hpp::fcl::OBBRSS > > collisionRobotPtr
Definition: SafetyImpedanceController.h:168
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::rtReady
std::atomic_bool rtReady
Definition: SafetyImpedanceController.h:96
armarx::control::common::control_law::SafetyTaskspaceImpedanceController
Definition: SafetyTaskspaceImpedanceController.h:45
ArVizComponentPlugin.h
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::validateConfigData
void validateConfigData(Config &config, ArmPtr &arm)
Definition: SafetyImpedanceController.cpp:604
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::isSafeForceTorque
bool isSafeForceTorque(const std::string &nodeSetName, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: SafetyImpedanceController.cpp:544
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::onPublish
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: SafetyImpedanceController.cpp:1091
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::bufferConfigRtToOnPublish
TripleBuffer< Config > bufferConfigRtToOnPublish
Definition: SafetyImpedanceController.h:85
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::qposActuatedJoints
Eigen::VectorXd qposActuatedJoints
Definition: SafetyImpedanceController.h:177
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::maxCollisionPairs
int maxCollisionPairs
Definition: SafetyImpedanceController.h:175
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::controller
law::SafetyTaskspaceImpedanceController controller
controller (maths)
Definition: SafetyImpedanceController.h:78
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::RtStatus
law::SafetyTaskspaceImpedanceController::RtStatus RtStatus
Definition: SafetyImpedanceController.h:64
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::updateConfig
void updateConfig(const ::armarx::aron::data::dto::DictPtr &dto, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
NJointController interface.
Definition: SafetyImpedanceController.cpp:503
RobotUnit.h
armarx::SynchronousNJointController
Definition: NJointControllerBase.h:1145
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::limb
std::map< std::string, ArmPtr > limb
Definition: SafetyImpedanceController.h:164
armarx::control::common::control_law::SafetyTaskspaceImpedanceController::ConfigDict
common::control_law::arondto::SafetyTaskspaceImpedanceControllerConfigDict ConfigDict
Definition: SafetyTaskspaceImpedanceController.h:55
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::bufferRtStatusToUser
TripleBuffer< RtStatus > bufferRtStatusToUser
Definition: SafetyImpedanceController.h:91
armarx::control::njoint_controller::task_space
Definition: AdmittanceController.cpp:37
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::pointsOnArm
std::shared_ptr< std::vector< int > > pointsOnArm
Definition: SafetyImpedanceController.h:106
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::limbReInit
void limbReInit(ArmPtr &arm)
Definition: SafetyImpedanceController.cpp:1114
armarx::control::common::SensorDevicesForNJointTorqueController
Definition: device.h:12
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::getTCPVel
Ice::FloatSeq getTCPVel(const std::string &rns, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: SafetyImpedanceController.cpp:489
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::onInitNJointController
void onInitNJointController() override
NJointControllerBase interface.
Definition: SafetyImpedanceController.cpp:199
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::rtFirstRun
std::atomic_bool rtFirstRun
flags
Definition: SafetyImpedanceController.h:95
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::tcpName
std::string tcpName
Definition: SafetyImpedanceController.h:75
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::collisionPairs
std::shared_ptr< std::vector<::simox::control::environment::DistanceResult > > collisionPairs
store collision pairs in vector to be able to preallocate memory
Definition: SafetyImpedanceController.h:173
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::rtStatus
RtStatus rtStatus
Definition: SafetyImpedanceController.h:89
device.h
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::bufferConfigRtToUser
TripleBuffer< Config > bufferConfigRtToUser
Definition: SafetyImpedanceController.h:86
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::jointNames
std::vector< std::string > jointNames
Definition: SafetyImpedanceController.h:74
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::rtStatusInNonRT
RtStatus rtStatusInNonRT
Definition: SafetyImpedanceController.h:88
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::rtConfig
Config rtConfig
Definition: SafetyImpedanceController.h:82
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::targets
std::vector< ControlTarget1DoFActuatorTorque * > targets
Definition: SafetyImpedanceController.h:70
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::nonRtConfig
Config nonRtConfig
set data containers and buffers
Definition: SafetyImpedanceController.h:81
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::NJointTaskspaceSafetyImpedanceController::actuatedJoints
std::vector< std::string > actuatedJoints
Definition: SafetyImpedanceController.h:176
armarx::ArVizComponentPluginUser
Provides a ready-to-use ArViz client arviz as member variable.
Definition: ArVizComponentPlugin.h:36
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::nonRtRobot
VirtualRobot::RobotPtr nonRtRobot
robot
Definition: SafetyImpedanceController.h:100
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: SafetyImpedanceController.cpp:1306
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController
Brief description of class NJointTaskspaceSafetyImpedanceController.
Definition: SafetyImpedanceController.h:55
armarx::control::common::control_law::SafetyTaskspaceImpedanceController::Config
common::control_law::arondto::SafetyTaskspaceImpedanceControllerConfig Config
Definition: SafetyTaskspaceImpedanceController.h:53
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: SafetyImpedanceController.cpp:1293
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::bufferConfigUserToNonRt
TripleBuffer< Config > bufferConfigUserToNonRt
Definition: SafetyImpedanceController.h:83
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::NJointTaskspaceSafetyImpedanceController
NJointTaskspaceSafetyImpedanceController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: SafetyImpedanceController.cpp:118
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::Config
law::SafetyTaskspaceImpedanceController::Config Config
Definition: SafetyImpedanceController.h:62
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: SafetyImpedanceController.cpp:366
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::bufferConfigNonRtToRt
TripleBuffer< Config > bufferConfigNonRtToRt
Definition: SafetyImpedanceController.h:84
ControlTarget1DoFActuator.h
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::reInitPreActivate
std::atomic_bool reInitPreActivate
Definition: SafetyImpedanceController.h:97
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::getConfig
::armarx::aron::data::dto::DictPtr getConfig(const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: SafetyImpedanceController.cpp:593
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::pointsOnArmIndex
int pointsOnArmIndex
Definition: SafetyImpedanceController.h:107
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::kinematicChainName
std::string kinematicChainName
names
Definition: SafetyImpedanceController.h:73
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData
Definition: SafetyImpedanceController.h:66
NJointController.h
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::simoxReducedRobotPtr
std::shared_ptr< simox::control::simox::robot::Robot > simoxReducedRobotPtr
Definition: SafetyImpedanceController.h:170
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::limbRT
void limbRT(ArmPtr &arm, const double deltaT)
Definition: SafetyImpedanceController.cpp:273
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::bufferRtStatusToNonRt
TripleBuffer< RtStatus > bufferRtStatusToNonRt
Definition: SafetyImpedanceController.h:92
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::nonRtRobot
VirtualRobot::RobotPtr nonRtRobot
Definition: SafetyImpedanceController.h:165
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ConfigDict
law::SafetyTaskspaceImpedanceController::ConfigDict ConfigDict
Definition: SafetyImpedanceController.h:63
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::enableSafeGuardForceTorque
void enableSafeGuardForceTorque(const std::string &nodeSetName, const bool forceGuard, const bool torqueGuard, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: SafetyImpedanceController.cpp:518
SafetyTaskspaceImpedanceController.h
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::userConfig
ConfigDict userConfig
Definition: SafetyImpedanceController.h:171
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::sensorDevices
common::SensorDevicesForNJointTorqueController sensorDevices
devices
Definition: SafetyImpedanceController.h:69
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::simoxControlRobotPtr
std::shared_ptr<::simox::control::simox::robot::Robot > simoxControlRobotPtr
Definition: SafetyImpedanceController.h:169
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::limbPublish
void limbPublish(ArmPtr &arm, const DebugObserverInterfacePrx &debugObs)
Definition: SafetyImpedanceController.cpp:683
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::robotUnit
RobotUnitPtr robotUnit
Definition: SafetyImpedanceController.h:166
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::inertiaPtr
std::shared_ptr< simox::control::geodesics::metric::Inertia > inertiaPtr
self-collision avoidance
Definition: SafetyImpedanceController.h:103
armarx::control::TargetPoseMap
dictionary< string, FloatSeqSeq > TargetPoseMap
Definition: ControllerInterface.ice:39
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::bufferRtStatusToOnPublish
TripleBuffer< RtStatus > bufferRtStatusToOnPublish
Definition: SafetyImpedanceController.h:90
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::collisionPairsPtr
std::shared_ptr< std::vector< simox::control::environment::DistanceResult > > collisionPairsPtr
Definition: SafetyImpedanceController.h:105
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::limbInit
void limbInit(const std::string nodeSetName, ArmPtr &arm, Config &cfg, VirtualRobot::RobotPtr &nonRtRobotPtr, std::shared_ptr< std::vector<::simox::control::environment::DistanceResult >> collisionPairs)
Definition: SafetyImpedanceController.cpp:44
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::preFilterDistance
float preFilterDistance
Definition: SafetyImpedanceController.h:174
armarx::control::NJointTaskspaceSafetyImpedanceControllerInterface::calibrateFTSensor
void calibrateFTSensor()
ft sensor
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmPtr
std::unique_ptr< ArmData > ArmPtr
Definition: SafetyImpedanceController.h:112
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::getClassName
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: SafetyImpedanceController.cpp:193
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::ArmData::simoxReducedRobotPtr
std::shared_ptr< simox::control::simox::robot::Robot > simoxReducedRobotPtr
Definition: SafetyImpedanceController.h:109
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::updateTargetPose
bool updateTargetPose(const TargetPoseMap &targetPoseMap, const TargetNullspaceMap &targetNullspaceMap, const Ice::Current &=Ice::emptyCurrent) override
Definition: SafetyImpedanceController.cpp:561
armarx::TripleBuffer< Config >
armarx::control::njoint_controller::task_space::NJointTaskspaceSafetyImpedanceController::limbNonRT
void limbNonRT(ArmPtr &arm)
Definition: SafetyImpedanceController.cpp:225
armarx::control::NJointTaskspaceSafetyImpedanceControllerInterface
Definition: ControllerInterface.ice:66