Component.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 control::ArmarXObjects::controller_creator
17  * @author Jianfeng Gao ( jianfeng dot gao at kit dot edu )
18  * @date 2023
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
24 #pragma once
25 
26 
27 // #include <mutex>
28 #include <VirtualRobot/Robot.h>
30 // #include <ArmarXCore/libraries/ArmarXCoreComponentPlugins/DebugObserverComponentPlugin.h>
31 
32 // #include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h>
33 
34 // #include <RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h>
35 
36 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
41 
47 #include <armarx/control/components/controller_creator/ComponentInterface.h>
49 
50 
52 {
53 
54  class Component :
55  virtual public armarx::Component
56  , virtual public ComponentInterface
59  , virtual public armem::ListeningClientPluginUser
60  // , virtual public armarx::DebugObserverComponentPluginUser
61  // , virtual public armarx::LightweightRemoteGuiComponentPluginUser
62  // , virtual public armarx::ArVizComponentPluginUser
63 
64  {
65  public:
66  Component();
67 
68  ~Component() override;
69 
70  /// @see armarx::ManagedIceObject::getDefaultName()
71  std::string getDefaultName() const override;
72 
73  /// Get the component's default name.
74  static std::string GetDefaultName();
75 
76 
77  protected:
78 
79  /// @see PropertyUser::createPropertyDefinitions()
81 
82  /// @see armarx::ManagedIceObject::onInitComponent()
83  void onInitComponent() override;
84 
85  /// @see armarx::ManagedIceObject::onConnectComponent()
86  void onConnectComponent() override;
87 
88  /// @see armarx::ManagedIceObject::onDisconnectComponent()
89  void onDisconnectComponent() override;
90 
91  /// @see armarx::ManagedIceObject::onExitComponent()
92  void onExitComponent() override;
93 
94 
95  /* (Requires armarx::LightweightRemoteGuiComponentPluginUser.)
96  /// This function should be called once in onConnect() or when you
97  /// need to re-create the Remote GUI tab.
98  void createRemoteGuiTab();
99 
100  /// After calling `RemoteGui_startRunningTask`, this function is
101  /// called periodically in a separate thread. If you update variables,
102  /// make sure to synchronize access to them.
103  void RemoteGui_update() override;
104  */
105 
106  public:
107  std::string createController(const std::string& controllerNamePrefix, const std::string &robotNodeSet, const std::string& controllerType, const std::string& configFilename, const Ice::Current& = Ice::emptyCurrent) override;
108  Ice::FloatSeq getPoseInRootFrame(const std::string& nodeName, const Ice::Current& = Ice::emptyCurrent) override;
109  Ice::FloatSeq getPrevTargetPose(const std::string& controllerName, const Ice::Current& = Ice::emptyCurrent) override;
110  Ice::FloatSeq getPrevNullspaceTargetAngle(const std::string& controllerName, const Ice::Current& = Ice::emptyCurrent) override;
111  std::string kinestheticTeaching(const std::string& kinematicChainName, const std::string& side, const std::string &fileName, const Ice::Current& = Ice::emptyCurrent) override;
112  void enableVelocityMode(const Ice::Current& = Ice::emptyCurrent) override;
113 
114  bool updateTargetPose(const std::string &controllerName, const std::string& controllerType, const Ice::FloatSeq& targetPoseVector, const Ice::Current & = Ice::emptyCurrent) override;
115  bool updateTargetNullspaceJointAngles(const std::string &controllerName, const std::string &controllerType, const Ice::FloatSeq& targetNullspaceJointAngle, const Ice::Current & = Ice::emptyCurrent) override;
116  bool updateTarget(const std::string &controllerName, const std::string &controllerType, const Ice::FloatSeq& targetPoseVector, const Ice::FloatSeq& targetNullspaceJointAngle, const Ice::Current & = Ice::emptyCurrent) override;
117 
118  private:
119 
120  // Private methods go here.
121 
122  // Forward declare `Properties` if you used it before its defined.
123  // struct Properties;
124 
125  /* (Requires the armarx::ArVizComponentPluginUser.)
126  /// Draw some boxes in ArViz.
127  void drawBoxes(const Properties& p, viz::Client& arviz);
128  */
129 
130  std::string createImpedanceController(const std::string &controllerNamePrefix, const std::string &robotNodeSet, const std::string &configFilename);
131  std::string createImpedanceMPController(const std::string &controllerNamePrefix, const std::string &robotNodeSet, const std::string &configFilename);
132  std::string createAdmittanceController(const std::string &controllerNamePrefix, const std::string &robotNodeSet, const std::string &configFilename);
133 
134 
135  private:
136 
137  static const std::string defaultName;
138 
139 
140  // Private member variables go here.
141  RobotUnitInterfacePrx m_robot_unit = nullptr;
142  VirtualRobot::RobotPtr m_robot = nullptr;
144 
145  /// observer
146  ForceTorqueUnitObserverInterfacePrx m_force_torque_observer;
149 
150  /// robot node sets
151  VirtualRobot::RobotNodeSetPtr m_rns_l;
152  VirtualRobot::RobotNodeSetPtr m_rns_r;
153 
154  std::map<std::string, std::optional<control::client::ControllerWrapper<control::common::ControllerType::TSImpedance>>> m_ctrlTSImpedance;
155  std::map<std::string, std::optional<control::client::ControllerWrapper<control::common::ControllerType::TSAdmittance>>> m_ctrlTSAdmittance;
156  std::map<std::string, std::optional<control::client::ControllerWrapper<control::common::ControllerType::TSImpedanceMP>>> m_ctrlTSImpedanceMP;
157  std::map<std::string, VirtualRobot::RobotNodeSetPtr> m_robotNodeSets;
158  std::map<std::string, unsigned int> m_controllerJointNumbers;
159 
160  std::map<std::string, Eigen::Matrix4f> m_prevTargetPose;
161  std::map<std::string, Eigen::VectorXf> m_prevNullspaceJointTarget;
162 
163 
164  /// Properties shown in the Scenario GUI.
165  struct Properties
166  {
167  std::string robotName = "Armar6";
168  std::string robotUnitName = "Armar6Unit";
169  std::string ftObserverName = "Armar6ForceTorqueObserver";
170  std::string ftSensorNameLeft = "FT L_ArmL_FT";
171  std::string ftSensorNameRight = "FT R_ArmR_FT";
172 
173  std::string defaultRobotNodeSetLeft = "LeftArm";
174  std::string defaultRobotNodeSetRight = "RightArm";
175  };
176  Properties properties;
177  /* Use a mutex if you access variables from different threads
178  * (e.g. ice functions and RemoteGui_update()).
179  std::mutex propertiesMutex;
180  */
181 
182 
183  /* (Requires the armarx::LightweightRemoteGuiComponentPluginUser.)
184  /// Tab shown in the Remote GUI.
185  struct RemoteGuiTab : armarx::RemoteGui::Client::Tab
186  {
187  armarx::RemoteGui::Client::LineEdit boxLayerName;
188  armarx::RemoteGui::Client::IntSpinBox numBoxes;
189 
190  armarx::RemoteGui::Client::Button drawBoxes;
191  };
192  RemoteGuiTab tab;
193  */
194 
195  };
196 
197 } /// namespace armarx::control::components::controller_creator
armarx::control::components::controller_creator::Component::updateTargetNullspaceJointAngles
bool updateTargetNullspaceJointAngles(const std::string &controllerName, const std::string &controllerType, const Ice::FloatSeq &targetNullspaceJointAngle, const Ice::Current &=Ice::emptyCurrent) override
Definition: Component.cpp:477
armarx::control::components::controller_creator::ComponentInterface
Definition: ComponentInterface.ice:31
RobotStateComponentPlugin.h
armarx::armem::client::plugins::ReaderWriterPlugin
A component plugin offering client-side access to a reader or writer and manages the lifecycle,...
Definition: ReaderWriterPlugin.h:44
armarx::control::components::controller_creator::Component::onExitComponent
void onExitComponent() override
Definition: Component.cpp:159
armarx::control::components::controller_creator::Component::kinestheticTeaching
std::string kinestheticTeaching(const std::string &kinematicChainName, const std::string &side, const std::string &fileName, const Ice::Current &=Ice::emptyCurrent) override
Definition: Component.cpp:594
armarx::control::components::controller_creator::Component
Definition: Component.h:54
ReaderWriterPlugin.h
ForceTorqueUtility.h
armarx::control::components::controller_creator::Component::Component
Component()
Definition: Component.cpp:46
type.h
armarx::control::components::controller_creator::Component::getPrevNullspaceTargetAngle
Ice::FloatSeq getPrevNullspaceTargetAngle(const std::string &controllerName, const Ice::Current &=Ice::emptyCurrent) override
Definition: Component.cpp:1061
armarx::control::client::ComponentPluginUser
Definition: ComponentPlugin.h:147
armarx::control::common::ft::ForceTorqueUtilityPtr
std::shared_ptr< ForceTorqueUtility > ForceTorqueUtilityPtr
Definition: ForceTorqueUtility.h:37
armarx::control::components::controller_creator::Component::getPoseInRootFrame
Ice::FloatSeq getPoseInRootFrame(const std::string &nodeName, const Ice::Current &=Ice::emptyCurrent) override
Definition: Component.cpp:1032
armarx::control::components::controller_creator::Component::getPrevTargetPose
Ice::FloatSeq getPrevTargetPose(const std::string &controllerName, const Ice::Current &=Ice::emptyCurrent) override
Definition: Component.cpp:1047
VirtualRobotReader.h
armarx::control::components::controller_creator::Component::~Component
~Component() override
ControllerBuilder.h
plugins.h
controller_descriptions.h
armarx::control::components::controller_creator::Component::onInitComponent
void onInitComponent() override
Definition: Component.cpp:90
armarx::control::components::controller_creator::Component::GetDefaultName
static std::string GetDefaultName()
Get the component's default name.
Definition: Component.cpp:1081
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::control::components::controller_creator::Component::createController
std::string createController(const std::string &controllerNamePrefix, const std::string &robotNodeSet, const std::string &controllerType, const std::string &configFilename, const Ice::Current &=Ice::emptyCurrent) override
Definition: Component.cpp:396
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::control::components::controller_creator::Component::getDefaultName
std::string getDefaultName() const override
Definition: Component.cpp:1074
IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface >
ComponentPlugin.h
armarx::control::components::controller_creator::Component::updateTargetPose
bool updateTargetPose(const std::string &controllerName, const std::string &controllerType, const Ice::FloatSeq &targetPoseVector, const Ice::Current &=Ice::emptyCurrent) override
Definition: Component.cpp:429
armarx::control::components::controller_creator::ComponentInterface::enableVelocityMode
void enableVelocityMode()
armarx::control::components::controller_creator::Component::onConnectComponent
void onConnectComponent() override
Definition: Component.cpp:102
armarx::armem::client::plugins::ListeningPluginUser
A memory name system client which listens to the memory updates topic (MemoryListenerInterface).
Definition: ListeningPluginUser.h:23
armarx::RobotStateComponentPluginUser
Definition: RobotStateComponentPlugin.h:167
armarx::control::components::controller_creator
Definition: Component.cpp:40
armarx::control::components::controller_creator::Component::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: Component.cpp:56
armarx::control::components::controller_creator::Component::onDisconnectComponent
void onDisconnectComponent() override
Definition: Component.cpp:153
armarx::control::components::controller_creator::Component::updateTarget
bool updateTarget(const std::string &controllerName, const std::string &controllerType, const Ice::FloatSeq &targetPoseVector, const Ice::FloatSeq &targetNullspaceJointAngle, const Ice::Current &=Ice::emptyCurrent) override
Definition: Component.cpp:519
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
controller_descriptions.h