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/Robot.h>
26 
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 
38 {
40 
41  /**
42  * @defgroup Library-NJointTaskspaceZeroTorqueOrVelocityController NJointTaskspaceZeroTorqueOrVelocityController
43  * @ingroup Library-RobotUnit-NJointControllers
44  * A description of the library NJointTaskspaceZeroTorqueOrVelocityController.
45  *
46  * @class NJointTaskspaceZeroTorqueOrVelocityController
47  * @ingroup Library-NJointTaskspaceZeroTorqueOrVelocityController
48  * @brief Brief description of class NJointTaskspaceZeroTorqueOrVelocityController.
49  *
50  * Detailed description of class NJointTaskspaceZeroTorqueOrVelocityController.
51  */
53  virtual public NJointController,
55  {
56  public:
57  using ConfigPtrT = ConfigurableNJointControllerConfigPtr;
58  // using AronDTO = law::arondto::ZeroTorqueOrVelocityControllerConfigDict;
59  // using BO = law::ZeroTorqueOrVelocityController::ConfigDict;
60 
61  using Config = common::control_law::arondto::ZeroTorqueOrVelocityControllerConfig;
62  using ConfigDict = common::control_law::arondto::ZeroTorqueOrVelocityControllerConfigDict;
63 
64  struct ArmData
65  {
67  std::vector<ControlTarget1DoFActuatorZeroTorque*> targetsTorque;
68  std::vector<ControlTarget1DoFActuatorZeroVelocity*> targetsVel;
69 
70  std::vector<size_t> torqueControlledIndex;
71  std::vector<size_t> velocityControlledIndex;
72 
73  std::string kinematicChainName;
74  std::vector<std::string> jointNames;
76 
77  /// set buffers
79 
81  law::ZeroTorqueOrVelocityController::RtStatus rtStatusInNonRT;
86 
87  law::ZeroTorqueOrVelocityController::RtStatus rtStatus;
91 
92  std::atomic_bool rtFirstRun{true};
93  std::atomic_bool rtReady{false};
94  // std::atomic_bool reInitPreActivate{false};
95 
97  };
98 
99  using ArmPtr = std::unique_ptr<ArmData>;
100 
102  const NJointControllerConfigPtr& config,
103  const VirtualRobot::RobotPtr&);
104 
105  std::string getClassName(const Ice::Current&) const override;
106 
107  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
108  const IceUtil::Time& timeSinceLastIteration) override;
109 
110  /// NJointController interface
112  const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
113 
115  getConfig(const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
116 
119  const std::map<std::string, ConstControlDevicePtr>&,
120  const std::map<std::string, ConstSensorDevicePtr>&);
121 
123 
124 
125  /// ft sensor
126  void calibrateFTSensor(const Ice::Current&) override;
127 
128  protected:
129  void validateConfigData(Config& config, ArmPtr& arm);
130  void onPublish(const SensorAndControl&,
132  const DebugObserverInterfacePrx&) override;
133 
134  void limbInit(const std::string nodeSetName,
135  ArmPtr& arm,
136  Config cfg,
137  VirtualRobot::RobotPtr& nonRtRobotPtr);
138  void limbRT(ArmPtr& arm, const double deltaT);
139  void limbPublish(ArmPtr& arm, const DebugObserverInterfacePrx& debugObs);
140  void limbReInit(ArmPtr& arm);
141 
142  protected:
143  std::map<std::string, ArmPtr> limb;
145  RobotUnitPtr robotUnit;
147 
148  protected:
149  /// NJointControllerBase interface
150  void onInitNJointController() override;
151  void rtPreActivateController() override;
152  void rtPostDeactivateController() override;
153  };
154 } // 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:422
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: ZeroTorqueOrVelocityController.cpp:166
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: ZeroTorqueOrVelocityController.cpp:433
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::targetsTorque
std::vector< ControlTarget1DoFActuatorZeroTorque * > targetsTorque
Definition: ZeroTorqueOrVelocityController.h:67
RobotUnit.h
armarx::SynchronousNJointController
Definition: NJointControllerBase.h:1145
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::robotUnit
RobotUnitPtr robotUnit
Definition: ZeroTorqueOrVelocityController.h:145
armarx::control::njoint_controller::task_space
Definition: AdmittanceController.cpp:37
armarx::control::common::SensorDevicesForNJointTorqueController
Definition: device.h:12
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtConfig
Config rtConfig
Definition: ZeroTorqueOrVelocityController.h:82
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:299
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtStatusToUser
TripleBuffer< law::ZeroTorqueOrVelocityController::RtStatus > bufferRtStatusToUser
Definition: ZeroTorqueOrVelocityController.h:89
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limbRT
void limbRT(ArmPtr &arm, const double deltaT)
Definition: ZeroTorqueOrVelocityController.cpp:177
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::controller
law::ZeroTorqueOrVelocityController controller
Definition: ZeroTorqueOrVelocityController.h:75
device.h
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtFirstRun
std::atomic_bool rtFirstRun
Definition: ZeroTorqueOrVelocityController.h:92
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::jointNames
std::vector< std::string > jointNames
Definition: ZeroTorqueOrVelocityController.h:74
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limbReInit
void limbReInit(ArmPtr &arm)
Definition: ZeroTorqueOrVelocityController.cpp:367
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::velocityControlledIndex
std::vector< size_t > velocityControlledIndex
Definition: ZeroTorqueOrVelocityController.h:71
ZeroTorqueOrVelocityController.h
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmPtr
std::unique_ptr< ArmData > ArmPtr
Definition: ZeroTorqueOrVelocityController.h:99
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferUserToNonRt
TripleBuffer< Config > bufferUserToNonRt
set buffers
Definition: ZeroTorqueOrVelocityController.h:78
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtStatusInNonRT
law::ZeroTorqueOrVelocityController::RtStatus rtStatusInNonRT
Definition: ZeroTorqueOrVelocityController.h:81
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtReady
std::atomic_bool rtReady
Definition: ZeroTorqueOrVelocityController.h:93
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:271
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferNonRtToRt
TripleBuffer< Config > bufferNonRtToRt
Definition: ZeroTorqueOrVelocityController.h:83
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::nonRtConfig
Config nonRtConfig
Definition: ZeroTorqueOrVelocityController.h:80
armarx::control::NJointTaskspaceZeroTorqueOrVelocityControllerInterface::calibrateFTSensor
void calibrateFTSensor()
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData
Definition: ZeroTorqueOrVelocityController.h:64
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limb
std::map< std::string, ArmPtr > limb
Definition: ZeroTorqueOrVelocityController.h:143
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::nonRtRobot
VirtualRobot::RobotPtr nonRtRobot
Definition: ZeroTorqueOrVelocityController.h:144
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limbInit
void limbInit(const std::string nodeSetName, ArmPtr &arm, Config cfg, VirtualRobot::RobotPtr &nonRtRobotPtr)
Definition: ZeroTorqueOrVelocityController.cpp:43
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:146
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController
Brief description of class NJointTaskspaceZeroTorqueOrVelocityController.
Definition: ZeroTorqueOrVelocityController.h:52
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:442
ControlTarget1DoFActuator.h
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtStatusToOnPublish
TripleBuffer< law::ZeroTorqueOrVelocityController::RtStatus > bufferRtStatusToOnPublish
Definition: ZeroTorqueOrVelocityController.h:88
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:346
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::rtStatus
law::ZeroTorqueOrVelocityController::RtStatus rtStatus
Definition: ZeroTorqueOrVelocityController.h:87
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::GenerateConfigFromVariants
static ConfigPtrT GenerateConfigFromVariants(const StringVariantBaseMap &values)
Definition: ZeroTorqueOrVelocityController.cpp:546
NJointController.h
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::validateConfigData
void validateConfigData(Config &config, ArmPtr &arm)
Definition: ZeroTorqueOrVelocityController.cpp:310
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::torqueControlledIndex
std::vector< size_t > torqueControlledIndex
Definition: ZeroTorqueOrVelocityController.h:70
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtToNonRt
TripleBuffer< law::ZeroTorqueOrVelocityController::RtStatus > bufferRtToNonRt
Definition: ZeroTorqueOrVelocityController.h:90
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::limbPublish
void limbPublish(ArmPtr &arm, const DebugObserverInterfacePrx &debugObs)
Definition: ZeroTorqueOrVelocityController.cpp:328
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtConfigToOnPublish
TripleBuffer< Config > bufferRtConfigToOnPublish
Definition: ZeroTorqueOrVelocityController.h:84
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::kinematicChainName
std::string kinematicChainName
Definition: ZeroTorqueOrVelocityController.h:73
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ConfigDict
common::control_law::arondto::ZeroTorqueOrVelocityControllerConfigDict ConfigDict
Definition: ZeroTorqueOrVelocityController.h:62
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::onInitNJointController
void onInitNJointController() override
NJointControllerBase interface.
Definition: ZeroTorqueOrVelocityController.cpp:172
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:283
armarx::control::common::control_law::ZeroTorqueOrVelocityController
Definition: ZeroTorqueOrVelocityController.h:40
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::sensorDevices
common::SensorDevicesForNJointTorqueController sensorDevices
Definition: ZeroTorqueOrVelocityController.h:66
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::NJointTaskspaceZeroTorqueOrVelocityController
NJointTaskspaceZeroTorqueOrVelocityController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: ZeroTorqueOrVelocityController.cpp:142
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::targetsVel
std::vector< ControlTarget1DoFActuatorZeroVelocity * > targetsVel
Definition: ZeroTorqueOrVelocityController.h:68
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::bufferRtConfigToUser
TripleBuffer< Config > bufferRtConfigToUser
Definition: ZeroTorqueOrVelocityController.h:85
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::Config
common::control_law::arondto::ZeroTorqueOrVelocityControllerConfig Config
Definition: ZeroTorqueOrVelocityController.h:61
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::TripleBuffer< Config >
armarx::control::njoint_controller::task_space::NJointTaskspaceZeroTorqueOrVelocityController::ArmData::nonRtRobot
VirtualRobot::RobotPtr nonRtRobot
Definition: ZeroTorqueOrVelocityController.h:96