Continuous Execution Plugin

Source code on GitHub.

Plugin Class

cx::ExecutivePlugin

This plugin provides continuous execution of CLIPS environments. Additionally, it enables reasoning about the current ROS and system time.

Configuration

refresh_rate:

Type

Default

int

10

Description

Target rate (in Hz) with which agendas are refreshed and run is called. This is done sequentially for the registered environments.

publish_on_refresh:

Type

Default

bool

false

Description

Whether to publish an empty message with each agenda refresh on the clips_executive/refresh_agenda topic. Mainly useful for debug purposes to measure the actual refresh rate.

assert_time:

Type

Default

bool

true

Description

Whether the latest ROS time as fact into the CLIPS environment on each iteration.

Features

With the set refresh_rate the executive plugin refreshes all agendas and then runs the loaded CLIPS environments.

Facts

If assert_time is set to true, it asserts the ordered fact time with the current ROS time as float.

(time ?ros-time-float)

Functions

This plugin adds deffunctions to retrieve the current time.

(bind ?ros-time (now))         ; returns a FLOAT holding get_clock()->now().seconds()
(bind ?sys-time (now-systime)) ; returns a FLOAT of system time

Rules

If assert_time is set to true, it defines a rule to clean up the time fact at the end of agenda execution.

(defglobal
  ?*PRIORITY-TIME-RETRACT*    = -10000
)

(defrule time-retract
  (declare (salience ?*PRIORITY-TIME-RETRACT*))
  ?f <- (time $?)
  =>
  (retract ?f)
)

Other

Lastly, the time facts and time-retract rule are unwatched.

(unwatch facts time)
(unwatch rules time-retract)

Usage Example

A minimal working example is provided by the cx_bringup package. Run it via:

ros2 launch cx_bringup cx_launch.py manager_config:=plugin_examples/executive.yaml

It prints the current ROS and system time in each iteration and compares the time at the start of the iteration with the time at the time the rule is fired.

Configuration

File cx_bringup/params/plugin_examples/executive.yaml.

clips_manager:
  ros__parameters:
    environments: ["cx_executive"]
    cx_executive:
      plugins: ["executive", "files"]
      log_clips_to_file: true
      watch: ["facts", "rules"]

    executive:
      plugin: "cx::ExecutivePlugin"
      publish_on_refresh: false
      assert_time: true
      refresh_rate: 10
    files:
      plugin: "cx::FileLoadPlugin"
      pkg_share_dirs: ["cx_bringup"]
      load: [
        "clips/plugin_examples/executive.clp"]

Code

File cx_bringup/clips/plugin_examples/executive.clp.

(defrule print-time
  (time ?now)
  =>
  (printout info "time between agenda refresh and rule fire: " (- (now) ?now) crlf)
  (printout info "ROS time: " (now) crlf)
  (printout info "sys time: " (now-systime) crlf)
)