-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository is for developing agents using the ros2 clips executive for the robocup logistics league.
The ros2-clips-executive can be found here: https://github.com/fawkesrobotics/ros2-clips-executive/tree/tviehmann/major-cleanup
We will use ros2 jazzy.
Key aspects when working with ROS 2:
- projects utilize different packages
- packages are organized in workspaces
- colcon is used to build packages in a workspace
- vcstool and repos files may be used to fetch packages from multiple sources to easily set up workspaces
- ROS is tightly scoped, workspaces need to be sourced for them to be available in your current environment (here, environment typically refers to your current terminal)
ROS 2 offers several meta packages that can provide you with the core features needed in every ROS environment.
On Ubuntu machines the base installation is located under /opt/ros/jazzy
, on our Fedora-based lab machines the base installation is located at /usr/lib64/ros2-jazzy
as this matches packaging guidelines for fedora. The ROS packages on fedora come from here.
To source your base installation, simply run:
source /usr/lib64/ros2-jazzy/setup.bash
This will give you access in your current terminal to basic ros2 features, such as the ros2 command line interface ros2cli.
ros2 --help # check out what the cli offers
ros2 pkg list # example to list all packages known in your environment
ament_index packages # another useful tool to query the ament_index directly, which is enabling all this scoping magic
Get familiar with the basics of ROS 2 by doing the basic CLI tutorials
Notes:
- You do not have to (and in fact, can not install anything on the system, meaning that you should ignore all commands asking you to install packages via
apt
as those packages should already be available for you and are installed viadnf
by the system administrator. - Remember, sourcing the base installation is different compared to the description in the tutorials, as described above!
Now that you are familiar with the basics of ROS, ime to setup our infrastructure with CLIPS:
We will setup the our project using 3 different workspaces as follows follows:
ros2/
deps_clips_executive_ws # for dependencies that we do not need to update
clips_executive_ws
labcegor_ws
The idea is to have one workspace for dependencies that are not relevant.
Firstly, create a directory structure for ros2 workspaces
mkdir -p ~/ros2/{clips_executive_ws,deps_clips_executive_ws/labcegor_ws}/src
Then, get the ros2-clips-executive by following the build steps.
Note: Make sure to always be on the correct branch, which for now is tviehmann/major-cleanup
.
Get Familiar with the CLIPS-Executive by reading through the following readmes:
- Main repository
- CLIPS Environment Manager
- File Load Plugin
- Executive Plugin
- Ros Msgs Plugin
- cx_bringup
Utilizing the RosMsgs, FileLoad and the Executive plugin, try to control the Turtlebot by publishing to the topics /turtle1/cmd_vel
and subscribing to the topic /turtle1/pose
.
The turtle should move in a loop between bottom-left (1.0 , 1.0) bottom-right (1.0 , 9.0) top-right (9.0 , 9.0) and top-left (9.0 , 1.0).
You can use this repository to start the task and you should perform a few basic steps that will help you on your mission:
- Create a new workspace (e.g.,
~/ros2/labcegor_ws
) - inside the
src
directory of the workspace, clone this repository and create a new package, e.g., via:
ros2 pkg create --build-type ament_cmake --license Apache-2.0 labcegor_bringup
- Inside the package, you need
params
andlaunch
andclips
directories that also need to be installed in the respective CMakeLists.txt via
install(DIRECTORY launch params DESTINATION share/${PROJECT_NAME})
install(DIRECTORY clips/ DESTINATION share/${PROJECT_NAME}/clips/${PROJECT_NAME}/)
- A simple launch file adapted from cx_bringup will probably suffice for you:
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable
from launch.actions import OpaqueFunction
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
def launch_with_context(context, *args, **kwargs):
labcegor_dir = get_package_share_directory('labcegor_bringup')
manager_config = LaunchConfiguration("manager_config")
log_level = LaunchConfiguration('log_level')
manager_config_file = os.path.join(labcegor_dir, "params", manager_config.perform(context))
# re-issue warning as it is not colored otherwise ...
if not os.path.isfile(manager_config_file):
logger = get_logger("cx_bringup_launch")
logger.warning(f"Parameter file path is not a file: {manager_config_file}")
cx_node = Node(
package='cx_bringup',
executable='cx_node',
output='screen',
emulate_tty=True,
parameters=[
manager_config_file,
],
arguments=['--ros-args', '--log-level', log_level]
)
return [cx_node]
def generate_launch_description():
declare_log_level_ = DeclareLaunchArgument(
"log_level",
default_value='info',
description="Logging level for cx_node executable",
)
declare_manager_config = DeclareLaunchArgument(
"manager_config",
default_value="clips_env_manager.yaml",
description="Name of the CLIPS environment manager configuration",
)
# The lauchdescription to populate with defined CMDS
ld = LaunchDescription()
ld.add_action(declare_log_level_)
ld.add_action(declare_manager_config)
ld.add_action(OpaqueFunction(function=launch_with_context))
return ld
- Write a simple CLIPS manager config (you can orient yourself on the config for the ros msgs plugin example from the cx_bringup package.
We use the standard turtlesim simulation launched via:
ros2 run turtlesim turtlesim_node
Inspect the topics /turtle1/cmd_vel
and /turtle1/pose
using the ros2
cli tool to find out what message types are used and get familiar how to steer the turtle from the command line.
Encode the task at hand in CLIPS with the help of the CLIPS basic programming guide (bpg) and the documentation for the RosMsgsPlugin (you can of course also look at the provided usage example from the cx_bringup package).
- Use deftemplate constructs to encode the task at hand. (Chapter 3 in bpg)
- Use the deffacts construct to initialize your knowledge about the task. (Chapter 4 in bpg)
- Write rules to interface with the ROS topics and steer the turtle. (Chapter 5.4 up to 5.4.9 in bpg)
- If needed, use deffunctions to write some functions. (Chapter 7 in bpg)
In addition, Chapter 12 (in particular up to 12.14) of the bpg serves as a reference for CLIPS functions available in every environment.
Now that we got the first hang on CLIPS and it`s interfaces to the outside world, we can start with the RoboCup Logistics League Domain.
The required software is bundled via containers with setup files in the rcll-get-started repository.
cd ~/
git clone -b tviehmann/lab-setup https://github.com/robocup-logistics/rcll-get-started.git
In essence, just sourcing the contained setup.sh
file should provide you with a bunch of new terminal commands, all prefixed by rc_
(press tab twice after typing the prefix to see a full list of commands).
cd ~/rcll-get-started
source setup.sh
We will just need the two commands
-
rc_start
which starts everything -
rc_stop
which stops everything
In order to verify that everything works as expected, you can query the state of containers using podman. The main useful commands are:
podman ps # shows list of containers
podman pod ps # shows list of pods
podman rm <c-id> # removes a container
podman pod rm <p-id> # removes a pod
- If everything is running correctly, you should be able to open a browser and go to localhost:8080 to see the refbox frontend.
- Pressing
ctrl
+alt
+o
lets you connect as referee. - Press the play button in the top middle to go to Setup Phase
- Switch to Procuction phase by clicking on the phase on top.
All communication in the RCLL is done via protobuf. The cx_protobuf_plugin of the CLIPS-Executive lets you interface with protobuf from within CLIPS.
There is already a useful repository containing message definitions at https://github.com/carologistics/rcll-protobuf which you can clone an build in your workspace to obtain all message definitions that you need.
In order to not multicast to other lab machines, we will need to setup Cyclone-DDS. Open a new file in the editor of your choice:
gedit ~/cyclone_dds.xml
Paste this in:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-model href="https://raw.githubusercontent.com/eclipse-cyclonedds/cyclonedds/master/etc/cyclonedds.xsd" schematypens="http://www.w3.org/2001/XMLSchema" ?>
<CycloneDDS xmlns="https://cdds.io/config">
<Domain Id= "any">
<General>
<Interfaces>
<NetworkInterface address="127.0.0.1"/>
</Interfaces>
<AllowMulticast>true</AllowMulticast>
<EnableMulticastLoopback>true</EnableMulticastLoopback>
</General>
</Domain>
</CycloneDDS>
Lastly, register Cyclone-DDS as your ROS middleware (replace <YOUR-USER-NAME>
by your user name) by putting these lines in your terminal config (.bashrc
):
gedit ~/.config.xml
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export CYCLONEDDS_URI=file:///home/<YOUR-USER-NAME>/cyclone_dds.xml
Notes:
- This In order for these changes to take effect in existing terminals (and terminal tabs), they need to reload the
.bashrc
again:
source ~/.bashrc
- It might require to stop the ros2 daemon once for the changes to take effect:
ros2 daemon stop