Public
Edited
Aug 23, 2024
Paused
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Initial position of the mechanism: [x,y,θ1A,θ2A,θ1B,θ2B]
initial_position = [331.5,-806.5,54.43,4.75,14.83,-26.28]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
x = Inputs.range([x_Min, x_Max], {value: initial_position[0], step: 0.1, label: htl.html`<b>x</b> [mm]`, disabled: false})
Insert cell
mutable x_value = 0
Insert cell
y = Inputs.range([y_Min, y_Max], {value: initial_position[1], step: 0.1, label: htl.html`<b>y</b> [mm]`, disabled: false})
Insert cell
mutable y_value = 0
Insert cell
mutable y_value_offset = 0
Insert cell
theta_1_A = Inputs.range([theta_1_Min, theta_1_Max], {value: initial_position[2], step: 0.01, label: htl.html`<b></b> θ<sub>1A</sub> [°]`, disabled: true})
Insert cell
theta_1_A.value = theta_1_A_IK[IK_solution_A.indices[0]]
Insert cell
theta_2_A = Inputs.range([theta_2_Min, theta_2_Max], {value: initial_position[3], step: 0.01, label: htl.html`<b></b> θ<sub>2A</sub> [°]`, disabled: true})
Insert cell
theta_2_A.value = theta_2_A_IK[IK_solution_A.indices[1]]
Insert cell
theta_1_B = Inputs.range([theta_1_Min, theta_1_Max], {value: initial_position[4], step: 0.01, label: htl.html`<b></b> θ<sub>1B</sub> [°]`, disabled: true})
Insert cell
theta_1_B.value = theta_1_B_IK[IK_solution_B.indices[0]]
Insert cell
theta_2_B = Inputs.range([theta_2_Min, theta_2_Max], {value: initial_position[5], step: 0.01, label: htl.html`<b></b> θ<sub>2B</sub> [°]`, disabled: true})
Insert cell
theta_2_B.value = theta_2_B_IK[IK_solution_B.indices[1]]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
loadSketchfab(uid, "api-frame");
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
load_success = (api) => {
api.start(function () {
api.addEventListener("viewerready", function () {
api.getNodeMap(function (err, nodes) {
// console.log(nodes);
const end_effector = getNodeByName(nodes, end_effector_ID);
const L1A = getNodeByName(nodes, L1A_ID);
const L2A = getNodeByName(nodes, L2A_ID);
const L1B = getNodeByName(nodes, L1B_ID);
const L2B = getNodeByName(nodes, L2B_ID);

// Directly invoke the function with the current value on page load
(function initialize() {
updateMatrix(); // This ensures the initial values are applied immediately
})();

// 3D model is reactive to the slider value changes.
// For IK, we recalculate the transformation on mouse events with a slight delay.
// This ensures the 3D model updates correctly, even if the slider is clicked rather than dragged.
[x, y].forEach(slider => {
slider.addEventListener('input', updateMatrix);
slider.addEventListener("mousedown", () => {
setTimeout(updateMatrix, 100); // Adjust the delay (ms) as needed
});
slider.addEventListener("change", updateMatrix); // Improves the behavior if the slider is changed via text input
});

function updateMatrix() {
mutable x_value = x.value;
mutable y_value = y.value;
mutable y_value_offset = mutable y_value - y_offset - y_offset_model;

// Orientation of the 3D model differs from notebook: (x,y,z) -> (x,z,-y)
translateNode(api, end_effector.instanceID, [mutable x_value, 0, -mutable y_value_offset]);

const angle1A = -degToRad(theta_1_A.value);
const angle1B = -degToRad(theta_1_B.value);
const angle2A = -degToRad(theta_2_A.value - theta_2_offset_model);
const angle2B = -degToRad(theta_2_B.value + theta_2_offset_model);

rotateNode(api, L1A.instanceID, angle1A, 0, 1, 0);
rotateNode(api, L1B.instanceID, angle1B, 0, 1, 0);
rotateNode(api, L2A.instanceID, angle2A, 0, 1, 0);
rotateNode(api, L2B.instanceID, angle2B, 0, 1, 0);

}
});
});
});
};
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more