Conscience Core
CscJacobianInverseKinematic.h
Go to the documentation of this file.
1 /*
2  * CscJacobianInverseKinematic.h
3  *
4  * Created on: 31 mai 2014
5  * Author: AilvinCarbon
6  */
7 
8 #ifndef CscJacobianInverseKinematic_h
9 #define CscJacobianInverseKinematic_h
10 
11 #include "../Simulator/CscEnvironmentSimulator.h"
13 #include "Util/conscience_util.h"
14 
15 #include <bullet/Bullet3Common/b3AlignedObjectArray.h>
16 #include <bullet/ThirdPartyLibs/BussIK/Jacobian.h>
17 #include <bullet/ThirdPartyLibs/BussIK/Node.h>
18 #include <bullet/ThirdPartyLibs/BussIK/Tree.h>
19 #include <bullet/ThirdPartyLibs/BussIK/VectorRn.h>
20 
21 #include <math.h>
22 
23 #define RADIAN(X) ((X) * RadiansToDegrees)
24 #define MAX_NUM_EFFECT 100
25 #define PROJECTION_DISTANCE 5.0f
26 #define MAX_TIME_FOR_RESET_TARGETS_IN_MS 1000
27 
29 
30 enum Method {
37 };
38 
40  public:
42  private:
43  const int stationaryPivotId;
44  const int memberToMoveId;
45  CscPoint3d *targetToReach;
46  optional<CscPoint3d *> orientationTarget;
47  public:
48  TargetIKParams(int stationaryPivotId, int memberToMoveId, CscPoint3d *targetToReach, optional<CscPoint3d *> orientationTarget = nullopt);
49  const int getStationaryPivotId() const;
50  const int getMemberToMoveId() const;
51  CscPoint3d *getTargetToReach() const;
52  CscPoint3d *getOrientationTarget() const;
53  ~TargetIKParams();
54  TargetIKParams *clone();
55  };
56 
57  CscJacobianInverseKinematic(CscEnvironmentSimulator *env, float maxHorizontalDistance, float maxVerticalDistance, float maxDepthDistance, CscPoint3d *offsetCenter, CscState *beginState, const CscEntityModel *entityModel, vector<TargetIKParams *> targets, map<int, CscPoint3d *> &centerOfMassOfAllMemberByMemberId, bool debugWithBox = false, bool constraintOnDistance = false, vector<int> pivotIdToIgnore = vector<int>());
58 
59  void initIk();
60 
61  CscPoint3d *getEntityCenterOfMass();
62 
66  void changeTargets(vector<TargetIKParams *> newTargets, bool relativeValues = false);
67  void compute();
68  void computeRandomly();
69  double getDistanceFromTarget();
70  map<int, float> getResult() const;
71  vector<vector<int>> getPivotIdPaths() const;
72  vector<TargetIKParams *> getTargets() const;
73  void updateThetasRandomly();
74 
76 
77  const float targetPrecision = 1.5f;
78 
96  void changeTargetsWithCenterOfMass(const bool applyDimensionXYZ[3], vector<int> idTargetsToChange);
97 
98  Tree getIkTree();
99 
100 private:
101  b3AlignedObjectArray<Node *> ikNodes;
102  Tree ikTree;
103  Jacobian *ikJacobian = nullptr;
104  int sleepCounter = 0;
105  VectorR3 targetsPositions[MAX_NUM_EFFECT];
106  const int sleepsPerStep = 100; // Make higher to take larger steps less frequently
107  float offsetX = 1505;
108  float offset = 1500;
109  float offsetZ = 1500;
110  float offsetY = 107;
111  float maxHorizontalDistance;
112  float maxVerticalDistance;
113  float maxDepthDistance;
114  CscPoint3d *offsetCenter = nullptr;
115  CscWorldObject *targetBox = nullptr;
116  CscState *beginState = nullptr;
117  vector<vector<int>> pivotIdPaths; // contains the different paths of the members
118  const CscEntityModel *entityModel = nullptr;
119  Method choiceMethod = NOTHING;
120  int countForMethod = 0;
121  vector<TargetIKParams *> targets;
122  vector<TargetIKParams *> lastTargetsValid;
123  bool debugWithBox;
124  bool constraintOnDistance;
125  map<int, CscPoint3d *> initCenterOfMassOfAllMemberByMemberId;
126 
127  map<int, float> result;
128  vector<int> nNodeCenterOfMass;
129  map<int, int> memberIdFromNode;
131  CscPoint3d *entityCenterOfMass;
132  vector<string> objectsId;
133 
134  int idObject = 3;
135  unsigned long long timeForResetTargets;
136  vector<int> pivotIdToIgnore;
137  bool computeEnable = true;
138 
149  CscPoint3d *findCenterOfMass();
150 
151  void clearTargets();
152 
153  void updateThetas();
154 
159  Tree createTreePivots(bool centerOfMass = true);
160 
168  vector<int> createPivotIdPath(int stationaryPivotId, int memberToMoveId);
169 
181  void fillTreePivotId(vector<int> &treeToFill, int pivotId, int endId, const map<int, int> &memberAIdByPivotId, const map<int, int> &memberBIdByPivotId, const vector<const CscMemberJoint *> *pivots, int memberId);
182 
191  Method nextMethod(Method currentMethod);
192 
210  Tree addNodeCenterOfMass(int nbTarget, int indexPivotIdPaths, int ikNodesSizeWithoutCenterOfMass, int nbNodes, Tree &currentTree);
211 };
212 
213 #endif /* CscJacobianInverseKinematic_H_ */
conscience_core::axiomes::CscPoint3d
The CscPoint3d class represents a point in three-dimensional space. It is primarily used to denote a ...
Definition: Csc3dTypes.h:24
Method
Method
Definition: CscJacobianInverseKinematic.h:30
CSC_DLL_IMPORTEXPORT
#define CSC_DLL_IMPORTEXPORT
Definition: os.h:34
IK_SDLS
@ IK_SDLS
Definition: CscJacobianInverseKinematic.h:34
CscWorldObject
Definition: CscWorldObject.h:26
conscience_util.h
CscEntityModel
Definition: CscEntityModel.h:54
NOTHING
@ NOTHING
Definition: CscJacobianInverseKinematic.h:36
CscJacobianInverseKinematic::TargetIKParams
Definition: CscJacobianInverseKinematic.h:41
IK_DLS
@ IK_DLS
Definition: CscJacobianInverseKinematic.h:33
IK_JACOB_TRANS
@ IK_JACOB_TRANS
Definition: CscJacobianInverseKinematic.h:31
CscWorldElementsFactory.h
IK_DLS_SVD
@ IK_DLS_SVD
Definition: CscJacobianInverseKinematic.h:35
CscState
Definition: CscState.h:24
conscience_core::core_objects::exchange::common
Definition: CscWorldElementsFactory.cpp:27
CscJacobianInverseKinematic
Definition: CscJacobianInverseKinematic.h:39
MAX_NUM_EFFECT
#define MAX_NUM_EFFECT
Definition: CscJacobianInverseKinematic.h:24
IK_PURE_PSEUDO
@ IK_PURE_PSEUDO
Definition: CscJacobianInverseKinematic.h:32
CscEnvironmentSimulator
Definition: CscEnvironmentSimulator.h:31