Roban2 Docs
Development InterfacesRoban2 C++ SDK Interfaces

Robot Information and Status Interfaces

This page documents the basic information, hardware state, joint state, IMU, standard gamepad, and Quest input interfaces currently available for Roban2.

General Initialization

The subscription interfaces of lejusdk-lowlevel use a global robot instance:

const auto version = leju::RobotVersion::from_env();
if (!leju::GlobalRobot::init_env(version)) return 1;
auto& robot = leju::GlobalRobot::getInstance();

GlobalRobot::init_env() is called only once per process. The low-level SDK code snippets below assume that robot has been initialized as described above.

Basic Robot Information

1. Function Description

Queries the robot version, motor count, all joint names, and the arm, waist, head, and leg joint names. When parsing joint arrays later, the name order returned by the SDK should be treated as authoritative.

2. SDK and Header File

  • SDK: lejusdk-lowlevel
  • Header file: <lejusdk-lowlevel/leju_sdk.h>
  • Object: leju::RobotBaseAPI

3. Request or Message Type

uint8_t getMotorNumber() const;
std::vector<std::string> getMotorNames() const;
std::vector<std::string> getArmJointNames() const;
std::vector<std::string> getWaistJointNames() const;
std::vector<std::string> getHeadJointNames() const;
std::vector<std::string> getLegJointNames() const;
const leju::RobotVersion& getRobotVersion() const;

4. Field Description

No request fields. The joint name interfaces return ordered string arrays whose indices correspond to the joint indices in RobotState and RobotCmd.

5. Return Value

  • getMotorNumber(): motor count.
  • get...JointNames(): array of joint names for the corresponding body part.
  • getRobotVersion(): reference to the RobotVersion used by the current instance.

6. Prerequisites

  • ROBOT_VERSION has been set to the actual robot model version; Roban2.2 uses 17.
  • GlobalRobot::init_env() has been called successfully.
  • This query comes from the SDK's model definition and does not require waiting for DDS state messages.

7. C++ Example

#include <iostream>
#include <lejusdk-lowlevel/leju_sdk.h>

int main() {
  const auto version = leju::RobotVersion::from_env();
  if (!leju::GlobalRobot::init_env(version)) return 1;
  auto& robot = leju::GlobalRobot::getInstance();

  std::cout << "motor count: "
            << static_cast<int>(robot.getMotorNumber()) << '\n';
  for (const auto& name : robot.getMotorNames()) {
    std::cout << name << '\n';
  }
  robot.shutdown();
  return 0;
}

8. Corresponding Repository Examples

  • src/lejusdk/examples/src/joint_cmd_publisher.cpp
  • src/lejusdk/examples/src/kuavo_control_example.cpp

Both examples establish the joint order via getMotorNames(); the file names retain the generic historical naming and do not imply that this page uses a Kuavo model.

Hardware State

1. Function Description

subscribeHardwareState() continuously receives low-level hardware stages. Programs that use low-level joint commands should wait for READY_OK before publishing.

2. SDK and Header File

  • SDK: lejusdk-lowlevel
  • Header file: <lejusdk-lowlevel/leju_sdk.h>

3. Request or Message Type

void subscribeHardwareState(const leju::HwStateCallback& callback);
using HwStateCallback =
    std::function<void(const leju::StringDataConstPtr&)>;

4. Field Description

FieldTypeDescription
timestampdoubleTimestamp, in s
datastd::stringHardware state string, including unknown, initializing, ready_ok, error

String2HwState() converts the string to a HardwareState: UNKNOWN, STOPPED, ERROR, INITIALIZING, READY_OK.

5. Return Value

The subscription method has no return value; when a new state arrives, the callback is invoked on the DDS receive thread.

6. Prerequisites

  • The low-level SDK has been initialized, and the robot hardware or simulation node is publishing /rt/hardware/state.
  • Avoid long blocking inside the callback; perform your own synchronization when sharing state across threads.

7. C++ Example

robot.subscribeHardwareState([](const leju::StringDataConstPtr& msg) {
  const auto state = leju::String2HwState(msg->data);
  std::cout << leju::HardwareState2String(state) << '\n';
});

8. Corresponding Repository Examples

  • Source: src/lejusdk/examples/src/hw_state_subscriber.cpp
  • Compiled program: hw_state_subscriber

Joint State

1. Function Description

subscribeRobotState() subscribes to robot joint positions, velocities, accelerations, and torques.

2. SDK and Header File

  • SDK: lejusdk-lowlevel
  • Header file: <lejusdk-lowlevel/leju_sdk.h>

3. Request or Message Type

void subscribeRobotState(const leju::RobotStateCallback& callback);
using RobotStateCallback =
    std::function<void(const leju::RobotStateConstPtr&)>;

4. Field Description

FieldTypeUnitDescription
qstd::vector<double>radJoint positions
vstd::vector<double>rad/sJoint velocities
vdstd::vector<double>rad/sยฒJoint accelerations
taustd::vector<double>NยทmJoint torques
timestampdoublesTimestamp

The array order matches the joint order returned by getMotorNames(). isValid() can check whether the dimensions of the four arrays are consistent.

5. Return Value

The subscription method has no return value; the callback parameter is a read-only shared pointer.

6. Prerequisites

  • The state publisher is publishing /rt/joint_state.
  • When retaining data outside the callback, copy the required fields or store the shared pointer safely.

7. C++ Example

const auto names = robot.getMotorNames();
robot.subscribeRobotState([names](const leju::RobotStateConstPtr& state) {
  if (state->isValid() && !state->q.empty()) {
    std::cout << names.front() << ": " << state->q.front() << " rad\n";
  }
});

8. Corresponding Repository Examples

  • Source: src/lejusdk/examples/src/joint_state_subscriber.cpp
  • Compiled program: joint_state_subscriber

IMU Data

1. Function Description

subscribeImuData() subscribes to inertial measurement data, including angular velocity, acceleration with gravity, gravity-free acceleration, and attitude quaternion.

2. SDK and Header File

  • SDK: lejusdk-lowlevel
  • Header file: <lejusdk-lowlevel/leju_sdk.h>

3. Request or Message Type

void subscribeImuData(const leju::ImuDataCallback& callback);
using ImuDataCallback =
    std::function<void(const leju::ImuDataConstPtr&)>;

4. Field Description

FieldTypeUnit/Order
gyrostd::array<double, 3>rad/s, [x, y, z]
accstd::array<double, 3>m/sยฒ, includes gravity
free_accstd::array<double, 3>m/sยฒ, gravity removed
quatstd::array<double, 4>Quaternion [w, x, y, z]
timestampdoubles

5. Return Value

The subscription method has no return value; the callback is invoked when new data arrives.

6. Prerequisites

  • The IMU publisher is publishing /rt/imu_state.
  • When computing attitude, parse in [w, x, y, z] order; do not use it as [x, y, z, w].

7. C++ Example

robot.subscribeImuData([](const leju::ImuDataConstPtr& imu) {
  std::cout << "gyro_z=" << imu->gyro[2]
            << ", qw=" << imu->quat[0] << '\n';
});

8. Corresponding Repository Examples

  • Source: src/lejusdk/examples/src/imu_data_subscriber.cpp
  • Compiled program: imu_data_subscriber

Standard Gamepad Data

1. Function Description

subscribeJoyData() subscribes to Xbox- or PlayStation-style gamepads. This interface differs from the Quest controller interface described later.

2. SDK and Header File

  • SDK: lejusdk-lowlevel
  • Header file: <lejusdk-lowlevel/leju_sdk.h>

3. Request or Message Type

void subscribeJoyData(const leju::JoyDataCallback& callback);
using JoyDataCallback = std::function<void(const leju::JoyDataConstPtr&)>;

4. Field Description

  • timestamp: timestamp, in s.
  • axes.left_x, left_y, right_x, right_y: stick axes, range [-1, 1].
  • axes.left_trigger, right_trigger: triggers, range [0, 1].
  • buttons: south, east, west, north, back, guide, start, the left and right stick buttons, shoulder buttons, D-pad, and misc1/misc2; 0 means not pressed, non-zero means pressed.

5. Return Value

The subscription method has no return value; the callback parameter is JoyDataConstPtr.

6. Prerequisites

  • leju-joystick or another driver is publishing /rt/joy.
  • The specific button functions are determined by the current teleop_bindings.yaml; the SDK data types represent raw input only.

7. C++ Example

robot.subscribeJoyData([](const leju::JoyDataConstPtr& joy) {
  std::cout << "left=(" << joy->axes.left_x << ", "
            << joy->axes.left_y << ") start="
            << joy->buttons.start << '\n';
});

8. Corresponding Repository Examples

  • src/leju-joystick/src/leju_joy_autostart_manager.cpp
  • src/leju-controllers/leju-rl-controller/src/runtime/input/teleop/joy_teleop_adapter.cpp

Quest Controller Data

1. Function Description

subscribeQuestJoystickData() subscribes to the stick, trigger, grip, button press, and touch states of the Quest left and right controllers. publishQuestJoystickData() is intended for data sources such as the Quest UDP bridge program; regular applications mainly subscribe.

2. SDK and Header File

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

3. Request or Message Type

void subscribeQuestJoystickData(leju::vr::QuestJoystickDataCallback callback);
bool publishQuestJoystickData(const leju::vr::QuestJoystickData& data);

4. Field Description

FieldTypeDescription
header_sec, header_nanosecint32_t, uint32_tDDS frame timestamp
left_x, left_y, right_x, right_yfloatLeft and right hand stick axes
left_trigger, right_triggerfloatLeft and right hand trigger values
left_grip, right_gripfloatLeft and right hand grip values
left_first_button_pressed, left_second_button_pressedboolLeft hand primary/secondary button pressed state
right_first_button_pressed, right_second_button_pressedboolRight hand primary/secondary button pressed state
*_first_button_touched, *_second_button_touchedboolTouch state of the corresponding buttons

5. Return Value

  • subscribeQuestJoystickData(): no return value.
  • publishQuestJoystickData(): returns true on successful publish, false on failure.

6. Prerequisites

  • RobanVRAPI has been initialized successfully.
  • When subscribing, the Quest bridge program is publishing /rt/quest/joysticks.
  • The binding of buttons to control functions is part of the teleoperation configuration, not fixed semantics of QuestJoystickData.

7. C++ Example

leju::vr::RobanVRAPI vr(leju::RobotVersion::from_env());
if (!vr.initialize()) return 1;

vr.subscribeQuestJoystickData(
    [](const leju::vr::QuestJoystickData& joy) {
      std::cout << "left stick: " << joy.left_x << ", "
                << joy.left_y << "  left grip: "
                << joy.left_grip << '\n';
    });

8. Corresponding Repository Examples

  • Data publishing: src/leju-remote/src/quest_udp_to_dds_node.cpp
  • Data subscription: src/leju-vr-control/src/quest_vr_abs_control_node.cpp
  • Teleoperation adaptation: src/leju-controllers/leju-rl-controller/src/runtime/input/teleop/quest_teleop_adapter.cpp

Quest Bone Pose Data

1. Function Description

subscribeQuestBonePoses() subscribes to the positions and quaternion orientations of Quest bone nodes. publishQuestBonePoses() is used on the Quest data bridge side to publish full-frame data.

2. SDK and Header File

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

3. Request or Message Type

void subscribeQuestBonePoses(leju::vr::QuestBonePosesCallback callback);
bool publishQuestBonePoses(const leju::vr::QuestBonePosesData& data);

4. Field Description

QuestBonePosesData fields:

FieldTypeDescription
header_sec, header_nanosecint32_t, uint32_tDDS frame timestamp
timestamp_msint64_tQuest original millisecond timestamp
is_high_confidenceboolWhether this frame is high-confidence
is_hand_trackingboolWhether the data comes from hand tracking mode
posesstd::vector<Pose>Array of skeleton node poses

Pose contains the position x/y/z and the quaternion qx/qy/qz/qw, all of which are float. The specific node indices are determined by the upstream Quest protocol and the conversion logic in the repository; do not guess them based on the array length.

5. Return Values

  • subscribeQuestBonePoses(): no return value.
  • publishQuestBonePoses(): returns true on successful publish, false on failure.

6. Prerequisites

  • RobanVRAPI has been successfully initialized.
  • The Quest bridge program is publishing /rt/quest/bone_poses.
  • Before using the poses, check is_high_confidence, the length of poses, and the actual node definitions.

7. C++ Example

vr.subscribeQuestBonePoses(
    [](const leju::vr::QuestBonePosesData& frame) {
      if (!frame.is_high_confidence || frame.poses.empty()) return;
      const auto& pose = frame.poses.front();
      std::cout << "first pose: " << pose.x << ", "
                << pose.y << ", " << pose.z << '\n';
    });

8. Corresponding Repository Examples

  • Data publishing: src/leju-remote/src/quest_udp_to_dds_node.cpp
  • Data subscription: src/leju-vr-control/src/quest_vr_abs_control_node.cpp
  • Pose conversion: src/leju-vr-control/src/quest_to_ik_converter.cpp