Roban2 Docs
Development InterfacesRoban2 C++ SDK Interfaces

Motion and Audio Tools

This page documents the motion, tact, and local audio playback capabilities that can be verified in the current development package. motion and tact are provided by the public C++ API of lejusdk-vr; audio playback currently exposes only a bundled command-line tool, with no public C++ SDK headers.

Motion State Query

1. Function Description

getMotionState() queries whether the current controller supports motion, whether a motion is currently playing, the current motion name, and the list of actually available motions.

2. SDK and Header File

  • SDK: lejusdk-vr
  • Header: <lejusdk-vr/lejusdk_vr.h>

3. Request or Message Type

bool getMotionState(leju::vr::MotionState& state,
                    int timeout_ms = 3000);

4. Field Description

FieldTypeDescription
supportedboolWhether the current controller supports motion query/playback
motion_playingboolWhether a motion is currently playing
current_motion_namestd::stringCurrent motion name
available_motion_namesstd::vector<std::string>Names of currently playable motions
timeout_msintRPC timeout, default 3000 ms

5. Return Value

Returns true and populates state when the RPC query succeeds; returns false when the service is unavailable or the request times out. true does not mean supported=true; the two must be evaluated separately.

6. Prerequisites

  • RobanVRAPI is initialized, and the controller management program has started.
  • Do not guess motion names in your application; use the actual list returned in available_motion_names.

7. C++ Example

leju::vr::MotionState state;
if (!vr.getMotionState(state)) return 1;

if (!state.supported) {
  std::cout << "当前控制器不支持 motion\n";
  return 0;
}
for (const auto& name : state.available_motion_names) {
  std::cout << name << '\n';
}

8. Corresponding Repository Examples

Currently, src/lejusdk/examples/ contains no standalone user example for getMotionState(). For the actual service-side handling, refer to:

  • src/leju-controllers/leju-rl-controller/src/runtime/input/external_interface.cpp
  • Public types: installed/include/lejusdk-vr/data_types.h

Starting a Motion

1. Function Description

startMotion() requests that the current controller play a CSV motion. You can pass a specific motion name, or pass an empty string to invoke the current controller's default motion behavior.

2. SDK and Header File

  • SDK: lejusdk-vr
  • Header: <lejusdk-vr/lejusdk_vr.h>

3. Request or Message Type

bool startMotion(const std::string& name = "",
                 std::string* message = nullptr,
                 int timeout_ms = 3000);

4. Field Description

  • name: Motion name; obtain the list of names from getMotionState().
  • message: Optional output parameter that returns the server-side text.
  • timeout_ms: RPC timeout, default 3000 ms.

5. Return Value

Returns true when the server successfully starts the motion; returns false when the motion is unsupported, the motion does not exist, the request times out, or any other failure occurs.

6. Prerequisites

  • The runtime is running, and the robot's pose and environment satisfy the conditions for executing the motion.
  • getMotionState() succeeds and supported=true.
  • If a name is specified, that name exists in available_motion_names.
  • Do not send external joint commands that conflict with the motion while it is playing.

7. C++ Example

leju::vr::MotionState state;
if (!vr.getMotionState(state) ||
    !state.supported ||
    state.available_motion_names.empty()) {
  return 1;
}

const std::string name = state.available_motion_names.front();
std::string message;
if (!vr.startMotion(name, &message, 3000)) {
  std::cerr << message << '\n';
  return 2;
}

8. Corresponding Repository Examples

The current SDK examples directory does not provide a standalone startMotion() client program. The actual control routing in the repository is:

  • src/leju-controllers/leju-rl-controller/src/controllers/controller_manager.cpp
  • src/leju-controllers/leju-rl-controller/src/controllers/generic_rl_controller.cpp

Playing Tact Actions

1. Function Description

playTact() plays .tact actions through the TactPlayer DDS-RPC. This channel is independent of the CSV motion interface in startMotion().

2. SDK and Header File

  • SDK: lejusdk-vr
  • Header: <lejusdk-vr/lejusdk_vr.h>

3. Request or Message Type

bool playTact(const std::string& name = "",
              std::string* message = nullptr,
              int timeout_ms = 3000);

4. Field Description

  • name: tact action name, without the .tact suffix.
  • message: Optional text returned by the server.
  • timeout_ms: RPC timeout, default 3000 ms.

5. Return Value

Returns true when the server successfully accepts and starts the tact; returns false on failure. The detailed reason is returned through message.

6. Prerequisites

  • RobanVRAPI is initialized, and the TactPlayer service has started.
  • The tact resource already exists in the resource directory of the current deployment, and the actual action name is passed without the suffix.
  • The robot is in a safe state that permits playing this action.

7. C++ Example

std::string message;
const std::string tact_name = "<已部署的动作名>";
if (!vr.playTact(tact_name, &message, 5000)) {
  std::cerr << message << '\n';
  return 1;
}

8. Corresponding Repository Examples

  • Source: src/lejusdk/examples/src/lejusdk-vr/09_play_tact.cpp
  • Compiled program: vr_09_play_tact

The repository example uses KuavoVRAPI to demonstrate the generic RPC flow; secondary development on Roban2 should use RobanVRAPI.

Tact Command Subscription

1. Function Description

subscribeTactCommand() subscribes to tact action names sent over a Topic from the NX bridge. This interface is intended for advanced scenarios where you need to implement the tact command consumer side; for ordinary client-side playback, use playTact().

2. SDK and Header File

  • SDK: lejusdk-vr
  • Header: <lejusdk-vr/lejusdk_vr.h>

3. Request or Message Type

using TactCmdCallback = std::function<void(const std::string&)>;
void subscribeTactCommand(leju::vr::TactCmdCallback callback);

4. Field Description

The callback parameter is an action name string without the .tact suffix.

5. Return Value

The subscription method has no return value.

6. Prerequisites

  • RobanVRAPI is initialized.
  • The caller is the command consumer and has implemented its own resource checks, playback serialization, and safe-state determination.

7. C++ Example

vr.subscribeTactCommand([](const std::string& name) {
  std::cout << "received tact command: " << name << '\n';
});

8. Corresponding Repository Examples

Currently, src/lejusdk/examples/ contains no standalone subscription example. The public declarations are located in:

  • installed/include/lejusdk-vr/vr_api/vr_base.h
  • installed/include/lejusdk-vr/data_types.h

Local Audio File Playback

1. Function Description

play_audio_cli requests that audio_player_node play a local audio file through the AudioPlayerService DDS-RPC. It is a command-line tool bundled in installed/bin, not a public C++ SDK class.

2. SDK and Header File

  • Bundled program: installed/bin/play_audio_cli
  • Server: installed/bin/audio_player_node
  • Public C++ SDK headers: none

3. Request or Message Type

play_audio_cli <file_name> [volume]

Internally, the tool sends the AudioPlayerService PlayAudioRequest and waits for the PlayAudioReply. Because the current development package does not expose this RPC type as a public SDK header, this secondary-development documentation does not fabricate direct RPC code.

4. Field Description

ParameterDescription
file_nameA bare filename is resolved relative to AUDIO_FILE_DIR of audio_player_node; an absolute path on the actual robot may also be used
volumeVolume percentage, optional, default 100

The default value of AUDIO_FILE_DIR is ~/.config/lejuconfig/music.

5. Return Value

Command-line exit codes:

  • 0: The server reported successful playback.
  • 1: The service is unavailable, the request timed out, an RPC error occurred, or the server returned a failure.
  • 2: file_name was not provided; the arguments are incomplete.

The terminal also prints [OK] / [FAIL] along with the server message.

6. Prerequisites

  • ROBOT_VERSION=17 has been set and installed/setup.bash has been sourced.
  • audio_player_node is running; launch_real.sh starts it as an optional node, and the node may exit when no usable playback device is available.
  • The playback node can access the audio file, and the system has a working speaker and decoding environment.

7. C++ Example

The current development package does not expose public C++ SDK headers for AudioPlayerService, so this section does not provide fabricated C++ calls. Use the bundled tool:

play_audio_cli demo.wav
play_audio_cli demo.wav 50

Here, demo.wav is an illustrative filename and must be replaced with an actually deployed file.

8. Corresponding Repository Examples

  • Command-line client: installed/bin/play_audio_cli
  • Playback service node: installed/bin/audio_player_node
  • On-robot launch orchestration: src/leju_launch/scripts/launch_real.sh

The current development package does not provide a public text-to-speech (TTS) SDK, and this page does not carry over the legacy RobotAudio or speech synthesis interfaces.