RobotIK.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2015-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 RobotComponents::ArmarXObjects::RobotIK
19  * @author Joshua Haustein ( joshua dot haustein at gmail dot com )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
30 
32 #include <RobotComponents/interface/components/RobotIK.h>
33 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
34 #include <RobotAPI/interface/core/RobotState.h>
35 
36 #include <VirtualRobot/IK/GenericIKSolver.h>
37 
38 #include <mutex>
39 
40 namespace armarx
41 {
48  {
49  public:
52  {
53  defineRequiredProperty<std::string>("RobotFileName", "Filename of VirtualRobot robot model (e.g. robot_model.xml)");
54  //Define optional properties
55  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the robot state component that should be used");
56  defineOptionalProperty<std::string>("ReachabilitySpacesFolder", "Path to a folder containing reachability spaces");
57  defineOptionalProperty<int>("NumIKTrials", 10, "Number of trials to find an ik solution");
58  defineOptionalProperty<std::string>("InitialReachabilitySpaces", "", "Reachability spaces to load initially (semi-colon separated)");
59  }
60  };
61 
118  virtual public Component,
119  virtual public RobotIKInterface
120  {
121  public:
122 
126  virtual std::string getRobotFilename(const Ice::Current&) const;
127 
131  PropertyDefinitionsPtr createPropertyDefinitions() override;
132 
133  std::string getDefaultName() const override
134  {
135  return "RobotIK";
136  }
137 
151  NameValueMap computeIKFramedPose(const std::string& robotNodeSetName,
152  const FramedPoseBasePtr& tcpPose, armarx::CartesianSelection cs, const Ice::Current& = Ice::emptyCurrent) override;
153 
166  NameValueMap computeIKGlobalPose(const std::string& robotNodeSetName,
167  const PoseBasePtr& tcpPose, armarx::CartesianSelection cs, const Ice::Current& = Ice::emptyCurrent) override;
168 
181  ExtendedIKResult computeExtendedIKGlobalPose(const std::string& robotNodeSetName,
182  const PoseBasePtr& tcpPose, armarx::CartesianSelection cs, const Ice::Current& = Ice::emptyCurrent) override;
183 
195  NameValueMap computeCoMIK(const std::string& robotNodeSetJoints, const CoMIKDescriptor& desc, const Ice::Current& = Ice::emptyCurrent) override;
196 
220  NameValueMap computeHierarchicalDeltaIK(const std::string& robotNodeSet,
221  const IKTasks& iktasks, const CoMIKDescriptor& comIK,
222  float stepSize, bool avoidJointLimits, bool enableCenterOfMass, const Ice::Current& = Ice::emptyCurrent) override;
223 
244  bool createReachabilitySpace(const std::string& chainName, const std::string& coordinateSystem, float stepTranslation, float stepRotation,
245  const WorkspaceBounds& minBounds, const WorkspaceBounds& maxBounds, int numSamples, const Ice::Current& = Ice::emptyCurrent) override;
246 
258  bool defineRobotNodeSet(const std::string& name, const NodeNameList& nodes,
259  const std::string& tcpName, const std::string& rootNode, const Ice::Current& = Ice::emptyCurrent) override;
260 
268  bool hasReachabilitySpace(const std::string& chainName, const Ice::Current& = Ice::emptyCurrent) const override;
269 
284  bool isFramedPoseReachable(const std::string& chainName, const FramedPoseBasePtr& tcpPose, const Ice::Current& = Ice::emptyCurrent) const override;
285 
299  bool isPoseReachable(const std::string& chainName, const PoseBasePtr& tcpPose, const Ice::Current& = Ice::emptyCurrent) const override;
300 
311  bool loadReachabilitySpace(const std::string& filename, const Ice::Current& = Ice::emptyCurrent) override;
312 
322  bool saveReachabilitySpace(const std::string& robotNodeSet, const std::string& filename, const Ice::Current& = Ice::emptyCurrent) const override;
323 
324 
325  protected:
330  void onInitComponent() override;
331  void onConnectComponent() override;
332  void onDisconnectComponent() override;
333 
334  private:
335  bool solveIK(const Eigen::Matrix4f& tcpPose, armarx::CartesianSelection cs, VirtualRobot::RobotNodeSetPtr nodeSet);
336  void computeIK(const std::string& robotNodeSetName, const Eigen::Matrix4f& tcpPose,
337  armarx::CartesianSelection cs, NameValueMap& iksolution);
338 
339  void computeIK(VirtualRobot::RobotNodeSetPtr nodeSet, const Eigen::Matrix4f& tcpPose,
340  armarx::CartesianSelection cs, NameValueMap& iksolution);
341 
342  void computeIK(const std::string& robotNodeSetName, const Eigen::Matrix4f& tcpPose,
343  armarx::CartesianSelection cs, ExtendedIKResult& iksolution);
344 
345  void computeIK(VirtualRobot::RobotNodeSetPtr nodeSet, const Eigen::Matrix4f& tcpPose,
346  armarx::CartesianSelection cs, ExtendedIKResult& iksolution);
347 
348  Eigen::Matrix4f toGlobalPose(const FramedPoseBasePtr& tcpPose) const;
349  Eigen::Matrix4f toReachabilityMapFrame(const FramedPoseBasePtr& tcpPose, const std::string& chainName) const;
350 
351  bool isReachable(const std::string& setName, const Eigen::Matrix4f& tcpPose) const;
352 
353  VirtualRobot::IKSolver::CartesianSelection convertCartesianSelection(armarx::CartesianSelection cs) const;
354 
355  VirtualRobot::JacobiProvider::InverseJacobiMethod convertInverseJacobiMethod(armarx::InverseJacobiMethod aenum) const;
356 
357  void synchRobot() const;
358 
359  // Lock this mutex if you plan to modify the robot model
360  // Exception: When adding node sets we don't need to.
361  // Invariant: We never delete node sets nor nodes!
362  mutable std::recursive_mutex _modifyRobotModelMutex;
363  // Lock this mutex if you are adding a node set, to ensure we do not add
364  // a similar node set at the same time.
365  mutable std::recursive_mutex _editRobotNodeSetsMutex;
366  // Lock this mutex if you are reading or editing the reachability cache.
367  mutable std::recursive_mutex _accessReachabilityCacheMutex;
368  // Needs to be locked when computing IKs! Internally thread safe though.
369  VirtualRobot::RobotPtr _robotModel;
370  std::string _robotFile;
371  RobotStateComponentInterfacePrx _robotStateComponentPrx;
372  SharedRobotInterfacePrx _synchronizedRobot;
373  DebugDrawerInterfacePrx debugDrawer;
374 
375  // Reachability cache: not thread safe, always lock!
376  using ReachabilityCacheType = std::map<std::string, VirtualRobot::WorkspaceRepresentationPtr>;
377  ReachabilityCacheType _reachabilities;
378  int _numIKTrials;
379  };
380 
381 }
382 
Properties.h
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
RobotAPIObjectFactories.h
armarx::RobotIK
Refer to RobotIK.
Definition: RobotIK.h:117
armarx::SharedRobotInterfacePrx
::IceInternal::ProxyHandle< ::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
Definition: FramedPose.h:57
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::RobotIKPropertyDefinitions
Definition: RobotIK.h:46
filename
std::string filename
Definition: VisualizationRobot.cpp:84
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::RobotIKPropertyDefinitions::RobotIKPropertyDefinitions
RobotIKPropertyDefinitions(std::string prefix)
Definition: RobotIK.h:50
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RobotIK::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: RobotIK.h:133
armarx::DebugDrawerInterfacePrx
::IceInternal::ProxyHandle< ::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
Definition: JointController.h:40
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ImportExportComponent.h