27 #define MIN_JOINT_WEIGHT 0.01 29 #define MAX_CONDITION_NUMBER 100.0 38 :
virtual public Chain 108 double Update(
double timestep);
190 IKHandle*
AddMarker(
const std::string& label,
const std::string& linkname,
const std::string& charname,
const fVec3& rel_pos);
201 int init(SceneGraph* sg);
202 int myinit(SceneGraph* sg);
273 joint_name =
new char [strlen(_jname) + 1];
274 strcpy(joint_name, _jname);
287 if(joint_name)
delete[] joint_name;
409 int count_constraints();
435 const fVec3& _rel_pos = 0.0,
const fMat33& _rel_att = 1.0,
436 Joint* _other_joint = 0)
438 rel_pos(_rel_pos), rel_att(_rel_att) {
439 for(
int i=0;
i<6;
i++)
441 const_index[
i] = cindex[
i];
445 other_joint = _other_joint;
451 abs_att.mul(joint->abs_att, rel_att);
452 abs_pos.mul(joint->abs_att, rel_pos);
453 abs_pos += joint->abs_pos;
459 rt.
tran(other_joint->abs_att);
461 pp.
sub(abs_pos, other_joint->abs_pos);
463 abs_att.mul(rt, att);
481 abs_att.mul(joint->abs_att, rel_att);
482 abs_pos.mul(joint->abs_att, rel_pos);
483 abs_pos += joint->abs_pos;
489 rt.
tran(other_joint->abs_att);
491 pp.
sub(abs_pos, other_joint->abs_pos);
493 abs_att.mul(rt, att);
500 abs_pos.set(_abs_pos);
504 abs_att.set(_abs_att);
509 _abs_pos.
set(abs_pos);
513 _abs_att.
set(abs_att);
518 rel_pos.set(_rel_pos);
527 for(
int i=0;
i<6;
i++)
529 _cindex[
i] = const_index[
i];
566 if(joint && joint->n_dof > 0)
569 J.
resize(joint->n_dof, ik->NumDOF());
575 switch(joint->j_type)
579 joint->GetJointValue(q_des);
582 joint->GetJointValue(att_des);
585 joint->GetJointValue(pos_des, att_des);
597 if(joint && joint->n_dof > 0)
599 switch(joint->j_type)
603 joint->GetJointValue(q_des);
606 joint->GetJointValue(att_des);
609 joint->GetJointValue(pos_des, att_des);
638 int calc_jacobian_rotate(
Joint* cur);
639 int calc_jacobian_slide(
Joint* cur);
640 int calc_jacobian_sphere(
Joint* cur);
641 int calc_jacobian_free(
Joint* cur);
664 charname =
new char [strlen(_charname)+1];
665 strcpy(charname, _charname);
668 for(
int i=0;
i<3;
i++)
670 const_index[
i] = cindex[
i];
681 des_com.set(cur_com);
685 if(charname)
delete[] charname;
692 ik->TotalCOM(des_com, charname);
725 if(joint && (joint->j_type ==
JROTATE || joint->j_type ==
JSLIDE))
765 int calc_jacobian_rotate(
Joint* cur);
766 int calc_jacobian_slide(
Joint* cur);
int ConstraintIndex(ConstType _type, const char *jname)
int n_const[N_PRIORITY_TYPES]
number of constraints of each type
int SetDesireGain(const char *jname, double _gain)
Set gain of desire constraint of the specific joint.
int n_constraints
number of current constraints
Base class for constraints.
double TotalCOM(fVec3 &com, const char *chname=0)
Center of mass of the chain.
int SetJointWeight(const char *jname, double _weight)
Set joint weight, for single-DOF joints.
void Enable()
enable the constraint
void SetGain(double _gain)
set the gain
virtual int calc_jacobian_sphere(Joint *cur)
char * charname
target character name
double GetMaxConditionNumber()
Get maximum condition number.
double solve_ik()
compute the joint velocity
int edit_marker(IKHandle *marker, const char *body_name, Joint *parent_joint, const fVec3 &abs_pos)
int resize(int i, int j)
Changes the matrix size.
fMat33 abs_att
current constraint orientation
IKHandle * AddMarker(const std::string &label, const std::string &linkname, const std::string &charname, const fVec3 &rel_pos)
Add new marker constraint.
int init(SceneGraph *sg)
Initialize the parameters.
fVec3 des_com
desired COM position
void set(const fMat33 &mat)
Copies a matrix.
int ResetAllConstraints()
Reset all constraints.
int RemoveAllConstraints()
friend fMat33 tran(const fMat33 &m)
Returns the transpose.
void SetRelPos(const fVec3 &_rel_pos)
set relative position of the constraint
IKConstraint ** constraints
list of current constraints
int AddConstraint(IKConstraint *_constraint)
#define DEFAULT_MAX_INTEG_ERROR
int LoadMarkerXML(const char *fname, const char *_charname)
Load marker information from XML file.
IKConstraint * FindConstraint(ConstType _type, const char *jname, const char *charname=0)
void SetMaxConditionNumber(double cn)
Set maximum condition number.
void SetDesire(double _q)
virtual int calc_jacobian_rotate(Joint *cur)
void set_character_scale(Joint *jnt, double _scale, const char *charname)
void SetConstraintScale(double _scale, const char *charname=0)
Set constraint scale parameter.
IKHandle * add_marker(const char *marker_name, Joint *parent_joint, const fVec3 &abs_pos)
int id
ID (unique to each constraint)
IK::ConstType GetType()
Returns the constraint type.
void set(double *v)
Set element values from array or three values.
fVec3 pos_des
desired joint position for 6DOF joints
IKDesire(IK *_ik, const char *_jname, Joint *_jnt, IK::Priority _pri, double _gain)
int Active()
whether the constraint is activate
fMat J[N_PRIORITY_TYPES]
Jacobian matrix of each type.
int i_const
feedback velocity (n_const)
IK::ConstType GetType()
Returns the constraint type.
double q_des
desired joint value for 1DOF joints
int SaveMarkers(const char *fname)
fMat33 att_des
desired joint orientation for 3/6 DOF joints
void zero()
Creates a zero matrix.
fVec joint_weights
joint weights
void GetConstIndex(IK::ConstIndex _cindex[])
void CalcPosition()
Forward kinematics.
int assign_constraints(int _n)
Joint * joint
target joint
virtual int calc_jacobian_slide(Joint *cur)
IKHandle(IK *_ik, const char *_jname, Joint *_jnt, IK::ConstIndex cindex[6], IK::Priority _pri, double _gain, const fVec3 &_rel_pos=0.0, const fMat33 &_rel_att=1.0, Joint *_other_joint=0)
strictly satisfied if possible
int calc_jacobian()
compute the Jacobian matrix
fVec fb
Jacobian matrix (n_const x total DOF)
void SetCharacterScale(double _scale, const char *charname=0)
Set character scale parameter.
void SetMin(double _q_min)
fVec3 abs_pos
current constraint position
int Reset()
reset the constraint position/orientation by the current values
int is_dropped
index in the constraints with the same priority
void Diactivate()
diactivate the constraint
void resize(int i)
Change the size.
IK::Priority GetPriority()
get the priproty
Classes for defining open/closed kinematic chains.
joint limit for rotate and slide joints
void SetAtt(const fMat33 &_abs_att)
set the constraint orientation
int enabled
number of constraints
IKCom(IK *_ik, const char *_charname, IK::ConstIndex cindex[3], IK::Priority _pri, double _gain)
double max_condnum
maximum condition number
double Update(double timestep)
void SetPos(const fVec3 &p)
int RemoveConstraint(int _id)
void SetDesire(const fVec3 &_pos, const fMat33 &_att)
int myinit(SceneGraph *sg)
The class representing the whole mechanism. May contain multiple characters.
void zero()
Creates a zero vector.
static const char joint_name_separator
Joint limit constraint for 1-DOF joints.
void sub(const fVec3 &vec1, const fVec3 &vec2)
int NumConstraints()
Number of constraints.
fVec3 cur_com
current COM position
position/orientation of link
IKScalarJointLimit(IK *_ik, const char *_jname, Joint *_jnt, IK::Priority _pri, double _gain)
virtual void SetCharacterScale(double _scale, const char *charname=0)
int n_total_const
number of total constraints used so far, including removed ones
virtual int calc_jacobian_free(Joint *cur)
double GetGain()
get the gain
IK::ConstType GetType()
Returns the constraint type.
int load_markers(SceneGraph *sg, Joint *rj)
void GetAtt(fMat33 &_abs_att)
obtain constraint orientation
void SetDesire(const fMat33 &_att)
int n_assigned_constraints
void Activate()
activate the constraint
The class for representing a joint.
int ResetConstraints(ConstType t)
Reset the constraints with the specific type.
IK::ConstType GetType()
Returns the constraint type.
void GetPos(fVec3 &_abs_pos)
obtain constraint position
int DisableDesire(const char *jname)
Disable desire constraint of the specific joint.
IKConstraint(IK *_ik, const char *_jname, Joint *_jnt, IK::Priority _pri, double _gain)
Default constructor.
int EditMarker(IKHandle *marker, const char *body_name, Joint *parent_joint, const fVec3 &abs_pos=0.0)
int EnableDesire(const char *jname)
Enable desire constraint of the specific joint.
void SetPos(const fVec3 &_abs_pos)
set the constraint position
int save_marker(TransformNode *top_tnode, IKHandle *h)
fVec weight[N_PRIORITY_TYPES]
weight of each type
virtual ~IKConstraint()
Destructor.
void SetMax(double _q_max)
void Disable()
disable the constraint
Main class for inverse kinematic computation.
Matrix of generic size. The elements are stored in a one-dimensional array in row-major order...
void SetDesire(const fVec3 &_pos)
fVec fb[N_PRIORITY_TYPES]
constraint error of each type
void SetPriority(IK::Priority _pri)
set the priproty
Joint * other_joint
connected to other joint: constrains the relative position and/or orientation w.r.t. other_joint's frame
int ConstraintID(ConstType _type, const char *jname)