Misty Community Forum

Two robots dance Sync/Async with other robot

Hello, can you help me for project for Christmas.
I want from Robot One to start script for dancing but in same time to trigger remote Robot2 to start the skill.
The main goal is to 1st robot to trigger 2nd robot skill and they dance ( the true goal is to make 7 robots dance)
1- 2 -3 - (4) - 5 - 6 -7
1 and 7 start first, and then 2,3, the 4 is the singer :smiley:

Really awesome idea! How precise do you need the robots to be in sync? A robust solution would be to use PTP to synchronize all the clocks between the robots, and then they can communicate go at time X, so that all the robots would start at the same time. However, a simpler solution, might just be to have a computer or a single robot broadcast a UDP message to start, and then all the robots cue off of that message.

So far the script looks like code bellow, but the song on 3rd robot start a little bit after the others and this is not okkk…
Video : Streamable

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>xChristmas</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
		<script src="javascript/axios.min.js"></script>		
		<script src="javascript/lightClient.js"></script>
		<script src="javascript/lightSocket.js"></script>
</head>
<body>
	<button type="button" id="startx">Start</button> 
	<button type="button" id="stopx">Stop</button> 
	<script> 
		startx.onclick = function() {   
					Promise.race([
						// ================================================= MIDDLE , FAR-LEFT+RIGHT  --- song
							fetch('http://192.168.1.51/api/skills/start', { method: 'POST', body: '{ Skill: "4d5ea6ce-1ffd-42d6-bafb-27a5c4603397" }' }),
							fetch('http://192.168.1.56/api/skills/start', { method: 'POST', body: '{ Skill: "4d5ea6ce-1ffd-42d6-bafb-27a5c4603397" }' }),
							fetch('http://192.168.1.57/api/skills/start', { method: 'POST', body: '{ Skill: "4d5ea6ce-1ffd-42d6-bafb-27a5c4603397" }' }),
						 
						// ================================================= 
						new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 10000))
					])
					.then(response => response.json())
					.then(jsonData => console.log(jsonData)) 
				// ==============================================  
		};  
		stopx.onclick = function() {   
					Promise.race([
						fetch('http://192.168.1.51/api/audio/stop', { method: 'POST', body: '{ }' }),
						fetch('http://192.168.1.56/api/audio/stop', { method: 'POST', body: '{ }' }),
						fetch('http://192.168.1.57/api/audio/stop', { method: 'POST', body: '{ }' }),
						new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 10000))
					])
					.then(response => response.json())
					.then(jsonData => console.log(jsonData))
				// ==============================================  
		};  
	</script>
</body>
</html>

Maybe you can do an asynchronous parallel fetch, refer to Programmatically fetch multiple APIs in parallel using async and await in JavaScript | Shawn Tabrizi

This allows you to send the start command to all the robots at the same time.