跳转到内容

底盘相关接口

ChassisFactory 类用于创建底盘实例。

  • 方法原型:

    create_chassis_from_config(config_file: str) -> ChassisInterface
  • 参数说明:

    参数名称说明
    config_path

    配置文件路径。配置文件为 JSON 文件,包含以下键值对。

    {
    "chassis_type":"xxx", # 底盘厂商
    "chassis_name":"chassis", # 底盘名称
    "ip":"127.0.0.1", # IP 地址
    "port":51051 # 端口号
    }
  • 返回值:

    若创建成功,则返回 ChassisInterface 实例;否则返回 None

ChassisFactoryParam 类用于描述创建底盘时所需的参数。

属性数据类型说明
chassis_typestr底盘厂商。
chassis_namestr底盘名称,例如 "chassis"
ipstrIP 地址,例如 "127.0.0.1"
portint端口号,例如 54051

ChassisInterface 类提供了一系列用于控制底盘的公共方法,例如移动底盘、获取轮廓和查询状态等。在使用前,请确保已创建底盘实例。

在创建底盘实例后,用户可通过如下方法与底盘建立连接。

  • 方法原型:

    connect(self) -> alphabot.core.AbcErrorCode
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

用户可通过如下方法断开与底盘的连接。

  • 方法原型:

    disconnect(self) -> alphabot.core.AbcErrorCode
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    get_pose_speed(self) -> tuple[alphabot.core.AbcErrorCode, ChassisPoseSpeed]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    ChassisPoseSpeed底盘位置和速度,具体参见 ChassisPoseSpeed
  • 方法原型:

    get_pose(self) -> tuple[alphabot.core.AbcErrorCode, ChassisPose2D]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    ChassisPose2D底盘位置,具体参见 ChassisPose2D
  • 方法原型:

    get_speed(self) -> tuple[alphabot.core.AbcErrorCode, ChassisTwist]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    ChassisTwist底盘速度,具体参见 ChassisTwist
  • 方法原型:

    get_mileage(self) -> tuple[alphabot.core.AbcErrorCode, int]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    int底盘里程数。
  • 方法原型:

    get_battery(self) -> tuple[alphabot.core.AbcErrorCode, ChassisBattery]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    ChassisBattery底盘电池相关的信息,具体参见 ChassisBattery
  • 方法原型:

    get_robot_state(self) -> tuple[alphabot.core.AbcErrorCode, ChassisState]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    ChassisState底盘状态相关的信息,具体参见 ChassisState
  • 方法原型:

    get_status_code(self) -> tuple[alphabot.core.AbcErrorCode, ChassisStatusCode]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    ChassisStatusCode底盘相关的状态码,具体参见 ChassisStatusCode
  • 方法原型:

    get_hardware_state(self) -> tuple[alphabot.core.AbcErrorCode, ChassisHardwareState]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    ChassisHardwareState底盘硬件相关的状态信息,具体参见 ChassisHardwareState
  • 方法原型:

    get_static_tf(self) -> tuple[alphabot.core.AbcErrorCode, list[ChassisTransformStamped]]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    list[ChassisTransformStamped]底盘静态变换,具体参见 ChassisTransformStamped
  • 方法原型:

    twist_control(self, linear: float, angular: float) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    linear线速度
    angular角速度
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    set_max_speed(self, max_spd: float) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    max_spd设置的最大速度
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    init_robot(self, pose: ChassisPose2D, update_flg: int) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    pose底盘位置,具体参见 ChassisPose2D
    update_flg是否更新位置。
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    move_to_point_sync(
    self,
    x: float,
    y: float,
    theta: float,
    callback: typing.Callable,
    max_spd: float = 1.0
    ) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    x目标位置的 X 轴坐标值
    y目标位置的 Y 轴坐标值
    theta目标位置的朝向
    callback回调函数
    max_spd最大速度
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    to_charge_sync(self, max_spd: float = 1.0) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    max_spd最大速度
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    exit_charge_sync(self, max_spd: float = 1.0) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    max_spd最大速度
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    move_straight_sync(
    self,
    distance: float,
    speed: float,
    callback: typing.Callable,
    use_avoid: bool = True
    ) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    distance移动距离
    speed移动速度
    callback回调函数
    use_avoid是否启用避障
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    move_rotate_sync(
    self,
    angle: float,
    speed: float,
    callback: typing.Callable,
    use_avoid: bool = True
    ) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    angle旋转角度
    speed旋转速度
    callback回调函数
    use_avoid是否启用避障
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    get_local_footprint(self) -> tuple[alphabot.core.AbcErrorCode, list[ChassisPoint32]]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    list[ChassisPoint32]轮廓点,具体参见 ChassisPoint32
  • 方法原型:

    get_global_footprint(self) -> tuple[alphabot.core.AbcErrorCode, list[ChassisPoint32]]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    list[ChassisPoint32]轮廓点,具体参见 ChassisPoint32
  • 方法原型:

    get_all_footprint(self) -> tuple[alphabot.core.AbcErrorCode, tuple[list[ChassisPoint32], list[ChassisPoint32]]]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    tuple[list[ChassisPoint32], list[ChassisPoint32]]第一个元素为局部轮廓,第二个元素为全局轮廓。轮廓点相关的数据结构,请参见 ChassisPoint32
Section titled “获取静态轮廓(基于 odom 和 base_link 坐标系)”
  • 方法原型:

    ai2_get_local_footprint(self) -> tuple[alphabot.core.AbcErrorCode, list[ChassisPoint32]]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    list[ChassisPoint32]轮廓点,具体参见 ChassisPoint32
Section titled “获取静态轮廓(基于 map 和 base_link 坐标系)”
  • 方法原型:

    ai2_get_global_footprint(self) -> tuple[alphabot.core.AbcErrorCode, list[ChassisPoint32]]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    list[ChassisPoint32]轮廓点,具体参见 ChassisPoint32
  • 方法原型:

    ai2_get_all_footprint(self) -> tuple[alphabot.core.AbcErrorCode, tuple[list[ChassisPoint32], list[ChassisPoint32]]]
  • 返回值:

    包含两个元素的元组。

    元素数据类型说明
    AbcErrorCodeAbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode
    tuple[list[ChassisPoint32], list[ChassisPoint32]]第一个元素为基于 odom 和 base_link 坐标系解算的轮廓,第二个元素为基于 map 和 base_link 坐标系解算的轮廓。

    轮廓点相关的数据结构,请参见 ChassisPoint32
  • 方法原型:

    set_local_footprint(self, points: list[ChassisPoint32]) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    points轮廓点,具体参见 ChassisPoint32
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    set_global_footprint(self, points: list[ChassisPoint32]) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    points轮廓点,具体参见 ChassisPoint32
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    set_all_footprint(
    self,
    local_points: list[ChassisPoint32],
    global_points: list[ChassisPoint32]
    ) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    local_points局部轮廓点,具体参见 ChassisPoint32
    global_points全局轮廓点,具体参见 ChassisPoint32
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    get_name(self) -> str
  • 返回值:

    底盘名称。

属性数据类型说明
map_idint当前地图 ID
mileageint累计里程数
robot_idint底盘 ID
poseChassisPose2D2D 位姿
twistChassisTwist速度

ChassisPose2D 类用于表示底盘 2D 位姿。

属性数据类型说明
thetafloat朝向
xfloatX 轴坐标值
yfloatY 轴坐标值

ChassisPoint32 类用于表示轮廓点的位置。

属性数据类型说明
xfloatX 轴坐标值
yfloatY 轴坐标值
zfloatZ 轴坐标值

ChassisTwist 类用于表示底盘速度。

属性数据类型说明
angularfloat角速度
linearfloat线速度
属性数据类型说明
charge_stateChargeState充电状态
robot_idint底盘 ID
powerint电量百分比,取值范围为 0~100。
- 100:全满。
- 0:无电量。
healthint电池健康(充满容量/设计容量)
charge_cycleint循环次数
battery_cycleint电池寿命
temp_maxint电池温度(最高温度)
successbool请求是否成功。
- True:成功响应请求。
- False:未成功处理请求。
msgstr应答消息描述,通常用于请求未能处理时的原因描述。

ChargeState 类是一个表示底盘电池充电状态的枚举器。

常量成员说明
UNDEFINED0未定义
NOT1未充电
MANUAL2手动充电中
AUTO3自动充电中
属性数据类型说明
robot_idint底盘 ID
stateChassisStateType底盘自动模式状态
successbool请求是否成功。
- True:成功响应请求。
- False:未成功处理请求。
msgstr应答消息描述,通常用于请求未能处理时的原因描述。

ChassisStateType 类是一个表示底盘状态的枚举器。

常量成员说明
UNDEFINED0未定义
UNINIT1未初始化
IDLE2空闲
PARKING3泊车中
TASK4任务中
WARNING5警告
FAULT6异常
FOLLOWING7跟随中
CHARGING8充电中
MAPPING9构图中
属性数据类型说明
robot_idint底盘 ID
codeint状态码
timeint时间
status_msgstr描述
robot_task_idint任务 ID
stateStatusCodeRobotState自动模式状态
typeActionType动作类型
levelStatusLevel等级
successbool请求是否成功。
- True:成功响应请求。
- False:未成功处理请求。
msgstr应答消息描述,通常用于请求未能处理时的原因描述。
常量成员说明
UNDEFINED0未定义
UNINIT1未初始化
IDLE2空闲
PARKING3泊车中
TASK4任务中
WARNING5警告
FAULT6异常
FOLLOWING7跟随中
CHARGING8充电中
MAPPING9构图中

ActionType 类是一个表示底盘动作类型的枚举器。

常量成员说明
UNDEFINED0未定义
NAV1导航
STEP_CTRL2单步控制
SECONDPOS_ENTER3二次定位进入
SECONDPOS_QUIT4二次定位退出
CARRY5搬运动作
WAIT6等待
CHARGE7充电
常量成员说明
NORMAL0正常
TIPS1提示
WARN2警告
FAULT3故障
属性数据类型说明
robot_idint底盘 ID
lidarslist[HardwareStateType]repeated 激光雷达 2
cameraslist[HardwareStateType]repeated 摄像头 2
successbool请求是否成功。
- True:成功响应请求。
- False:未成功处理请求。
msgstr应答消息描述,通常用于请求未能处理时的原因描述。
常量成员说明
NORMAL0正常
INFO1提示
WARN16警告
FATAL17故障
属性数据类型说明
frame_idstr父坐标系
secsint
nsecsint纳秒
child_frame_idstrfloat
t_xfloatXYZ 坐标值
t_yfloat
t_zfloat
r_xfloat四元数
r_yfloat
r_zfloat
r_wfloat
属性数据类型说明
robot_idint底盘 ID
navNavState底盘导航相关位信息
robotRobotBit底盘位信息
successbool请求是否成功。
- True:成功响应请求。
- False:未成功处理请求。
msgstr应答消息描述,通常用于请求未能处理时的原因描述。
常量成员说明
UNDEFINED0未定义
NARROW1狭窄通道
GUIDE2引导到达
INA_LIFT3乘梯中
IMPEDE4阻碍
QR_CODE5二维码
STAGE6分段到达
常量成员说明
UNDEFINED0未定义
TASKABLE1可接任务