Skip to content

Torso APIs

The torso APIs are implemented by the following classes. You can find the corresponding header files in the c++/include/drivers/torso directory to access the complete set of APIs.

Header FileClass NameDescription
torso_factory.hTorsoFactoryA factory class for creating torso instances of different types.
torso_interface.hTorsoInterfaceThe base interface class defining common APIs for torso control. All vendor-specific drivers should inherit from this class.

There are two ways to create a torso instance.

  1. Create a torso instance by torso parameters.

    • Method:

      static std::shared_ptr<TorsoInterface<PoseType>> create_torso(
      const TorsoFactoryParam& param)
    • Parameter:

      Parameter
      Type
      Description
      paramInputParameters related to the torso. For details, please refer to TorsoFactoryParam.
    • Return Value:

      Returns a shared pointer to an object of a class derived from TorsoInterface if the instance is created successfully; otherwise, returns nullptr. PoseType is a placeholder type name that is specified when the TorsoFactory class is instantiated.

  2. Create a torso instance from a configuration file.

    • Method:

      static std::shared_ptr<TorsoInterface<PoseType>> create_torso_from_config(
      const std::string& config_path)
    • Parameter:

      ParameterTypeDescription

      config_path

      Input

      Path to the configuration file. The configuration file must be a JSON file.

      {
      "torso_type": "ti5", // Torso name
      "torso_name": "ti5_torso", // Torso name
      "torso_joint_num": 4, // Number of Torso joints
      "can_device": "can0", // CAN device name
      "can_id": 0, // CAN node ID (0x00~0xFF)
      "motor_params": [ // # Motor parameters
      {
      "motor_id": 1, // Motor ID
      "reduction_ratio": 121,// Reduction ratio
      "position_max": 1.0, // Maximum rotation angle
      "position_min": -68.0, // Minimum rotation angle
      "speed_max": 30, // Maximum rotation speed
      "speed_min": -30, // Minimum rotation speed
      "acc_max": 10, // Maximum rotation acceleration
      "acc_min": -10 // Minimum rotation acceleration
      }
      ]
      }
    • Return Value:

      Returns a shared pointer to an object of a class derived from TorsoInterface if the instance is created successfully; otherwise, returns nullptr. PoseType is a placeholder type name that is specified when the TorsoFactory class is instantiated.

  • Method:

    AbcErrorCode connect()
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    AbcErrorCode disconnect()
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

In joint space, a motion trajectory is planned to drive each joint of the torso to the specified target joint positions.

  • Method:

    AbcErrorCode move_joint_position(
    const std::vector<AbcType>& joints,
    int v,
    int block)
  • Parameters:

    Parameter
    Type
    Description
    jointsInputTarget joint positions, in degrees. For details, please refer to AbcType.
    vInputPercentage of the maximum joint linear velocity and acceleration used for planning. Valid range: 0–100.
    blockInputBlocking mode flag. Accepts 0 or 1.
    - 0: Non-blocking mode. The method returns immediately after successfully sending the motion command to the controller.
    - 1: Blocking mode. The method waits until the torso completes the motion or an error occurs before returning.
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

In Cartesian space, a linear motion trajectory is planned to move the torso along a straight line to the specified target pose.

  • Method:

    AbcErrorCode move_cartesian_linear(
    const PoseType& pose,
    int v,
    int block)
  • Parameters:

    Parameter
    Type
    Description
    poseInputTarget pose. PoseType is a placeholder type name, matching the type specified when the TorsoInterface class is instantiated.
    vInputPercentage of the maximum joint linear velocity and acceleration used for planning. Valid range: 0–100.
    blockInputBlocking mode flag. Accepts 0 or 1.
    - 0: Non-blocking mode. The method returns immediately after successfully sending the motion command to the controller.
    - 1: Blocking mode. The method waits until the torso completes the motion or an error occurs before returning.
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

In joint space, a motion trajectory is planned to move the torso to the specified target pose.

  • Method:

    AbcErrorCode move_joint_pose(
    const PoseType& pose,
    int v,
    int block)
  • Parameters:

    Parameter
    Type
    Description
    poseInputTarget pose. PoseType is a placeholder type name, matching the type specified when the TorsoInterface class is instantiated.
    vInputPercentage of the maximum joint angular velocity and joint angular acceleration used for planning. Valid range: 0–100.
    blockInputBlocking mode flag. Accepts 0 or 1.
    - 0: Non-blocking mode. The method returns immediately after successfully sending the motion command to the controller.
    - 1: Blocking mode. The method waits until the torso completes the motion or an error occurs before returning.
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

Joint angles are sent to the torso via CAN FD (Controller Area Network Flexible Data-rate), bypassing trajectory planning by the controller. If the method is called correctly, the torso executes the motion immediately.

  • Method:

    AbcErrorCode move_joint_position_canfd(const std::vector<AbcType>& joints)
  • Parameter:

    Parameter
    Type
    Description
    jointsInputTarget joint positions, in degrees. For details, please refer to AbcType.
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    AbcErrorCode get_joint_degree(std::vector<AbcType>& joints)
  • Parameter:

    Parameter
    Type
    Description
    jointsOutputCurrent joint angles. For details, please refer to AbcType.
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    AbcErrorCode get_error_flag(std::vector<int32_t>& error_flag)
  • Parameter:

    Parameter
    Type
    Description
    error_flagOutputError codes.
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    AbcErrorCode forward_kinematics(
    const std::vector<AbcType>& joints,
    PoseType& pose)
  • Parameters:

    Parameter
    Type
    Description
    jointsInputJoint angles. For details, please refer to AbcType.
    poseOutputPose computed by forward kinematics. PoseType is a placeholder type name, matching the type specified when the TorsoInterface class is instantiated.
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    AbcErrorCode inverse_kinematics(
    const PoseType& pose,
    const std::vector<AbcType>& ref_joints,
    std::vector<AbcType>& joints,
    int mode = 0)
  • Parameters:

    Parameter
    Type
    Description
    poseInputThe target pose. PoseType is a placeholder type name, matching the type specified when the TorsoInterface class is instantiated.
    ref_jointsInputReference joint angles.
    jointsOutputJoint angles computed by inverse kinematics. For details, please refer to AbcType.
    modeInput (optional)Solution mode. Accepts 0 or 1. Default is 0.
    - 0: Single-step solution.
    - 1: Iterative search solution.
  • Return Value:

    AbcErrorCode::SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    void set_torso_state_callback(AbcTorsoStateCallback realtime_callback)
  • Parameter:

    Parameter
    Type
    Description
    realtime_callbackInputAbcTorsoStateCallback is a function pointer type. For details, please refer to AbcTorsoStateCallback. The callback function is called whenever a torso state update is received.
  • Return Value:

    None (void).

  • Method:

    std::string get_name() const
  • Return Value:

    The name of the torso instance.