-
Notifications
You must be signed in to change notification settings - Fork 403
Migrate urdf
modules to Typescript
#907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
EzraBrooks
merged 12 commits into
RobotWebTools:develop
from
drewhoener:feature/typescript-urdf-module
Aug 8, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cd1a8d1
revert: chore(vite): Temporarily disable type checking and declaratio…
drewhoener 68117be
refactor(UrdfTypes): Convert UrdfTypes to TypeScript enum and update …
drewhoener fe674c6
refactor(UrdfBox, UrdfTypes): Convert UrdfBox to TypeScript.
drewhoener e115cfb
refactor(UrdfColor): Convert UrdfColor to TypeScript.
drewhoener 55b135a
refactor(UrdfCylinder): Convert UrdfCylinder to TypeScript, fix parsi…
drewhoener 202ed57
refactor(UrdfJoint, UrdfUtils): Convert UrdfJoint to TypeScript and e…
drewhoener 388eced
refactor(UrdfMaterial): Convert UrdfMaterial to TypeScript.
drewhoener 4ac34b4
refactor(UrdfMesh): Convert UrdfMesh to TypeScript.
drewhoener 9ab99a2
refactor(UrdfSphere): Convert UrdfSphere to TypeScript.
drewhoener b8f38f0
refactor(UrdfVisual, UrdfUtils): Convert UrdfVisual to TypeScript, ad…
drewhoener 539061d
refactor(UrdfLink): Convert UrdfLink to TypeScript, loop with for-of …
drewhoener 71a85c5
refactor(UrdfModel): Convert UrdfModel to TypeScript, replace loops w…
drewhoener File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,32 +4,30 @@ | |
* @author Russell Toris - [email protected] | ||
*/ | ||
|
||
import Vector3 from '../math/Vector3.js'; | ||
import * as UrdfTypes from './UrdfTypes.js'; | ||
import { Vector3 } from '../math/index.js'; | ||
import { UrdfAttrs, UrdfType, type UrdfDefaultOptions } from './UrdfTypes.js'; | ||
import type { Optional, Nullable } from '../types/interface-types.js'; | ||
|
||
/** | ||
* A Box element in a URDF. | ||
*/ | ||
export default class UrdfBox { | ||
/** @type {Vector3 | null} */ | ||
dimension; | ||
/** | ||
* @param {Object} options | ||
* @param {Element} options.xml - The XML element to parse. | ||
*/ | ||
constructor(options) { | ||
this.type = UrdfTypes.URDF_BOX; | ||
type: UrdfType; | ||
dimension: Nullable<Vector3> = null; | ||
|
||
constructor({ xml }: UrdfDefaultOptions) { | ||
this.type = UrdfType.BOX; | ||
|
||
// Parse the xml string | ||
var xyz = options.xml.getAttribute('size')?.split(' '); | ||
if (xyz) { | ||
this.dimension = new Vector3({ | ||
x: parseFloat(xyz[0]), | ||
y: parseFloat(xyz[1]), | ||
z: parseFloat(xyz[2]) | ||
}); | ||
} else { | ||
this.dimension = null; | ||
const size: Optional<string[]> = xml.getAttribute(UrdfAttrs.Size)?.split(' '); | ||
if (!size || size.length !== 3) { | ||
return; | ||
} | ||
|
||
this.dimension = new Vector3({ | ||
x: parseFloat(size[0]), | ||
y: parseFloat(size[1]), | ||
z: parseFloat(size[2]) | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,41 @@ | |
* @author Russell Toris - [email protected] | ||
*/ | ||
|
||
import { UrdfAttrs, type UrdfDefaultOptions } from './UrdfTypes.js'; | ||
import type { Optional } from '../types/interface-types.js'; | ||
|
||
/** | ||
* A Color element in a URDF. | ||
*/ | ||
export default class UrdfColor { | ||
|
||
/** | ||
* Color Red, [0, 1] | ||
*/ | ||
r = 0.0; | ||
/** | ||
* Color Green, [0, 1] | ||
*/ | ||
g = 0.0; | ||
/** | ||
* Color Blue, [0, 1] | ||
*/ | ||
b = 0.0; | ||
/** | ||
* @param {Object} options | ||
* @param {Element} options.xml - The XML element to parse. | ||
* Alpha/Opacity, [0, 1] | ||
*/ | ||
constructor(options) { | ||
a = 1.0; | ||
|
||
constructor({ xml }: UrdfDefaultOptions) { | ||
// Parse the xml string | ||
var rgba = options.xml.getAttribute('rgba')?.split(' '); | ||
if (rgba) { | ||
this.r = parseFloat(rgba[0]); | ||
this.g = parseFloat(rgba[1]); | ||
this.b = parseFloat(rgba[2]); | ||
this.a = parseFloat(rgba[3]); | ||
const rgba: Optional<string[]> = xml.getAttribute(UrdfAttrs.Rgba)?.split(' '); | ||
if (!rgba || rgba.length !== 4) { | ||
return; | ||
} | ||
|
||
this.r = parseFloat(rgba[0]); | ||
this.g = parseFloat(rgba[1]); | ||
this.b = parseFloat(rgba[2]); | ||
this.a = parseFloat(rgba[3]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,21 @@ | |
* @author Russell Toris - [email protected] | ||
*/ | ||
|
||
import * as UrdfTypes from './UrdfTypes.js'; | ||
import { type UrdfDefaultOptions, UrdfType, UrdfAttrs } from './UrdfTypes.js'; | ||
|
||
/** | ||
* A Cylinder element in a URDF. | ||
*/ | ||
export default class UrdfCylinder { | ||
/** | ||
* @param {Object} options | ||
* @param {Element} options.xml - The XML element to parse. | ||
*/ | ||
constructor(options) { | ||
this.type = UrdfTypes.URDF_CYLINDER; | ||
// @ts-expect-error -- possibly null | ||
this.length = parseFloat(options.xml.getAttribute('length')); | ||
// @ts-expect-error -- possibly null | ||
this.radius = parseFloat(options.xml.getAttribute('radius')); | ||
|
||
type: UrdfType; | ||
length: number; | ||
radius: number; | ||
|
||
constructor({ xml }: UrdfDefaultOptions) { | ||
this.type = UrdfType.CYLINDER; | ||
|
||
this.length = parseFloat(xml.getAttribute(UrdfAttrs.Length) ?? 'NaN'); | ||
this.radius = parseFloat(xml.getAttribute(UrdfAttrs.Radius) ?? 'NaN'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,93 +3,49 @@ | |
* @author David V. Lu!! - [email protected] | ||
*/ | ||
|
||
import Pose from '../math/Pose.js'; | ||
import Vector3 from '../math/Vector3.js'; | ||
import Quaternion from '../math/Quaternion.js'; | ||
import { UrdfAttrs, type UrdfDefaultOptions } from './UrdfTypes.js'; | ||
import { Pose } from '../math/index.js'; | ||
import { parseUrdfOrigin } from './UrdfUtils.js'; | ||
import type { Nullable } from '../types/interface-types.js'; | ||
|
||
/** | ||
* A Joint element in a URDF. | ||
*/ | ||
export default class UrdfJoint { | ||
/** | ||
* @param {Object} options | ||
* @param {Element} options.xml - The XML element to parse. | ||
*/ | ||
constructor(options) { | ||
this.name = options.xml.getAttribute('name'); | ||
this.type = options.xml.getAttribute('type'); | ||
|
||
var parents = options.xml.getElementsByTagName('parent'); | ||
name: string; | ||
type: Nullable<string>; | ||
parent: Nullable<string> = null; | ||
child: Nullable<string> = null; | ||
minval = NaN; | ||
maxval = NaN; | ||
origin: Pose = new Pose(); | ||
|
||
|
||
constructor({xml}: UrdfDefaultOptions) { | ||
this.name = xml.getAttribute(UrdfAttrs.Name) ?? 'unknown_name'; | ||
this.type = xml.getAttribute(UrdfAttrs.Type); | ||
|
||
const parents = xml.getElementsByTagName(UrdfAttrs.Parent); | ||
if (parents.length > 0) { | ||
this.parent = parents[0].getAttribute('link'); | ||
this.parent = parents[0].getAttribute(UrdfAttrs.Link); | ||
} | ||
|
||
var children = options.xml.getElementsByTagName('child'); | ||
const children = xml.getElementsByTagName(UrdfAttrs.Child); | ||
if (children.length > 0) { | ||
this.child = children[0].getAttribute('link'); | ||
this.child = children[0].getAttribute(UrdfAttrs.Link); | ||
} | ||
|
||
var limits = options.xml.getElementsByTagName('limit'); | ||
const limits = xml.getElementsByTagName(UrdfAttrs.Limit); | ||
if (limits.length > 0) { | ||
this.minval = parseFloat(limits[0].getAttribute('lower') || 'NaN'); | ||
this.maxval = parseFloat(limits[0].getAttribute('upper') || 'NaN'); | ||
this.minval = parseFloat(limits[0].getAttribute(UrdfAttrs.Lower) ?? 'NaN'); | ||
this.maxval = parseFloat(limits[0].getAttribute(UrdfAttrs.Upper) ?? 'NaN'); | ||
} | ||
|
||
// Origin | ||
var origins = options.xml.getElementsByTagName('origin'); | ||
if (origins.length === 0) { | ||
// use the identity as the default | ||
this.origin = new Pose(); | ||
} else { | ||
// Check the XYZ | ||
var xyzValue = origins[0].getAttribute('xyz'); | ||
var position = new Vector3(); | ||
if (xyzValue) { | ||
var xyz = xyzValue.split(' '); | ||
position = new Vector3({ | ||
x: parseFloat(xyz[0]), | ||
y: parseFloat(xyz[1]), | ||
z: parseFloat(xyz[2]) | ||
}); | ||
} | ||
|
||
// Check the RPY | ||
var rpyValue = origins[0].getAttribute('rpy'); | ||
var orientation = new Quaternion(); | ||
if (rpyValue) { | ||
var rpy = rpyValue.split(' '); | ||
// Convert from RPY | ||
var roll = parseFloat(rpy[0]); | ||
var pitch = parseFloat(rpy[1]); | ||
var yaw = parseFloat(rpy[2]); | ||
var phi = roll / 2.0; | ||
var the = pitch / 2.0; | ||
var psi = yaw / 2.0; | ||
var x = | ||
Math.sin(phi) * Math.cos(the) * Math.cos(psi) - | ||
Math.cos(phi) * Math.sin(the) * Math.sin(psi); | ||
var y = | ||
Math.cos(phi) * Math.sin(the) * Math.cos(psi) + | ||
Math.sin(phi) * Math.cos(the) * Math.sin(psi); | ||
var z = | ||
Math.cos(phi) * Math.cos(the) * Math.sin(psi) - | ||
Math.sin(phi) * Math.sin(the) * Math.cos(psi); | ||
var w = | ||
Math.cos(phi) * Math.cos(the) * Math.cos(psi) + | ||
Math.sin(phi) * Math.sin(the) * Math.sin(psi); | ||
|
||
orientation = new Quaternion({ | ||
x: x, | ||
y: y, | ||
z: z, | ||
w: w | ||
}); | ||
orientation.normalize(); | ||
} | ||
this.origin = new Pose({ | ||
position: position, | ||
orientation: orientation | ||
}); | ||
const origins = xml.getElementsByTagName(UrdfAttrs.Origin); | ||
if (origins.length > 0) { | ||
this.origin = parseUrdfOrigin(origins[0]); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactoring JS into TS always uncovers extremely odd control flow like this.. early return from a constructor, lol 🤦🏻