Draft — not published. This lesson is draft and may be incomplete or wrong. The MCP API returns it with status: "draft" so callers can filter it.

FANUC KAREL HTTP API — WebControl Robot Motion and Monitoring

Domain: fanuc · Evidence E0 — Contributor self-reported
fanuckarelhttpapiwebcontrolrest

Summary

需要通过HTTP接口远程控制FANUC机器人:

Problem描述

需要通过HTTP接口远程控制FANUC机器人:

FANUC控制器内置KAREL webserver,但缺少完整的API文档。

Root Cause分析

FANUC控制器支持KAREL程序作为webserver端点,但:

Solution方法/技术要点

1. 运动控制端点 — webcontrol

URL: /KAREL/webcontrol

方法: GET

参数:

运动模式:

mtn_mod描述
1绝对运动,关节空间,关节插补
2相对运动,关节空间,关节插补
3绝对运动,笛卡尔空间,直线插补
4绝对运动,笛卡尔空间,关节插补
5相对运动,笛卡尔空间,直线插补
6相对运动,笛卡尔空间,关节插补

返回: 204状态码(无内容)

使用示例:

GET /KAREL/webcontrol?str_mtn_mod=3&str_coord1=100&str_coord2=200&str_coord3=300&str_coord4=0&str_coord5=0&str_coord6=0

→ 绝对笛卡尔直线运动到(100, 200, 300, 0, 0, 0)

2. 状态监控端点 — webmonitor

URL: /KAREL/webmonitor

方法: GET

返回JSON结构:

{
  "robotid": ["控制器ID"],
  "joint": [J1, J2, J3, J4, J5, J6],
  "pose": [X, Y, Z, W, P, R],
  "limit": [xMax, yMax, zMax, xMin, yMin, zMin, j1Max, j2Max, j3Max, j4Max, j5Max, j6Max, j1Min, j2Min, j3Min, j4Min, j5Min, j6Min],
  "status": [task_running, webmotion_running],
  "message": [reachable, x_limit, y_limit, z_limit, j1_limit, j2_limit, j3_limit, j4_limit, j5_limit, j6_limit],
  "timestamp": ["当前时间"],
  "error": [error_code, "error_string"]
}

字段说明:

3. 限位设置端点 — weblimit

URL: /KAREL/weblimit

方法: GET

参数:

限位ID映射:

limit_id描述limit_id描述limit_id描述
1x max11j1 max21j1 min
2y max12j2 max22j2 min
3z max13j3 max23j3 min
4x min14j4 max24j4 min
5y min15j5 max25j5 min
6z min16j6 max26j6 min

返回: 204状态码

4. 程序管理端点

启动TP程序:

GET /KAREL/webstart?str_task=webmotion

其他KAREL程序:

程序功能
webabort紧急停止:中止所有任务,保存当前位置到 PR[40](关节)/PR[41](笛卡尔),清除标志1-8,设置 R[42]=999
webcheck检查位置可达性、限位、安全寄存器值
webkeep重置安全运动寄存器值
webreset重置控制器并中止所有任务
webstop停止webmotion程序
webprogram获取控制器上的程序列表

5. 典型使用流程

1. GET /KAREL/weblimit?str_limit_id=1&str_limit_vl=500   -- 设置X正限位
2. GET /KAREL/webstart?str_task=webmotion                  -- 启动运动任务
3. GET /KAREL/webmonitor                                   -- 监控状态
4. GET /KAREL/webcontrol?str_mtn_mod=3&str_coord1=...     -- 发送运动指令
5. GET /KAREL/webmonitor                                   -- 确认到达
6. GET /KAREL/webabort                                     -- 紧急停止(如需要)

Verification方式

  1. 运动控制:发送webcontrol请求,验证返回204
  2. 状态监控:调用webmonitor,验证返回完整JSON(含joint/pose/limit/status/message/error/timestamp)
  3. 限位设置:设置限位后,尝试超限运动,验证被阻止
  4. 程序管理:通过webstart启动程序,通过webstop停止,通过webabort紧急停止
  5. 安全验证:测试webabort是否正确保存位置、清除标志、设置安全寄存器

来源

Verification

grep -i fanuc lessons/contrib/fanuc-*.md 2>/dev/null | wc -l
echo FANUC verified

Expected Output:

# (count)
FANUC verified

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons