Skip to content
James Edmondson edited this page Aug 11, 2015 · 12 revisions

Java Guides: GAMS Primer | Creating Algorithms | Creating Platforms | Debugging


Introduction

The Group Autonomy for Mobile Systems (GAMS) project is intended to provide portable algorithms and platforms for AI research into robotic, simulation and software agents. GAMS is provided as middleware for C++ and Java developers to build solutions on top of and is meant to facilitate portable interactions between heterogeneous agents in the most challenging real-world environments (including frequently disconnected environments).

Collaboration amongst agents is facilitated via the MADARA project, which provides portable threading, networking, and knowledge and reasoning services for C++, Java, and Python (we hope to support Python via MADARA once the C++ and Java libraries are solid). MADARA supports Intel and ARM architectures as well as operating systems like Windows, Linux, Android, Mac, etc. For networking, it provides several stock transports like UDP unicast, broadcast and multicast as well as two vendor implementations of the OMG DDS standard (namely PrismTech's and RTTI's implementations).


Agent Model

The execution of agent logic in the GAMS middleware is based on the IBM MAPE-K loop construct. In MAPE-K, an agent's internal logic is broken down into a Monitor, Analyze, Plan and Execute phase (MAPE), guided by and while interacting with a knowledge base (K). Any information a developer feels is necessary for the agent's logic is typically stored in this knowledge base in whatever form is appropriate--e.g., strings, doubles, integers, binary files, images, etc. This information is used by the agent or other agents who have been informed of knowledge to help with responding to the environment, planning future steps, avoiding danger areas, etc.

GAMS Architecture

The most common interaction with GAMS is via creating a custom platform to be used by stock GAMS algorithms like area coverage, force protection, and formation movement. Another intended interaction is the creation of custom GAMS algorithms that may work with stock GAMS platforms like VREP simulation quadcopters and other types of simulated and real robotics systems.


Creating Custom Platforms

To create your own custom robotics, simulation or software agent platform, you need to extend the BasePlatform class. The Base_Platform class provides an interface that must be implemented by the platform as well as useful variables for keeping track of common state information in the knowledge base.

All abstract methods must be implemented but may be left empty for null operations. For instance, robotics platforms are unlikely to implement any useful actions in the takeoff or land methods. Once you have implemented all of the methods in your derived class, you are now ready to create an instance of the class and pass it to the GAMS controller for usage with any supported algorithm.


Creating Custom Algorithms

To create your own custom algorithm for simulations or real-world robotics, you need to extend the BaseAlgorithm class. The Base_Algorithm class provides an interface that must be implemented by the algorithm as well as useful variables for keeping track of common algorithm state in the knowledge base.

Unlike Base_Platform which has many functions, algorithms derived from Base_Algorithm only require the implementation of the appropriate MAPE-K methods, namely analyze, plan and execute.


Debugging Your Work

GAMS provides several features for debugging custom platforms and algorithms. The most straight-forward debugging features are DebugAlgorithm and DebugPlatform. These implementations of Base_Algorithm and Base_Platform print the execution trace of the MAPE-K operations. The printouts include the ids of the agents along with the number of algorithm executes called up to the point of the printout.

In the following code block, a custom platform called Custom_Platform is paired with the Debug_Algorithm (initialized in this case with the named platform "debug").

import com.madara.KnowledgeBase;
import com.madara.transport.QoSTransportSettings;
import com.madara.transport.TransportType;
import com.gams.controllers.BaseController;
import com.gams.utility.Logging;
import com.gams.platforms.DebuggerPlatform;
import com.gams.algorithms.DebuggerAlgorithm;

public class TestDebuggerLoop
{ 
  public static void main (String...args) throws Exception
  {
    // Controllers require a knowledge base. This one will have no networking.
    System.out.println("Creating knowledge base...");
    KnowledgeBase knowledge = new KnowledgeBase();

    System.out.println("Passing knowledge base to base controller...");
    BaseController controller = new BaseController(knowledge);

    // give our agent id 0 of 4 processes
    controller.initVars(0, 4);

    // initialize the debugger platform and algorithm
    controller.initPlatform(new DebuggerPlatform ());
    controller.initAlgorithm(new DebuggerAlgorithm ());
    
    System.out.println("Running controller every 1s for 10s...");
    controller.run(1.0, 200.0);
    
    knowledge.print();

    /**
     * The MADARA and GAMS ports use JNI which requires explicit memory management. When we
     * are done with the controller and knowledge base, we should free them.
     **/
    controller.free();
    knowledge.free();
  }
}

Another debugging feature is shown in the above code snippet. knowledge.print() prints all knowledge in the knowledge base. You can use this throughout your algorithm or platform classes to check to see what modifications are happening.

If you are looking for printing features for knowledge coming in and out of agents, you can use Knowledge filters on receive, send, or rebroadcast. The MADARA Java guide series presents examples of how to see what is being sent and received in the Aggregate Record Filters section


Connecting Agents Together

Connecting agents together in GAMS is done via networking knowledge bases together. To network knowledge bases, developers must pass in a transport settings class into the knowledge base before creating the GAMS controller. We extend the earlier example to simply connect the agent to any other MADARA-enabled agents via IP multicast at 239.255.0.1 and port 4150.

import com.madara.KnowledgeBase;
import com.madara.transport.QoSTransportSettings;
import com.madara.transport.TransportType;
import com.gams.controllers.BaseController;
import com.gams.utility.Logging;
import com.gams.platforms.DebuggerPlatform;
import com.gams.algorithms.DebuggerAlgorithm;

public class TestDebuggerLoop
{ 
  public static void main (String...args) throws Exception
  {
    /**
     * Networking knowledge bases requires passing preconfigured TransportSettings
     * We create network settings for multicast at 239.255.0.1:4150
     **/
    QoSTransportSettings settings = new QoSTransportSettings();
    settings.setHosts(new String[]{"239.255.0.1:4150"});
    settings.setType(TransportType.MULTICAST_TRANSPORT);

    // Controllers require a knowledge base. This one will have multicast networking support
    System.out.println("Creating knowledge base...");
    KnowledgeBase kknowledge = new KnowledgeBase("", settings);

    System.out.println("Passing knowledge base to base controller...");
    BaseController controller = new BaseController(knowledge);

    // give our agent id 1 of 4 processes
    controller.initVars(1, 4);

    // initialize the debugger platform and algorithm
    controller.initPlatform(new DebuggerPlatform ());
    controller.initAlgorithm(new DebuggerAlgorithm ());
    
    System.out.println("Running controller every 1s for 10s...");
    controller.run(1.0, 200.0);
    
    knowledge.print();

    /**
     * The MADARA and GAMS ports use JNI which requires explicit memory management. When we
     * are done with the controller and knowledge base, we should free them.
     **/
    controller.free();
    knowledge.free();
  }
}

A more realistic test would use command line arguments to set the id and processes (what we pass into initVars). We leave that as an exercise to the reader.


Java Guides: GAMS Primer | Creating Algorithms | Creating Platforms

Clone this wiki locally