diff options
| author | Yann C <yann.clarisse@epita.fr> | 2024-04-19 12:48:43 +0300 |
|---|---|---|
| committer | Yann C <yann.clarisse@epita.fr> | 2024-04-19 12:48:43 +0300 |
| commit | cdb21e3e914e4aa0353827c2c3d97269932d1237 (patch) | |
| tree | f0ceccfb3ae1c7895891eefae8888b95713a9f89 /temp_robot.js | |
| parent | 55045dfe27374ade8cdd55667197f42595917669 (diff) | |
Diffstat (limited to 'temp_robot.js')
| -rw-r--r-- | temp_robot.js | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/temp_robot.js b/temp_robot.js deleted file mode 100644 index b47ace2..0000000 --- a/temp_robot.js +++ /dev/null @@ -1,59 +0,0 @@ -const client = mqtt.connect("ws://marcellus.cc:9001"); - -function wait(ms) -{ - return new Promise((resolve, reject) => { - let isObstacle = false; - - const timer = setTimeout(() => { - if(!isObstacle){ - resolve(0); - } // Le délai s'est écoulé sans détecter d'obstacle - }, ms); - - // Supposons que `client` est un objet qui écoute les messages - client.on('message', (topic, message) => { - if (topic === 'move' && parseInt(message.toString()) < 150) { - isObstacle = true; - clearTimeout(timer); - resolve(1); // Un obstacle a été détecté - } - }); - }); -} - -function getTime(dist) -{ - let res = (dist / 200)*1000 - //console.log('time is '+res) - return res -} - -async function moveTo(dist,angle) -{ - console.log('dist is '+ dist) - ang = angle * 180 /Math.PI - console.log('ang is :' + ang.toString()) - var str = 'T'+(Math.floor(ang)).toString() - client.publish('move',str) - client.publish('move','D200') - const time = getTime(dist) - let tmp = await wait(time); - if (tmp == 0){ - client.publish('move', 'STOP'); - } - stop() - -} - -client.on('connect', () => { - console.log('Connecté au courtier MQTT'); - client.subscribe('move') -}); -// client.publish('move','ULT1') - - -/* client.on('close', function () { - console.log('Déconnecté du courtier MQTT'); -});*/ - |
