|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { DOMParser } from '@xmldom/xmldom'; |
| 3 | +import UrdfJoint from '../src/urdf/UrdfJoint'; |
| 4 | + |
| 5 | +describe('UrdfJoint', () => { |
| 6 | + it('should parse axis correctly from URDF', () => { |
| 7 | + const jointWithAxisUrdf = ` |
| 8 | + <joint name="test_joint" type="revolute"> |
| 9 | + <parent link="link1"/> |
| 10 | + <child link="link2"/> |
| 11 | + <axis xyz="0 1 0"/> |
| 12 | + </joint>`; |
| 13 | + const parser = new DOMParser(); |
| 14 | + const xml = parser.parseFromString(jointWithAxisUrdf, 'text/xml').documentElement; |
| 15 | + const joint = new UrdfJoint({ xml }); |
| 16 | + expect(joint.axis.x).toBe(0); |
| 17 | + expect(joint.axis.y).toBe(1); |
| 18 | + expect(joint.axis.z).toBe(0); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should default axis to (1,0,0) if not present', () => { |
| 22 | + const jointNoAxisUrdf = ` |
| 23 | + <joint name="test_joint" type="revolute"> |
| 24 | + <parent link="link1"/> |
| 25 | + <child link="link2"/> |
| 26 | + </joint> |
| 27 | + `; |
| 28 | + const parser = new DOMParser(); |
| 29 | + const xml = parser.parseFromString(jointNoAxisUrdf, 'text/xml').documentElement; |
| 30 | + const joint = new UrdfJoint({ xml }); |
| 31 | + expect(joint.axis.x).toBe(1); |
| 32 | + expect(joint.axis.y).toBe(0); |
| 33 | + expect(joint.axis.z).toBe(0); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should default axis to (1,0,0) if axis xyz is malformed', () => { |
| 37 | + const jointMalformedAxisUrdf = ` |
| 38 | + <joint name="test_joint" type="revolute"> |
| 39 | + <parent link="link1"/> |
| 40 | + <child link="link2"/> |
| 41 | + <axis xyz="malformed data"/> |
| 42 | + </joint> |
| 43 | + `; |
| 44 | + const parser = new DOMParser(); |
| 45 | + const xml = parser.parseFromString(jointMalformedAxisUrdf, 'text/xml').documentElement; |
| 46 | + const joint = new UrdfJoint({ xml }); |
| 47 | + expect(joint.axis.x).toBe(1); |
| 48 | + expect(joint.axis.y).toBe(0); |
| 49 | + expect(joint.axis.z).toBe(0); |
| 50 | + }); |
| 51 | +}); |
0 commit comments