Creating a SayHello Objective From the Command Line

This guide will show you how to make a site config package containing an objective that will run the HelloWorld Behavior we created in this tutorial.

Note

The Create a Custom Behavior and Use a Custom Behavior in the Objective Editor UI tutorials are prerequisites for this tutorial.

1. Create a Site Config Package

Run this command to create a new simulated UR5e site config package by customizing a template package:

cookiecutter $(ros2 pkg prefix --share moveit_studio_site_config_template) --output-dir $STUDIO_GENERATE_PACKAGE_OUTPUT_PATH

This will launch an interactive query to get some important values that will be used to create the package.

When asked to provide the name of the package, name it my_site_config.

When asked to provide the name of a custom Behavior plugin, enter my_behaviors::MyBehaviorsBehaviorsLoader, which is the name of the Behavior loader plugin we created in this tutorial.

Enter your name and email address to complete the package author description.

2. Add a New Objective XML File

Within the my_site_config/objectives directory, create a new file named say_hello.xml:

touch my_site_config/objectives/say_hello.xml

Open this file in your editor and paste in the text provided below:

<?xml version="1.0"?>
<root BTCPP_format="4" main_tree_to_execute="Say Hello" _description="Print a Hello World message to the console.">
    <BehaviorTree ID="Say Hello">
       <Action ID="HelloWorld" />
    </BehaviorTree>
</root>

This defines a very simple Behavior tree that just contains the HelloWorld Behavior we created earlier.

3. Set the STUDIO_CONFIG_PACKAGE Environment Variable

To tell the MoveIt Studio Agent that it should use your new custom site config package, add the following to your ~/.bashrc file:

export STUDIO_CONFIG_PACKAGE="my_site_config"

4. Source the Workspace

Before we can run an objective containing a new Behavior, we need to update our environment to let other ROS nodes know about this package and the new plugin within it.

Run source $STUDIO_GENERATE_PACKAGE_OUTPUT_PATH/../install/setup.bash.

5. Build the Workspace

From the root directory of your workspace, run the following command:

colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --symlink-install

6. Launch the MoveIt Studio Agent

Run the MoveIt Studio Agent ROS nodes in headless mode by running the following commands in separate terminal windows.

rest_api.app
agent_robot.app

7. Run the Objective

Use the Agent’s ROS action interface to execute the Say Hello objective:

ros2 action send_goal /do_objective moveit_studio_agent_msgs/action/DoObjectiveSequence "{objective_name: Say Hello}"

The Agent will load and run the objective and print out some logs to the console while it’s running:

[objective_server_node_main-7] Hello, world!
[objective_server_node_main-7] [1659450223.469]: HelloWorld                IDLE -> SUCCESS
[objective_server_node_main-7] [1659450223.469]: HelloWorld                SUCCESS -> IDLE

These logs show that:

  • The Say Hello objective was loaded by the Agent.

  • The HelloWorld Behavior used by this objective was run successfully.

  • The Behavior printed its friendly message to the console when it was ticked by the objective server.