8bitkick
commited on
Commit
·
33a4562
1
Parent(s):
98fa906
disco
Browse files
reachy_mini_app_example/src/RobotManager.js
CHANGED
|
@@ -181,11 +181,14 @@ export class RobotManager {
|
|
| 181 |
|
| 182 |
// Update antennas if available
|
| 183 |
if (data.antennas_position && Array.isArray(data.antennas_position)) {
|
|
|
|
| 184 |
if (this.jointMap['left_antenna'] && data.antennas_position[0] !== undefined) {
|
| 185 |
-
this.jointMap['left_antenna']
|
|
|
|
| 186 |
}
|
| 187 |
if (this.jointMap['right_antenna'] && data.antennas_position[1] !== undefined) {
|
| 188 |
-
this.jointMap['right_antenna']
|
|
|
|
| 189 |
}
|
| 190 |
}
|
| 191 |
|
|
@@ -233,6 +236,9 @@ export class RobotManager {
|
|
| 233 |
this.baseHeadPosition.copy(localPosition);
|
| 234 |
this.baseHeadRotation.setFromQuaternion(localRotation);
|
| 235 |
|
|
|
|
|
|
|
|
|
|
| 236 |
// Hide the original head and add the cloned head to the scene
|
| 237 |
child.visible = false;
|
| 238 |
this.robot.add(this.clonedHead);
|
|
@@ -243,6 +249,23 @@ export class RobotManager {
|
|
| 243 |
}, 3000); // Wait 3 seconds for STL meshes to load
|
| 244 |
}
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
debugHeadMovement() {
|
| 247 |
// Removed debug movement tracking for cleaner performance
|
| 248 |
}
|
|
|
|
| 181 |
|
| 182 |
// Update antennas if available
|
| 183 |
if (data.antennas_position && Array.isArray(data.antennas_position)) {
|
| 184 |
+
console.log('Updating antennas:', data.antennas_position);
|
| 185 |
if (this.jointMap['left_antenna'] && data.antennas_position[0] !== undefined) {
|
| 186 |
+
console.log('Left antenna:', this.jointMap['left_antenna'], 'value:', -data.antennas_position[0]);
|
| 187 |
+
this.jointMap['left_antenna'].setJointValue(-data.antennas_position[0]);
|
| 188 |
}
|
| 189 |
if (this.jointMap['right_antenna'] && data.antennas_position[1] !== undefined) {
|
| 190 |
+
console.log('Right antenna:', this.jointMap['right_antenna'], 'value:', -data.antennas_position[1]);
|
| 191 |
+
this.jointMap['right_antenna'].setJointValue(-data.antennas_position[1]);
|
| 192 |
}
|
| 193 |
}
|
| 194 |
|
|
|
|
| 236 |
this.baseHeadPosition.copy(localPosition);
|
| 237 |
this.baseHeadRotation.setFromQuaternion(localRotation);
|
| 238 |
|
| 239 |
+
// Remap antenna joints to point to the cloned head's joints instead of original
|
| 240 |
+
this.remapAntennaJoints(child, this.clonedHead);
|
| 241 |
+
|
| 242 |
// Hide the original head and add the cloned head to the scene
|
| 243 |
child.visible = false;
|
| 244 |
this.robot.add(this.clonedHead);
|
|
|
|
| 249 |
}, 3000); // Wait 3 seconds for STL meshes to load
|
| 250 |
}
|
| 251 |
|
| 252 |
+
remapAntennaJoints(originalHead, clonedHead) {
|
| 253 |
+
// Find antenna joints in the cloned head and update the joint map
|
| 254 |
+
console.log('Remapping antenna joints from original to cloned head...');
|
| 255 |
+
let remappedCount = 0;
|
| 256 |
+
clonedHead.traverse((child) => {
|
| 257 |
+
if (child.isURDFJoint && (child.name === 'left_antenna' || child.name === 'right_antenna')) {
|
| 258 |
+
// Update the joint map to point to the cloned version
|
| 259 |
+
console.log(`Found ${child.name} joint in cloned head:`, child);
|
| 260 |
+
this.jointMap[child.name] = child;
|
| 261 |
+
remappedCount++;
|
| 262 |
+
console.log(`✅ Remapped ${child.name} joint to cloned head`);
|
| 263 |
+
}
|
| 264 |
+
});
|
| 265 |
+
console.log(`Total antenna joints remapped: ${remappedCount}`);
|
| 266 |
+
console.log('Current joint map:', Object.keys(this.jointMap));
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
debugHeadMovement() {
|
| 270 |
// Removed debug movement tracking for cleaner performance
|
| 271 |
}
|
reachy_mini_app_example/src/SceneManager.js
CHANGED
|
@@ -76,26 +76,29 @@ export class SceneManager {
|
|
| 76 |
|
| 77 |
setupLighting() {
|
| 78 |
// Ambient light
|
| 79 |
-
const ambientLight = new THREE.AmbientLight(0xffffff, 0.
|
| 80 |
this.scene.add(ambientLight);
|
| 81 |
|
| 82 |
// Directional light
|
| 83 |
-
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.
|
| 84 |
-
directionalLight.position.set(1,
|
| 85 |
directionalLight.castShadow = true;
|
| 86 |
this.scene.add(directionalLight);
|
| 87 |
|
| 88 |
-
//
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
this.scene.add(
|
| 98 |
-
this.scene.add(
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
|
| 101 |
onWindowResize() {
|
|
@@ -117,4 +120,57 @@ export class SceneManager {
|
|
| 117 |
requestAnimationFrame(() => this.animate());
|
| 118 |
this.render();
|
| 119 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
}
|
|
|
|
| 76 |
|
| 77 |
setupLighting() {
|
| 78 |
// Ambient light
|
| 79 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
|
| 80 |
this.scene.add(ambientLight);
|
| 81 |
|
| 82 |
// Directional light
|
| 83 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.7);
|
| 84 |
+
directionalLight.position.set(1, 0, 2);
|
| 85 |
directionalLight.castShadow = true;
|
| 86 |
this.scene.add(directionalLight);
|
| 87 |
|
| 88 |
+
// Disco spotlight! 🕺💃
|
| 89 |
+
this.discoSpotLight = new THREE.SpotLight(0xff0000, 2.0);
|
| 90 |
+
this.discoSpotLight.position.set(0.5, 0.8, 0.5);
|
| 91 |
+
this.discoSpotLight.angle = Math.PI / 3;
|
| 92 |
+
this.discoSpotLight.penumbra = 0.2;
|
| 93 |
+
this.discoSpotLight.decay = 1.5;
|
| 94 |
+
this.discoSpotLight.distance = 4;
|
| 95 |
+
this.discoSpotLight.castShadow = true;
|
| 96 |
+
this.discoSpotLight.target.position.set(0, 0.1, 0);
|
| 97 |
+
this.scene.add(this.discoSpotLight);
|
| 98 |
+
this.scene.add(this.discoSpotLight.target);
|
| 99 |
+
|
| 100 |
+
// Setup disco beat
|
| 101 |
+
this.setupDiscoBeat();
|
| 102 |
}
|
| 103 |
|
| 104 |
onWindowResize() {
|
|
|
|
| 120 |
requestAnimationFrame(() => this.animate());
|
| 121 |
this.render();
|
| 122 |
}
|
| 123 |
+
|
| 124 |
+
setupDiscoBeat() {
|
| 125 |
+
// Disco colors: red, green, blue, white, purple, orange
|
| 126 |
+
this.discoColors = [
|
| 127 |
+
0xff0000, // red
|
| 128 |
+
0x00ff00, // green
|
| 129 |
+
0x0000ff, // blue
|
| 130 |
+
0xffffff, // white
|
| 131 |
+
0xff00ff, // purple/magenta
|
| 132 |
+
0xff8000, // orange
|
| 133 |
+
0x00ffff, // cyan
|
| 134 |
+
0xffff00 // yellow
|
| 135 |
+
];
|
| 136 |
+
|
| 137 |
+
this.currentColorIndex = 0;
|
| 138 |
+
this.beatTime = 0;
|
| 139 |
+
this.beatInterval = 120; // BPM - change color every 120 BPM (500ms)
|
| 140 |
+
|
| 141 |
+
// Start the disco beat
|
| 142 |
+
this.discoInterval = setInterval(() => {
|
| 143 |
+
this.changeDiscoColor();
|
| 144 |
+
}, 60000 / this.beatInterval); // Convert BPM to milliseconds
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
changeDiscoColor() {
|
| 148 |
+
if (!this.discoSpotLight) return;
|
| 149 |
+
|
| 150 |
+
// Change to next color
|
| 151 |
+
this.currentColorIndex = (this.currentColorIndex + 1) % this.discoColors.length;
|
| 152 |
+
const newColor = this.discoColors[this.currentColorIndex];
|
| 153 |
+
|
| 154 |
+
this.discoSpotLight.color.setHex(newColor);
|
| 155 |
+
|
| 156 |
+
// Add some intensity variation for extra disco effect
|
| 157 |
+
const intensityVariation = 1.5 + Math.random() * 1.0; // 1.5 - 2.5
|
| 158 |
+
this.discoSpotLight.intensity = intensityVariation;
|
| 159 |
+
|
| 160 |
+
// Slightly move the spotlight for dynamic effect
|
| 161 |
+
const angle = Date.now() * 0.001;
|
| 162 |
+
this.discoSpotLight.position.x = 0.5 + Math.sin(angle) * 0.2;
|
| 163 |
+
this.discoSpotLight.position.z = 0.5 + Math.cos(angle) * 0.2;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
stopDisco() {
|
| 167 |
+
if (this.discoInterval) {
|
| 168 |
+
clearInterval(this.discoInterval);
|
| 169 |
+
this.discoInterval = null;
|
| 170 |
+
}
|
| 171 |
+
if (this.discoSpotLight) {
|
| 172 |
+
this.discoSpotLight.color.setHex(0xffffff);
|
| 173 |
+
this.discoSpotLight.intensity = 1.0;
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
}
|
reachy_mini_app_example/src/WebSocketManager.js
CHANGED
|
@@ -7,7 +7,7 @@ export class WebSocketManager {
|
|
| 7 |
this.chartManager = chartManager;
|
| 8 |
|
| 9 |
this.WS_URL = new URLSearchParams(location.search).get("ws")
|
| 10 |
-
|| "ws://127.0.0.1:8000/api/state/ws/full";
|
| 11 |
|
| 12 |
this.robotClient = new RobotStateClient(this.WS_URL);
|
| 13 |
}
|
|
@@ -34,6 +34,11 @@ export class WebSocketManager {
|
|
| 34 |
}
|
| 35 |
|
| 36 |
handleDataUpdate(data) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
// Update robot joints
|
| 38 |
this.robotManager.updateJoints(data);
|
| 39 |
|
|
|
|
| 7 |
this.chartManager = chartManager;
|
| 8 |
|
| 9 |
this.WS_URL = new URLSearchParams(location.search).get("ws")
|
| 10 |
+
|| "ws://127.0.0.1:8000/api/state/ws/full?with_passive_joints=true&head_joints=true";
|
| 11 |
|
| 12 |
this.robotClient = new RobotStateClient(this.WS_URL);
|
| 13 |
}
|
|
|
|
| 34 |
}
|
| 35 |
|
| 36 |
handleDataUpdate(data) {
|
| 37 |
+
// Log antenna data for debugging
|
| 38 |
+
if (data.antennas_position) {
|
| 39 |
+
console.log('Antenna positions received:', data.antennas_position);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
// Update robot joints
|
| 43 |
this.robotManager.updateJoints(data);
|
| 44 |
|