PositionControllerHelper.h
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),
5  * Karlsruhe Institute of Technology (KIT), all rights reserved.
6  *
7  * ArmarX is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #pragma once
25 
26 #include <Eigen/Dense>
27 
29 
30 #include <VirtualRobot/Robot.h>
31 
34 
35 namespace Eigen
36 {
38 }
39 
40 
41 namespace armarx
42 {
43 
44  class PositionControllerHelper;
45  using PositionControllerHelperPtr = std::shared_ptr<PositionControllerHelper>;
46 
48  {
49  public:
50  PositionControllerHelper(const VirtualRobot::RobotNodePtr& tcp, const VelocityControllerHelperPtr& velocityControllerHelper, const Eigen::Matrix4f& target);
51  PositionControllerHelper(const VirtualRobot::RobotNodePtr& tcp, const VelocityControllerHelperPtr& velocityControllerHelper, const std::vector<Eigen::Matrix4f>& waypoints);
52  PositionControllerHelper(const VirtualRobot::RobotNodePtr& tcp, const VelocityControllerHelperPtr& velocityControllerHelper, const std::vector<PosePtr>& waypoints);
53 
54  void readConfig(const CartesianPositionControllerConfigBase& config);
55  void readConfig(const CartesianPositionControllerConfigBasePtr& config);
56 
57  // read data and write targets, call this if you are unsure, anywhere in your control loop.
58  // use updateRead and updateWrite for better performance
59  void update();
60  // read data, call this after robot sync
61  void updateRead();
62  // write targets, call this at the end of your control loop, before the sleep
63  void updateWrite();
64 
65  void setNewWaypoints(const std::vector<Eigen::Matrix4f>& waypoints);
66  void setNewWaypoints(const std::vector<PosePtr>& waypoints);
67  void addWaypoint(const Eigen::Matrix4f& waypoint);
68  void setTarget(const Eigen::Matrix4f& target);
70  void setFeedForwardVelocity(const Eigen::Vector3f& feedForwardVelocityPos, const Eigen::Vector3f& feedForwardVelocityOri);
72  void immediateHardStop(bool clearTargets = true);
73 
74  float getPositionError() const;
75 
76  float getOrientationError() const;
77 
78  bool isCurrentTargetReached() const;
79  bool isCurrentTargetNear() const;
80  bool isFinalTargetReached() const;
81  bool isFinalTargetNear() const;
82 
83  bool isLastWaypoint() const;
84 
85  const Eigen::Matrix4f& getCurrentTarget() const;
86  const Eigen::Vector3f getCurrentTargetPosition() const;
87 
88  size_t skipToClosestWaypoint(float rad2mmFactor);
89 
90  void setNullSpaceControl(bool enabled);
91 
92  std::string getStatusText();
93 
95  {
97  int loops = 100;
98  float stepLength = 0.05f;
99  float eps = 0.001;
100  float maxOriErrorIncrease = 1.f / 180 * M_PI;
103  VirtualRobot::JacobiProvider::InverseJacobiMethod invJacMethod = VirtualRobot::JacobiProvider::eSVD;
104  };
105 
106  /**
107  * @brief OptimizeNullspace
108  * @param tcp
109  * @param rns
110  * @param target target pose in root frame of the robot
111  * @param args
112  * @return
113  */
114  static bool OptimizeNullspace(const VirtualRobot::RobotNodePtr& tcp, const VirtualRobot::RobotNodeSetPtr& rns, const Eigen::Matrix4f& target, const NullspaceOptimizationArgs& args = NullspaceOptimizationArgs());
115 
118 
119  std::vector<Eigen::Matrix4f> waypoints;
121 
126  Eigen::Vector6f feedForwardVelocity = Eigen::Vector6f::Zero();
127  bool autoClearFeedForward = true;
128  };
129 }
armarx::PositionControllerHelper::NullspaceOptimizationArgs::maxOriErrorIncrease
float maxOriErrorIncrease
Definition: PositionControllerHelper.h:100
armarx::PositionControllerHelper::clearFeedForwardVelocity
void clearFeedForwardVelocity()
Definition: PositionControllerHelper.cpp:136
Eigen
Definition: Elements.h:36
armarx::PositionControllerHelper::isCurrentTargetNear
bool isCurrentTargetNear() const
Definition: PositionControllerHelper.cpp:165
armarx::PositionControllerHelper::NullspaceOptimizationArgs::loops
int loops
Definition: PositionControllerHelper.h:97
armarx::PositionControllerHelper::getStatusText
std::string getStatusText()
Definition: PositionControllerHelper.cpp:219
armarx::PositionControllerHelper::thresholdPositionNear
float thresholdPositionNear
Definition: PositionControllerHelper.h:124
armarx::PositionControllerHelper::addWaypoint
void addWaypoint(const Eigen::Matrix4f &waypoint)
Definition: PositionControllerHelper.cpp:113
armarx::PositionControllerHelper::getCurrentTargetPosition
const Eigen::Vector3f getCurrentTargetPosition() const
Definition: PositionControllerHelper.cpp:190
Pose.h
armarx::PositionControllerHelper::posController
CartesianPositionController posController
Definition: PositionControllerHelper.h:116
VelocityControllerHelper.h
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::PositionControllerHelper::setNullSpaceControl
void setNullSpaceControl(bool enabled)
Definition: PositionControllerHelper.cpp:214
armarx::PositionControllerHelper::isFinalTargetNear
bool isFinalTargetNear() const
Definition: PositionControllerHelper.cpp:175
armarx::PositionControllerHelper::NullspaceOptimizationArgs::maxPoseErrorIncrease
float maxPoseErrorIncrease
Definition: PositionControllerHelper.h:101
armarx::PositionControllerHelper::NullspaceOptimizationArgs::stepLength
float stepLength
Definition: PositionControllerHelper.h:98
armarx::PositionControllerHelper::thresholdOrientationNear
float thresholdOrientationNear
Definition: PositionControllerHelper.h:125
armarx::PositionControllerHelper
Definition: PositionControllerHelper.h:47
armarx::PositionControllerHelper::NullspaceOptimizationArgs
Definition: PositionControllerHelper.h:94
armarx::PositionControllerHelper::updateWrite
void updateWrite()
Definition: PositionControllerHelper.cpp:86
armarx::PositionControllerHelper::immediateHardStop
void immediateHardStop(bool clearTargets=true)
Definition: PositionControllerHelper.cpp:141
armarx::PositionControllerHelper::feedForwardVelocity
Eigen::Vector6f feedForwardVelocity
Definition: PositionControllerHelper.h:126
armarx::PositionControllerHelper::isFinalTargetReached
bool isFinalTargetReached() const
Definition: PositionControllerHelper.cpp:170
armarx::PositionControllerHelper::update
void update()
Definition: PositionControllerHelper.cpp:72
armarx::PositionControllerHelper::thresholdPositionReached
float thresholdPositionReached
Definition: PositionControllerHelper.h:122
armarx::PositionControllerHelper::waypoints
std::vector< Eigen::Matrix4f > waypoints
Definition: PositionControllerHelper.h:119
M_PI
#define M_PI
Definition: MathTools.h:17
armarx::PositionControllerHelper::updateRead
void updateRead()
Definition: PositionControllerHelper.cpp:78
armarx::PositionControllerHelper::NullspaceOptimizationArgs::eps
float eps
Definition: PositionControllerHelper.h:99
armarx::PositionControllerHelper::setFeedForwardVelocity
void setFeedForwardVelocity(const Eigen::Vector6f &feedForwardVelocity)
Definition: PositionControllerHelper.cpp:125
armarx::PositionControllerHelper::velocityControllerHelper
VelocityControllerHelperPtr velocityControllerHelper
Definition: PositionControllerHelper.h:117
armarx::PositionControllerHelper::autoClearFeedForward
bool autoClearFeedForward
Definition: PositionControllerHelper.h:127
armarx::PositionControllerHelper::NullspaceOptimizationArgs::invJacMethod
VirtualRobot::JacobiProvider::InverseJacobiMethod invJacMethod
Definition: PositionControllerHelper.h:103
armarx::NJointTaskSpaceDMPControllerMode::CartesianSelection
CartesianSelection
Definition: ControllerInterface.ice:34
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
armarx::PositionControllerHelper::currentWaypointIndex
size_t currentWaypointIndex
Definition: PositionControllerHelper.h:120
armarx::PositionControllerHelper::getCurrentTarget
const Eigen::Matrix4f & getCurrentTarget() const
Definition: PositionControllerHelper.cpp:185
armarx::PositionControllerHelper::skipToClosestWaypoint
size_t skipToClosestWaypoint(float rad2mmFactor)
Definition: PositionControllerHelper.cpp:195
armarx::PositionControllerHelper::PositionControllerHelper
PositionControllerHelper(const VirtualRobot::RobotNodePtr &tcp, const VelocityControllerHelperPtr &velocityControllerHelper, const Eigen::Matrix4f &target)
Definition: PositionControllerHelper.cpp:35
Eigen::Vector6f
Matrix< float, 6, 1 > Vector6f
Definition: CartesianNaturalPositionController.h:40
armarx::PositionControllerHelperPtr
std::shared_ptr< PositionControllerHelper > PositionControllerHelperPtr
Definition: PositionControllerHelper.h:45
CartesianPositionController.h
armarx::PositionControllerHelper::thresholdOrientationReached
float thresholdOrientationReached
Definition: PositionControllerHelper.h:123
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::PositionControllerHelper::OptimizeNullspace
static bool OptimizeNullspace(const VirtualRobot::RobotNodePtr &tcp, const VirtualRobot::RobotNodeSetPtr &rns, const Eigen::Matrix4f &target, const NullspaceOptimizationArgs &args=NullspaceOptimizationArgs())
OptimizeNullspace.
Definition: PositionControllerHelper.cpp:227
armarx::PositionControllerHelper::NullspaceOptimizationArgs::NullspaceOptimizationArgs
NullspaceOptimizationArgs()
Definition: PositionControllerHelper.h:96
armarx::PositionControllerHelper::getOrientationError
float getOrientationError() const
Definition: PositionControllerHelper.cpp:155
armarx::PositionControllerHelper::NullspaceOptimizationArgs::cartesianSelection
VirtualRobot::IKSolver::CartesianSelection cartesianSelection
Definition: PositionControllerHelper.h:102
armarx::PositionControllerHelper::readConfig
void readConfig(const CartesianPositionControllerConfigBase &config)
Definition: PositionControllerHelper.cpp:55
armarx::CartesianPositionController
Definition: CartesianPositionController.h:41
armarx::PositionControllerHelper::isCurrentTargetReached
bool isCurrentTargetReached() const
Definition: PositionControllerHelper.cpp:160
Eigen::Matrix
Definition: EigenForwardDeclarations.h:27
armarx::PositionControllerHelper::setTarget
void setTarget(const Eigen::Matrix4f &target)
Definition: PositionControllerHelper.cpp:118
armarx::PositionControllerHelper::isLastWaypoint
bool isLastWaypoint() const
Definition: PositionControllerHelper.cpp:180
armarx::PositionControllerHelper::getPositionError
float getPositionError() const
Definition: PositionControllerHelper.cpp:150
armarx::VelocityControllerHelperPtr
std::shared_ptr< VelocityControllerHelper > VelocityControllerHelperPtr
Definition: VelocityControllerHelper.h:36
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PositionControllerHelper::setNewWaypoints
void setNewWaypoints(const std::vector< Eigen::Matrix4f > &waypoints)
Definition: PositionControllerHelper.cpp:97