Skip to content

Commit edaca0d

Browse files
committed
Convert URDF definitions to typescript
1 parent 1c11f45 commit edaca0d

24 files changed

+713
-625
lines changed

src/urdf/UrdfBox.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/urdf/UrdfBox.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @fileOverview
3+
* @author Benjamin Pitzer - [email protected]
4+
* @author Russell Toris - [email protected]
5+
*/
6+
7+
8+
import {Vector3} from "../math/index.js";
9+
import {UrdfAttrs, UrdfDefaultOptions, UrdfType} from "./UrdfTypes.js";
10+
11+
/**
12+
* A Box element in a URDF.
13+
*/
14+
export default class UrdfBox {
15+
type: UrdfType;
16+
dimension: Vector3 | null = null;
17+
18+
constructor({ xml }: UrdfDefaultOptions) {
19+
this.type = UrdfType.BOX;
20+
21+
// Parse the xml string
22+
const size: string[] | undefined = xml.getAttribute(UrdfAttrs.Size)?.split(' ');
23+
if(!size || size.length !== 3) {
24+
return;
25+
}
26+
27+
this.dimension = new Vector3({
28+
x: parseFloat(size[0]),
29+
y: parseFloat(size[1]),
30+
z: parseFloat(size[2])
31+
});
32+
}
33+
}

src/urdf/UrdfColor.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/urdf/UrdfColor.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @fileOverview
3+
* @author Benjamin Pitzer - [email protected]
4+
* @author Russell Toris - [email protected]
5+
*/
6+
7+
import {UrdfAttrs, UrdfDefaultOptions} from "./UrdfTypes.js";
8+
9+
/**
10+
* A Color element in a URDF.
11+
*/
12+
export default class UrdfColor {
13+
14+
/**
15+
* Color Red, [0, 1]
16+
*/
17+
r: number = 0.0;
18+
/**
19+
* Color Green, [0, 1]
20+
*/
21+
g: number = 0.0;
22+
/**
23+
* Color Blue, [0, 1]
24+
*/
25+
b: number = 0.0;
26+
/**
27+
* Alpha/Opacity, [0, 1]
28+
*/
29+
a: number = 1.0;
30+
31+
constructor({ xml }: UrdfDefaultOptions) {
32+
// Parse the xml string
33+
const rgba: string[] | undefined = xml.getAttribute(UrdfAttrs.Rgba)?.split(' ');
34+
if (!rgba || rgba.length !== 4) {
35+
return;
36+
}
37+
38+
this.r = parseFloat(rgba[0]);
39+
this.g = parseFloat(rgba[1]);
40+
this.b = parseFloat(rgba[2]);
41+
this.a = parseFloat(rgba[3]);
42+
}
43+
}

src/urdf/UrdfCylinder.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/urdf/UrdfCylinder.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @fileOverview
3+
* @author Benjamin Pitzer - [email protected]
4+
* @author Russell Toris - [email protected]
5+
*/
6+
7+
import {UrdfDefaultOptions, UrdfType, UrdfAttrs} from "./UrdfTypes.js";
8+
9+
/**
10+
* A Cylinder element in a URDF.
11+
*/
12+
export default class UrdfCylinder {
13+
14+
type: UrdfType;
15+
length: number;
16+
radius: number;
17+
18+
constructor({ xml }: UrdfDefaultOptions) {
19+
this.type = UrdfType.CYLINDER;
20+
21+
this.length = parseFloat(xml.getAttribute(UrdfAttrs.Length) ?? 'NaN');
22+
this.radius = parseFloat(xml.getAttribute(UrdfAttrs.Radius) ?? 'NaN');
23+
}
24+
}

src/urdf/UrdfJoint.js

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/urdf/UrdfJoint.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @fileOverview
3+
* @author David V. Lu!! - [email protected]
4+
*/
5+
6+
import {UrdfAttrs, UrdfDefaultOptions} from "./UrdfTypes.js";
7+
import {Pose} from "../math/index.js";
8+
import {parseUrdfOrigin} from "./UrdfUtils.js";
9+
10+
/**
11+
* A Joint element in a URDF.
12+
*/
13+
export default class UrdfJoint {
14+
15+
name: string;
16+
type: string | null;
17+
parent: string | null = null;
18+
child: string | null = null;
19+
minval: number = NaN;
20+
maxval: number = NaN;
21+
origin: Pose = new Pose();
22+
23+
24+
constructor({ xml }: UrdfDefaultOptions) {
25+
this.name = xml.getAttribute(UrdfAttrs.Name) ?? "unknown_name";
26+
this.type = xml.getAttribute(UrdfAttrs.Type);
27+
28+
const parents = xml.getElementsByTagName(UrdfAttrs.Parent);
29+
if (parents.length > 0) {
30+
this.parent = parents[0].getAttribute(UrdfAttrs.Link);
31+
}
32+
33+
const children = xml.getElementsByTagName(UrdfAttrs.Child);
34+
if (children.length > 0) {
35+
this.child = children[0].getAttribute(UrdfAttrs.Link);
36+
}
37+
38+
const limits = xml.getElementsByTagName(UrdfAttrs.Limit);
39+
if (limits.length > 0) {
40+
this.minval = parseFloat(limits[0].getAttribute(UrdfAttrs.Lower) ?? 'NaN');
41+
this.maxval = parseFloat(limits[0].getAttribute(UrdfAttrs.Upper) ?? 'NaN');
42+
}
43+
44+
// Origin
45+
const origins = xml.getElementsByTagName(UrdfAttrs.Origin);
46+
if(origins.length > 0) {
47+
this.origin = parseUrdfOrigin(origins[0]);
48+
}
49+
}
50+
}

src/urdf/UrdfLink.js renamed to src/urdf/UrdfLink.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
*/
66

77
import UrdfVisual from './UrdfVisual.js';
8+
import {UrdfAttrs, UrdfDefaultOptions} from "./UrdfTypes.js";
89

910
/**
1011
* A Link element in a URDF.
1112
*/
1213
export default class UrdfLink {
13-
/**
14-
* @param {Object} options
15-
* @param {Element} options.xml - The XML element to parse.
16-
*/
17-
constructor(options) {
18-
this.name = options.xml.getAttribute('name');
19-
this.visuals = [];
20-
var visuals = options.xml.getElementsByTagName('visual');
2114

22-
for (var i = 0; i < visuals.length; i++) {
15+
name: string;
16+
visuals: UrdfVisual[] = [];
17+
18+
constructor({ xml }: UrdfDefaultOptions) {
19+
this.name = xml.getAttribute(UrdfAttrs.Name) ?? "unknown_name";
20+
const visuals = xml.getElementsByTagName(UrdfAttrs.Visuals);
21+
22+
for (let i = 0; i < visuals.length; i++) {
2323
this.visuals.push(
2424
new UrdfVisual({
2525
xml: visuals[i]

0 commit comments

Comments
 (0)