ZeroTorqueOrVelocityController.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 
28 
30 
32 #include <armarx/control/common/control_law/aron/ZeroTorqueOrVelocityControllerConfig.aron.generated.h>
34 #include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
35 #include <armarx/control/njoint_controller/task_space/ControllerInterface.h>
36 
37 namespace armarx
38 {
39  class ControlTarget1DoFActuatorZeroTorque;
40  class ControlTarget1DoFActuatorZeroVelocity;
41 } // namespace armarx
42 
44 {
46 
47  /**
48  * @defgroup Library-NJointTaskspaceZeroTorqueOrVelocityController NJointTaskspaceZeroTorqueOrVelocityController
49  * @ingroup Library-RobotUnit-NJointControllers
50  * A description of the library NJointTaskspaceZeroTorqueOrVelocityController.
51  *
52  * @class NJointTaskspaceZeroTorqueOrVelocityController
53  * @ingroup Library-NJointTaskspaceZeroTorqueOrVelocityController
54  * @brief Brief description of class NJointTaskspaceZeroTorqueOrVelocityController.
55  *
56  * Detailed description of class NJointTaskspaceZeroTorqueOrVelocityController.
57  */
59  virtual public NJointController,
61  {
62  public:
63  using ConfigPtrT = ConfigurableNJointControllerConfigPtr;
64  // using AronDTO = law::arondto::ZeroTorqueOrVelocityControllerConfigDict;
65  // using BO = law::ZeroTorqueOrVelocityController::ConfigDict;
66 
67  using Config = common::control_law::arondto::ZeroTorqueOrVelocityControllerConfig;
68  using ConfigDict = common::control_law::arondto::ZeroTorqueOrVelocityControllerConfigDict;
69 
70  struct ArmData
71  {
73  std::vector<ControlTarget1DoFActuatorZeroTorque*> targetsTorque;
74  std::vector<ControlTarget1DoFActuatorZeroVelocity*> targetsVel;
75 
76  std::vector<size_t> torqueControlledIndex;
77  std::vector<size_t> velocityControlledIndex;
78 
79  std::string kinematicChainName;
80  std::vector<std::string> jointNames;
82 
83  /// set buffers
85 
87  law::ZeroTorqueOrVelocityController::RtStatus rtStatusInNonRT;
92 
93  law::ZeroTorqueOrVelocityController::RtStatus rtStatus;
97 
98  std::atomic_bool rtFirstRun{true};
99  std::atomic_bool rtReady{false};
100  // std::atomic_bool reInitPreActivate{false};
101 
103  };
104 
105  using ArmPtr = std::unique_ptr<ArmData>;
106 
108  const NJointControllerConfigPtr& config,
109  const VirtualRobot::RobotPtr&);
110 
111  std::string getClassName(const Ice::Current&) const override;
112 
113  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
114  const IceUtil::Time& timeSinceLastIteration) override;
115 
116  /// NJointController interface
118  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
119 
121  getConfig(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
122 
125  const std::map<std::string, ConstControlDevicePtr>&,
126  const std::map<std::string, ConstSensorDevicePtr>&);
127 
129 
130 
131  /// ft sensor
132  void calibrateFTSensor(const Ice::Current&) override;
133 
134  protected:
135  void validateConfigData(Config& config, ArmPtr& arm);
136  void onPublish(const SensorAndControl&,
138  const DebugObserverInterfacePrx&) override;
139 
140  void limbInit(const std::string nodeSetName,
141  ArmPtr& arm,
142  Config cfg,
143  VirtualRobot::RobotPtr& nonRtRobotPtr);
144  void limbRT(ArmPtr& arm, const double deltaT);
145  void limbPublish(ArmPtr& arm, const DebugObserverInterfacePrx& debugObs);
146  void limbReInit(ArmPtr& arm);
147 
148  protected:
149  std::map<std::string, ArmPtr> limb;
153 
154  protected:
155  /// NJointControllerBase interface
156  void onInitNJointController() override;
157  void rtPreActivateController() override;
158  void rtPostDeactivateController() override;
159  };
160 } // namespace armarx::control::njoint_controller::task_space
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: ZeroTorqueOrVelocityController.cpp:430
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: ZeroTorqueOrVelocityController.cpp:172
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: ZeroTorqueOrVelocityController.cpp:441
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:110
NJointControllerBase.h
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::targetsTorque
std::vector< ControlTarget1DoFActuatorZeroTorque * > targetsTorque
Definition: ZeroTorqueOrVelocityController.h:73
armarx::SynchronousNJointController
Definition: NJointControllerBase.h:1146
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::robotUnit
RobotUnitPtr robotUnit
Definition: ZeroTorqueOrVelocityController.h:151
armarx::control::njoint_controller::task_space
Definition: AdmittanceController.cpp:43
armarx::control::common::SensorDevicesForNJointTorqueController
Definition: device.h:12
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtConfig
Config rtConfig
Definition: ZeroTorqueOrVelocityController.h:88
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::getConfig
::armarx::aron::data::dto::DictPtr getConfig(const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: ZeroTorqueOrVelocityController.cpp:307
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtStatusToUser
TripleBuffer< law::ZeroTorqueOrVelocityController::RtStatus > bufferRtStatusToUser
Definition: ZeroTorqueOrVelocityController.h:95
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limbRT
void limbRT(ArmPtr &arm, const double deltaT)
Definition: ZeroTorqueOrVelocityController.cpp:183
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:587
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::controller
law::ZeroTorqueOrVelocityController controller
Definition: ZeroTorqueOrVelocityController.h:81
device.h
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtFirstRun
std::atomic_bool rtFirstRun
Definition: ZeroTorqueOrVelocityController.h:98
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::jointNames
std::vector< std::string > jointNames
Definition: ZeroTorqueOrVelocityController.h:80
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limbReInit
void limbReInit(ArmPtr &arm)
Definition: ZeroTorqueOrVelocityController.cpp:375
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::velocityControlledIndex
std::vector< size_t > velocityControlledIndex
Definition: ZeroTorqueOrVelocityController.h:77
ZeroTorqueOrVelocityController.h
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:182
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmPtr
std::unique_ptr< ArmData > ArmPtr
Definition: ZeroTorqueOrVelocityController.h:105
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferUserToNonRt
TripleBuffer< Config > bufferUserToNonRt
set buffers
Definition: ZeroTorqueOrVelocityController.h:84
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtStatusInNonRT
law::ZeroTorqueOrVelocityController::RtStatus rtStatusInNonRT
Definition: ZeroTorqueOrVelocityController.h:87
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtReady
std::atomic_bool rtReady
Definition: ZeroTorqueOrVelocityController.h:99
armarx::control::NJointTaskspaceZeroTorqueOrVelocityControllerInterface
Definition: ControllerInterface.ice:144
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: ZeroTorqueOrVelocityController.cpp:279
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferNonRtToRt
TripleBuffer< Config > bufferNonRtToRt
Definition: ZeroTorqueOrVelocityController.h:89
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::nonRtConfig
Config nonRtConfig
Definition: ZeroTorqueOrVelocityController.h:86
armarx::control::NJointTaskspaceZeroTorqueOrVelocityControllerInterface::calibrateFTSensor
void calibrateFTSensor()
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData
Definition: ZeroTorqueOrVelocityController.h:70
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limb
std::map< std::string, ArmPtr > limb
Definition: ZeroTorqueOrVelocityController.h:149
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::nonRtRobot
VirtualRobot::RobotPtr nonRtRobot
Definition: ZeroTorqueOrVelocityController.h:150
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limbInit
void limbInit(const std::string nodeSetName, ArmPtr &arm, Config cfg, VirtualRobot::RobotPtr &nonRtRobotPtr)
Definition: ZeroTorqueOrVelocityController.cpp:49
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::userConfig
ConfigDict userConfig
Definition: ZeroTorqueOrVelocityController.h:152
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController
Brief description of class NJointTaskspaceZeroTorqueOrVelocityController.
Definition: ZeroTorqueOrVelocityController.h:58
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::GenerateConfigDescription
static WidgetDescription::WidgetPtr GenerateConfigDescription(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &, const std::map< std::string, ConstSensorDevicePtr > &)
Definition: ZeroTorqueOrVelocityController.cpp:450
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtStatusToOnPublish
TripleBuffer< law::ZeroTorqueOrVelocityController::RtStatus > bufferRtStatusToOnPublish
Definition: ZeroTorqueOrVelocityController.h:94
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::onPublish
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: ZeroTorqueOrVelocityController.cpp:354
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtStatus
law::ZeroTorqueOrVelocityController::RtStatus rtStatus
Definition: ZeroTorqueOrVelocityController.h:93
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::GenerateConfigFromVariants
static ConfigPtrT GenerateConfigFromVariants(const StringVariantBaseMap &values)
Definition: ZeroTorqueOrVelocityController.cpp:554
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
TripleBuffer.h
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::validateConfigData
void validateConfigData(Config &config, ArmPtr &arm)
Definition: ZeroTorqueOrVelocityController.cpp:318
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::torqueControlledIndex
std::vector< size_t > torqueControlledIndex
Definition: ZeroTorqueOrVelocityController.h:76
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtToNonRt
TripleBuffer< law::ZeroTorqueOrVelocityController::RtStatus > bufferRtToNonRt
Definition: ZeroTorqueOrVelocityController.h:96
IceUtil::Handle< class RobotUnit >
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limbPublish
void limbPublish(ArmPtr &arm, const DebugObserverInterfacePrx &debugObs)
Definition: ZeroTorqueOrVelocityController.cpp:336
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtConfigToOnPublish
TripleBuffer< Config > bufferRtConfigToOnPublish
Definition: ZeroTorqueOrVelocityController.h:90
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::kinematicChainName
std::string kinematicChainName
Definition: ZeroTorqueOrVelocityController.h:79
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ConfigDict
common::control_law::arondto::ZeroTorqueOrVelocityControllerConfigDict ConfigDict
Definition: ZeroTorqueOrVelocityController.h:68
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::onInitNJointController
void onInitNJointController() override
NJointControllerBase interface.
Definition: ZeroTorqueOrVelocityController.cpp:178
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::updateConfig
void updateConfig(const ::armarx::aron::data::dto::DictPtr &dto, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
NJointController interface.
Definition: ZeroTorqueOrVelocityController.cpp:291
armarx::control::common::control_law::ZeroTorqueOrVelocityController
Definition: ZeroTorqueOrVelocityController.h:34
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::sensorDevices
common::SensorDevicesForNJointTorqueController sensorDevices
Definition: ZeroTorqueOrVelocityController.h:72
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::NJointTaskspaceZeroTorqueOrVelocityController
NJointTaskspaceZeroTorqueOrVelocityController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: ZeroTorqueOrVelocityController.cpp:148
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::targetsVel
std::vector< ControlTarget1DoFActuatorZeroVelocity * > targetsVel
Definition: ZeroTorqueOrVelocityController.h:74
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtConfigToUser
TripleBuffer< Config > bufferRtConfigToUser
Definition: ZeroTorqueOrVelocityController.h:91
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::Config
common::control_law::arondto::ZeroTorqueOrVelocityControllerConfig Config
Definition: ZeroTorqueOrVelocityController.h:67
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
armarx::TripleBuffer< Config >
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::nonRtRobot
VirtualRobot::RobotPtr nonRtRobot
Definition: ZeroTorqueOrVelocityController.h:102