kinematics-dynamics
KdlTreeSolver.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __KDL_TREE_SOLVER_HPP__
4 #define __KDL_TREE_SOLVER_HPP__
5 
6 #include <map>
7 #include <string>
8 #include <vector>
9 
10 #include <yarp/dev/DeviceDriver.h>
11 
12 #include <kdl/tree.hpp>
13 #include <kdl/treefksolver.hpp>
14 #include <kdl/treeiksolver.hpp>
15 #include <kdl/treeidsolver.hpp>
16 
17 #include "ICartesianSolver.h"
18 
19 namespace roboticslab
20 {
21 
33 class KdlTreeSolver : public yarp::dev::DeviceDriver,
34  public ICartesianSolver
35 {
36 public:
37  KdlTreeSolver() : fkSolverPos(nullptr),
38  ikSolverPos(nullptr),
39  ikSolverVel(nullptr),
40  idSolver(nullptr)
41  {}
42 
43  // -- ICartesianSolver declarations. Implementation in ICartesianSolverImpl.cpp --
44 
45  // Get number of joints for which the solver has been configured.
46  int getNumJoints() override;
47 
48  // Get number of TCPs for which the solver has been configured.
49  int getNumTcps() override;
50 
51  // Append an additional link.
52  bool appendLink(const std::vector<double> & x) override;
53 
54  // Restore original kinematic chain.
55  bool restoreOriginalChain() override;
56 
57  // Change reference frame.
58  bool changeOrigin(const std::vector<double> & x_old_obj,
59  const std::vector<double> & x_new_old,
60  std::vector<double> & x_new_obj) override;
61 
62  // Perform forward kinematics.
63  bool fwdKin(const std::vector<double> & q, std::vector<double> & x) override;
64 
65  // Obtain difference between supplied pose inputs.
66  bool poseDiff(const std::vector<double> & xLhs, const std::vector<double> & xRhs, std::vector<double> & xOut) override;
67 
68  // Perform inverse kinematics.
69  bool invKin(const std::vector<double> & xd, const std::vector<double> & qGuess, std::vector<double> & q,
70  reference_frame frame) override;
71 
72  // Perform differential inverse kinematics.
73  bool diffInvKin(const std::vector<double> & q, const std::vector<double> & xdot, std::vector<double> & qdot,
74  reference_frame frame) override;
75 
76  // Perform inverse dynamics.
77  bool invDyn(const std::vector<double> & q, std::vector<double> & t) override;
78 
79  // Perform inverse dynamics.
80  bool invDyn(const std::vector<double> & q, const std::vector<double> & qdot, const std::vector<double> & qdotdot,
81  const std::vector<double> & ftip, std::vector<double> & t, reference_frame frame) override;
82 
83  // -------- DeviceDriver declarations. Implementation in IDeviceImpl.cpp --------
84 
85  bool open(yarp::os::Searchable & config) override;
86 
87  bool close() override;
88 
89 protected:
90  std::vector<std::string> endpoints;
91  std::map<std::string, std::string> mergedEndpoints;
92  KDL::Tree tree;
93  KDL::TreeFkSolverPos * fkSolverPos;
94  KDL::TreeIkSolverPos * ikSolverPos;
95  KDL::TreeIkSolverVel * ikSolverVel;
96  KDL::TreeIdSolver * idSolver;
97 };
98 
99 } // namespace roboticslab
100 
101 #endif // __KDL_TREE_SOLVER_HPP__
Contains roboticslab::ICartesianSolver.
Abstract base class for a cartesian solver.
Definition: ICartesianSolver.h:23
reference_frame
Lists supported reference frames.
Definition: ICartesianSolver.h:27
The KdlTreeSolver class implements ICartesianSolver.
Definition: KdlTreeSolver.hpp:35
bool poseDiff(const std::vector< double > &xLhs, const std::vector< double > &xRhs, std::vector< double > &xOut) override
Obtain difference between supplied pose inputs.
Definition: ICartesianSolverImpl.cpp:103
bool invDyn(const std::vector< double > &q, std::vector< double > &t) override
Perform inverse dynamics.
Definition: ICartesianSolverImpl.cpp:262
bool diffInvKin(const std::vector< double > &q, const std::vector< double > &xdot, std::vector< double > &qdot, reference_frame frame) override
Perform differential inverse kinematics.
Definition: ICartesianSolverImpl.cpp:193
bool restoreOriginalChain() override
Restore original kinematic chain.
Definition: ICartesianSolverImpl.cpp:42
bool invKin(const std::vector< double > &xd, const std::vector< double > &qGuess, std::vector< double > &q, reference_frame frame) override
Perform inverse kinematics.
Definition: ICartesianSolverImpl.cpp:127
int getNumJoints() override
Get number of joints for which the solver has been configured.
Definition: ICartesianSolverImpl.cpp:20
bool fwdKin(const std::vector< double > &q, std::vector< double > &x) override
Perform forward kinematics.
Definition: ICartesianSolverImpl.cpp:73
bool appendLink(const std::vector< double > &x) override
Append an additional link.
Definition: ICartesianSolverImpl.cpp:34
int getNumTcps() override
Get number of TCPs for which the solver has been configured.
Definition: ICartesianSolverImpl.cpp:27
bool changeOrigin(const std::vector< double > &x_old_obj, const std::vector< double > &x_new_old, std::vector< double > &x_new_obj) override
Change origin in which a pose is expressed.
Definition: ICartesianSolverImpl.cpp:50
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6