Note: This tutorial assumes that you have completed the previous tutorials: Creating specifications.
(!) Please ask about problems and questions regarding this tutorial on Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Creating constraints

Description: This tutorial shows how to create constraints checking the rating of statistics and executing actions according to the ratings.

Tutorial Level: INTERMEDIATE

In the last tutorial we found out how a statistic gets rated. Now we are going to use those rated statistics to define reactions that get executed if statistics are (not) as we want them to be.

Launching the countermeasure node

A short note at the beginning: Countermeasures take some time to set up properly but can be very mighty.

Now start the processing node to rate statistics:

$ rosrun arni_countermeasure arni_countermeasure

Creating a constraint

We need to create a yaml file to save our constraint to.


        - or:
            c!/listener!/chatter!/talker: {bandwidth: low}
            c!/listener!/chatter!/talker: {frequency: low}
            c!/listener!/chatter!/talker: {alive: low}
        min_reaction_interval: 5
        reaction_timeout: 20
          im_warning: {action: publish, autonomy_level: 13, message: everything is fine, loglevel: warn}
          im_telling_an_error: {action: publish, autonomy_level: 100, message: im not getting executed, loglevel: err}
      reaction_autonomy_level: 50

low_notifier is the name of the constraint. We're defining that either the frequency or the bandwidth of c!/listener!/chatter!/talker has to be low or the node no longer being alive for the constraint to be true. Be careful when editing yaml files - tabs are not permitted and the amount of spaces has be correct or weird errors might be thrown.

        min_reaction_interval: 5
        reaction_timeout: 20

The first line tells us that the constraint has to be true for at least 5 seconds before reactions get executed. The second states that the time between a reaction beeing executed again is at least 20 seconds.

          im_warning: {action: publish, autonomy_level: 13, message: everything is fine, loglevel: warn}
          im_telling_an_error: {action: publish, autonomy_level: 100, message: im not getting executed, loglevel: err}

We're defining two reactions to be taken: the reaction im_warning is publishing the message 'everything is fine' on rosout as warning, and im_telling_an_error is publishing the message 'im not getting executed' as error on rosout.

the autonomy_level makes sure that only reactions with an autonomy_level <= reaction_autonomy_level will get executed.

      reaction_autonomy_level: 50

Since the reaction autonomy level is set to 50, im_telling_an_error will not be executed.

Enabeling the new constraint

Now the constraint needs to be loaded to the parameter server:

rosparam load const.yaml

And finally the countermeasure node needs to know that there is a new constraint:

rosservice call /countermeasure/reload_constraints

Seeing the results

Open rqt and Logging->Console. Now kill the talker (rosnode kill /talker) to make sure we match the countermeasure.

Watching Logging->Console in rqt_gui will show the message getting published every 20 seconds.


Alternatively you also see this in arni detail on the detail window, tab Log. connection_error.png

Now go on and create many more constraints, this is it.

More Information

This were our short tutorials, if anything was explained wrong or simply not understable do not hesitate to write us or open an issue. Any questions on are also highly appreciated though it might take some time until we find those.

For creating more specifications and countermeasures we can only recommend you to look into our source code, especially the test folders. They often have very good and extensive examples which can help you to create good content on your own. Also we recommend reading our chapter about Advanced ROS Network Introspection (ARNI) in Robot Operating System (ROS): The Complete Reference (Volume 1) , it is an almost twenty sites long tutorial explaining everything in a more detailed way.

And finally: Have fun using arni!

Wiki: arni/Tutorials/CreatingConstraints (last edited 2016-03-09 18:21:28 by Matthias Hadlich)