Plugin.cpp
Go to the documentation of this file.
1 #include "Plugin.h"
2 
4 
5 namespace armarx
6 {
7 
9  {
10  addPlugin(plugin);
11  }
12 } // namespace armarx
13 
14 namespace armarx::plugins
15 {
16 
17  void
19  {
21 
22  ARMARX_INFO << "Got as config: " << properties.configJson;
23 
24  nlohmann::json config = nlohmann::json::parse(properties.configJson);
25 
26  if (config.contains(CONFIG_ROBOT_NAME))
27  {
28  robot.name = config[CONFIG_ROBOT_NAME];
29  }
30 
31  if (config.contains(CONFIG_XML_PACKAGE_PATH))
32  {
33  auto config_pp = config[CONFIG_XML_PACKAGE_PATH];
34  if (config_pp.contains(CONFIG_XML_PACKAGE_PATH_PACKAGE))
35  {
36  robot.xmlPackagePath.package = config_pp[CONFIG_XML_PACKAGE_PATH_PACKAGE];
37  }
38  if (config_pp.contains(CONFIG_XML_PACKAGE_PATH_PATH))
39  {
40  robot.xmlPackagePath.path = config_pp[CONFIG_XML_PACKAGE_PATH_PATH];
41  }
42  }
43  auto& p = parent<RobotNameServiceComponentPluginUser>();
44 
45  if (config.contains(CONFIG_MNS_PRX))
46  {
47  p.usingProxy(config[CONFIG_MNS_PRX]);
48  }
49  if (config.contains(CONFIG_SKILLS_MANAGER_PRX))
50  {
51  p.usingProxy(config[CONFIG_SKILLS_MANAGER_PRX]);
52  }
53 
54  if (config.contains(CONFIG_ARMS))
55  {
56  for (const auto& [k, config_arm] : config[CONFIG_ARMS].items())
57  {
58  auto& arm = robot.armInfos[k];
59 
60  if (config_arm.contains(CONFIG_ARM_KINEMATIC_CHAIN_NAME))
61  {
62  arm.kinematicChainName = config_arm[CONFIG_ARM_KINEMATIC_CHAIN_NAME];
63  }
64 
65  if (config_arm.contains(CONFIG_ARM_HAND))
66  {
67  auto config_hand = config_arm[CONFIG_ARM_HAND];
68 
69  if (config_hand.contains(CONFIG_ARM_HAND_NAME))
70  {
71  arm.hand.name = config_hand[CONFIG_ARM_HAND_NAME];
72  }
73  if (config_hand.contains(CONFIG_ARM_HAND_FT_NAME))
74  {
75  arm.hand.ft_name = config_hand[CONFIG_ARM_HAND_FT_NAME];
76  }
77 
78  if (config_hand.contains(CONFIG_ARM_HAND_PRX))
79  {
80  p.usingProxy(config_hand[CONFIG_ARM_HAND_PRX]);
81  }
82  }
83  }
84  }
85  }
86 
87  void
89  {
91 
92  nlohmann::json config = nlohmann::json::parse(properties.configJson);
93 
94  auto& p = parent<RobotNameServiceComponentPluginUser>();
95 
96  if (config.contains(CONFIG_MNS_PRX))
97  {
98  auto mns = p.getProxy<armarx::armem::mns::MemoryNameSystemInterfacePrx>(
99  config[CONFIG_MNS_PRX]);
100  robot.memoryNameSystem = armarx::armem::client::MemoryNameSystem(mns, &p);
101  }
102 
103  if (config.contains(CONFIG_SKILLS_MANAGER_PRX))
104  {
105  auto skill_manager = p.getProxy<armarx::skills::manager::dti::SkillManagerInterfacePrx>(
106  config[CONFIG_SKILLS_MANAGER_PRX]);
107  robot.skillManager = skill_manager;
108  }
109 
110  if (config.contains(CONFIG_ARMS))
111  {
112  for (const auto& [k, config_arm] : config[CONFIG_ARMS].items())
113  {
114  auto& arm = robot.armInfos[k];
115 
116  if (config_arm.contains(CONFIG_ARM_HAND))
117  {
118  auto config_hand = config_arm[CONFIG_ARM_HAND];
119 
120  if (config_hand.contains(CONFIG_ARM_HAND_PRX))
121  {
122  auto hand_prx = p.getProxy<armarx::HandUnitInterfacePrx>(
123  config_hand[CONFIG_ARM_HAND_PRX]);
124  arm.hand.handUnitInterface = hand_prx;
125  }
126  }
127  }
128  }
129 
130  // finally commit robot
131  properties.rns->registerRobotInfo(robot.toIce());
132  }
133 
134  void
136  {
137  def->optional(properties.configJson, "robotConfigJson");
138  def->component(properties.rns);
139  }
140 
141  void
143  {
144  properties.rns->unregisterRobotInfo(robot.name);
145  }
146 
147 } // namespace armarx::plugins
armarx::plugins::RobotNameServiceComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: Plugin.cpp:88
Plugin.h
armarx::robot_name_service::client::constants
Definition: Plugin.h:18
armarx::robot_name_service::client::constants::CONFIG_ARM_HAND_FT_NAME
const auto CONFIG_ARM_HAND_FT_NAME
Definition: Plugin.h:30
armarx::robot_name_service::client::constants::CONFIG_XML_PACKAGE_PATH_PACKAGE
const auto CONFIG_XML_PACKAGE_PATH_PACKAGE
Definition: Plugin.h:22
armarx::robot_name_service::client::constants::CONFIG_MNS_PRX
const auto CONFIG_MNS_PRX
Definition: Plugin.h:24
armarx::robot_name_service::client::constants::CONFIG_SKILLS_MANAGER_PRX
const auto CONFIG_SKILLS_MANAGER_PRX
Definition: Plugin.h:25
armarx::ManagedIceObject::addPlugin
PluginT * addPlugin(const std::string prefix="", ParamsT &&...params)
Definition: ManagedIceObject.h:182
armarx::plugins::RobotNameServiceComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
Definition: Plugin.cpp:135
armarx::robot_name_service::client::constants::CONFIG_ARM_HAND
const auto CONFIG_ARM_HAND
Definition: Plugin.h:28
armarx::plugins::RobotNameServiceComponentPlugin::postOnInitComponent
void postOnInitComponent() override
Definition: Plugin.cpp:18
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:28
armarx::robot_name_service::core::RobotInfo::name
std::string name
Definition: Robot.h:44
armarx::robot_name_service::client::constants::CONFIG_XML_PACKAGE_PATH_PATH
const auto CONFIG_XML_PACKAGE_PATH_PATH
Definition: Plugin.h:23
Component.h
armarx::robot_name_service::client::constants::CONFIG_ARM_KINEMATIC_CHAIN_NAME
const auto CONFIG_ARM_KINEMATIC_CHAIN_NAME
Definition: Plugin.h:27
armarx::robot_name_service::client::constants::CONFIG_ARM_HAND_PRX
const auto CONFIG_ARM_HAND_PRX
Definition: Plugin.h:31
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::robot_name_service::client::constants::CONFIG_ARM_HAND_NAME
const auto CONFIG_ARM_HAND_NAME
Definition: Plugin.h:29
armarx::robot_name_service::client::constants::CONFIG_ROBOT_NAME
const auto CONFIG_ROBOT_NAME
Definition: Plugin.h:20
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::robot_name_service::client::constants::CONFIG_XML_PACKAGE_PATH
const auto CONFIG_XML_PACKAGE_PATH
Definition: Plugin.h:21
armarx::RobotNameServiceComponentPluginUser::RobotNameServiceComponentPluginUser
RobotNameServiceComponentPluginUser()
Definition: Plugin.cpp:8
armarx::robot_name_service::client::constants::CONFIG_ARMS
const auto CONFIG_ARMS
Definition: Plugin.h:26
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::plugins::RobotNameServiceComponentPlugin::preOnDisconnectComponent
void preOnDisconnectComponent() override
Definition: Plugin.cpp:142