Please review any and all PUBLIC repositories, groups, and associated files. These allow anyone on the Internet to access without authentication. Repository and group owners are responsible for their content and permission settings. Go to your project(s), click on Settings > General and expand the "Visibility, project features, permissions" to change this setting.

Commit 4c895fb9 authored by Norbraten, Terry's avatar Norbraten, Terry
Browse files

[Terry N.] integrate and refactor for OpenDIS v7

parent c633b936
......@@ -64,11 +64,12 @@ lib.dir=lib
project.licensePath=${docs.dir}/LICENSE
open.dis.ver=7
# compile
aviatrix3d-all.jar=${lib.dir}/aviatrix3d-all_3.1.1-nps.jar
commons-compress.jar=lib/commons-compress-1.11.jar
commons-io.jar=${lib.dir}/commons-io-2.6.jar
dis-enums.jar=lib/dis-enums.jar
fastinfoset.jar=lib/FastInfoset-1.2.17.jar
geoapi-nogenerics-2.1.0.jar=lib/geoapi-nogenerics-2.1.0.jar
gt2-main-2.4.4.jar=lib/gt2-main-2.4.4.jar
......@@ -85,7 +86,8 @@ jmf.jar=lib/jmf.jar
js.jar=lib/js.jar
jsr108-0.01.jar=lib/jsr108-0.01.jar
odejava.jars=lib/odejava.jar:lib/odejava-jni.jar
open-dis.jar=lib/open-dis_4.08.jar
#open-dis.jars=lib/dis-enums.jar:lib/open-dis_4.08.jar
open-dis.jars=${lib.dir}/open-dis7-enumerations-classes.jar:${lib.dir}/open-dis7-pdus-classes.jar
hibernate-jpa-api.jar=lib/hibernate-jpa-2.0-api-1.0.0.Final.jar
openmali.jar=lib/openmali.jar
smack.jars=lib/smack.jar:lib/smackx.jar
......@@ -114,15 +116,15 @@ macosx.installer.jar=${product.shortname}-${product.Version}-macosx-installer.ja
javac.classpath=${aviatrix3d-all.jar}:\
${commons-compress.jar}:\
${commons-io.jar}:\
${dis-enums.jar}:\
${fastinfoset.jar}:\
${geoapi-nogenerics-2.1.0.jar}:\
${gt2-main-2.4.4.jar}:\
${gt2-metadata-2.4.4.jar}:\
${gt2-referencing-2.4.4.jar}:\
${hibernate-jpa-api.jar}:\
${jaxb-api.jar}:\
${im4java.jar}:\
${j3d-org-all.jar}:\
${jaxb-api.jar}:\
${jogamp-fat.jar}:\
${jgeom-core.jar}:\
${jhall.jar}:\
......@@ -130,13 +132,12 @@ javac.classpath=${aviatrix3d-all.jar}:\
${js.jar}:\
${jsr108-0.01.jar}:\
${odejava.jars}:\
${open-dis.jar}:\
${hibernate-jpa-api.jar}:\
${open-dis.jars}:\
${openmali.jar}:\
${smack.jars}:\
${toxiclibscore.jar}:\
${uri.jars}:\
${vecmath.jar}:\
${vecmath.jar}
# Override inlining java privileged extensions folder ${javac.extdirs}
javac.extdirs=-extdirs ' '
......
......@@ -11,18 +11,21 @@
*
****************************************************************************/
import edu.nps.moves.dis.*;
import edu.nps.moves.dis7.pdus.DeadReckoningParameters;
import edu.nps.moves.dis7.pdus.DisTime;
import edu.nps.moves.dis7.pdus.EntityID;
import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.EulerAngles;
import edu.nps.moves.dis7.pdus.VariableParameter;
import edu.nps.moves.dis7.pdus.Vector3Double;
import edu.nps.moves.dis7.pdus.Vector3Float;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import edu.nps.moves.dis7.utilities.PduFactory;
import edu.nps.moves.net.BehaviorProducerUDP;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Random;
import java.util.StringTokenizer;
/**
......@@ -30,7 +33,8 @@ import java.util.StringTokenizer;
* places for the AUV to collide with.
*
* @author Alan Hudson
* @version
* @author <a href="mailto:tdnorbra@nps.edu?subject=AUVController">Terry D. Norbraten</a>
* @version 2 (modified for OpenDIS v7)
*/
public class AUVController {
......@@ -69,6 +73,7 @@ public class AUVController {
private static final int PORT = 62040;
private static final String GROUP = "224.2.181.145";
private DisThreadedNetworkInterface writer;
public static void main(String args[]) {
if (args.length > 1) {
......@@ -81,83 +86,57 @@ public class AUVController {
AUVController controller = new AUVController();
controller.test();
}
public void test() {
System.out.println("Starting Controller");
DatagramSocket socket = null;
InetAddress address;
int pause = 500 / numEntities;
int sleepTime = 500 / numEntities;
float offset = -10;
writer = new DisThreadedNetworkInterface(GROUP, PORT);
try {
try {
socket = new MulticastSocket(PORT);
address = InetAddress.getByName(GROUP);
((MulticastSocket) socket).joinGroup(address);
} catch (IOException e) {
System.err.println("Unicast fallback");
if (socket != null)
socket.close();
socket = new DatagramSocket();
address = InetAddress.getByName("localhost");
for (int i = 0; i < numEntities; i++) {
if (i % 10 == 0) {
offset += 2.5;
}
launchEntity(DATA_LAYOUT, 0, 1, i, 0, 0, offset);
for (int i = 0; i < numEntities; i++) {
if (i % 10 == 0) {
offset += 2.5;
}
launchEntity(socket, address, PORT, DATA_LAYOUT, 0, 1, i, 0, 0, offset);
try {
Thread.sleep(pause);
} catch (InterruptedException e) {}
}
System.out.println("Launching Target");
launchTarget(socket, address, PORT, DATA_LAYOUT, 0, 1, numEntities, 0, 0, offset);
} catch (SocketException | UnknownHostException e) {
e.printStackTrace(System.err);
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {}
}
System.out.println("Launching Target");
launchTarget(DATA_LAYOUT, 0, 1, numEntities, 0, 0, offset);
}
private void launchEntity(DatagramSocket socket, InetAddress address, int port, String path,
int siteID, int appID, int entityID,
private void launchEntity(String path, int siteID, int appID, int entityID,
float xoff, float yoff, float zoff) {
Thread thread;
BehaviorProducerUDP writer1 = new BehaviorProducerUDP(socket);
writer1.setDefaultDestination(address, port);
writer1.setUseCopies(false);
Runner2 e1 = new Runner2(writer1, path, siteID, appID, entityID, pauseTime);
e1.setOffset(xoff, yoff, zoff);
thread = new Thread(e1);
EntityRunner r = new EntityRunner(writer, path, siteID, appID, entityID, pauseTime);
r.setOffset(xoff, yoff, zoff);
Thread thread = new Thread(r);
// thread.setDaemon(true);
thread.start();
}
private void launchTarget(DatagramSocket socket, InetAddress address, int port, String path,
int siteID, int appID, int entityID,
private void launchTarget(String path, int siteID, int appID, int entityID,
float xoff, float yoff, float zoff) {
Thread thread;
BehaviorProducerUDP writer1 = new BehaviorProducerUDP(socket);
writer1.setDefaultDestination(address, port);
writer1.setUseCopies(false);
TargetRunner e1 = new TargetRunner(writer1, path, siteID, appID, entityID, 500);
e1.setOffset(xoff, yoff, zoff);
thread = new Thread(e1);
TargetRunner r = new TargetRunner(writer, path, siteID, appID, entityID, 500);
r.setOffset(xoff, yoff, zoff);
Thread thread = new Thread(r);
// thread.setDaemon(true);
thread.start();
}
}
class Runner2 implements Runnable {
class EntityRunner implements Runnable {
EntityID id;
BehaviorProducerUDP writer;
DisThreadedNetworkInterface writer;
String data;
EntityStatePdu espdu;
float xoff;
......@@ -165,32 +144,32 @@ class Runner2 implements Runnable {
float zoff;
int entityID;
int pauseTime;
ByteBuffer buffer;
boolean sendingPDUs = true;
StringTokenizer lineTokenizer;
public Runner2(BehaviorProducerUDP writer, String data, int siteID, int appID, int entityID, int pauseTime) {
public EntityRunner(DisThreadedNetworkInterface writer, String data, int siteID, int appID, int entityID, int pauseTime) {
this.writer = writer;
this.data = data;
this.entityID = entityID;
this.pauseTime = pauseTime;
id = new EntityID();
id.setSite(siteID);
id.setApplication(appID);
id.setEntity(entityID);
espdu = new EntityStatePdu();
id.setSiteID(siteID);
id.setApplicationID(appID);
id.setEntityID(entityID);
PduFactory fac = new PduFactory();
fac.setTimeStampStyle(PduFactory.TimestampStyle.NPS);
espdu = fac.makeEntityStatePdu();
espdu.setEntityID(id);
espdu.getArticulationParameters().clear();
espdu.getVariableParameters().clear();
if (entityID == 0) {
ArticulationParameter p = new ArticulationParameter();
p.setParameterValue(10.0);
espdu.getArticulationParameters().add(p);
VariableParameter p = new VariableParameter();
p.setRecordSpecificFields(ByteBuffer.allocate(4).putFloat(10.0f).array());
espdu.getVariableParameters().add(p);
}
buffer = ByteBuffer.allocate(espdu.getLength());
}
public void setOffset(float x, float y, float z) {
......@@ -201,30 +180,37 @@ class Runner2 implements Runnable {
@Override
public void run() {
int totalPacketsSent = 0;
String lineString; // one line from the string
StringTokenizer itemTokenizer;
float pduValues[];
int valueCount;
float value;
String token;
Vector3Double v3d = new Vector3Double();
Vector3Float v3f = new Vector3Float();
EulerAngles orient = new EulerAngles();
DeadReckoningParameters dp;
DisTime disTime = new DisTime();
while (sendingPDUs) {
String lineString; // one line from the string
StringTokenizer itemTokenizer;
// Check to see if we're beyond the time-out limit. If so, generate a fake event
// that presses the "stop" button. This saves us having to write a bunch of
// duplicate code.
lineTokenizer = new StringTokenizer(data, "\r\n");
// while we have more lines....
while (lineTokenizer.hasMoreTokens() && sendingPDUs) {
float pduValues[] = new float[12]; //holds x,y,z; dx,dy,dz; psi,theta,phi; angX,angY,angZ
int valueCount;
while (lineTokenizer.hasMoreTokens() /*&& sendingPDUs*/) {
pduValues = new float[12]; //holds x,y,z; dx,dy,dz; psi,theta,phi; angX,angY,angZ
valueCount = 0;
// get one line of input, then decode each token in that string
lineString = lineTokenizer.nextToken();
itemTokenizer = new StringTokenizer(lineString);
valueCount = 0;
while (itemTokenizer.hasMoreTokens()) {
float value;
String token;
token = itemTokenizer.nextToken();
......@@ -251,49 +237,49 @@ class Runner2 implements Runnable {
}
// location
Vector3Double v3d = new Vector3Double();
v3d.setX(pduValues[0] + xoff);
v3d.setY(pduValues[1] + yoff);
v3d.setZ(pduValues[2] + zoff);
espdu.setEntityLocation(v3d);
// velocity
Vector3Float v3f = new Vector3Float();
v3f.setX(pduValues[3]);
v3f.setY(pduValues[4]);
v3f.setZ(pduValues[5]);
espdu.setEntityLinearVelocity(v3f);
// orientation
Orientation orient = new Orientation();
orient.setPsi(pduValues[6]); // h
orient.setTheta(pduValues[7]); // p
orient.setPhi(pduValues[8]); // r
espdu.setEntityOrientation(orient);
// angular velocity
DeadReckoningParameter dp = espdu.getDeadReckoningParameters();
dp = espdu.getDeadReckoningParameters();
v3f = dp.getEntityAngularVelocity();
v3f.setX(pduValues[9]); // h
v3f.setY(pduValues[10]); // p
v3f.setZ(pduValues[11]); // r
dp.setEntityAngularVelocity(v3f);
buffer.clear();
espdu.marshalWithNpsTimestamp(buffer);
writer.write(buffer, espdu.getMarshalledSize());
try {
Thread.sleep(pauseTime);
} catch (InterruptedException e) {}
espdu.setTimestamp(disTime.getNpsTimestamp());
writer.send(espdu);
sleep(pauseTime);
}
}
}
private void sleep(long time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {}
}
}
class TargetRunner implements Runnable {
EntityID id;
BehaviorProducerUDP writer;
DisThreadedNetworkInterface writer;
String data;
EntityStatePdu espdu;
float xoff;
......@@ -301,31 +287,32 @@ class TargetRunner implements Runnable {
float zoff;
int entityID;
int pauseTime;
Buffer buffer;
boolean sendingPDUs = true;
StringTokenizer lineTokenizer;
public TargetRunner(BehaviorProducerUDP writer, String data, int siteID, int appID, int entityID, int pauseTime) {
public TargetRunner(DisThreadedNetworkInterface writer, String data, int siteID, int appID, int entityID, int pauseTime) {
this.writer = writer;
this.data = data;
this.entityID = entityID;
this.pauseTime = pauseTime;
id = new EntityID();
id.setSite(siteID);
id.setApplication(appID);
id.setEntity(entityID);
espdu = new EntityStatePdu();
id.setSiteID(siteID);
id.setApplicationID(appID);
id.setEntityID(entityID);
PduFactory fac = new PduFactory();
fac.setTimeStampStyle(PduFactory.TimestampStyle.NPS);
espdu = fac.makeEntityStatePdu();
espdu.setEntityID(id);
espdu.getArticulationParameters().clear();
espdu.getVariableParameters().clear();
if (entityID == 0) {
ArticulationParameter p = new ArticulationParameter();
p.setParameterValue(10.0);
espdu.getArticulationParameters().add(p);
VariableParameter p = new VariableParameter();
p.setRecordSpecificFields(ByteBuffer.allocate(4).putFloat(10.0f).array());
espdu.getVariableParameters().add(p);
}
buffer = ByteBuffer.allocate(espdu.getLength());
}
public void setOffset(float x, float y, float z) {
......@@ -336,12 +323,23 @@ class TargetRunner implements Runnable {
@Override
public void run() {
int totalPacketsSent = 0;
String lineString; // one line from the string
StringTokenizer itemTokenizer;
float pduValues[];
int valueCount;
float value;
String token;
Vector3Double v3d = new Vector3Double();
Vector3Float v3f = new Vector3Float();
EulerAngles orient = new EulerAngles();
DeadReckoningParameters dp;
Random rand = new Random();
DisTime disTime = new DisTime();
while (sendingPDUs) {
String lineString; // one line from the string
StringTokenizer itemTokenizer;
// Check to see if we're beyond the time-out limit. If so, generate a fake event
// that presses the "stop" button. This saves us having to write a bunch of
// duplicate code.
......@@ -349,16 +347,14 @@ class TargetRunner implements Runnable {
// while we have more lines....
while (lineTokenizer.hasMoreTokens() /*&& sendingPDUs*/) {
float pduValues[] = new float[12]; //holds x,y,z; dx,dy,dz; psi,theta,phi; angX,angY,angZ
int valueCount = 0;
pduValues = new float[12]; //holds x,y,z; dx,dy,dz; psi,theta,phi; angX,angY,angZ
valueCount = 0;
// get one line of input, then decode each token in that string
lineString = lineTokenizer.nextToken();
itemTokenizer = new StringTokenizer(lineString);
while (itemTokenizer.hasMoreTokens()) {
float value;
String token;
token = itemTokenizer.nextToken();
......@@ -379,54 +375,50 @@ class TargetRunner implements Runnable {
pduValues[valueCount - 1] = value;
}
float rand = (float) Math.random();
if (valueCount == 0 || rand > 0.1f) { // got a blank line; skip it, and don't send out a zero PDU
try {
Thread.sleep(pauseTime);
} catch (InterruptedException e) {}
if (valueCount == 0 || rand.nextFloat() > 0.1f) { // got a blank line; skip it, and don't send out a zero PDU
sleep(pauseTime);
continue;
}
System.out.println("Moving target:" + entityID + " rand: " + rand);
// location
Vector3Double v3d = new Vector3Double();
v3d.setX(pduValues[0] + xoff);
v3d.setY(pduValues[1] + yoff);
v3d.setZ(pduValues[2] + zoff);
espdu.setEntityLocation(v3d);
// velocity
Vector3Float v3f = new Vector3Float();
v3f.setX(pduValues[3]);
v3f.setY(pduValues[4]);
v3f.setZ(pduValues[5]);
espdu.setEntityLinearVelocity(v3f);
// orientation
Orientation orient = new Orientation();
orient.setPsi(pduValues[6]); // h
orient.setTheta(pduValues[7]); // p
orient.setPhi(pduValues[8]); // r
espdu.setEntityOrientation(orient);
// angular velocity
DeadReckoningParameter dp = espdu.getDeadReckoningParameters();
dp = espdu.getDeadReckoningParameters();
v3f = dp.getEntityAngularVelocity();
v3f.setX(pduValues[9]); // h
v3f.setY(pduValues[10]); // p
v3f.setZ(pduValues[11]); // r
dp.setEntityAngularVelocity(v3f);
buffer.clear();
espdu.marshalWithNpsTimestamp((ByteBuffer) buffer);
writer.write((ByteBuffer) buffer, espdu.getMarshalledSize());
try {
Thread.sleep(pauseTime);
} catch (InterruptedException e) {}
espdu.setTimestamp(disTime.getNpsTimestamp());
writer.send(espdu);
sleep(pauseTime);
}
}
}
private void sleep(long time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {}
}
}
......@@ -20,4 +20,4 @@ a real simulation this traffic would come from several sources.
PickerServer.java - Detects and reports whether the whiskers hit a target.
Loads pick_world.x3dv which describes the world the robot is in. Also includes
the LinePicker used to detect targets.
\ No newline at end of file
the LinePicker used to detect targets.
......@@ -253,12 +253,14 @@
<echo message="jdpa address=${jpda.address}"/>
<java classname="${debug.class}" dir="${examples.browser.dir}" failonerror="true" fork="true">
<classpath refid="cp"/>
<jvmarg line="${run.args}"/>
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=none"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
<!-- Comment out for native DIS handling -->
<!--sysproperty key="${dis.protocol.handler.prop}"
value="${dis.xmpp.protocol.handler}"/-->
<jvmarg line="${run.args}"/>
<!-- Enable the Smack debugger -->
<!--jvmarg value="-Dsmack.debugEnabled=true"/-->
<arg line="${example.loader.args}"/>
......@@ -278,9 +280,11 @@
<echo>Processing ${scene}</echo>
<java classname="${debug.class}" dir="${replica.dir}" fork="true">
<classpath refid="cp"/>
<jvmarg line="${run.args}"/>
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=none"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
<jvmarg line="${run.args}"/>
<arg line="${app.replica.args}"/>
</java>
</target>
......@@ -295,9 +299,11 @@
</nbjpdastart>
<java classname="${debug.class}" dir="${parsetest.dir}/eai" fork="true">
<classpath refid="cp"/>
<jvmarg line="${run.args}"/>
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=none"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
<jvmarg line="${run.args}"/>
</java>
</target>
<target depends="init" name="debug-selected-file-in-cadfilter">
......@@ -312,6 +318,8 @@
<classpath refid="cp"/>
<jvmarg line="${run.args}"/>
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=none"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
<!-- args should be the full path to convertible file -->
<!-- commandline given/supplied arguments cadfilter.args=%1 etc -->
......@@ -328,9 +336,11 @@
</nbjpdastart>
<java classname="${debug.class}" dir="${sai.test.dir}" fork="true">
<classpath refid="cp"/>
<jvmarg line="${run.args}"/>
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=none"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
<jvmarg line="${run.args}"/>
</java>
</target>