Skip to content

Conversation

drewhoener
Copy link
Contributor

@drewhoener drewhoener commented Aug 8, 2025

Public API Changes
None

Description

Overview

This PR migrates the classes in the urdf module to Typescript. This PR is slightly more involved as there's a lot of interdependency between the URDF elements, but other than that it's still largely trivial.

Contents

  • Add TS enum for Urdf Type
  • Add an enum to reduce magic strings when accessing attributes
  • Extract logic for getting element origin into a separate function in UrdfUtils.ts
  • Add stricter type checking for getting attributes from XML
  • Use for-of loops added in ES6, building off my base PR. It's hit the "widely supported" threshold of 95% so there's really no reason not to use it.

Going to leave converting tests for another PR, but they all pass in my docker container

Depends on #906

GitHub doesn't have "dependent PRs" so all previous commits are included here. Might not be worth reviewing until dependencies are merged

@drewhoener drewhoener force-pushed the feature/typescript-urdf-module branch from 1567f32 to e5824be Compare August 8, 2025 06:59
@drewhoener drewhoener force-pushed the feature/typescript-urdf-module branch 4 times, most recently from 19b3e78 to 8d84634 Compare August 8, 2025 18:44
Copy link
Contributor

@EzraBrooks EzraBrooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub is being GitHub here and the commit where you used git mv to ensure history continuity is not being represented in the PR diff. We might need to break that into its own PR (knowing it will probably break the build).

@drewhoener drewhoener force-pushed the feature/typescript-urdf-module branch from 8d84634 to 7e1189c Compare August 8, 2025 18:52
@drewhoener
Copy link
Contributor Author

GitHub is being GitHub here and the commit where you used git mv to ensure history continuity is not being represented in the PR diff. We might need to break that into its own PR (knowing it will probably break the build).

GitHub's diff viewer might have a different threshold for what it considers a different file? At least locally with git in my terminal I can see the file history which is what I was hoping to preserve
image

@EzraBrooks
Copy link
Contributor

Yeah, unfortunately it looks like if I squash-merge this it will lose the history :(

@drewhoener
Copy link
Contributor Author

Yeah, unfortunately it looks like if I squash-merge this it will lose the history :(

Created at #910

Add enum of Urdf Attributes to remove magic strings when getting attributes from xml

Signed-off-by: Drew Hoener <[email protected]>
…xtract origin parsing logic to UrdfUtils.

Signed-off-by: Drew Hoener <[email protected]>
…d isElement check in UrdfUtils

Signed-off-by: Drew Hoener <[email protected]>
…ith for-of, and improve type safety

Signed-off-by: Drew Hoener <[email protected]>
@drewhoener drewhoener force-pushed the feature/typescript-urdf-module branch from 7e1189c to 71a85c5 Compare August 8, 2025 19:09
Copy link
Contributor

@EzraBrooks EzraBrooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for putting the effort in to doing this incrementally so I can scan it more easily!

this.a = parseFloat(rgba[3]);
const rgba: Optional<string[]> = xml.getAttribute(UrdfAttrs.Rgba)?.split(' ');
if (!rgba || rgba.length !== 4) {
return;
Copy link
Contributor

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 🤦🏻

Comment on lines +8 to +31
export enum UrdfAttrs {
Name = 'name',
Type = 'type',
Parent = 'parent',
Link = 'link',
Child = 'child',
Limit = 'limit',
Upper = 'upper',
Lower = 'lower',
Origin = 'origin',
Xyz = 'xyz',
Rpy = 'rpy',
Size = 'size',
Rgba = 'rgba',
Length = 'length',
Radius = 'radius',
Visuals = 'visual',
Texture = 'texture',
Filename = 'filename',
Color = 'color',
Geometry = 'geometry',
Material = 'material',
Scale = 'scale',
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This smells odd to me - I don't feel like we should need this enum to keep track of the magic strings (because each string would only be used once), but I understand you're just refactoring the code in-place here.

The URDF stuff could probably use a refactor soon. I've been using https://github.com/gkjohnson/urdf-loaders for years because I found the URDF implementation here roslibjs and in ros3djs too janky.

Not in the scope of this PR anyhow!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also honestly maybe roslibjs and ros3djs should be merged into one package now that most of the world uses bundlers in their javascript apps and can tree-shake out unnecessary dependencies)

@EzraBrooks EzraBrooks merged commit 18fbe4c into RobotWebTools:develop Aug 8, 2025
2 checks passed
@drewhoener
Copy link
Contributor Author

drewhoener commented Aug 8, 2025

LGTM. Thanks for putting the effort in to doing this incrementally so I can scan it more easily!

Yeah of course! Glad I finally have the time to get it done, I've been wanting to for a while. I feel like it's needed a bit of modernization.
I probably won't have the next one until next week sometime, I need to think out the cbor/event emitter shenanigans and how that's all going to work.

Thanks for being so responsive with my wave of PRs lol

@EzraBrooks
Copy link
Contributor

Yeah, I kept meaning to come back and do this refactor myself after I added Vite and tsc but never had time and at least in my application the JSDoc-generated types have been "fine" in the meantime

@drewhoener drewhoener deleted the feature/typescript-urdf-module branch August 8, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants