-
-
Save msantang78/0c32e6a2b6aa7d2f2da78dcae8d8cdbe to your computer and use it in GitHub Desktop.
Robot hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Communication, Commands, delay } from "node-jimu"; | |
| import say from "say"; | |
| const comm = new Communication("My_Jimu_CA16"); // name of the robot as seen in jimu app | |
| const robot: Commands = new Commands(comm); | |
| const voice = "Samantha"; | |
| say.speak("He"); | |
| async function move(delayTime: number, speed = 0x30, dir = 1) { | |
| if (dir === 1) { | |
| await robot.setSpeed(1, 2, speed); | |
| await robot.setSpeed(2, 1, speed); | |
| } else { | |
| await robot.setSpeed(1, 1, speed); | |
| await robot.setSpeed(2, 2, speed); | |
| } | |
| await delay(delayTime); | |
| await robot.stop(); | |
| } | |
| async function turn(delayTime: number, speed = 0x30, dir = 1) { | |
| if (dir === 1) { | |
| await robot.setSpeed(1, 1, speed); | |
| await robot.setSpeed(2, 1, speed); | |
| } else { | |
| await robot.setSpeed(1, 2, speed); | |
| await robot.setSpeed(2, 2, speed); | |
| } | |
| await delay(delayTime); | |
| await robot.stop(); | |
| } | |
| comm.connect(async () => { | |
| // enable predefined animation for the eyes: red, green, blue, animation (0 - 15), eye (1, 2 or 3 for both) | |
| await robot.setEyesAnimation(253, 158, 254, 1, 3, 1); | |
| await delay(500); | |
| // set servo positions central, left arm, right arm, speed | |
| await robot.setPosition(210, 170, 80, 20); | |
| await move(100, 25); | |
| await delay(3000); | |
| await robot.setEyesAnimation(253, 158, 254, 5, 1, 5); | |
| await delay(100); | |
| await robot.setEyesAnimation(253, 158, 254, 5, 2, 5); | |
| say.speak("ohh no!", voice); | |
| await robot.setPosition(200, 100, 150, 35); | |
| await delay(1000); | |
| say.speak("I got hacked!", voice); | |
| await delay(4000); | |
| // enable predefined animation for the eyes: red, green, blue, animation (0 - 15), eye (1, 2 or 3 for both) | |
| await robot.setEyesAnimation(253, 158, 254, 6, 3, 20); | |
| say.speak("Hey Minds users!", voice); | |
| // set servo positions central, left arm, right arm, speed | |
| await robot.setPosition(190, 150, 100, 40); | |
| // set wheels speed (sadly, it seems like you only can do it individually ) | |
| await turn(350, 30, 2); | |
| await turn(350, 30, 1); | |
| await delay(3000); | |
| // set eyes color red, green, blue, eye (1, 2 or 3 for both), time | |
| say.speak("Do you like blue eyes?", voice); | |
| await robot.setEyesAnimation(0, 0, 130, 2, 3, 5); | |
| // set position again | |
| await robot.setPosition(195, 170, 80, 20); | |
| await robot.setSpeed(1, 1, 0x30); | |
| await robot.setSpeed(2, 2, 0x30); | |
| await delay(350); | |
| await robot.setPosition(195, 120, 80, 30); | |
| // full stop! | |
| await robot.stop(); | |
| await delay(4000); | |
| await robot.setSpeed(1, 2, 0x40); | |
| await robot.setSpeed(2, 1, 0x30); | |
| say.speak("Do you?", "Samantha"); | |
| await robot.setPosition(190, 160, 70, 30); | |
| await delay(350); | |
| // full stop! | |
| await robot.stop(); | |
| await delay(2000); | |
| // set position again | |
| await robot.setPosition(220, 140, 100, 44); | |
| await delay(1200); | |
| await robot.setPosition(220, 100, 140, 20); | |
| await delay(100); | |
| // disconnect | |
| comm.disconnect(); | |
| // close | |
| process.exit(0); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment