KinematicUnit.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::units
19  * @author Christian Boege (boege at kit dot edu)
20  * @date 2011
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #include "KinematicUnit.h"
27 
28 #include <SimoxUtility/algorithm/string/string_tools.h>
29 #include <VirtualRobot/Nodes/RobotNode.h>
30 #include <VirtualRobot/RobotNodeSet.h>
31 #include <VirtualRobot/VirtualRobot.h>
32 #include <VirtualRobot/VirtualRobotException.h>
33 #include <VirtualRobot/XML/RobotIO.h>
34 
38 
39 namespace armarx
40 {
41  void
43  {
44  // read names of kinematic chain elements belonging to this unit from XML and setup a map of all joints
45  // the kinematic chain elements belonging to this unit are defined in a RobotNodeSet
46  robotNodeSetName = getProperty<std::string>("RobotNodeSetName").getValue();
47 
48  const std::string project = getProperty<std::string>("RobotFileNameProject").getValue();
49  {
50  std::vector<std::string> result;
51  const auto& packages = armarx::Application::GetProjectDependencies();
52  std::set<std::string> packageSet{packages.begin(), packages.end()};
53  packageSet.emplace(Application::GetProjectName());
54  packageSet.emplace(project);
55  packageSet.erase("");
56  armarXPackages.assign(packageSet.begin(), packageSet.end());
57  }
58 
59  if (relativeRobotFile.empty())
60  {
61  relativeRobotFile = getProperty<std::string>("RobotFileName").getValue();
62  }
63 
64  if (!robot)
65  {
66  Ice::StringSeq includePaths;
67 
68  if (!project.empty())
69  {
71 
72  auto pathsString = finder.getDataDir();
73  Ice::StringSeq projectIncludePaths = simox::alg::split(pathsString, ";,");
74  includePaths.insert(
75  includePaths.end(), projectIncludePaths.begin(), projectIncludePaths.end());
76  }
77  std::string robotFile = relativeRobotFile;
78  if (!ArmarXDataPath::getAbsolutePath(robotFile, robotFile, includePaths))
79  {
80  throw UserException("Could not find robot file " + robotFile);
81  }
82 
83  // read the robot
84  try
85  {
86  robot =
87  VirtualRobot::RobotIO::loadRobot(robotFile, VirtualRobot::RobotIO::eStructure);
88  }
89  catch (VirtualRobot::VirtualRobotException& e)
90  {
91  throw UserException(e.what());
92  }
93  }
94  // read the robot node set and initialize the joints of this kinematic unit
95  if (robotNodeSetName == "")
96  {
97  throw UserException("RobotNodeSet not defined");
98  }
99 
100  VirtualRobot::RobotNodeSetPtr robotNodeSetPtr = robot->getRobotNodeSet(robotNodeSetName);
101  robotNodes = robotNodeSetPtr->getAllRobotNodes();
102 
103  // component dependencies
104  listenerName =
105  getProperty<std::string>("TopicPrefix").getValue() + robotNodeSetName + "State";
107 
108  offeringTopicFromProperty("SkillProviderTopic");
109 
110  this->onInitKinematicUnit();
111  }
112 
113  void
115  {
116  ARMARX_INFO << "setting report topic to " << listenerName << flush;
117  listenerPrx = getTopic<KinematicUnitListenerPrx>(listenerName);
118 
119  this->onStartKinematicUnit();
120  }
121 
122  void
124  {
125  this->onExitKinematicUnit();
126  }
127 
128  void
129  KinematicUnit::switchControlMode(const NameControlModeMap& targetJointModes,
130  const Ice::Current& c)
131  {
132  }
133 
134  void
135  KinematicUnit::setJointAngles(const NameValueMap& targetJointAngles, const Ice::Current& c)
136  {
137  }
138 
139  void
140  KinematicUnit::setJointVelocities(const NameValueMap& targetJointVelocities,
141  const Ice::Current& c)
142  {
143  }
144 
145  void
147  {
148  NameControlModeMap c;
149  NameValueMap t;
150  for (const auto& j : getJoints())
151  {
152  c[j] = ControlMode::ePositionControl;
153  t[j] = 0;
154  }
156  setJointAngles(t);
157  }
158 
159  void
161  {
162  NameControlModeMap c;
163  NameValueMap t;
164  for (const auto& j : getJoints())
165  {
166  c[j] = ControlMode::eVelocityControl;
167  t[j] = 0;
168  }
171  }
172 
173  void
174  KinematicUnit::requestKinematicUnit(const Ice::StringSeq& nodes, const Ice::Current& c)
175  {
177  }
178 
179  void
180  KinematicUnit::releaseKinematicUnit(const Ice::StringSeq& nodes, const Ice::Current& c)
181  {
183  }
184 
185  std::string
186  KinematicUnit::getRobotFilename(const Ice::Current&) const
187  {
188  return relativeRobotFile;
189  }
190 
191  std::vector<std::string>
192  KinematicUnit::getArmarXPackages(const Ice::Current&) const
193  {
194  return armarXPackages;
195  }
196 
197  std::string
198  KinematicUnit::getRobotName(const Ice::Current&) const
199  {
200  if (robot)
201  {
202  return robot->getName();
203  }
204  else
205  {
206  throw NotInitializedException("Robot Ptr is NULL", "getName");
207  }
208  }
209 
210  std::string
211  KinematicUnit::getRobotNodeSetName(const Ice::Current&) const
212  {
213  if (robotNodeSetName.empty())
214  {
215  throw NotInitializedException("RobotNodeSetName is empty", "getRobotNodeSetName");
216  }
217  return robotNodeSetName;
218  }
219 
220  std::string
221  KinematicUnit::getReportTopicName(const Ice::Current&) const
222  {
223  return listenerName;
224  }
225 
228  {
230  }
231 } // namespace armarx
armarx::KinematicUnit::relativeRobotFile
std::string relativeRobotFile
Definition: KinematicUnit.h:154
armarx::Application::GetProjectName
static const std::string & GetProjectName()
Definition: Application.cpp:879
armarx::KinematicUnit::setJointAngles
void setJointAngles(const NameValueMap &targetJointAngles, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnit.cpp:135
armarx::KinematicUnit::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: KinematicUnit.cpp:123
armarx::SensorActorUnit::release
void release(const Ice::Current &c=Ice::emptyCurrent) override
Release exclusive access to current unit.
Definition: SensorActorUnit.cpp:149
armarx::KinematicUnit::onStartKinematicUnit
virtual void onStartKinematicUnit()=0
armarx::KinematicUnit::robotNodeSetName
std::string robotNodeSetName
Definition: KinematicUnit.h:156
armarx::Component::offeringTopicFromProperty
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Definition: Component.cpp:159
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:52
armarx::SensorActorUnit::request
void request(const Ice::Current &c=Ice::emptyCurrent) override
Request exclusive access to current unit.
Definition: SensorActorUnit.cpp:130
armarx::KinematicUnit::getArmarXPackages
std::vector< std::string > getArmarXPackages(const Ice::Current &=Ice::emptyCurrent) const override
getArmarXPackages
Definition: KinematicUnit.cpp:192
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::KinematicUnit::setJointAnglesToZero
void setJointAnglesToZero()
Definition: KinematicUnit.cpp:146
KinematicUnit.h
project
std::string project
Definition: VisualizationRobot.cpp:85
armarx::KinematicUnit::getReportTopicName
std::string getReportTopicName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: KinematicUnit.cpp:221
armarx::KinematicUnit::getRobotName
std::string getRobotName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: KinematicUnit.cpp:198
armarx::KinematicUnit::onExitKinematicUnit
virtual void onExitKinematicUnit()=0
armarx::KinematicUnit::setJointVelocitiesToZero
void setJointVelocitiesToZero()
Definition: KinematicUnit.cpp:160
armarx::KinematicUnit::armarXPackages
std::vector< std::string > armarXPackages
Definition: KinematicUnit.h:159
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::KinematicUnit::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: KinematicUnit.cpp:114
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:194
armarx::KinematicUnit::setJointVelocities
void setJointVelocities(const NameValueMap &targetJointVelocities, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnit.cpp:140
armarx::KinematicUnitPropertyDefinitions
Definition: KinematicUnit.h:44
armarx::KinematicUnit::getRobotNodeSetName
std::string getRobotNodeSetName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: KinematicUnit.cpp:211
armarx::KinematicUnit::releaseKinematicUnit
virtual void releaseKinematicUnit(const Ice::StringSeq &nodes, const Ice::Current &c=Ice::emptyCurrent)
Definition: KinematicUnit.cpp:180
armarx::KinematicUnit::switchControlMode
void switchControlMode(const NameControlModeMap &targetJointModes, const Ice::Current &c=Ice::emptyCurrent) override
Definition: KinematicUnit.cpp:129
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:88
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
CMakePackageFinder.h
armarx::KinematicUnit::listenerName
std::string listenerName
Definition: KinematicUnit.h:157
armarx::KinematicUnit::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: KinematicUnit.cpp:227
armarx::KinematicUnit::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: KinematicUnit.cpp:42
armarx::KinematicUnit::listenerPrx
KinematicUnitListenerPrx listenerPrx
Definition: KinematicUnit.h:152
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::KinematicUnit::requestKinematicUnit
virtual void requestKinematicUnit(const Ice::StringSeq &nodes, const Ice::Current &c=Ice::emptyCurrent)
Definition: KinematicUnit.cpp:174
armarx::KinematicUnit::onInitKinematicUnit
virtual void onInitKinematicUnit()=0
armarx::KinematicUnit::getRobotFilename
std::string getRobotFilename(const Ice::Current &=Ice::emptyCurrent) const override
Definition: KinematicUnit.cpp:186
armarx::ArmarXDataPath::getAbsolutePath
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
Definition: ArmarXDataPath.cpp:109
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
ArmarXDataPath.h
armarx::KinematicUnit::robot
VirtualRobot::RobotPtr robot
Definition: KinematicUnit.h:155
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::Application::GetProjectDependencies
static const Ice::StringSeq & GetProjectDependencies()
Definition: Application.cpp:885
Application.h
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:38
armarx::KinematicUnit::robotNodes
std::vector< VirtualRobot::RobotNodePtr > robotNodes
Definition: KinematicUnit.h:158