Head APIs
HeadFactory
Section titled “HeadFactory”The HeadFactory class provides the following method for creating a head instance.
-
Method:
create_head_from_config(config_path: str) -> HeadInterface -
Parameter:
Parameter Description config_pathPath to the configuration file. The configuration file must be a JSON file.
{"head_type":"ti5", # Head vendor"head_name":"ti5_head", # Head name"head_joint_num":2, # Number of head joints"can_device":"can0", # CAN device name"can_id":0, # CAN node ID (0x00~0xFF)"motor_params":[ # Motor parameters{"motor_id":5, # Motor ID"reduction_ratio":51, # Reduction ratio"position_max":90, # Maximum rotation angle"position_min":-90.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:
An HeadInterface instance if creation succeeds, otherwise
None.
HeadInterface
Section titled “HeadInterface”The HeadInterface class provides a series of public methods for controlling the head, such as obtaining head joint angles and controlling head trajectories. Ensure a head instance has been created before using these methods.
Connect to the Head
Section titled “Connect to the Head”After creating a head instance, you can establish a connection to the head using the following method.
-
Method:
connect(self) -> alphabot.core.AbcErrorCode -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Disconnect from the Head
Section titled “Disconnect from the Head”You can disconnect from the head using the following method.
-
Method:
disconnect(self) -> alphabot.core.AbcErrorCode -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Joint Motion
Section titled “Joint Motion”In joint space, a motion trajectory is planned to drive each joint of the head to the specified target joint positions.
-
Method:
move_joint_position(self,joints: list[float],v: int,block: bool) -> alphabot.core.AbcErrorCode -
Parameters:
ParameterDescription jointsTarget joint positions, in degrees. vPercentage of the maximum joint linear velocity and acceleration used for planning. Valid range: 0-100. blockBlocking mode flag. Accepts FalseorTrue.
-False: Non-blocking mode. The method returns immediately after successfully sending the motion command to the controller.
-True: Blocking mode. The method waits until the head 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 head via CAN FD (Controller Area Network Flexible Data-rate), bypassing trajectory planning by the controller. If the method is called correctly, the head executes the motion immediately.
-
Method:
move_joint_position_canfd(self, joints: list[float]) -> alphabot.core.AbcErrorCode -
Parameter:
ParameterDescription jointsTarget joint positions, in degrees. -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Get Current Joint Angles
Section titled “Get Current Joint Angles”-
Method:
get_joint_degree(self) -> tuple[alphabot.core.AbcErrorCode, list[float]] -
Return Value:
A tuple containing two elements.
Element Type Description AbcErrorCodeAbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.list[float]Current joint angles.
Get Error Information
Section titled “Get Error Information”-
Method:
get_error_flag(self) -> tuple[alphabot.core.AbcErrorCode, list[int]] -
Return Value:
A tuple containing two elements.
Element Type Description AbcErrorCodeAbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.list[int]Error codes.
Compute Forward Kinematics
Section titled “Compute Forward Kinematics”-
Method:
forward_kinematics(self,joints: list[float]) -> tuple[alphabot.core.AbcErrorCode, alphabot.core.Pose] -
Parameter:
ParameterDescription jointsJoint angles. -
Return Value:
A tuple containing two elements.
Element Type Description AbcErrorCodeAbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.PosePose computed by forward kinematics. For details, please refer to Pose.
Get Head Name
Section titled “Get Head Name”-
Method:
get_name(self) -> str -
Return Value:
The name of the head instance.
AbcHeadState
Section titled “AbcHeadState”| Attribute | Data Type | Description |
|---|---|---|
err_code | list[int] | Error codes for each joint |
joints_current | list[float] | Current for each joint |
joints_positions | list[float] | Angle for each joint |
joints_speed | list[float] | Speed for each joint |
timestamp | typing.Any | Timestamp |