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
39namespace 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 {
70 CMakePackageFinder finder(project);
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
105 getProperty<std::string>("TopicPrefix").getValue() + robotNodeSetName + "State";
107
108 offeringTopicFromProperty("SkillProviderTopic");
109
110 this->onInitKinematicUnit();
111 }
112
113 void
121
122 void
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 }
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
231} // namespace armarx
constexpr T c
static const std::string & GetProjectName()
static const Ice::StringSeq & GetProjectDependencies()
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
std::string getRobotName(const Ice::Current &=Ice::emptyCurrent) const override
void onInitComponent() override
Pure virtual hook for the subclass.
virtual void onStartKinematicUnit()=0
VirtualRobot::RobotPtr robot
std::vector< std::string > armarXPackages
std::string relativeRobotFile
void setJointAngles(const NameValueMap &targetJointAngles, const Ice::Current &c=Ice::emptyCurrent) override
void switchControlMode(const NameControlModeMap &targetJointModes, const Ice::Current &c=Ice::emptyCurrent) override
virtual void releaseKinematicUnit(const Ice::StringSeq &nodes, const Ice::Current &c=Ice::emptyCurrent)
std::vector< VirtualRobot::RobotNodePtr > robotNodes
std::vector< std::string > getArmarXPackages(const Ice::Current &=Ice::emptyCurrent) const override
getArmarXPackages
std::string robotNodeSetName
virtual void requestKinematicUnit(const Ice::StringSeq &nodes, const Ice::Current &c=Ice::emptyCurrent)
void onConnectComponent() override
Pure virtual hook for the subclass.
virtual void onExitKinematicUnit()=0
PropertyDefinitionsPtr createPropertyDefinitions() override
virtual void onInitKinematicUnit()=0
void onExitComponent() override
Hook for subclass.
std::string getRobotFilename(const Ice::Current &=Ice::emptyCurrent) const override
KinematicUnitListenerPrx listenerPrx
std::string getRobotNodeSetName(const Ice::Current &=Ice::emptyCurrent) const override
void setJointVelocities(const NameValueMap &targetJointVelocities, const Ice::Current &c=Ice::emptyCurrent) override
std::string getReportTopicName(const Ice::Current &=Ice::emptyCurrent) const override
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
void release(const Ice::Current &c=Ice::emptyCurrent) override
Release exclusive access to current unit.
void request(const Ice::Current &c=Ice::emptyCurrent) override
Request exclusive access to current unit.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const LogSender::manipulator flush
Definition LogSender.h:251