Skip to content

Commit

Permalink
Fix joint translations (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
pac48 authored Apr 22, 2024
1 parent 7711237 commit 5ded815
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions javascript/src/URDFClasses.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Euler, Object3D, Vector3 } from 'three';
import { Euler, Object3D, Vector3, Quaternion, Matrix4 } from 'three';

const _tempAxis = new Vector3();
const _tempEuler = new Euler();
const _tempTransform = new Matrix4();
const _tempOrigTransform = new Matrix4();
const _tempQuat = new Quaternion();
const _tempScale = new Vector3(1.0, 1.0, 1.0);
const _tempPosition = new Vector3();

class URDFBase extends Object3D {

Expand Down Expand Up @@ -253,26 +258,27 @@ class URDFJoint extends URDFBase {
this.jointValue[0] = values[0] !== null ? values[0] : this.jointValue[0];
this.jointValue[1] = values[1] !== null ? values[1] : this.jointValue[1];
this.jointValue[2] = values[2] !== null ? values[2] : this.jointValue[2];
this.position.copy(this.origPosition);
// Respect origin RPY when setting position
_tempAxis.set(1, 0, 0).applyEuler(this.rotation);
this.position.addScaledVector(_tempAxis, this.jointValue[0]);
_tempAxis.set(0, 1, 0).applyEuler(this.rotation);
this.position.addScaledVector(_tempAxis, this.jointValue[1]);
_tempAxis.set(0, 0, 1).applyEuler(this.rotation);
this.position.addScaledVector(_tempAxis, this.jointValue[2]);

this.jointValue[3] = values[3] !== null ? values[3] : this.jointValue[3];
this.jointValue[4] = values[4] !== null ? values[4] : this.jointValue[4];
this.jointValue[5] = values[5] !== null ? values[5] : this.jointValue[5];
this.quaternion.setFromEuler(
_tempEuler.set(
this.jointValue[3],
this.jointValue[4],
this.jointValue[5],
'XYZ',
),
).premultiply(this.origQuaternion);

// Compose transform of joint origin and transform due to joint values
_tempOrigTransform.compose(this.origPosition, this.origQuaternion, _tempScale);
_tempQuat.setFromEuler(
_tempEuler.set(

Check failure on line 268 in javascript/src/URDFClasses.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 20 spaces but found 18
this.jointValue[3],

Check failure on line 269 in javascript/src/URDFClasses.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 24 spaces but found 20
this.jointValue[4],

Check failure on line 270 in javascript/src/URDFClasses.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 24 spaces but found 20
this.jointValue[5],

Check failure on line 271 in javascript/src/URDFClasses.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 24 spaces but found 20
'XYZ',

Check failure on line 272 in javascript/src/URDFClasses.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 24 spaces but found 20
),

Check failure on line 273 in javascript/src/URDFClasses.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 20 spaces but found 18
);
_tempPosition.set(this.jointValue[0], this.jointValue[1], this.jointValue[2]);
_tempTransform.compose(_tempPosition, _tempQuat, _tempScale);

// Calcualte new transform
_tempOrigTransform.premultiply(_tempTransform);
this.position.setFromMatrixPosition(_tempOrigTransform);
this.rotation.setFromRotationMatrix(_tempOrigTransform);

this.matrixWorldNeedsUpdate = true;
return true;
Expand All @@ -287,16 +293,16 @@ class URDFJoint extends URDFBase {
this.jointValue[1] = values[1] !== null ? values[1] : this.jointValue[1];
this.jointValue[2] = values[2] !== null ? values[2] : this.jointValue[2];

// Respect existing RPY when modifying the position of the X,Y axes
this.position.copy(this.origPosition);
// Compose transform of joint origin and transform due to joint values
_tempOrigTransform.compose(this.origPosition, this.origQuaternion, _tempScale);
_tempQuat.setFromAxisAngle(this.axis, this.jointValue[2])

Check failure on line 298 in javascript/src/URDFClasses.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (98% of all statements in
the enclosing function
have an explicit semicolon).
_tempPosition.set(this.jointValue[0], this.jointValue[1], 0.0);
_tempTransform.compose(_tempPosition, _tempQuat, _tempScale);

_tempAxis.set(1, 0, 0).applyEuler(this.rotation);
this.position.addScaledVector(_tempAxis, this.jointValue[0]);
_tempAxis.set(0, 1, 0).applyEuler(this.rotation);
this.position.addScaledVector(_tempAxis, this.jointValue[1]);
this.quaternion
.setFromAxisAngle(this.axis, this.jointValue[2])
.premultiply(this.origQuaternion);
// Calcualte new transform
_tempOrigTransform.premultiply(_tempTransform);
this.position.setFromMatrixPosition(_tempOrigTransform);
this.rotation.setFromRotationMatrix(_tempOrigTransform);

this.matrixWorldNeedsUpdate = true;
return true;
Expand Down

0 comments on commit 5ded815

Please sign in to comment.