From 40905cbb36a784c7f86bd5966418d263e8143525 Mon Sep 17 00:00:00 2001 From: Jake Wilkinson Date: Sat, 22 Nov 2025 14:15:18 +0800 Subject: [PATCH] all major body parts moving, roll,pitch,yaw for ehad on ctrl & alt. --- URDFEditor.js | 64 ++++++++++-------- robots/LittleSophia/urdf/LittleSophia.urdf | 75 +++++++++------------- 2 files changed, 70 insertions(+), 69 deletions(-) diff --git a/URDFEditor.js b/URDFEditor.js index da09f9b..8ba14cf 100644 --- a/URDFEditor.js +++ b/URDFEditor.js @@ -229,8 +229,19 @@ export class URDFEditor { this.lastX = event.clientX; this.controls.enabled = false; - this.draggedJoint = this.findJointAncestor(this.hoveredJoint); - if (!this.draggedJoint) return; + // Decide how far up the chain to go + let levelsUp = 0; // default: climb one level from link → joint +if (event.ctrlKey) levelsUp = 1; +if (event.altKey) levelsUp = 2; + +this.draggedJoint = this.findJointAncestor(this.hoveredJoint, levelsUp); +if (!this.draggedJoint) return; + +// ✅ Skip mimic joints +if (this.draggedJoint.type === 'URDFMimicJoint') { + this.draggedJoint = findJointAncestor(this.draggedJoint, 1); +} + const jointName = this.draggedJoint.name; const jointData = this.robot.joints?.[jointName]; @@ -238,29 +249,19 @@ export class URDFEditor { const axis = jointData.axis.clone(); if (axis.lengthSq() === 0) return; - this.worldAxis = axis.normalize(); - // ✅ Use transmission-derived limits if available const { lower, upper } = getJointLimits(jointName, this.robot); - //console.log(lower, upper); - - const jointTransmission = this.robot.joints[jointName].transmission; - const jointMimic = this.robot.joints[jointName].mimic; - console.log(this.robot.joints[jointName]); - - // Bail only if neither transmission nor mimic - if (!jointTransmission && !jointMimic) return; - - // If transmission exists, use its encoderRange - let encoderRange = 180; // sensible default - if (jointTransmission) { - encoderRange = jointTransmission.encoderRange / jointTransmission.mechanicalReduction; - } + const transmission = jointData.transmission; + const encoderRange = transmission + ? transmission.encoderRange / transmission.mechanicalReduction + : Math.PI; const sector = createRotationSector(this.worldAxis, lower, upper, encoderRange); const indicator = createAngleIndicator(this.worldAxis, this.jointAngles[jointName] ?? 0); + sector.position.copy(this.draggedJoint.position); + indicator.position.copy(this.draggedJoint.position); this.draggedJoint.parent.add(sector); this.draggedJoint.parent.add(indicator); @@ -268,6 +269,7 @@ export class URDFEditor { } + onPointerUp() { this.isDragging = false; this.controls.enabled = true; @@ -282,14 +284,23 @@ export class URDFEditor { this.worldAxis = null; } - findJointAncestor(object) { - while (object && object.parent) { - if (object.type === 'URDFJoint') return object; - object = object.parent; + findJointAncestor(joint, levelsUp = 0) { + let current = joint; + let steps = 0; + + while (current && steps <= levelsUp) { + current = current.parent; + // climb until we find a URDFJoint (not a mimic) + while (current && !(current.type === 'URDFJoint')) { + current = current.parent; + } + steps++; } - return null; + + return current; } + animate() { requestAnimationFrame(() => this.animate()); this.drawJointOverlay(); // ✅ fixed overlay @@ -326,8 +337,11 @@ export class URDFEditor { const rotatedChild = jointObject.children?.[0]; const childName = rotatedChild?.name || '(unnamed)'; - - ctx.fillText(childName, nameX, y); + const motorName = jointData.transmission?.actuatorName || '(no motor)'; + if (motorName == "(no motor)") { + continue; + } + ctx.fillText(motorName, nameX, y); const angleStr = `${degrees}°`; const angleWidth = ctx.measureText(angleStr).width; ctx.fillText(angleStr, angleX - angleWidth, y); diff --git a/robots/LittleSophia/urdf/LittleSophia.urdf b/robots/LittleSophia/urdf/LittleSophia.urdf index adee6ca..29eca95 100644 --- a/robots/LittleSophia/urdf/LittleSophia.urdf +++ b/robots/LittleSophia/urdf/LittleSophia.urdf @@ -1,11 +1,11 @@ - + @@ -208,7 +208,7 @@ - + @@ -359,6 +359,7 @@ + @@ -439,26 +440,12 @@ - - transmission_interface/SimpleTransmission - - PositionJointInterface - - - 1 - PositionJointInterface - 4096 - 200 - 3500 - 270 - - transmission_interface/SimpleTransmission PositionJointInterface - + 1 PositionJointInterface 4096 @@ -467,28 +454,12 @@ 270 - - - transmission_interface/SimpleTransmission - - PositionJointInterface - - - 1 - PositionJointInterface - 4096 - 200 - 3500 - 270 - - - transmission_interface/SimpleTransmission PositionJointInterface - + 1 PositionJointInterface 4096 @@ -503,7 +474,7 @@ PositionJointInterface - + 1 PositionJointInterface 4096 @@ -534,7 +505,7 @@ PositionJointInterface - + 1 PositionJointInterface 4096 @@ -549,7 +520,7 @@ PositionJointInterface - + 1 PositionJointInterface 4096 @@ -564,7 +535,7 @@ PositionJointInterface - + 1 PositionJointInterface 4096 @@ -594,7 +565,7 @@ PositionJointInterface - + 1 PositionJointInterface 4096 @@ -609,7 +580,23 @@ PositionJointInterface - + + 1 + PositionJointInterface + 4096 + 200 + 3500 + 270 + + + + + + transmission_interface/SimpleTransmission + + PositionJointInterface + + 1 PositionJointInterface 4096 @@ -625,7 +612,7 @@ PositionJointInterface - + 1 PositionJointInterface 4096 @@ -641,7 +628,7 @@ PositionJointInterface - + 1 PositionJointInterface 4096 @@ -657,7 +644,7 @@ PositionJointInterface - + 1 PositionJointInterface 4096