Blender V4.3
Armature.hpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Benoit Bolsee
2 *
3 * SPDX-License-Identifier: LGPL-2.1-or-later */
4
9#ifndef ARMATURE_HPP_
10#define ARMATURE_HPP_
11
12#include "ControlledObject.hpp"
13#include "ConstraintSet.hpp"
16#include <vector>
17
18namespace iTaSC {
19
21public:
22 Armature();
23 virtual ~Armature();
24
25 bool addSegment(const std::string& segment_name, const std::string& hook_name, const Joint& joint, const double& q_rest, const Frame& f_tip=F_identity, const Inertia& M = Inertia::Zero());
26 // general purpose constraint on joint
27 int addConstraint(const std::string& segment_name, ConstraintCallback _function, void* _param=NULL, bool _freeParam=false, bool _substep=false);
28 // specific limit constraint on joint
29 int addLimitConstraint(const std::string& segment_name, unsigned int dof, double _min, double _max);
30 double getMaxJointChange();
32 bool getSegment(const std::string& segment_name, const unsigned int q_size, const Joint* &p_joint, double &q_rest, double &q, const Frame* &p_tip);
33 bool getRelativeFrame(Frame& result, const std::string& segment_name, const std::string& base_name=m_root);
34
35 virtual bool finalize();
36
37 virtual int addEndEffector(const std::string& name);
38 virtual const Frame& getPose(const unsigned int end_effector);
39 virtual bool updateJoint(const Timestamp& timestamp, JointLockCallback& callback);
40 virtual void updateKinematics(const Timestamp& timestamp);
41 virtual void pushCache(const Timestamp& timestamp);
42 virtual void updateControlOutput(const Timestamp& timestamp);
43 virtual bool setControlParameter(unsigned int constraintId, unsigned int valueId, ConstraintAction action, double value, double timestep=0.0);
44 virtual void initCache(Cache *_cache);
45 virtual bool setJointArray(const KDL::JntArray& joints);
46 virtual const KDL::JntArray& getJointArray();
47
48 virtual double getArmLength()
49 {
50 return m_armlength;
51 }
52
54 std::string name;
57 Effector_struct(const std::string& _name) {name = _name; oldpose = pose = F_identity;}
58 };
59 typedef std::vector<Effector_struct> EffectorList;
60
71 SegmentMap::const_iterator segment;
75 unsigned int v_nr;
76 unsigned int y_nr; // first coordinate of constraint in Y vector
77 void* param;
79 bool substep;
80 JointConstraint_struct(SegmentMap::const_iterator _segment, unsigned int _y_nr, ConstraintCallback _function, void* _param, bool _freeParam, bool _substep);
82 };
83 typedef std::vector<JointConstraint_struct*> JointConstraintList;
84
85 struct Joint_struct {
87 unsigned short ndof;
89 bool locked;
90 double rest;
91 double min;
92 double max;
93
94 Joint_struct(KDL::Joint::JointType _type, unsigned int _ndof, double _rest) :
95 type(_type), ndof(_ndof), rest(_rest) { useLimit=locked=false; min=0.0; max=0.0; }
96 };
97 typedef std::vector<Joint_struct> JointList;
98
99protected:
100 virtual void updateJacobian();
101
102private:
103 static std::string m_root;
104 Tree m_tree;
105 unsigned int m_njoint;
106 unsigned int m_nconstraint;
107 unsigned int m_noutput;
108 unsigned int m_neffector;
109 bool m_finalized;
110 Cache* m_cache;
111 double *m_buf;
112 int m_qCCh;
113 CacheTS m_qCTs;
114 int m_yCCh;
115#if 0
116 CacheTS m_yCTs;
117#endif
118 JntArray m_qKdl;
119 JntArray m_oldqKdl;
120 JntArray m_newqKdl;
121 JntArray m_qdotKdl;
122 Jacobian* m_jac;
123 double m_armlength;
124
125 KDL::TreeJntToJacSolver* m_jacsolver;
127 EffectorList m_effectors;
128 JointConstraintList m_constraints;
129 JointList m_joints;
130
131 void pushQ(CacheTS timestamp);
132 bool popQ(CacheTS timestamp);
133 //void pushConstraints(CacheTS timestamp);
134 //bool popConstraints(CacheTS timestamp);
135
136};
137
138}
139
140#endif /* ARMATURE_HPP_ */
represents a frame transformation in 3D space (rotation + translation)
Definition frames.hpp:526
static Inertia Zero()
Definition inertia.hpp:46
This class encapsulates a simple joint, that is with one parameterized degree of freedom and with sca...
Definition joint.hpp:43
This class encapsulates a tree kinematic interconnection structure. It is build out of segments.
Definition tree.hpp:68
virtual void initCache(Cache *_cache)
Definition Armature.cpp:136
std::vector< Joint_struct > JointList
Definition Armature.hpp:97
bool addSegment(const std::string &segment_name, const std::string &hook_name, const Joint &joint, const double &q_rest, const Frame &f_tip=F_identity, const Inertia &M=Inertia::Zero())
Definition Armature.cpp:232
int addLimitConstraint(const std::string &segment_name, unsigned int dof, double _min, double _max)
Definition Armature.cpp:336
virtual void updateControlOutput(const Timestamp &timestamp)
Definition Armature.cpp:669
virtual void pushCache(const Timestamp &timestamp)
Definition Armature.cpp:420
virtual bool updateJoint(const Timestamp &timestamp, JointLockCallback &callback)
Definition Armature.cpp:444
virtual void updateKinematics(const Timestamp &timestamp)
Definition Armature.cpp:622
bool getRelativeFrame(Frame &result, const std::string &segment_name, const std::string &base_name=m_root)
Definition Armature.cpp:662
virtual const Frame & getPose(const unsigned int end_effector)
Definition Armature.cpp:655
virtual ~Armature()
Definition Armature.cpp:49
std::vector< JointConstraint_struct * > JointConstraintList
Definition Armature.hpp:83
int addConstraint(const std::string &segment_name, ConstraintCallback _function, void *_param=NULL, bool _freeParam=false, bool _substep=false)
Definition Armature.cpp:298
virtual int addEndEffector(const std::string &name)
Definition Armature.cpp:355
std::vector< Effector_struct > EffectorList
Definition Armature.hpp:59
virtual bool finalize()
Definition Armature.cpp:374
bool getSegment(const std::string &segment_name, const unsigned int q_size, const Joint *&p_joint, double &q_rest, double &q, const Frame *&p_tip)
Definition Armature.cpp:249
virtual void updateJacobian()
Definition Armature.cpp:636
virtual bool setControlParameter(unsigned int constraintId, unsigned int valueId, ConstraintAction action, double value, double timestep=0.0)
Definition Armature.cpp:715
virtual double getArmLength()
Definition Armature.hpp:48
double getMaxEndEffectorChange()
Definition Armature.cpp:279
virtual bool setJointArray(const KDL::JntArray &joints)
Definition Armature.cpp:428
double getMaxJointChange()
Definition Armature.cpp:265
virtual const KDL::JntArray & getJointArray()
Definition Armature.cpp:439
DEGForeachIDComponentCallback callback
#define NULL
#define M
const Frame F_identity
bool(* ConstraintCallback)(const Timestamp &timestamp, struct ConstraintValues *const _values, unsigned int _nvalues, void *_param)
unsigned int CacheTS
Definition Cache.hpp:33
Definition DNA_ID.h:413
Effector_struct(const std::string &_name)
Definition Armature.hpp:57
JointConstraint_struct(SegmentMap::const_iterator _segment, unsigned int _y_nr, ConstraintCallback _function, void *_param, bool _freeParam, bool _substep)
Definition Armature.cpp:66
SegmentMap::const_iterator segment
Definition Armature.hpp:71
KDL::Joint::JointType type
Definition Armature.hpp:86
Joint_struct(KDL::Joint::JointType _type, unsigned int _ndof, double _rest)
Definition Armature.hpp:94