Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Dead Reckoning dis 7 implementation #160

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/nbproject/
*.orig
*.rej
.vscode
.vscode
.idea
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.7.0</version>
<version>3.10.0</version>
<configuration>
<source>8</source> <!-- workaround https://stackoverflow.com/a/60322437/52176 -->
<additionalparam>-Xdoclint:none</additionalparam>
Expand All @@ -153,7 +153,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.7.0</version>
<version>3.10.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -179,7 +179,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.4</version>
<version>3.2.7</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
377 changes: 377 additions & 0 deletions src/main/java/edu/nps/moves/deadreckoning/AbstractDeadReckoner.java

Large diffs are not rendered by default.

320 changes: 19 additions & 301 deletions src/main/java/edu/nps/moves/deadreckoning/DeadReckoner.java

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions src/main/java/edu/nps/moves/deadreckoning/Dis6DeadReckoner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package edu.nps.moves.deadreckoning;

import edu.nps.moves.dis.ArticulationParameter;
import edu.nps.moves.dis.EntityStatePdu;
import edu.nps.moves.dis7.Orientation;
import edu.nps.moves.dis7.Vector3Double;
import edu.nps.moves.dis7.Vector3Float;

/**
* Dis6DeadReckoner
* <br>
* DIS v6 Dead Reckoning algorithm
* @author Alessio Matricardi
*/
public final class Dis6DeadReckoner extends AbstractDeadReckoner<EntityStatePdu> {
@Override
protected DeadReckoningEntity convertToDeadReckoningEntity(EntityStatePdu entityStatePdu) {
DeadReckoningEntity toReturn = new DeadReckoningEntity();
// timestamp
toReturn.setTimestamp(entityStatePdu.getTimestamp());
// dead reckoning algorithm
toReturn.setDeadReckoningAlgorithm(entityStatePdu.getDeadReckoningParameters().getDeadReckoningAlgorithm());
// entity location
toReturn.setLocation(new Vector3Double());
toReturn.getLocation().setX(entityStatePdu.getEntityLocation().getX());
toReturn.getLocation().setY(entityStatePdu.getEntityLocation().getY());
toReturn.getLocation().setZ(entityStatePdu.getEntityLocation().getZ());
// entity orientation
toReturn.setEntityOrientation(new Orientation());
toReturn.getEntityOrientation().setPhi(entityStatePdu.getEntityOrientation().getPhi());
toReturn.getEntityOrientation().setTheta(entityStatePdu.getEntityOrientation().getTheta());
toReturn.getEntityOrientation().setPsi(entityStatePdu.getEntityOrientation().getPsi());
// entity linear velocity
toReturn.setLinearVelocity(new Vector3Float());
toReturn.getLinearVelocity().setX(entityStatePdu.getEntityLinearVelocity().getX());
toReturn.getLinearVelocity().setY(entityStatePdu.getEntityLinearVelocity().getY());
toReturn.getLinearVelocity().setZ(entityStatePdu.getEntityLinearVelocity().getZ());
// entity linear acceleration (from dead reckoning parameters)
toReturn.setLinearAcceleration(new Vector3Float());
toReturn.getLinearAcceleration().setX(entityStatePdu.getDeadReckoningParameters().getEntityLinearAcceleration().getX());
toReturn.getLinearAcceleration().setY(entityStatePdu.getDeadReckoningParameters().getEntityLinearAcceleration().getY());
toReturn.getLinearAcceleration().setZ(entityStatePdu.getDeadReckoningParameters().getEntityLinearAcceleration().getZ());
// entity angular velocity (from dead reckoning parameters)
toReturn.setAngularVelocity(new Vector3Float());
toReturn.getAngularVelocity().setX(entityStatePdu.getDeadReckoningParameters().getEntityAngularVelocity().getX());
toReturn.getAngularVelocity().setY(entityStatePdu.getDeadReckoningParameters().getEntityAngularVelocity().getY());
toReturn.getAngularVelocity().setZ(entityStatePdu.getDeadReckoningParameters().getEntityAngularVelocity().getZ());
return toReturn;
}

@Override
protected void copyParametersToEntityState(DeadReckoningEntity source, EntityStatePdu target) {
// timestamp
target.setTimestamp(source.getTimestamp());
// entity location
target.getEntityLocation().setX(source.getLocation().getX());
target.getEntityLocation().setY(source.getLocation().getY());
target.getEntityLocation().setZ(source.getLocation().getZ());
// entity orientation
target.getEntityOrientation().setPhi(source.getEntityOrientation().getPhi());
target.getEntityOrientation().setTheta(source.getEntityOrientation().getTheta());
target.getEntityOrientation().setPsi(source.getEntityOrientation().getPsi());
// entity linear velocity
target.getEntityLinearVelocity().setX(source.getLinearVelocity().getX());
target.getEntityLinearVelocity().setY(source.getLinearVelocity().getY());
target.getEntityLinearVelocity().setZ(source.getLinearVelocity().getZ());
// entity linear acceleration (from dead reckoning parameters)
target.getDeadReckoningParameters().getEntityLinearAcceleration().setX(source.getLinearAcceleration().getX());
target.getDeadReckoningParameters().getEntityLinearAcceleration().setY(source.getLinearAcceleration().getY());
target.getDeadReckoningParameters().getEntityLinearAcceleration().setZ(source.getLinearAcceleration().getZ());
}

@Override
protected void processArticulatedParameters(EntityStatePdu entityStatePdu, double deltaTime) {
// Process articulation parameters
for (ArticulationParameter thisRate : entityStatePdu.getArticulationParameters()) { // update articulation parameter values
if (thisRate.getParameterType() % 2 == 0) { // found a rate (even type)
// Search for the corresponding art. part value parameter
for (ArticulationParameter thisVal : entityStatePdu.getArticulationParameters()) {
if (thisVal.getParameterType() == thisRate.getParameterType() - 1 &&
thisVal.getPartAttachedTo() == thisRate.getPartAttachedTo()) { // found part's value
thisVal.setParameterValue(
getParameterValue(
deltaTime,
thisVal.getParameterType() % 32,
thisVal.getParameterValue(),
thisVal.getParameterValueFirstSubfield(),
thisRate.getParameterValue()
)
);
break; // exit the value search loop
} // end of found the corresponding value
} // end value search
} // end of found a rate
} // end update articulation parameter values
}
}
108 changes: 108 additions & 0 deletions src/main/java/edu/nps/moves/deadreckoning/Dis7DeadReckoner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package edu.nps.moves.deadreckoning;

import edu.nps.moves.dis7.ArticulatedParts;
import edu.nps.moves.dis7.EntityStatePdu;
import edu.nps.moves.dis7.Orientation;
import edu.nps.moves.dis7.VariableParameter;
import edu.nps.moves.dis7.Vector3Double;
import edu.nps.moves.dis7.Vector3Float;

/**
* Dis7DeadReckoner
* <br>
* DIS v7 Dead Reckoning algorithm
* @author Alessio Matricardi
*/
public final class Dis7DeadReckoner extends AbstractDeadReckoner<EntityStatePdu> {
@Override
protected DeadReckoningEntity convertToDeadReckoningEntity(EntityStatePdu entityStatePdu) {
DeadReckoningEntity toReturn = new DeadReckoningEntity();
// timestamp
toReturn.setTimestamp(entityStatePdu.getTimestamp());
// dead reckoning algorithm
toReturn.setDeadReckoningAlgorithm(entityStatePdu.getDeadReckoningParameters().getDeadReckoningAlgorithm());
// entity location
toReturn.setLocation(new Vector3Double());
toReturn.getLocation().setX(entityStatePdu.getEntityLocation().getX());
toReturn.getLocation().setY(entityStatePdu.getEntityLocation().getY());
toReturn.getLocation().setZ(entityStatePdu.getEntityLocation().getZ());
// entity orientation
toReturn.setEntityOrientation(new Orientation());
toReturn.getEntityOrientation().setPhi(entityStatePdu.getEntityOrientation().getPhi());
toReturn.getEntityOrientation().setTheta(entityStatePdu.getEntityOrientation().getTheta());
toReturn.getEntityOrientation().setPsi(entityStatePdu.getEntityOrientation().getPsi());
// entity linear velocity
toReturn.setLinearVelocity(new Vector3Float());
toReturn.getLinearVelocity().setX(entityStatePdu.getEntityLinearVelocity().getX());
toReturn.getLinearVelocity().setY(entityStatePdu.getEntityLinearVelocity().getY());
toReturn.getLinearVelocity().setZ(entityStatePdu.getEntityLinearVelocity().getZ());
// entity linear acceleration (from dead reckoning parameters)
toReturn.setLinearAcceleration(new Vector3Float());
toReturn.getLinearAcceleration().setX(entityStatePdu.getDeadReckoningParameters().getEntityLinearAcceleration().getX());
toReturn.getLinearAcceleration().setY(entityStatePdu.getDeadReckoningParameters().getEntityLinearAcceleration().getY());
toReturn.getLinearAcceleration().setZ(entityStatePdu.getDeadReckoningParameters().getEntityLinearAcceleration().getZ());
// entity angular velocity (from dead reckoning parameters)
toReturn.setAngularVelocity(new Vector3Float());
toReturn.getAngularVelocity().setX(entityStatePdu.getDeadReckoningParameters().getEntityAngularVelocity().getX());
toReturn.getAngularVelocity().setY(entityStatePdu.getDeadReckoningParameters().getEntityAngularVelocity().getY());
toReturn.getAngularVelocity().setZ(entityStatePdu.getDeadReckoningParameters().getEntityAngularVelocity().getZ());
return toReturn;
}

@Override
protected void copyParametersToEntityState(DeadReckoningEntity source, EntityStatePdu target) {
// timestamp
target.setTimestamp(source.getTimestamp());
// entity location
target.getEntityLocation().setX(source.getLocation().getX());
target.getEntityLocation().setY(source.getLocation().getY());
target.getEntityLocation().setZ(source.getLocation().getZ());
// entity orientation
target.getEntityOrientation().setPhi(source.getEntityOrientation().getPhi());
target.getEntityOrientation().setTheta(source.getEntityOrientation().getTheta());
target.getEntityOrientation().setPsi(source.getEntityOrientation().getPsi());
// entity linear velocity
target.getEntityLinearVelocity().setX(source.getLinearVelocity().getX());
target.getEntityLinearVelocity().setY(source.getLinearVelocity().getY());
target.getEntityLinearVelocity().setZ(source.getLinearVelocity().getZ());
// entity linear acceleration (from dead reckoning parameters)
target.getDeadReckoningParameters().getEntityLinearAcceleration().setX(source.getLinearAcceleration().getX());
target.getDeadReckoningParameters().getEntityLinearAcceleration().setY(source.getLinearAcceleration().getY());
target.getDeadReckoningParameters().getEntityLinearAcceleration().setZ(source.getLinearAcceleration().getZ());
}

@Override
protected void processArticulatedParameters(EntityStatePdu entityStatePdu, double deltaTime) {
// Process articulation parameters
for (VariableParameter thisRateGeneric : entityStatePdu.getVariableParameters()) { // update articulation parameter values
if (thisRateGeneric instanceof ArticulatedParts) {
ArticulatedParts thisRate = (ArticulatedParts) thisRateGeneric;
if (thisRate.getParameterType() % 2 != 0) {
continue;
}
// found a rate (even type)
// Search for the corresponding art. part value parameter
for (VariableParameter thisValGeneric : entityStatePdu.getVariableParameters()) {
if (thisValGeneric instanceof ArticulatedParts) {
ArticulatedParts thisVal = (ArticulatedParts) thisValGeneric;
if (thisVal.getParameterType() != thisRate.getParameterType() - 1 ||
thisVal.getPartAttachedTo() != thisRate.getPartAttachedTo()) {
continue;
}
// found part's value
thisVal.setParameterValue(
Double.valueOf(getParameterValue(
deltaTime,
(int) thisVal.getParameterType() % 32,
thisVal.getParameterValue(),
thisVal.getParameterValue(),
thisRate.getParameterValue()
)).floatValue()
);
break; // exit the value search loop
} // end of found the corresponding value
} // end value search
} // end of found a rate
} // end update articulation parameter values
}
}
20 changes: 20 additions & 0 deletions src/main/java/edu/nps/moves/deadreckoning/IDeadReckoner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package edu.nps.moves.deadreckoning;

/**
* IDeadReckoner
* <br>
* Provides the signature of Dead Reckoning algorithm
*
* @author Alessio Matricardi
*/
public interface IDeadReckoner<T> {

/**
* Perform the Dead Reckoning algorithm on {@code entityStatePdu}
*
* @param entityStatePdu the PDU
* @param deltaTime the time increment for the dead reckoning step
*/
void performDeadReckoning(T entityStatePdu, double deltaTime);

}
4 changes: 2 additions & 2 deletions src/main/java/edu/nps/moves/dis/EntityStatePdu.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class EntityStatePdu extends EntityInformationFamilyPdu implements Serial
* a series of bit flags that are used to help draw the entity, such as
* smoking, on fire, etc.
*/
protected int entityAppearance;
protected int entityAppearance = 0;

/**
* parameters used for dead reckoning
Expand All @@ -72,7 +72,7 @@ public class EntityStatePdu extends EntityInformationFamilyPdu implements Serial
/**
* a series of bit flags
*/
protected int capabilities;
protected int capabilities = 0;

/**
* variable length list of articulation parameters
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/nps/moves/dis7/EntityStatePdu.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class EntityStatePdu extends EntityInformationFamilyPdu implements Serial
* a series of bit flags that are used to help draw the entity, such as
* smoking, on fire, etc.
*/
protected long entityAppearance;
protected long entityAppearance = 0;

/**
* parameters used for dead reckoning
Expand All @@ -73,7 +73,7 @@ public class EntityStatePdu extends EntityInformationFamilyPdu implements Serial
/**
* a series of bit flags
*/
protected long capabilities;
protected long capabilities = 0;

/**
* variable length list of variable parameters. In earlier DIS versions this
Expand Down