+1 (972) 883-2091
ECSS 4.220, 800 W Campbell Rd, Richardson, TX 75083–0688, US

Implementing the “interaction” package

1. Package Description

The Figure below shows the package “edu.utdallas.mavs.traffic.simulation.sim.agent.interaction” that implements the vehicle agent’s interaction module. This package consists of the “Perception” and “Communication” packages which implement the vehicle agent’s Environment Perception Module and the Agent Communication Module respectively.

stimulus

Creating the inner-packages

  1. Inside the “edu.utdallas.mavs.traffic.simulation.sim.agent.interaction” package create two sub-packages named “perception” and “communication”.
  2. Inside the “perception” package create a sub-package named “sensors”.

2. Implementing the vehicle agent’s “Perception” package

The vehicle agent’s Perception Module implements the mechanisms necessary for a vehicle agent to perceive its environment using various sensors. In this tutorial, we chose to associate a vehicle agent’s Perception Module with a vision sensor. This sensor extends the abstract Physical Sensor to implement an algorithm that specifies the perception of other agents, environment objects, and environment events.

Implementation steps of “perception” package

    1. Inside the “perception” package, create a class named “VehiclePerceptionModule”. This class aggregates the set of physical sensors associated with a vehicle agent. In this example, a vehicle agent has only a visual sensor.
    2. Provide an implementation for the class “VehiclePerceptionModule” as follows:
package edu.utdallas.mavs.traffic.simulation.sim.agent.interaction.perception;

import java.io.Serializable;

import edu.utdallas.mavs.divas.core.sim.agent.interaction.perception.AbstractPerceptionModule;
import edu.utdallas.mavs.traffic.simulation.sim.agent.interaction.perception.sensors.VehicleVisualSensor;
import edu.utdallas.mavs.traffic.simulation.sim.agent.knowledge.VehicleKnowledgeModule;

public class VehiclePerceptionModule extends AbstractPerceptionModule<VehicleKnowledgeModule> implements Serializable
{
    private static final long     serialVersionUID = 1L;

    /**
     * The agent's vision sensor
     */
    protected VehicleVisualSensor visualSensor;

    public VehiclePerceptionModule(VehicleKnowledgeModule knowledgeModule)
    {
        super(knowledgeModule);
        visualSensor = new VehicleVisualSensor(knowledgeModule, this);
        addSense(visualSensor);
    }

    @Override
    protected void updateSensors()
    {

    }

}
    1. Inside the “sensors” package create a class named “VehicleVisualSensor” that extends the class “edu.utdallas.mavs.traffic.simulation.sim.agent.interaction.sensors.PhysicalSensor”.
    2. Provide an implementation of the “VehicleVisualSensor” class that defines how a vehicle agent perceives other agents, environment objects, and environment events. For instance, we assume that a vehicle agent can see everything within a circle of influence. The following code implements a vehicle visual sensor.
package edu.utdallas.mavs.traffic.simulation.sim.agent.interaction.perception.sensors;

import java.io.Serializable;
import java.util.List;

import com.jme3.math.Vector3f;

import edu.utdallas.mavs.divas.core.sim.agent.interaction.perception.sensors.PhysicalSensor;
import edu.utdallas.mavs.divas.core.sim.common.event.EnvEvent;
import edu.utdallas.mavs.divas.core.sim.common.state.AgentState;
import edu.utdallas.mavs.divas.core.sim.common.state.EnvObjectState;
import edu.utdallas.mavs.traffic.simulation.sim.agent.interaction.perception.VehiclePerceptionModule;
import edu.utdallas.mavs.traffic.simulation.sim.agent.knowledge.VehicleKnowledgeModule;

public class VehicleVisualSensor extends PhysicalSensor<VehicleKnowledgeModule, VehiclePerceptionModule>
		implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * Creates a new visual sensor
	 * 
	 * @param knowledgeModule
	 *            the agent's KnowledgeModule
	 * @param humanPerceptionModule
	 *            the agent's perception module
	 */
	public VehicleVisualSensor(VehicleKnowledgeModule knowledgeModule, VehiclePerceptionModule perceptionModule) {
		super(knowledgeModule, perceptionModule);
	}

	@Override
	protected void receiveAgents(List<AgentState> agents) {
		for (AgentState agent : agents) {
			if (isInCircleOfInfluence(agent.getPosition()))
				knowledgeModule.addAgent(agent);
		}

	}

	@Override
	protected void receiveEnvObjs(List<EnvObjectState> envObjs) {
		for (EnvObjectState obj : envObjs) {
			if (isInCircleOfInfluence(obj.getPosition()))
				knowledgeModule.addEnvObj(obj);
		}
	}

	@Override
	protected void receiveEvents(List<EnvEvent> arg0) {
		// TODO Auto-generated method stub
	}

	@Override
	public void resolveObstructions() {
		// TODO Auto-generated method stub
	}

	@Override
	public void setAlgorithm() {
		// TODO Auto-generated method stub
	}

	private boolean isInCircleOfInfluence(Vector3f nearAgentPosition) {
		if (knowledgeModule.getSelf().getPosition().distance(nearAgentPosition) - 10 < knowledgeModule.getSelf()
				.getVisibleDistance()) {
			return true;
		} else {
			return false;
		}
	}
}

3. Implementing the vehicle agent’s “communication” package

A vehicle agent communication module handles all vehicle-to-vehicle communications. Vehicle agents communicate with each other by exchanging V2VMessages. A V2VMessage extends the “AgentMessage” defined in the DIVAs framework and contains information about the current vehicle’s speed, heading, and position. The communication module is fully implemented in DIVAs and only requires a concrete implementation of “AgentMessage”.

Implementation steps of “communication” package

  1. Inside the “communication” package create a class named “V2VMessage” that extends the abstract class “edu.utdallas.mavs.traffic.simulation.sim.agent.interaction.communication.AgentMessage”.
  2. Provide an implementation for the “V2VMessage” to store the additional exchanged information, i.e., vehicle’s speed, heading, and position. The following code shows the implementation of the “V2VMessage”:
package edu.utdallas.mavs.traffic.simulation.sim.agent.interaction.communication;

import java.io.Serializable;

import com.jme3.math.Vector3f;

import edu.utdallas.mavs.divas.core.sim.agent.interaction.communication.AgentMessage;

public class V2VMessage extends AgentMessage implements Serializable
{
    private static final long serialVersionUID = 1L;

    /**
     * The vehicle's speed 
     */
    Vector3f speed;
    
    /**
     * The vehicle's heading
     */
    Vector3f heading;
    
    /**
     * The vehicle's position
     */
    Vector3f position;
    
    /**
     * @param sourceID
     * @param destinationID
     * @param message
     * @param speed the source vehilce's speed
     * @param heading the source vehilce's heading
     * @param position the source vehilce's position
     */
    public V2VMessage(int sourceID, int destinationID, String message, Vector3f speed, Vector3f heading, Vector3f position)
    {
        super(sourceID, destinationID, message);
        this.speed = speed;
        this.heading = heading;
        this.position = position;
    }

    /**
     * @return the the source vehilce's position
     */
    public Vector3f getSpeed()
    {
        return speed;
    }

    /**
     * @return the source vehilce's heading
     */
    public Vector3f getHeading()
    {
        return heading;
    }

	/**
	 * @return the source vehilce's position
	 */
	public Vector3f getPosition() {
		return position;
	}

	/**
	 * @param position the position to set
	 */
	public void setPosition(Vector3f position) {
		this.position = position;
	}
    
    
    

}

4. Implementing the “VehicleInteractionModule” class

The final step is to aggregate vehicle’s agent’s perception and communication to create the vehicle agent’s interaction module.

Implementation steps of “VehicleInteractionModule” class

  1. Inside the “edu.utdallas.mavs.traffic.simulation.sim.agent.interaction” package create a class named “VehicleInteractionModule” that extends the class “edu.utdallas.mavs.traffic.simulation.sim.agent.interaction.AbstractInteractionModule”.
  2. Write the following code to implement the class “VehicleInteractionModule”:
package edu.utdallas.mavs.traffic.simulation.sim.agent.interaction;

import java.io.Serializable;

import edu.utdallas.mavs.divas.core.sim.agent.interaction.AbstractInteractionModule;
import edu.utdallas.mavs.divas.core.sim.agent.interaction.communication.AgentCommunicationModule;
import edu.utdallas.mavs.divas.core.sim.agent.interaction.perception.PerceptionModule;
import edu.utdallas.mavs.traffic.simulation.sim.agent.interaction.perception.VehiclePerceptionModule;

public class VehicleInteractionModule extends AbstractInteractionModule<PerceptionModule, AgentCommunicationModule> implements Serializable
{
    private static final long serialVersionUID = 1L;

    public VehicleInteractionModule(VehiclePerceptionModule perceptionModule, AgentCommunicationModule communicationModule)
    {
        super(perceptionModule, communicationModule);
    }

}