Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added UML_structure.dia
Binary file not shown.
Empty file modified runSim.sh
100644 → 100755
Empty file.
16 changes: 8 additions & 8 deletions scenarios/scenario1_active.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
<simulation max_x="30.0" max_y="30.0" min_x="-30.0" min_y="-30.0">
<simulation max_x="15.0" max_y="15.0" min_x="-15.0" min_y="-15.0">
<cameras>
<camera ai_algorithm="epics.ai.ActiveAINodeMulti" name="Cam_01" x="-15" y="10" heading="-180" viewing_angle="70" range="20" comm="0"/>
<camera ai_algorithm="epics.ai.ActiveAINodeMulti" name="Cam_02" x="-5" y="10" heading="-180" viewing_angle="70" range="20" comm="0"/>
<camera ai_algorithm="epics.ai.ActiveAINodeMulti" name="Cam_03" x="5" y="10" heading="-180" viewing_angle="70" range="20" comm="0"/>
<camera ai_algorithm="epics.ai.ActiveAINodeMulti" name="Cam_04" x="15" y="10" heading="-180" viewing_angle="70" range="20" comm="0"/>
<camera ai_algorithm="epics.ai.ActiveAINodeMulti" name="Cam_05" x="26" y="8" heading="-135" viewing_angle="70" range="20" comm="0"/>
</cameras>
<camera ai_algorithm="epics.ai.PassiveAINodeMulti" name="Cam_01" x="-5" y="1" heading="52" viewing_angle="70" range="20" comm="0"/>
<camera ai_algorithm="epics.ai.PassiveAINodeMulti" name="Cam_02" x="-5" y="10" heading="-180" viewing_angle="70" range="20" comm="0"/>
<!-- <camera ai_algorithm="epics.ai.AWASSAINodeMulti" name="Cam_03" x="5" y="10" heading="-180" viewing_angle="70" range="20" comm="0"/>
<camera ai_algorithm="epics.ai.AWASSAINodeMulti" name="Cam_04" x="15" y="10" heading="-180" viewing_angle="70" range="20" comm="0"/>
<camera ai_algorithm="epics.ai.AWASSAINodeMulti" name="Cam_05" x="26" y="8" heading="-135" viewing_angle="70" range="20" comm="0"/>
--> </cameras>

<objects>
<object features="1.0" heading="90.0" speed="1.0" x="-30.0" y="-2.0"/>
<object features="1.0" heading="90" speed="1.0" x="-10.0" y="10"/>
</objects>
</simulation>
</root>
Expand Down
122 changes: 122 additions & 0 deletions src/epics/ai/AWASSLookAheadNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package epics.ai;

import static java.lang.Math.cos;
import static java.lang.Math.sin;

import java.util.HashMap;
import java.util.Map;

import epics.camsim.core.TraceableObject;
import epics.common.AbstractAINode;
import epics.common.Coordinate2D;
import epics.common.IBanditSolver;
import epics.common.IRegistration;
import epics.common.ITrObjectRepresentation;
import epics.common.RandomNumberGenerator;
import epics.common.RandomUse.USE;

public class AWASSLookAheadNode extends AbstractAINode { //ActiveAINodeMulti {

/** The confidence for an object below which we advertise */
public static final double CONF_THRESHOLD = 0.1;
private static final int LOOK_AHEAD = 2;
private static final double AUCT_PROB = 0.2;

/** Keep track of confidence from last time step to find whether
* it has increased or decreased */
private Map<ITrObjectRepresentation, Double> lastConfidence = new HashMap<ITrObjectRepresentation, Double>();

/**
* constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
* @param comm the communication policy
* @param staticVG if static or dynamic vision graph
* @param vg the initial vision graph
* @param r the global registration component - can be null
* @param rg the random number generator for this instance
*/
public AWASSLookAheadNode(boolean staticVG, Map<String, Double> vg, IRegistration r, RandomNumberGenerator rg){
super(staticVG, vg, r, rg);
}

/**
* constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
* @param comm the communication policy
* @param staticVG if static or dynamic vision graph
* @param vg the initial vision graph
* @param r the global registration component - can be null
* @param rg the random number generator for this instance
* @param bs the bandit solver to decide the best communication policy and auctioning schedule
*/
public AWASSLookAheadNode(boolean staticVG, Map<String, Double> vg, IRegistration r, RandomNumberGenerator rg, IBanditSolver bs){
super(staticVG, vg, r, rg, bs);
}

public AWASSLookAheadNode(boolean staticVG,
Map<String, Double> vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg) {
super(staticVG, vg, r, auctionDuration, rg);
}

public AWASSLookAheadNode(boolean staticVG,
Map<String, Double> vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg, IBanditSolver bs) {
super(staticVG, vg, r, auctionDuration, rg, bs);
}

/**
* creates a passive ai instance from another existing instance
* @param ai the given existing AI instance
*/
public AWASSLookAheadNode(AbstractAINode ai){
super(ai);
if (ai instanceof AWASSLookAheadNode) {
AWASSLookAheadNode pass = (AWASSLookAheadNode) ai;
lastConfidence = pass.lastConfidence;
}
}

private Coordinate2D toCameraSpace(final Coordinate2D pointPos){
final Coordinate2D camPos = camController.getPostion();
final double camAngle = -camController.getHeading();
final double dx = pointPos.getX()-camPos.getX();
final double dy = pointPos.getY()-camPos.getY();
final double x = dx * cos(camAngle) + dy * sin(camAngle);
final double y = -dx * sin(camAngle) + dy * cos(camAngle);
return new Coordinate2D(x, y);
}


@Override
public void advertiseTrackedObjects() {
for (ITrObjectRepresentation io : this.getAllTrackedObjects_bb().values()) {
double conf = this.getConfidence(io);
double lastConf = this.getLastConfidenceFor(io);
if (this.camController.objectIsVisible(io) == -1){
if (conf < CONF_THRESHOLD && (conf == 0 || conf < lastConf)) {
final TraceableObject obj = io.getTraceableObject();
//if(camController.isObjectInFOV(obj)){
final Coordinate2D expectedNext = toCameraSpace(obj.esteemNext(LOOK_AHEAD));
if((conf != 0 && !camController.isCoordinateInFOV(expectedNext)) || randomGen.nextDouble(USE.UNIV) < AUCT_PROB){
/*
* Start an auction if:
* - the object is in FOV and it's expected to exit the FOV in near future
* - the object is not in FOV with probability AUCT_PROB
*/
callForHelp(io);
}
}
}
this.addLastConfidence(io, conf);
}
}

protected void addLastConfidence(ITrObjectRepresentation io, double conf) {
this.lastConfidence.put(io, conf);
}

protected double getLastConfidenceFor(ITrObjectRepresentation io) {
if (lastConfidence.containsKey(io)) {
return lastConfidence.get(io);
} else {
return 0.0;
}
}
}
111 changes: 111 additions & 0 deletions src/epics/ai/AWASSLookAheadNodeClustering.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package epics.ai;

import static java.lang.Math.cos;
import static java.lang.Math.sin;

import java.util.HashMap;
import java.util.Map;

import epics.camsim.core.TraceableObject;
import epics.common.AbstractAINode;
import epics.common.Coordinate2D;
import epics.common.IBanditSolver;
import epics.common.IRegistration;
import epics.common.ITrObjectRepresentation;
import epics.common.RandomNumberGenerator;
import epics.common.RandomUse.USE;

public class AWASSLookAheadNodeClustering extends AbstractClusterFoVAINode { //ActiveAINodeMulti {

/** The confidence for an object below which we advertise */
public static final double CONF_THRESHOLD = 0.1;
private static final int LOOK_AHEAD = 2;
private static final double AUCT_PROB = 0.2;

/** Keep track of confidence from last time step to find whether
* it has increased or decreased */
private Map<ITrObjectRepresentation, Double> lastConfidence = new HashMap<ITrObjectRepresentation, Double>();

/**
* constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
* @param comm the communication policy
* @param staticVG if static or dynamic vision graph
* @param vg the initial vision graph
* @param r the global registration component - can be null
* @param rg the random number generator for this instance
*/
public AWASSLookAheadNodeClustering(boolean staticVG, Map<String, Double> vg, IRegistration r, RandomNumberGenerator rg){
super(staticVG, vg, r, rg);
}

/**
* constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
* @param comm the communication policy
* @param staticVG if static or dynamic vision graph
* @param vg the initial vision graph
* @param r the global registration component - can be null
* @param rg the random number generator for this instance
* @param bs the bandit solver to decide the best communication policy and auctioning schedule
*/
public AWASSLookAheadNodeClustering(boolean staticVG, Map<String, Double> vg, IRegistration r, RandomNumberGenerator rg, IBanditSolver bs){
super(staticVG, vg, r, rg, bs);
}

public AWASSLookAheadNodeClustering(boolean staticVG,
Map<String, Double> vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg) {
super(staticVG, vg, r, auctionDuration, rg);
}

public AWASSLookAheadNodeClustering(boolean staticVG,
Map<String, Double> vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg, IBanditSolver bs) {
super(staticVG, vg, r, auctionDuration, rg, bs);
}

/**
* creates a passive ai instance from another existing instance
* @param ai the given existing AI instance
*/
public AWASSLookAheadNodeClustering(AbstractAINode ai){
super(ai);
if (ai instanceof AWASSLookAheadNodeClustering) {
AWASSLookAheadNodeClustering pass = (AWASSLookAheadNodeClustering) ai;
lastConfidence = pass.lastConfidence;
}
}

@Override
public void advertiseTrackedObjects() {
for (ITrObjectRepresentation io : this.getAllTrackedObjects_bb().values()) {
double conf = this.getConfidence(io);
double lastConf = this.getLastConfidenceFor(io);
if (this.camController.objectIsVisible(io) == -1){
if (conf < CONF_THRESHOLD && (conf == 0 || conf < lastConf)) {
final TraceableObject obj = io.getTraceableObject();
//if(camController.isObjectInFOV(obj)){
final Coordinate2D expectedNext = toCameraSpace(obj.esteemNext(LOOK_AHEAD));
if((conf != 0 && !camController.isCoordinateInFOV(expectedNext)) || randomGen.nextDouble(USE.UNIV) < AUCT_PROB){
/*
* Start an auction if:
* - the object is in FOV and it's expected to exit the FOV in near future
* - the object is not in FOV with probability AUCT_PROB
*/
callForHelp(io);
}
}
}
this.addLastConfidence(io, conf);
}
}

protected void addLastConfidence(ITrObjectRepresentation io, double conf) {
this.lastConfidence.put(io, conf);
}

protected double getLastConfidenceFor(ITrObjectRepresentation io) {
if (lastConfidence.containsKey(io)) {
return lastConfidence.get(io);
} else {
return 0.0;
}
}
}
Loading