Automatic code generation with rpk
#
The rpk
tool is a command-line utility designed to streamline the
development of robotic applications in the ROS 2 ecosystem. It
facilitates the creation and management of standardized application
skeletons for robots, enabling developers to quickly bootstrap projects
and focus on implementation-specific details. Its flexibility and
modularity support a range of robot types, making it a valuable asset
for robotics software developers.
This section provides an overview of the tool’s functionality, usage, and the templates it offers for different components of robotic applications.
Note
If you are new to application development for robots, we recommend reading first 📝 Developing robot apps.
Role and purpose#
The primary role of rpk
is to provide a structured framework for
developing ROS 2-based robotic systems. By offering pre-defined
templates, it ensures consistency, adherence to best practices, and
reduces the overhead of setting up basic infrastructure for robot tasks,
skills, missions, and applications.
This tool is particularly beneficial for teams developing complex
robotic systems, as it fosters modularity and reuse of code. The use of
rpk
can significantly accelerate development cycles by standardizing
the initial setup of robot applications.
It can also be simply used as a quick way to start a new, clean and complete ROS 2 package.
As such, rpk
helps with:
Standardization: Ensures consistency across robot projects by using pre-defined templates adhering to ROS 2 conventions.
Modularity: Promotes the reuse of code and functionality across different projects and components.
Ease of Use: Simplifies the setup process for robot applications, reducing the learning curve for new developers.
Flexibility: Supports multiple robot types and use cases, making it adaptable to diverse projects.
Rapid Prototyping: Enables developers to quickly bootstrap complex systems, focusing on custom functionality rather than boilerplate code.
Main functions#
In its current form, the rpk
tool offers two primary commands:
create
: This command generates application skeletons for various components of a robot system. Developers can specify the type of component (e.g., skill, task, mission) and select from available templates tailored to specific robot types or use cases.list
: This command displays a catalog of available templates for intents, skills, tasks, missions, and applications. It provides brief descriptions of each template, including its programming language and example use cases.
create
command#
The create
command is central to rpk
’s functionality, enabling
developers to generate skeletons for the following components:
Intent: Modules for extracting user intentions from inputs, such as chatbot systems or interfaces leveraging Large Language Models (LLMs) (read more about intent recognition).
Skill: Reusable, atomic robot actions. These are basic building blocks for tasks and missions, such as “go to” or “say” actions (read more about skills).
Task: Time-limited activities that combine multiple skills. Tasks represent intermediate levels of robot behavior, such as greeting a person or fetching an object. (read more about tasks).
Mission: High-level controllers managing the robot’s overall behavior. Missions combine tasks to define the robot’s operational goals, such as acting as a receptionist or waiter. (read more about missions).
Application: Comprehensive frameworks combining mission controllers, tasks, and skills, along with necessary resources, to create complete robotic applications. (read more about applications).
The create
command supports the following options:
-r
or--robot
: Specifies the target robot type. Available options include generic robots and predefined configurations for robots like PAL ARI and PAL TIAGo. The ‘PAL’ variants include examples of calls to PAL specific API, and are not directly relevant to the ARISE project.-p
or--path
: Defines the directory path where the generated skeleton will be saved. By default, it uses the current directory.
list
command#
The list
command displays available templates, categorized by
component type. For each template, it provides:
A unique identifier (e.g.,
base_python
).A description of the template’s purpose and features.
The programming language used (e.g., Python).
Available Templates#
rpk
comes preloaded with a set of templates for intents, skills,
tasks, missions, and complete applications.
As of the current version, the following templates are available:
Intent Extractors:
basic_chatbot
: A simple chatbot skeleton.llm_bridge_python
: An intent extraction module utilizing LLMs via APIs like OpenAI’s ChatGPT.
Skills:
base_python
: A generic skill template.say_python
: Implements a “say” action as an example.db_connector_python
: A mock-up for database interaction.
Tasks:
base_python
: A generic task template.greet_task_python
: Demonstrates a “greet” task implementation.
Mission Controllers:
base_python
: A generic mission controller template.base_intents_python
: A supervisor with pre-filled intent handlers, as well as advanced features like internationalization support.chatbot_supervisor_python
: A complete supervisor example, using a basic chatbot to manage interactions with usersllm_supervisor_python
: An advanced supervisor leveraging LLMs for user interaction.
Applications:
basic_chatbot_python
: complete sample app, using a basic chatbot to interact with users. It includes a supervisor and sample tasks and skillsllm_chatbot_python
: A complete sample application featuring LLM-driven user interaction, with integrated mission controllers, tasks, and skills.
Some of these templates (the base_*
ones) were designed to be
generic and extensible, showcasing best practices in ROS 2 development
(including the use of lifecycle nodes, parameter-based configuration,
etc.). They are meant to be used as starting points for FSTP users to
create their own components.
Other templates are more specific and are meant as examples of how to integrate complete stacks.
For instance, the figure below illustrates the output of the
llm_chatbot_python
app template:
As seen in the figure, the llm_chatbot_python
template generates a
complete application skeleton, including mission controllers, tasks,
skills, intents, as well as the custom ROS 2 message packages required
for these nodes to communicate.
Availability#
The rpk
tool and its templates are available as open-source software
under the Apache 2.0 license. It is pre-installed in your development
Docker image.
In addition, to facilitate installation and usage, the tool is also distributed
as a Python package via the Python Package Index (PyPI). Developers can install
rpk
using the following command:
pip install rpk
Once installed, the tool can be accessed from the command line by running
rpk
followed by the desired command (e.g., create
or list
).
Warning
When using a pip
-installed rpk
, you can generate templates, but you
will not be have to build and run the generated code unless you have
a full ROS 2 environment set up. For this reason, we recommend using the
rpk
tool from the development Docker image.
See also#
Create an application with rpk - Tutorial on using the
rpk
tool.