Skip to content

Commit 6f64eb8

Browse files
committed
ensure that when requesting the chain of transforms that it always comes
back with valid data
1 parent b07df74 commit 6f64eb8

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

src/main/java/com/neuronrobotics/sdk/addons/kinematics/AbstractKinematicsNR.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,5 +1366,30 @@ protected String getCode(Element e,String tag){
13661366
public IMU getImu() {
13671367
return imu;
13681368
}
1369+
1370+
//New helper functions to make the API simpler
1371+
1372+
public void boundedLinkValueSet( int index,double value) throws Exception {
1373+
value=boundToLinkLimits(index,value);
1374+
double[] vect =getCurrentJointSpaceVector();
1375+
vect[index]=value;
1376+
setDesiredJointSpaceVector(vect, 0);
1377+
}
1378+
public double boundToLinkLimits( int index,double value) {
1379+
AbstractLink l1 = getAbstractLink(index);
1380+
if(value>l1.getMaxEngineeringUnits()){
1381+
value=l1.getMaxEngineeringUnits();
1382+
}
1383+
if(value<l1.getMinEngineeringUnits()){
1384+
value=l1.getMinEngineeringUnits();
1385+
}
1386+
return value;
1387+
}
1388+
1389+
public double linkMass(int linkIndex) {
1390+
return getLinkConfiguration(linkIndex).getMassKg();
1391+
}
1392+
1393+
13691394

13701395
}

src/main/java/com/neuronrobotics/sdk/addons/kinematics/DHChain.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,15 @@ public TransformNR forwardKinematics(double[] jointSpaceVector, boolean store) {
186186
* @return the matrix
187187
*/
188188
public Matrix forwardKinematicsMatrix(double[] jointSpaceVector, boolean store) {
189+
return forwardKinematicsMatrix(jointSpaceVector,store?getCachedChain():null);
190+
}
191+
private Matrix forwardKinematicsMatrix(double[] jointSpaceVector, ArrayList<TransformNR> chainToLoad) {
189192
if(getLinks() == null)
190193
return new TransformNR().getMatrixTransform();
191194
if (jointSpaceVector.length!=getLinks().size())
192195
throw new IndexOutOfBoundsException("DH links do not match defined links");
193196
Matrix current = new TransformNR().getMatrixTransform();
194-
if(store)
195-
setChain(new ArrayList<TransformNR>());
196-
ArrayList<TransformNR> cachedChain = getCachedChain();
197+
197198
for(int i=0;i<getLinks().size();i++) {
198199
LinkConfiguration conf= getFactory().getLinkConfigurations().get(i);
199200
Matrix step;
@@ -208,17 +209,17 @@ public Matrix forwardKinematicsMatrix(double[] jointSpaceVector, boolean store)
208209
final TransformNR pose =forwardOffset(new TransformNR(update));
209210
//getLinks().get(index).fireOnLinkGlobalPositionChange(pose);
210211

211-
if(store){
212+
if(chainToLoad!=null){
212213
if(intChain.size()<=i)
213214
intChain.add(new TransformNR(step));
214215
else{
215216
intChain.set(i, new TransformNR(step));
216217
}
217218

218-
if(cachedChain.size()<=i)
219-
cachedChain.add(pose);
219+
if(chainToLoad.size()<=i)
220+
chainToLoad.add(pose);
220221
else{
221-
cachedChain.set(i, pose);
222+
chainToLoad.set(i, pose);
222223
}
223224
}
224225
}
@@ -256,8 +257,9 @@ public void setChain(ArrayList<TransformNR> chain) {
256257
* @return the chain
257258
*/
258259
public ArrayList<TransformNR> getChain(double[] jointSpaceVector) {
259-
forwardKinematics(jointSpaceVector,true);
260-
return getCachedChain();
260+
ArrayList<TransformNR> chainToLoad = new ArrayList<TransformNR>();
261+
forwardKinematicsMatrix(jointSpaceVector,chainToLoad);
262+
return chainToLoad;
261263
}
262264

263265
/**

0 commit comments

Comments
 (0)