# KAREL（编程语言）

**KAREL**是一种编译型的、类Pascal的编程语言，用于为FANUC工业机器人编写程序。它与示教器（用于编程和点动机器人的手持控制台）语言TP一同运行在FANUC机器人控制器上，除运动之外，它可以访问并控制机器人的各个方面。<sup>[1](https://www.fanucamerica.com/products/software/robot/karel)</sup><sup> • </sup><sup>[2](https://cms.esi.info/Media/documents/FANUC_Softwarehardware_ML.pdf)</sup> FANUC将其描述为面向非常复杂应用的应用程序开发包，提供示教器环境（TPE）所不支持的功能。<sup>[2](https://cms.esi.info/Media/documents/FANUC_Softwarehardware_ML.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 性质 | 用于FANUC机器人控制器的编译型类Pascal高级语言<sup>[1](https://www.fanucamerica.com/products/software/robot/karel)</sup><sup> • </sup><sup>[2](https://cms.esi.info/Media/documents/FANUC_Softwarehardware_ML.pdf)</sup> |
| 运动 | 不能使机器人运动；运动由TP程序完成，KAREL可以派生并协调这些程序<sup>[1](https://www.fanucamerica.com/products/software/robot/karel)</sup><sup> • </sup><sup>[3](https://www.onerobotics.com/fanuc-robot-programming/)</sup> |
| 典型用途 | 文件I/O、套接字消息传递、位置变换、监控、通过表单管理器自定义用户界面，以及复杂的多任务处理<sup>[3](https://www.onerobotics.com/fanuc-robot-programming/)</sup> |
| 文件与编译 | 源文件使用.kl扩展名，编译为.pc文件；系统变量$KAREL_ENB必须设为1，.pc文件才会出现在示教器上<sup>[4](https://www.loullingen.lu/projekte/karel/Introduction%20to%20Fanuc%20Karel%20v2025.01.16%20EN.pdf)</sup> |
| 依赖关系 | FANUC的MQTT选项所必需；TCP/IP套接字消息传递同样用KAREL实现<sup>[1](https://www.fanucamerica.com/products/software/robot/karel)</sup><sup> • </sup><sup>[6](https://www.fanucamerica.com/products/robots/controllers/fanuc-r-50ia-controller)</sup> |

## 与TP并存的分工

FANUC机器人用两种原生语言编程：示教器语言TP和KAREL。从业者反映，日常工作的绝大部分——一位集成商估计约为99%——是用TP编写的，TP负责运动、工作站逻辑和I/O，几十年来基本没有变化。<sup>[3](https://www.onerobotics.com/fanuc-robot-programming/)</sup> 当TP无法完成工作时，才使用KAREL。<sup>[3](https://www.onerobotics.com/fanuc-robot-programming/)</sup>

这种分工源于两种语言各自提供的能力。TP简单、易读，可以完全通过示教器上的菜单编写，但它没有具名变量，只有系统寄存器，且全部是全局的，因此复杂程序难以管理。KAREL提供类型化变量、自定义数据结构（如RECORD类型和数组）、带引用传递参数的例程以及返回值。<sup>[7](https://www.robot-forum.com/robotforum/thread/41966-benefits-of-using-karel-over-teach-pendant-programming/)</sup><sup> • </sup><sup>[8](https://www.xpert-robotics.com/en/blog/fanuc-karel-vs-tp)</sup> 它还能处理文件I/O——在控制器闪存盘上读写CSV、文本或自定义数据文件——以及字符串操作和超出TP寄存器支持范围的浮点运算。<sup>[8](https://www.xpert-robotics.com/en/blog/fanuc-karel-vs-tp)</sup>

一种常见的模式是混合使用：KAREL程序承载复杂的逻辑、通信和数据处理，并调用或派生TP程序来完成实际运动，通过位置寄存器传递位置数据。<sup>[7](https://www.robot-forum.com/robotforum/thread/41966-benefits-of-using-karel-over-teach-pendant-programming/)</sup><sup> • </sup><sup>[4](https://www.loullingen.lu/projekte/karel/Introduction%20to%20Fanuc%20Karel%20v2025.01.16%20EN.pdf)</sup> KAREL还可以读取TP程序状态并等待其完成。<sup>[8](https://www.xpert-robotics.com/en/blog/fanuc-karel-vs-tp)</sup>

## 运动功能及其移除

KAREL不能使机器人运动。情况并非一直如此：早期控制器支持运动功能，但FANUC将其移除，多年来一直在逐步取消KAREL中的运动功能。<sup>[7](https://www.robot-forum.com/robotforum/thread/41966-benefits-of-using-karel-over-teach-pendant-programming/)</sup><sup> • </sup><sup>[3](https://www.onerobotics.com/fanuc-robot-programming/)</sup> 由于KAREL程序通常不执行运动，它们相对容易测试。<sup>[3](https://www.onerobotics.com/fanuc-robot-programming/)</sup>

## 开发流程

KAREL程序在文本编辑器中编写，保存为扩展名为.kl的文件。在FANUC的[ROBOGUIDE](https://www.edgepedia.org/zh/roboguide)离线仿真环境中，将文件添加到工作单元的“文件”区域并构建，生成编译后的.pc文件。然后，.pc文件被加载到ROBOGUIDE中的虚拟控制器上，或导出到真实的机器人控制器。<sup>[4](https://www.loullingen.lu/projekte/karel/Introduction%20to%20Fanuc%20Karel%20v2025.01.16%20EN.pdf)</sup> KAREL语言翻译器将源代码转换为一种称为p-code的内部格式。<sup>[9](https://www.mroelectric.com/static/application/product/pdfs/A05B-2518-C202-SGL.pdf)</sup>

若干实际限制影响着开发流程。相比之下，TP程序在每台FANUC机器人上都可以导出为可读的ASCII（.ls）文件，不过将其重新导入本身是一项付费选项。<sup>[7](https://www.robot-forum.com/robotforum/thread/41966-benefits-of-using-karel-over-teach-pendant-programming/)</sup>

在控制器上，KAREL程序可以作为后台任务运行。

## 许可与控制器

在R-30iB Plus控制器上，已安装选项列表显示需要R632（KAREL命令语言）和R642（KAREL运行时环境），R633（KAREL PC接口）为文件传输的可选项；在编译或运行KAREL程序之前，必须激活该选项。<sup>[5](https://industrialmonitordirect.com/blogs/knowledgebase/checking-fanuc-karel-option-installation-on-r-30ib-plus)</sup>

FANUC的若干软件选项基于KAREL构建。MQTT选项让机器人作为MQTT客户端运行，支持发布、订阅和代理连接，并支持TLS，该选项需要KAREL。<sup>[1](https://www.fanucamerica.com/products/software/robot/karel)</sup> 套接字消息传递功能使用KAREL实现TCP/IP套接字通信，以便与视觉系统、MES或自定义应用等外部系统集成。<sup>[6](https://www.fanucamerica.com/products/robots/controllers/fanuc-r-50ia-controller)</sup> FANUC自身的许多内部机器人软件也是用KAREL编写的。<sup>[11](https://www.robot-forum.com/robotforum/thread/21148-question-of-difference-between-tp-and-pc/)</sup>

## 语言特性

一项关于机器人编程语言的调查将KAREL归入工业机器人制造商持续维护的厂商专有结构化语言之列，与KUKA的KRL和ABB的RAPID并列。<sup>[12](https://www.annualreviews.org/docserver/fulltext/control/7/1/annurev-control-061323-095841.pdf?accname=guest&checksum=6F202941F7296D3DCD523861F87B6C2D&expires=1780072939&id=id)</sup> 该语言包含用于文件和设备操作、多任务处理、字典和表单的内置例程，还可通过GET_VAR等例程访问系统变量。<sup>[9](https://www.mroelectric.com/static/application/product/pdfs/A05B-2518-C202-SGL.pdf)</sup><sup> • </sup><sup>[13](https://industrialmonitordirect.com/blogs/knowledgebase/accessing-fanuc-system-variables-in-karel-with-get-var)</sup>

该名称与*Karel the Robot*有重叠但截然不同，后者是Richard Pattis（理查德·帕蒂斯）于1981年在斯坦福大学（Stanford University）推出的教育编程语言，见于其著作《Karel the Robot：编程艺术入门》。<sup>[14](https://nclab.com/wp-content/media/2018/09/karel.pdf)</sup>

## 近期变化

2024年推出的R-50iA控制器世代为系统级编程增加了KAREL之外的替代方案。它作为标准功能执行Python脚本，可从TP程序或KAREL程序调用，配有FANUC专有的[Python](https://www.edgepedia.org/zh/python-programming-language)库，可访问I/O信号、寄存器、机器人当前位置和报警历史，并可在[Visual Studio Code](https://www.edgepedia.org/zh/visual-studio-code)中进行开发和调试。<sup>[15](https://www.fanuc.co.jp/en/product/new_product/2025/202501_robot_r50ia.html)</sup> 然而，KAREL仍在当前控制器产品线中：FANUC的R-50iA产品页面仍将其列为用于访问机器人除运动之外所有方面的编译型语言，且MQTT仍然需要它。<sup>[1](https://www.fanucamerica.com/products/software/robot/karel)</sup>

## References

1. [KAREL, FANUC America](https://www.fanucamerica.com/products/software/robot/karel)
2. [FANUC Software and Hardware Options brochure](https://cms.esi.info/Media/documents/FANUC_Softwarehardware_ML.pdf)
3. [FANUC Robot Programming: The Complete Guide (TP & KAREL), ONE Robotics](https://www.onerobotics.com/fanuc-robot-programming/)
4. [Introduction to Fanuc Karel v2025.01.16 EN](https://www.loullingen.lu/projekte/karel/Introduction%20to%20Fanuc%20Karel%20v2025.01.16%20EN.pdf)
5. [Checking FANUC Karel Option Installation on R-30iB Plus, Industrial Monitor Direct](https://industrialmonitordirect.com/blogs/knowledgebase/checking-fanuc-karel-option-installation-on-r-30ib-plus)
6. [R-50iA Controller, FANUC America](https://www.fanucamerica.com/products/robots/controllers/fanuc-r-50ia-controller)
7. [Benefits of using Karel over teach pendant programming?, Robot-Forum](https://www.robot-forum.com/robotforum/thread/41966-benefits-of-using-karel-over-teach-pendant-programming/)
8. [FANUC Karel vs TP: When to Use Each, Xpert Robotics](https://www.xpert-robotics.com/en/blog/fanuc-karel-vs-tp)
9. [FANUC Robotics SYSTEM R-30iA/R-30iB KAREL Reference Manual, MRO Electric](https://www.mroelectric.com/static/application/product/pdfs/A05B-2518-C202-SGL.pdf)
10. [FANUC R-30iB/R-30iB Mate Controller Optional Function Operator's Manual (B-83284EN)](https://media.bidjs.com/raw/upload/v1686911375/production/5_R_30iB_basic_operator_manual_optional_function_B_83284EN_2_05_m0vuvw.pdf)
11. [Question of difference between *.tp and *.pc, Robot-Forum](https://www.robot-forum.com/robotforum/thread/21148-question-of-difference-between-tp-and-pc/)
12. [Robotics Software: Past, Present, and Future, Annual Review of Control, Robotics, and Autonomous Systems](https://www.annualreviews.org/docserver/fulltext/control/7/1/annurev-control-061323-095841.pdf?accname=guest&checksum=6F202941F7296D3DCD523861F87B6C2D&expires=1780072939&id=id)
13. [Accessing Fanuc System Variables in KAREL with GET_VAR, Industrial Monitor Direct](https://industrialmonitordirect.com/blogs/knowledgebase/accessing-fanuc-system-variables-in-karel-with-get-var)
14. [Karel course introduction, NCLab](https://nclab.com/wp-content/media/2018/09/karel.pdf)
15. [ROBOT New function: R-50iA Supports Python, FANUC CORPORATION](https://www.fanuc.co.jp/en/product/new_product/2025/202501_robot_r50ia.html)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 工程与制造 › 机器人技术与自动化 › Robot components and hardware › Controllers and computing boards

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/karel-programming-language

English original: https://www.edgepedia.org/karel-programming-language
