all major body parts moving, roll,pitch,yaw for ehad on ctrl & alt.

master
Jake Wilkinson 2025-11-22 14:15:18 +08:00
parent e04938d19a
commit 40905cbb36
2 changed files with 70 additions and 69 deletions

View File

@ -229,8 +229,19 @@ export class URDFEditor {
this.lastX = event.clientX; this.lastX = event.clientX;
this.controls.enabled = false; this.controls.enabled = false;
this.draggedJoint = this.findJointAncestor(this.hoveredJoint); // Decide how far up the chain to go
if (!this.draggedJoint) return; 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 jointName = this.draggedJoint.name;
const jointData = this.robot.joints?.[jointName]; const jointData = this.robot.joints?.[jointName];
@ -238,29 +249,19 @@ export class URDFEditor {
const axis = jointData.axis.clone(); const axis = jointData.axis.clone();
if (axis.lengthSq() === 0) return; if (axis.lengthSq() === 0) return;
this.worldAxis = axis.normalize(); this.worldAxis = axis.normalize();
// ✅ Use transmission-derived limits if available
const { lower, upper } = getJointLimits(jointName, this.robot); const { lower, upper } = getJointLimits(jointName, this.robot);
//console.log(lower, upper); const transmission = jointData.transmission;
const encoderRange = transmission
const jointTransmission = this.robot.joints[jointName].transmission; ? transmission.encoderRange / transmission.mechanicalReduction
const jointMimic = this.robot.joints[jointName].mimic; : Math.PI;
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 sector = createRotationSector(this.worldAxis, lower, upper, encoderRange); const sector = createRotationSector(this.worldAxis, lower, upper, encoderRange);
const indicator = createAngleIndicator(this.worldAxis, this.jointAngles[jointName] ?? 0); 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(sector);
this.draggedJoint.parent.add(indicator); this.draggedJoint.parent.add(indicator);
@ -268,6 +269,7 @@ export class URDFEditor {
} }
onPointerUp() { onPointerUp() {
this.isDragging = false; this.isDragging = false;
this.controls.enabled = true; this.controls.enabled = true;
@ -282,14 +284,23 @@ export class URDFEditor {
this.worldAxis = null; this.worldAxis = null;
} }
findJointAncestor(object) { findJointAncestor(joint, levelsUp = 0) {
while (object && object.parent) { let current = joint;
if (object.type === 'URDFJoint') return object; let steps = 0;
object = object.parent;
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() { animate() {
requestAnimationFrame(() => this.animate()); requestAnimationFrame(() => this.animate());
this.drawJointOverlay(); // ✅ fixed overlay this.drawJointOverlay(); // ✅ fixed overlay
@ -326,8 +337,11 @@ export class URDFEditor {
const rotatedChild = jointObject.children?.[0]; const rotatedChild = jointObject.children?.[0];
const childName = rotatedChild?.name || '(unnamed)'; const childName = rotatedChild?.name || '(unnamed)';
const motorName = jointData.transmission?.actuatorName || '(no motor)';
ctx.fillText(childName, nameX, y); if (motorName == "(no motor)") {
continue;
}
ctx.fillText(motorName, nameX, y);
const angleStr = `${degrees}°`; const angleStr = `${degrees}°`;
const angleWidth = ctx.measureText(angleStr).width; const angleWidth = ctx.measureText(angleStr).width;
ctx.fillText(angleStr, angleX - angleWidth, y); ctx.fillText(angleStr, angleX - angleWidth, y);

View File

@ -1,11 +1,11 @@
<robot name="robot"> <robot name="robot">
<link name="base_footprint"></link> <link name="base_footprint"></link>
<joint name="base_joint" type="fixed"> <!-- <joint name="base_joint" type="fixed">
<parent link="base_footprint" /> <parent link="base_footprint" />
<child link="base_link" /> <child link="base_link" />
<origin xyz="0 0 0.11" rpy="0 0 0" /> <origin xyz="0 0 0.11" rpy="0 0 0" />
<limit effort="1000.0" lower="-1" upper="1" velocity="0.5" /> <limit effort="1000.0" lower="-1" upper="1" velocity="0.5" />
</joint> </joint> -->
<link name="base_link"> <link name="base_link">
<visual> <visual>
<origin xyz="0 0 0" rpy="-1.5745 3.149 0" /> <origin xyz="0 0 0" rpy="-1.5745 3.149 0" />
@ -208,7 +208,7 @@
</link> </link>
<joint name="lower_leg_right_to_foot_right" type="revolute"> <joint name="lower_leg_right_to_foot_right" type="revolute">
<parent link="lower_leg_right" /> <parent link="lower_leg_right" />
<child link="foot_right" /> <child link="foot_right" />
<origin xyz="0 0 -0.043" rpy="0 0 0" /> <origin xyz="0 0 -0.043" rpy="0 0 0" />
@ -359,6 +359,7 @@
<limit effort="1000.0" lower="-1" upper="1" velocity="0.5" /> <limit effort="1000.0" lower="-1" upper="1" velocity="0.5" />
</joint> </joint>
<link name="foot_left"> <link name="foot_left">
<visual> <visual>
<origin xyz="0 0 0" rpy="-1.5745 3.149 0" /> <origin xyz="0 0 0" rpy="-1.5745 3.149 0" />
@ -439,26 +440,12 @@
</link> </link>
<transmission name="upper_arm_left">
<type>transmission_interface/SimpleTransmission</type>
<joint name="base_joint">
<hardwareInterface>PositionJointInterface</hardwareInterface>
</joint>
<actuator name="spine_motor_1">
<mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks>
<encoderValidMin>200</encoderValidMin>
<encoderValidMax>3500</encoderValidMax>
<encoderRange>270</encoderRange>
</actuator>
</transmission>
<transmission name="upper_arm_left"> <transmission name="upper_arm_left">
<type>transmission_interface/SimpleTransmission</type> <type>transmission_interface/SimpleTransmission</type>
<joint name="base_link_to_upper_arm_left"> <joint name="base_link_to_upper_arm_left">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="spine_motor_1"> <actuator name="upper_arm_left">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -467,28 +454,12 @@
<encoderRange>270</encoderRange> <encoderRange>270</encoderRange>
</actuator> </actuator>
</transmission> </transmission>
<transmission name="lower_arm_left">
<type>transmission_interface/SimpleTransmission</type>
<joint name="upper_arm_left_to_lower_arm_left">
<hardwareInterface>PositionJointInterface</hardwareInterface>
</joint>
<actuator name="spine_motor_1">
<mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks>
<encoderValidMin>200</encoderValidMin>
<encoderValidMax>3500</encoderValidMax>
<encoderRange>270</encoderRange>
</actuator>
</transmission>
<transmission name="hand_left"> <transmission name="hand_left">
<type>transmission_interface/SimpleTransmission</type> <type>transmission_interface/SimpleTransmission</type>
<joint name="lower_arm_left_to_hand_left"> <joint name="lower_arm_left_to_hand_left">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="spine_motor_1"> <actuator name="hand_left">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -503,7 +474,7 @@
<joint name="base_link_to_upper_arm_right"> <joint name="base_link_to_upper_arm_right">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="spine_motor_1"> <actuator name="upper_arm_right">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -534,7 +505,7 @@
<joint name="hip_right_to_upper_leg_right"> <joint name="hip_right_to_upper_leg_right">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="upper_leg_motor_right"> <actuator name="upper_leg_right">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -549,7 +520,7 @@
<joint name="upper_leg_right_to_lower_leg_right_roll"> <joint name="upper_leg_right_to_lower_leg_right_roll">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="lower_leg_motor_right"> <actuator name="lower_leg_right">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -564,7 +535,7 @@
<joint name="lower_leg_right_to_foot_right"> <joint name="lower_leg_right_to_foot_right">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="foot_motor_right"> <actuator name="foot_right">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -594,7 +565,7 @@
<joint name="hip_left_to_upper_leg_left"> <joint name="hip_left_to_upper_leg_left">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="upper_leg_motor_left"> <actuator name="upper_leg_left">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -609,7 +580,23 @@
<joint name="upper_leg_left_to_lower_leg_left_roll"> <joint name="upper_leg_left_to_lower_leg_left_roll">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="lower_leg_motor_left"> <actuator name="lower_leg_left">
<mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks>
<encoderValidMin>200</encoderValidMin>
<encoderValidMax>3500</encoderValidMax>
<encoderRange>270</encoderRange>
</actuator>
</transmission>
<transmission name="foot_left">
<type>transmission_interface/SimpleTransmission</type>
<joint name="lower_leg_left_to_foot_left">
<hardwareInterface>PositionJointInterface</hardwareInterface>
</joint>
<actuator name="foot_left">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -625,7 +612,7 @@
<joint name="base_link_to_neck_yaw"> <joint name="base_link_to_neck_yaw">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="neck_motor_yaw"> <actuator name="neck_yaw">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -641,7 +628,7 @@
<joint name="neck_pitch"> <joint name="neck_pitch">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="neck_motor_pitch"> <actuator name="neck_pitch">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>
@ -657,7 +644,7 @@
<joint name="neck_roll"> <joint name="neck_roll">
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
</joint> </joint>
<actuator name="neck_motor_roll"> <actuator name="neck_roll">
<mechanicalReduction>1</mechanicalReduction> <mechanicalReduction>1</mechanicalReduction>
<hardwareInterface>PositionJointInterface</hardwareInterface> <hardwareInterface>PositionJointInterface</hardwareInterface>
<encoderTicks>4096</encoderTicks> <encoderTicks>4096</encoderTicks>