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 File | Class Name | Description |
|---|---|---|
torso_factory.h | TorsoFactory | A factory class for creating torso instances of different types. |
torso_interface.h | TorsoInterface | The base interface class defining common APIs for torso control. All vendor-specific drivers should inherit from this class. |
Create a Torso Instance
Section titled “Create a Torso Instance”There are two ways to create a torso instance.
-
Create a torso instance by torso parameters.
-
Method:
static std::shared_ptr<TorsoInterface<PoseType>> create_torso(const TorsoFactoryParam& param) -
Parameter:
ParameterTypeDescription paramInput Parameters related to the torso. For details, please refer to TorsoFactoryParam. -
Return Value:
Returns a shared pointer to an object of a class derived from
TorsoInterfaceif the instance is created successfully; otherwise, returnsnullptr.PoseTypeis a placeholder type name that is specified when theTorsoFactoryclass is instantiated.
-
-
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:
Parameter Type Description config_pathInput
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
TorsoInterfaceif the instance is created successfully; otherwise, returnsnullptr.PoseTypeis a placeholder type name that is specified when theTorsoFactoryclass is instantiated.
-
Connect to the Torso
Section titled “Connect to the Torso”-
Method:
AbcErrorCode connect() -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Disconnect from the Torso
Section titled “Disconnect from the Torso”-
Method:
AbcErrorCode disconnect() -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Control Torso Trajectories
Section titled “Control Torso Trajectories”Joint Motion
Section titled “Joint Motion”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:
ParameterTypeDescription jointsInput Target joint positions, in degrees. For details, please refer to AbcType. vInput Percentage of the maximum joint linear velocity and acceleration used for planning. Valid range: 0–100. blockInput Blocking 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::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Cartesian Linear Motion
Section titled “Cartesian Linear Motion”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:
ParameterTypeDescription poseInput Target pose. PoseTypeis a placeholder type name, matching the type specified when theTorsoInterfaceclass is instantiated.vInput Percentage of the maximum joint linear velocity and acceleration used for planning. Valid range: 0–100. blockInput Blocking 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::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Move to Target Pose in Joint Space
Section titled “Move to Target Pose in Joint Space”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:
ParameterTypeDescription poseInput Target pose. PoseTypeis a placeholder type name, matching the type specified when theTorsoInterfaceclass is instantiated.vInput Percentage of the maximum joint angular velocity and joint angular acceleration used for planning. Valid range: 0–100. blockInput Blocking 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::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Angle Pass-through
Section titled “Angle Pass-through”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:
ParameterTypeDescription jointsInput Target joint positions, in degrees. For details, please refer to AbcType. -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Get Current Joint Angles
Section titled “Get Current Joint Angles”-
Method:
AbcErrorCode get_joint_degree(std::vector<AbcType>& joints) -
Parameter:
ParameterTypeDescription jointsOutput Current joint angles. For details, please refer to AbcType. -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Get Error Information
Section titled “Get Error Information”-
Method:
AbcErrorCode get_error_flag(std::vector<int32_t>& error_flag) -
Parameter:
ParameterTypeDescription error_flagOutput Error codes. -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Algorithms
Section titled “Algorithms”Compute Forward Kinematics
Section titled “Compute Forward Kinematics”-
Method:
AbcErrorCode forward_kinematics(const std::vector<AbcType>& joints,PoseType& pose) -
Parameters:
ParameterTypeDescription jointsInput Joint angles. For details, please refer to AbcType. poseOutput Pose computed by forward kinematics. PoseTypeis a placeholder type name, matching the type specified when theTorsoInterfaceclass is instantiated. -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Compute Inverse Kinematics
Section titled “Compute Inverse Kinematics”-
Method:
AbcErrorCode inverse_kinematics(const PoseType& pose,const std::vector<AbcType>& ref_joints,std::vector<AbcType>& joints,int mode = 0) -
Parameters:
ParameterTypeDescription poseInput The target pose. PoseTypeis a placeholder type name, matching the type specified when theTorsoInterfaceclass is instantiated.ref_jointsInput Reference joint angles. jointsOutput Joint 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::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Register Torso State Callback Function
Section titled “Register Torso State Callback Function”-
Method:
void set_torso_state_callback(AbcTorsoStateCallback realtime_callback) -
Parameter:
ParameterTypeDescription realtime_callbackInput AbcTorsoStateCallbackis 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).
Get Torso Name
Section titled “Get Torso Name”-
Method:
std::string get_name() const -
Return Value:
The name of the torso instance.