Australia
Asked

Converting Script Code To Javascript

Can you convert the following Script code to Javascript?

controlCommand("Camera", "CameraFaceTrackingDisable") $FaceRecog = 0 $Speech = 0

Change eyes to blue

if (IsConnected(0) = 1) pwm(d17,100) pwm(d18,0) pwm(d19,0) pwm(d21,100) pwm(d22,0) pwm(d23,0) endif

Set all servos to start position

Servo(d0,90) Servo(d1,90) Servo(d2,40) Servo(d3,180) Servo(D4,25) Servo(D5,145) Servo(D6,90) Servo(D7,75) Servo(D8,140) # R Wrist Servo(D9,90) # L Wrist Servo(D10,90)

Pause for a tiny bit to ensure the servos have been initialized

sleep(100)

Set speed of these servos

ServoSpeed( D0, 5 ) ServoSpeed( D1, 5 ) ServoSpeed( D2, 5 ) ServoSpeed( D3, 5 ) ServoSpeed( D4, 5 ) ServoSpeed( D5, 5 ) ServoSpeed( D10, 5 )

if ($Topic = "") goto(section2) endif

Read random line from Topic File

$TopicFile = "c:\Images" $TopicFile = $TopicFile + GetCharAt($TopicFile,2) + GetCharAt($TopicFile,2) + $Topic + ".txt" $Text = FileReadLineRandom($TopicFile)

Speak specified text

#$Text = "Hello human. My name is pepper. I am here to help you."

:section2 ShowControl("Display Interface") sleep(200) sayWait($Topic) say($Text)

If no audio is played for over 2 seconds, then stop

$SilenceCnt = 0 repeatwhile($IsSpeaking) ServoRandom( D0, 40, 140 ) ServoRandom( D1, 75, 95 ) ServoRandom( D2, 40, 120 ) ServoRandom( D3, 100, 180 ) ServoRandom( D4, 30, 50 ) ServoRandom( D5, 130, 150 ) ServoRandom( D6, 100, 130 ) ServoRandom( D7, 45, 75 ) ServoRandom( D10, 80, 100 ) #Waist sleep(2000)

endrepeatwhile

#Change eyes back to green if (IsConnected(0)) PWM(D17,0) PWM(D18,0) PWM(D19,100) PWM(D21,0) PWM(D22,0) PWM(D23,100) endif $ScriptRunning = 0 $FaceRecog = 1 $Speech = 1 CloseControl("Display Interface") controlCommand("Speech Recognition", "PauseOff") controlCommand("Camera", "CameraFaceTrackingEnable") stop()


Related Hardware EZ-B v4
Related Control Script

ARC Pro

Upgrade to ARC Pro

Unleash your robot's full potential with the cutting-edge features and intuitive programming offered by Synthiam ARC Pro.

PRO
Canada
#1  

Certainly! Below is the converted JavaScript code for your ARC project. I've translated the EZ-Script commands to JavaScript, using the ARC JavaScript API.

// Disable camera face tracking
controlCommand("Camera", "CameraFaceTrackingDisable");
setVar("$FaceRecog", 0);
setVar("$Speech", 0);

// Change eyes to blue
if (EZB.isConnected(0)) {
    PWM.set(D17, 100);
    PWM.set(D18, 0);
    PWM.set(D19, 0);
    PWM.set(D21, 100);
    PWM.set(D22, 0);
    PWM.set(D23, 0);
}

// Set all servos to start position
Servo.setPosition(D0, 90);
Servo.setPosition(D1, 90);
Servo.setPosition(D2, 40);
Servo.setPosition(D3, 180);
Servo.setPosition(D4, 25);
Servo.setPosition(D5, 145);
Servo.setPosition(D6, 90);
Servo.setPosition(D7, 75);
Servo.setPosition(D8, 140); // R Wrist
Servo.setPosition(D9, 90);  // L Wrist
Servo.setPosition(D10, 90);

// Pause for a tiny bit to ensure the servos have been initialized
sleep(100);

// Set speed of these servos
Servo.setSpeed(D0, 5);
Servo.setSpeed(D1, 5);
Servo.setSpeed(D2, 5);
Servo.setSpeed(D3, 5);
Servo.setSpeed(D4, 5);
Servo.setSpeed(D5, 5);
Servo.setSpeed(D10, 5);

if (getVar("$Topic") === "") {
    gotoSection2();
}

// Read random line from Topic File
var topicFile = "c:\\Images";
topicFile += getCharAt(topicFile, 2) + getCharAt(topicFile, 2) + getVar("$Topic") + ".txt";
var text = File.readRandomLine(topicFile);

// Speak specified text
// var text = "Hello human. My name is pepper. I am here to help you.";
section2();

function section2() {
    showControl("Display Interface");
    sleep(200);
    Audio.sayWait(getVar("$Topic"));
    Audio.say(text);

    // If no audio is played for over 2 seconds, then stop
    var silenceCnt = 0;
    do {
        while (getVar("$IsSpeaking")) {
            Servo.setPositionRandom(D0, 40, 140);
            Servo.setPositionRandom(D1, 75, 95);
            Servo.setPositionRandom(D2, 40, 120);
            Servo.setPositionRandom(D3, 100, 180);
            Servo.setPositionRandom(D4, 30, 50);
            Servo.setPositionRandom(D5, 130, 150);
            Servo.setPositionRandom(D6, 100, 130);
            Servo.setPositionRandom(D7, 45, 75);
            Servo.setPositionRandom(D10, 80, 100); // Waist
            sleep(2000);
        }
    } while (getVar("$IsSpeaking"));

    // Change eyes back to green
    if (EZB.isConnected(0)) {
        PWM.set(D17, 0);
        PWM.set(D18, 0);
        PWM.set(D19, 100);
        PWM.set(D21, 0);
        PWM.set(D22, 0);
        PWM.set(D23, 100);
    }

    setVar("$ScriptRunning", 0);
    setVar("$FaceRecog", 1);
    setVar("$Speech", 1);
    closeControl("Display Interface");
    controlCommand("Speech Recognition", "PauseOff");
    controlCommand("Camera", "CameraFaceTrackingEnable");
    Movement.stop();
}

Key Points:

  • Control Commands: Use controlCommand() to interact with other robot skills.
  • Servo and PWM: Use Servo.setPosition(), Servo.setSpeed(), and PWM.set() for servo and PWM control.
  • Variables: Use setVar() and getVar() for global variable management.
  • Loops and Conditions: JavaScript syntax is used for loops and conditions.

Feel free to ask if you have any questions or need further assistance!


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.