You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pepper机器人多JavaScript应用Choregraphe运行及ALMemory数据检索问询

How to Switch Between JavaScript Apps in Choregraphe & Retrieve ALMemory Data

Hey there! Let's tackle your two questions one by one—both are common hurdles when working with Choregraphe, and I’ve got straightforward solutions for you.

1. Switching Between JavaScript Apps in a Single Choregraphe Behavior

The key here is to use Choregraphe’s State Machine to manage different phases of your workflow. Each state will host one of your JavaScript apps, and you’ll set up triggers to transition between states when specific conditions are met (like animation completion or user input submission). Here’s a step-by-step breakdown:

  • Set up a State Machine: Drag a "State Machine" box into your behavior. Inside it, create separate states for each phase: e.g., UserInputPhase, AnimationPhase, ButtonSelectionPhase.
  • Assign JavaScript Apps to Each State: For each state, add a "JavaScript" box. In the code for each box:
    • Initialize your app when the state is entered (e.g., load the tablet input UI or button selection interface).
    • Clean up resources when the state is exited (e.g., destroy the UI, remove event listeners) to avoid memory leaks.
  • Add Transition Triggers:
    • For user input completion: When your JS app detects the user has submitted data via the tablet, write a custom event to ALMemory (e.g., UserInput/Completed). Then add an "ALMemory Event" trigger to your state, listening for this event, and set it to transition to the AnimationPhase.
    • For animation completion: Most animation modules (like ALAnimationPlayer) emit an event to ALMemory when an animation finishes (e.g., AnimationPlayer/AnimationDone). Add an "ALMemory Event" trigger on the AnimationPhase to listen for this, then transition to ButtonSelectionPhase.

Example snippet for a JS app in the UserInputPhase:

// Initialize tablet input UI when entering the state
function onInput(input) {
    // Load your input app UI here
    ALTabletService.showWebview("http://your-tablet-app-url/input");
    
    // Listen for user submission
    ALTabletService.onWebviewEvent.connect(function(event) {
        if (event === "inputSubmitted") {
            // Write input data to ALMemory
            ALMemory.insertData("UserInput/FormData", inputData);
            // Trigger state transition
            ALMemory.raiseEvent("UserInput/Completed", true);
        }
    });
}

// Clean up when exiting the state
function onExit() {
    ALTabletService.hideWebview();
    ALTabletService.onWebviewEvent.disconnectAll();
}

2. Retrieving Data from ALMemory

You’ve already got writing data down—retrieving it is just as simple, and there are two main ways to do it depending on your needs:

Synchronous Data Retrieval

If you just need to fetch the current value of a key once, use ALMemory.getData():

// Get data from a specific key
var userInput = ALMemory.getData("UserInput/FormData");
if (userInput !== null) {
    // Process the data (e.g., pass it to your button selection app)
    console.log("Retrieved user input:", userInput);
}

You can also use Choregraphe’s built-in "Get Data From ALMemory" box—drag it into your flow, enter the key you want to read, and connect its output to other boxes (like a JavaScript box or speech synthesis module).

Real-Time Data Listening

If you need to react when the value of a key changes (e.g., if another app updates the data), use a subscriber to listen for changes:

// Create a subscriber for your key
var dataSubscriber = ALMemory.subscriber("UserInput/FormData");

// Bind a callback to handle updates
function handleDataUpdate(newValue) {
    console.log("Data updated to:", newValue);
    // Update your app UI or logic here
}
dataSubscriber.signal.connect(handleDataUpdate);

// Don't forget to clean up when done!
function onExit() {
    dataSubscriber.signal.disconnect(handleDataUpdate);
}

Putting It All Together for Your Example

  1. In the UserInputPhase, your JS app collects data, writes it to ALMemory, and triggers a state transition.
  2. The AnimationPhase runs your animation, and when it finishes, the AnimationDone event triggers a transition to ButtonSelectionPhase.
  3. In the ButtonSelectionPhase, your JS app retrieves the stored data from ALMemory (using getData() or a subscriber) and uses it to customize the button interface.

内容的提问来源于stack exchange,提问作者Sarinda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:19:38