跳转到内容

底盘相关接口

底盘相关的接口由如下两个类实现。您可以在 c++\include\drivers\chassis 目录下找到对应的头文件以获取完整 API。

头文件类名说明
chassis_factory.hChassisFactory底盘工厂类,用于创建不同类型的底盘实例。
chassis_interface.hChassisInterface底盘接口基类,定义了底盘控制的通用接口。所有特定厂商的底盘驱动都应该继承此类。

ChassisFactory 类提供了两种方式创建底盘实例,具体如下。

  1. 根据底盘参数,创建底盘实例。

    • 方法原型:

      static std::shared_ptr<ChassisInterface> create_chassis_from_config(
      const std::string& config_path)
    • 参数说明:

      参数名类型说明
      config_path输入参数底盘相关参数,具体参见 ChassisFactoryParam
    • 返回值:

      若创建成功,则返回 ChassisInterface 类型的共享智能指针;否则返回 nullptr

  2. 根据配置文件,创建底盘实例。

    • 方法原型:

      static std::shared_ptr<ChassisInterface> create_chassis_from_config(
      const std::string& config_path)
    • 参数说明:

      参数名称类型说明

      config_path

      输入参数

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

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

      若创建成功,则返回 ChassisInterface 类型的共享智能指针;否则返回 nullptr

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

  • 方法原型:

    AbcErrorCode connect()
  • 返回值:

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

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

  • 方法原型:

    AbcErrorCode disconnect()
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_pose_speed(alphabot::ChassisPoseSpeed& pose_spd)
  • 参数说明:

    参数名称
    类型
    说明
    pose_spd输出参数底盘位置和速度。其内部数据结构,请参见 ChassisPoseSpeed
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_pose(alphabot::ChassisPose2D& pose)
  • 参数说明:

    参数名称
    类型
    说明
    pose输出参数底盘位置。其内部数据结构,请参见 ChassisPose2D
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_speed(alphabot::ChassisTwist& spd)
  • 参数说明:

    参数名称
    类型
    说明
    spd输出参数底盘速度。其内部数据结构,请参见 ChassisTwist
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_mileage(uint32_t& mileage)
  • 参数说明:

    参数名称
    类型
    说明
    mileage输出参数累计里程数
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_battery(alphabot::ChassisBattery& battery)
  • 参数说明:

    参数名称
    类型
    说明
    battery输出参数电池信息。其内部数据结构,请参见 ChassisBattery
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_robot_state(alphabot::ChassisState& robot_state)
  • 参数说明:

    参数名称
    类型
    说明
    robot_state输出参数底盘状态相关的信息。其内部数据结构,请参见 ChassisState
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_status_code(alphabot::ChassisStatusCode& status_code)
  • 参数说明:

    参数名称
    类型
    说明
    status_state输出参数底盘相关的状态码。其内部数据结构,请参见 ChassisStatusCode
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_hardware_state(alphabot::ChassisHardwareState& hardware_state)
  • 参数说明:

    参数名称
    类型
    说明
    hardware_state输出参数底盘硬件相关的状态信息。其内部数据结构,请参见 ChassisHardwareState
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_static_tf(std::vector<alphabot::ChassisTransformStamped>& transforms)
  • 参数说明:

    参数名称
    类型
    说明
    transforms输出参数底盘静态变换。其内部数据结构,请参见 ChassisTransformStamped
  • 返回值:

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

  • 方法原型:

    AbcErrorCode twist_control(float linear, float angular)
  • 参数说明:

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

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

  • 方法原型:

    AbcErrorCode set_max_speed(float max_spd)
  • 参数说明:

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

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

  • 方法原型:

    AbcErrorCode init_robot(alphabot::ChassisPose2D pose, uint8_t update_flg)
  • 参数说明:

    参数名称
    类型
    说明
    pose输入参数底盘位置。其内部数据结构,请参见 ChassisPose2D
    update_flg输入参数是否更新位置。
  • 返回值:

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

  • 方法原型:

    AbcErrorCode move_to_point_sync(
    float x,
    float y,
    float theta,
    std::function<void(alphabot::ChassisTaskResponse)> func_callback,
    float max_spd = 1.0)
  • 参数说明:

    参数名称
    类型
    说明
    x输入参数目标位置的 X 轴坐标值。
    y输入参数目标位置的 Y 轴坐标值。
    theta输入参数目标位置的朝向。
    func_callback输入参数回调函数。函数参数类型,请参见 ChassisTaskResponse
    max_spd输入参数(可缺省)最大速度。
  • 返回值:

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

  • 方法原型:

    AbcErrorCode to_charge_sync(float max_spd = 1.0)
  • 参数说明:

    参数名称
    类型
    说明
    max_spd输入参数(可缺省)最大速度
  • 返回值:

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

  • 方法原型:

    AbcErrorCode exit_charge_sync(float max_spd = 1.0)
  • 参数说明:

    参数名称
    类型
    说明
    max_spd输入参数(可缺省)最大速度
  • 返回值:

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

  • 方法原型:
AbcErrorCode move_straight_sync(
float distance,
float speed,
std::function<void(alphabot::ChassisTaskResponse)> func_callback,
bool use_avoid = true)
  • 参数说明:

    参数名称
    类型
    说明
    distance输入参数移动距离。
    speed输入参数移动速度。
    func_callback输入参数回调函数。函数参数类型,请参见 ChassisTaskResponse
    use_avoid输入参数(可缺省)是否启用避障。
  • 返回值:

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

  • 方法原型:

    AbcErrorCode move_rotate_sync(
    float angle,
    float speed,
    std::function<void(alphabot::ChassisTaskResponse)> func_callback,
    bool use_avoid = true)
  • 参数说明:

    参数名称
    类型
    说明
    angle输入参数旋转角度。
    speed输入参数旋转速度。
    func_callback输入参数回调函数。函数参数类型,请参见 ChassisTaskResponse
    use_avoid输入参数(可缺省)是否启用避障。
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_local_footprint(std::vector<alphabot::ChassisPoint32>& points)
  • 参数说明:

    参数名称
    类型
    说明
    points输出参数轮廓点。其内部数据结构,请参见 ChassisPoint32
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_global_footprint(std::vector<alphabot::ChassisPoint32>& points)
  • 参数说明:

    参数名称
    类型
    说明
    points输出参数轮廓点。其内部数据结构,请参见 ChassisPoint32
  • 返回值:

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

  • 方法原型:

    AbcErrorCode get_all_footprint(
    std::vector<alphabot::ChassisPoint32>& local_points,
    std::vector<alphabot::ChassisPoint32>& global_points)
  • 参数说明:

    参数名称
    类型
    说明
    local_points输出参数局部轮廓点。其内部数据结构,请参见 ChassisPoint32
    global_points输出参数全局轮廓点。其内部数据结构,请参见 ChassisPoint32
  • 返回值:

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

获取静态轮廓(基于odom和base_link坐标系)

Section titled “获取静态轮廓(基于odom和base_link坐标系)”
  • 方法原型:

    AbcErrorCode ai2_get_local_footprint(std::vector<alphabot::ChassisPoint32>& points)
  • 参数说明:

    参数名称
    类型
    说明
    points输出参数轮廓点。其内部数据结构,请参见 ChassisPoint32
  • 返回值:

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

获取静态轮廓(基于map和base_link坐标系)

Section titled “获取静态轮廓(基于map和base_link坐标系)”
  • 方法原型:

    AbcErrorCode ai2_get_global_footprint(std::vector<alphabot::ChassisPoint32>& points)
  • 参数说明:

    参数名称
    类型
    说明
    points输出参数轮廓点。其内部数据结构,请参见 ChassisPoint32
  • 返回值:

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

  • 方法原型:

    AbcErrorCode ai2_get_all_footprint(
    std::vector<alphabot::ChassisPoint32>& local_points,
    std::vector<alphabot::ChassisPoint32>& global_points)
  • 参数说明:

    参数名称
    类型
    说明
    local_points输出参数轮廓点(基于 odom 和 base_link 坐标系解算)。其内部数据结构,请参见 ChassisPoint32
    global_points输出参数轮廓点(基于 map 和 base_link 坐标系解算)。其内部数据结构,请参见 ChassisPoint32
  • 返回值:

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

  • 方法原型:

    AbcErrorCode set_local_footprint(const std::vector<alphabot::ChassisPoint32>& points)
  • 参数说明:

    参数名称
    类型
    说明
    points输入参数轮廓点。其内部数据结构,请参见 ChassisPoint32
  • 返回值:

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

  • 方法原型:

    AbcErrorCode set_global_footprint(const std::vector<alphabot::ChassisPoint32>& points)
  • 参数说明:

    参数名称
    类型
    说明
    points输入参数轮廓点。其内部数据结构,请参见 ChassisPoint32
  • 返回值:

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

  • 方法原型:

    AbcErrorCode set_all_footprint(
    const std::vector<alphabot::ChassisPoint32>& local_points,
    const std::vector<alphabot::ChassisPoint32>& global_points)
  • 参数说明:

    参数名称
    类型
    说明
    local_points输入参数局部轮廓点。其内部数据结构,请参见 ChassisPoint32
    global_points输入参数全局轮廓点。其内部数据结构,请参见 ChassisPoint32
  • 返回值:

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

  • 方法原型:

    std::string get_name() const
  • 返回值:

    底盘名称。