您好,欢迎访问景行慧动开发者文档中心!
400-827-9680

二次开发的软硬件资源

如何基于景行慧动底盘快速搭建一台机器人

作者:景行慧动时间:2023-04-21

当你拿到一台景行慧动底盘,可以在底盘上加装任何上位机形态,轻松打造自有品牌的机器人。我们提供了一整套接口方案,让您轻松驾驭机器人。

image.png

#连接到机器人

要控制机器人,首先我们必须建立连接。

连接机器人有三种方式:

1、使用 WIFI 连接到机器人并形成本地网络。使用http://192.168.12.1:8000

机器人默认为AP模式,对外提供以sn为名称的WiFi,开发者可以使用上位机连接到该WiFi进行二次开发。(wifi密码为12345678)

image.png

2、机器人设置为station模式,这时机器人可以连接客户提供的WiFi网络,比如办公室的局域网,拿到分配的局域ip,基于http://ip:8000也可以进行二次开发;

在AP模式下,访问http://192.168.12.1:8000/wifi_setup,可以将机器人设置为station模式,同时连接场所内的WiFi.(连续三次按压开关键,可以强制将机器人置为AP模式)

image.png

3、机器人底盘系统提供了标准网口,上位机可以使用网线与底盘连接,上位机可以设置192.168.25.x的网段,底盘可以通过http://192.168.25.25:8000访问进行二次开发;

#验证

假设有一个安全的本地网络,因此我们只有一个简单的基于 HTTP 标头的身份验证。所有 HTTP 请求都必须有一个标头Secret

但为了简单起见,在本教程中,我们不会到处重复。

#第一个请求:查询设备信息

以下命令用于curl发出 HTTP 请求,并使用jq (打开新窗口)格式化输出:

# The secret is hidden. The real one must be requested.curl -H "Secret: XXXXXXXXXXXXXXXXX" http://localhost:8000/device/status | jq
{
  "rosversion": "1.15.11",
  "rosdistro": "noetic",
  "axbot_version": "1.8.8-rc4-pi64",
  "device": {
    "model": "hygeia",
    "sn": "718xxxxxxx",
    "name": "718xxxxxxxx",
    "nickname": "hygeia_1016"
  },
  "baseboard": { "firmware_version": "22a32218" },
  "wheel_control": { "firmware_version": "amps_20211103" },
  "robot": {
    "inscribed_radius": 0.248,
    "height": 1.2,
    "thickness": 0.546,
    "wheel_distance": 0.36,
    "width": 0.496
  },
  "caps": {
    "supportsImuRecalibrateService": true,
    "supportsShutdownService": true,
    "supportsRestartService": true,
    "supportsResetOccupancyGridService": true,
    "supportsImuRecalibrationFeedback": true,
    "supportsSetControlModeService": true,
    "supportsSetEmergencyStopService": true,
    "supportsWheelStateTopic": true,
    "supportsWsV2": true,
    "supportsRgbCamera": true,
    "supportsExternalRgbCamera": true,
    "supportsVisionBasedDetector": true
  },
  "time": "2022/08/02 16:46:58"}

开始行动

要移动机器人,需要两个先决条件:

  1. 必须设置地图

  2. 必须给出初始姿势

#设置地图

可以使用RobotAdmin平台设置机器人所在的地图。

或者使用Map List API,查找并映射 id。并用于POST /chassis/current-map将地图设置为当前地图。

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"map_id": 286}' \
  http://localhost:8000/chassis/current-map
{
  "id": 286,
  "uid": "616cd441e1209813dd4bb25d",
  "map_name": "-1层",
  "create_time": 1647503669,
  "map_version": 6,
  "overlays_version": 8}

#坐标

在 上RobotAdmin,两个箭头(X 轴为红色,Y 轴为蓝色)在地图的原点上交叉。两轴构成正交直角坐标系。

点在地图上的坐标标记为 (x, y),即距原点的距离(以米为单位)。

Apose通常表示为:

{
  "pos": [0.12, 0.85], // position
  "ori": 1.57 // orientation, in radius. The x-positive direction is 0, counter-clockwise}

#设置姿势

要移动机器人,必须给出初始姿势。

作为一种常见的做法,映射从充电器开始。因此机器人(在充电器上)的初始姿势成为地图的原点。

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"position": [0, 0, 0], "ori": 1.57}' \
  http://localhost:8000/chassis/pose
  • position: [0, 0, 0]意思是x=0, y=0, z=0

  • ori: 1.57pi/2,表示机器人的航向为Y正向。

当同时给出地图和初始位姿时,机器人可以看作RobotAdmin

#开始行动

至于现在,用于POST /chassis/moves创建移动动作。

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"type":"standard", "target_x":0.731, "target_y":-1.525, "target_z":0, "creator":"head-unit"}' \
  http://localhost:8000/chassis/moves
{
  "id": 4409,
  "creator": "head-unit",
  "state": "moving",
  "type": "standard",
  "target_x": 0.731,
  "target_y": -1.525,
  "target_z": 0.0,
  "target_ori": null,
  "target_accuracy": null,
  "use_target_zone": null,
  "is_charging": null,
  "charge_retry_count": 0,
  "fail_reason": 0,
  "fail_reason_str": "None - None",
  "fail_message": "",
  "create_time": 1647509573,
  "last_modified_time": 1647509573}

#移动动作状态

用于GET /chassis/moves/:id查看移动操作的状态。

curl http://localhost:8000/chassis/moves/4409
{
  "id": 4409,
  "creator": "head-unit",
  "state": "finished",
  "type": "standard",
  "target_x": 0.7310126134385344,
  "target_y": -1.5250144001960249,
  "target_z": 0.0,
  "target_ori": null,
  "target_accuracy": null,
  "use_target_zone": null,
  "is_charging": null,
  "charge_retry_count": 0,
  "fail_reason": 0,
  "fail_reason_str": "None - None",
  "fail_message": "",
  "create_time": 1647509573,
  "last_modified_time": 1647509573}

state字段显示动作的状态。

当前动作的状态是不断变化的。虽然可以用上面的API查询,但是效率很低。所以我们提供websocketAPI,让机器人不断地反馈它的状态。这比 REST API 的请求/响应形式更有效。


更多控制接口,详见https://autoxingtech.github.io/axbot_rest_book/

热门标签:

上一篇: 景行慧动服务优势

下一篇:

开发者支持

热门信息