Skip to content

jason-lang/jason_ros

Repository files navigation

jason-ros

Description

This repository is being used to develop a possible integration between Jason and ROS.

This is being done by customizing the agent architecture, AgArch class, to include ROS functionalities, using rosjava. Also, an intermediary ros node, called HwBridge, is being used to serve as bridge between Jason and Hardware nodes.

Basically, the Jason agent publishes the action it wants to perform into the topic '/jason/actions' and it subscribes to the topic '/jason/actions_status' to receive the status of the action sent and to the topic '/jason/percepts'/ to receive new perceptions.

In other hand, HwBridge node subscribes to '/jason/actions' and using the information contained in the action_manifest it translates the action received and sends it to the right topic/service, when the action is completed it publishes its status into '/jason/actions_status' topic. Also, it publishes perceptions into '/jason/percepts' topic according to what is defined in perception_manifest.

Docker images containing this repo and needed environment can be found at dockerhub.

armv7 version at branch armv7 (out of date)

Installation

Install Dependencies

First you need to install ROS, this package was tested the last time with ROS noetic, but it should work with ROS melodic as well.

Then you need to install gradle (tested with gradle 8.1):

$ wget https://services.gradle.org/distributions/gradle-8.1-bin.zip -P /tmp
$ unzip -d /opt/gradle /tmp/gradle-*.zip

Set environment variables

echo `export GRADLE_HOME=/opt/gradle/gradle-8.1` >> ~/.bashrc
echo `export PATH=${GRADLE_HOME}/bin:${PATH}` >> ~/.bashrc

Don't forget to reload your terminal.

Install Java 17:

$ apt install openjdk-17-jdk

Set java environment variable:

$  echo `export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64` >> ~/.bashrc

Build jason_ros

Create a ROS workspace:

$ mkdir -p ~/jason_ros_ws/src
$ cd ~/jason_ros_ws/src
$ catkin_init_workspace

Clone this repo into:

$ git clone https://github.com/jason-lang/jason_ros.git

Install deps:

$ cd ~/jason_ros_ws/
$ rosdep init
$ rosdep update
$ rosdep install --from-paths src --ignore-src -r -y

Build workspace:

$ cd ~/jason_ros_ws/
$ catkin_make

PS: Don't forget to source ROS before running ROS commands

$ source /opt/ros/noetic/setup.bash

Usage

mas2j

Use jasonros.RosArch

MAS rosbridge_agents {

    infrastructure: Centralised

    agents: sample_agent agentArchClass jasonros.RosArch;
}

Gradle

Include jason, jasonros and jasonros_msgs to gradle:

repositories {
   mavenCentral()
   jcenter()

   maven { url "https://raw.github.com/rosjava/rosjava_mvn_repo/master" }
   maven { url "https://raw.github.com/jason-lang/mvn-repo/master" }
   maven { url "http://jacamo.sourceforge.net/maven2" }
}

dependencies {
  implementation group: 'org.jason',     name: 'jason' ,   version: '3.0-SNAPSHOT'
  implementation group: 'org.jason-lang',     name: 'jasonros' ,   version: '1.9.2'
  implementation group: 'org.jason-lang',     name: 'jasonros_msgs' ,   version: '1.9.2'
}

Edit Manifests

In order to use this project, one must modify the action_manifest and perception_manifest to include the information about the actions being performed and the perceptions of interest.

action_manifest:

[teste]
method = topic
name = /hw/teste
msg_type = String
dependencies = std_msgs.msg
params_name = data
params_type = str
latch = True
  • method - topic or service
  • name - name of the topic or service
  • msg_type - type of the message e.g. String, Bool, Int32
  • dependencies - python module which contains the message type e.g. std_msgs.msg, mavros_msgs.msg
  • params_name - name of the parameter being sent
  • params_type - type of the parameter e.g. bool, str, int. If not inclued the default type is str
  • latch - if the action should be latched e.g. true, True, yes, 1, False, false. If not included the default is true

For more examples of actions you can take a look at this action_manifest

perception_manifest:

[state]
name = /hw/teste2
msg_type = String
dependencies = std_msgs.msg
args = data
buf = add
  • name - name of the topic or service
  • msg_type - type of the message e.g. String, Bool, Int32
  • dependencies - python module which contains the message type e.g. std_msgs.msg, mavros_msgs.msg
  • args - fields that you want to perceive
  • buf (belief update function) - if the perception should be added or updated in the belief base. If not included the default option is update. The perception in the example would be added into the agent belief base as state(data)

For more examples of perceptions you can take a look at this perceptions_manifest

Running Bare Metal

Running

Initialize roscore:

$ roscore

Before running HwBridge node jason_ws must be built and sourced:

$ cd jason_ws
$ catkin_make
$ source devel/setup.bash

If you don't want to source everytime you open a new bash, do something like:

echo "source ~/jason-ros/jason_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

Note: Change "~/jason-ros/jason_ws/devel/setup.bash" for the right path in your computer

HwBridge node:

$ cd jason_ws/src/hw_bridge/src
$ ./hw_bridge.py

In order to inspect what is being exchanged between the nodes you can use rostopic echo/info to inspect the topics /jason/actions, /jason/actions_status, /jason/percepts, /hw/teste or /hw/teste2:

$ rostopic echo /jason/actions      #or any other topic

Jason node:

$ cd rosjava_agents
$ gradle

Running with Docker

Build image

$ docker build --tag jason-ros .

Create network:

$ docker network create ros_net

Container 1:

$ docker run -it --rm --net ros_net  --name master --env ROS_HOSTNAME=master --env ROS_MASTER_URI=http://master:11311 ros:melodic-ros-core roscore

Container 2:

$ docker run -it --rm  --net ros_net  --name hwbridge --env ROS_HOSTNAME=hwbridge --env ROS_MASTER_URI=http://master:11311 jason-ros

Then, at /jason_ws/src/hw_bridge/src folder:

$ ./hw_bridge.py

Container 3:

In order to inspect what is being exchanged between the nodes you can use rostopic echo/info to inspect the topics /jason/actions, /jason/actions_status, /jason/percepts, /hw/teste or /hw/teste2:

$ docker run -it --rm  --net ros_net  --name echo --env ROS_HOSTNAME=echo --env ROS_MASTER_URI=http://master:11311 jason-ros

Then:

$ rostopic echo /jason/actions      #or any other topic

Container 4:

$ docker run -it --rm  --net ros_net  --name agent --env ROS_HOSTNAME=agent --env ROS_MASTER_URI=http://master:11311 jason-ros   

Inside container at the agent folder:

$ gradle

Developers Note

In order to generate jason_ros_msgs.jar run:

$ docker build -t jason_ros_msgs . -f MsgDockerfile
$ docker run -it --rm -v ${PWD}/jason_ros/src/rosjava_agents/lib/:/artifacts jason_ros_msgs cp /jason_ros_ws/build/jason_ros/jason_ros_msgs/java/jason_ros_msgs/build/libs/jason_ros_msgs-1.9.0.jar /artifacts/jason_ros_msgs.jar

Note: Use the correct version according to jason_ros_msgs/package.xml

Examples

A functional example using docker can be found at the repo MAS-UAV For more examples check the example folder

Reference

If you find this repository usefull and use it in your project, please consider citing it:

@article{silva2020embedded,
  title={Embedded Architecture Composed of Cognitive Agents and ROS for Programming Intelligent Robots},
  author={Silva, Gustavo R and Becker, Leandro B and H{\"u}bner, Jomi F},
  journal={IFAC-PapersOnLine},
  volume={53},
  number={2},
  pages={10000--10005},
  year={2020},
  publisher={Elsevier}
}

Paper link