Skip to content

Commit

Permalink
Fix Detected Object class (#178)
Browse files Browse the repository at this point in the history
<!-- Thanks for the contribution, this is awesome. -->

# PR Details
## Description
Fix Detected Object class to include timestamp
<!--- Describe your changes in detail -->

## Related GitHub Issue

<!--- This project only accepts pull requests related to open GitHub
issues or Jira Keys -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please DO NOT name partially fixed issues, instead open an issue
specific to this fix -->
<!--- Please link to the issue here: -->

## Related Jira Key
[CDAR-446
](https://usdot-carma.atlassian.net/browse/CDAR-446)<!-- e.g. CAR-123
-->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
Unit testing 
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [x] Defect fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that cause existing functionality
to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] I have added any new packages to the sonar-scanner.properties file
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the
[**CONTRIBUTING**](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/Contributing.md)
document.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.
  • Loading branch information
paulbourelly999 authored Nov 22, 2023
1 parent 5b7237d commit fcd09a3
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public void processTimeAdvanceGrant() throws InternalFederateException, NoSuchFi
CartesianPoint.xyz(-1.1, -2, -3.2),
new Vector3d(1, 1, 1),
new Vector3d(.1, .2, .3),
new Size(2, 1, .5));
new Size(2, 1, .5),
100);
Double[][] covarianceMatrix = { {1.0, 0.0, 0.0} , {1.0, 0.0, 0.0} , {1.0, 0.0, 0.0}};
predictedCar.setPositionCovariance(covarianceMatrix);
predictedCar.setVelocityCovariance(covarianceMatrix);
Expand All @@ -151,7 +152,8 @@ public void processTimeAdvanceGrant() throws InternalFederateException, NoSuchFi
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(0, 0, 0),
new Vector3d(),
new Size(0, 0, 0));
new Size(0, 0, 0),
100);
Double[][] bus_covarianceMatrix = { {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0}};
predictedBus.setPositionCovariance(bus_covarianceMatrix);
predictedBus.setVelocityCovariance(bus_covarianceMatrix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public void testGetDetectedObjects() throws XmlRpcException {
+ "\"length\":2.0,"
+ "\"height\":1.0,"
+ "\"width\":0.5"
+ "}"
+ "},"
+ "\"timestamp\":100"
+ "},"
+ "{"
+ "\"type\":\"BUS\","
Expand Down Expand Up @@ -142,7 +143,8 @@ public void testGetDetectedObjects() throws XmlRpcException {
+ "\"length\":0.0,"
+ "\"height\":0.0,"
+ "\"width\":0.0"
+ "}"
+ "},"
+ "\"timestamp\":100"
+ "}"
+ "]";
// Create request params
Expand All @@ -165,7 +167,8 @@ public void testGetDetectedObjects() throws XmlRpcException {
CartesianPoint.xyz(-1.1, -2, -3.2),
new Vector3d(1, 1, 1),
new Vector3d(.1, .2, .3),
new Size(2, 1, .5));
new Size(2, 1, .5),
100);
Double[][] covarianceMatrix = { {1.0, 0.0, 0.0} , {1.0, 0.0, 0.0} , {1.0, 0.0, 0.0}};
predictedCar.setPositionCovariance(covarianceMatrix);
predictedCar.setVelocityCovariance(covarianceMatrix);
Expand All @@ -181,7 +184,8 @@ public void testGetDetectedObjects() throws XmlRpcException {
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(0, 0, 0),
new Vector3d(),
new Size(0, 0, 0));
new Size(0, 0, 0),
100);
Double[][] bus_covarianceMatrix = { {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0}};
predictedBus.setPositionCovariance(bus_covarianceMatrix);
predictedBus.setVelocityCovariance(bus_covarianceMatrix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public void testOnDetectedObject() throws IOException{
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(2, 3, 4),
new Vector3d(-4.4,-5.5,-6.6),
new Size(3, 4, 5));
new Size(3, 4, 5),
100);
Double[][] covarianceMatrix = { {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0}};
detectedObject1.setPositionCovariance(covarianceMatrix);
detectedObject1.setVelocityCovariance(covarianceMatrix);
Expand All @@ -152,7 +153,8 @@ public void testOnDetectedObject() throws IOException{
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(2, 3, 4),
new Vector3d(-4.4,-5.5,-6.6),
new Size(3, 4, 5));
new Size(3, 4, 5),
100);
detectedObject2.setPositionCovariance(covarianceMatrix);
detectedObject2.setVelocityCovariance(covarianceMatrix);
detectedObject2.setAngularVelocityCovariance(covarianceMatrix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public void testSendInteraction() throws IOException {
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(0, 0, 0),
new Vector3d(),
new Size(0, 0, 0));
new Size(0, 0, 0),
100);
Double[][] covarianceMatrix = { {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0}};
test_msg.setPositionCovariance(covarianceMatrix);
test_msg.setVelocityCovariance(covarianceMatrix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ public void testProcessInteraction() throws InternalFederateException{
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(2, 3, 4),
new Vector3d(-4.4,-5.5,-6.6),
new Size(3, 4, 5));
new Size(3, 4, 5),
100);
Double[][] covarianceMatrix = { {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0}};
detectedObject.setPositionCovariance(covarianceMatrix);
detectedObject.setVelocityCovariance(covarianceMatrix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void testGetterSetterConstructor() {
CartesianPoint.xyz(-1.1, -2, -3.2),
new Vector3d(1, 1, 1),
new Vector3d(.1, .2, .3),
new Size(2, 1, .5));
new Size(2, 1, .5),
100);
Double[][] covarianceMatrix = { {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0}};
detectedObject.setPositionCovariance(covarianceMatrix);
detectedObject.setVelocityCovariance(covarianceMatrix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public final class DetectedObject implements Serializable {
private Double[][] angularVelocityCovariance = new Double[3][3];

private Size size;

private int timestamp;
/**
* Constructor for Detected Object information.
*
Expand All @@ -66,7 +68,7 @@ public final class DetectedObject implements Serializable {
* @param size size of object including height,width and length.
*/
public DetectedObject(DetectionType type, double confidence, String sensorId, String projString, String objectId,
CartesianPoint position, Vector3d velocity, Vector3d angularVelocity, Size size) {
CartesianPoint position, Vector3d velocity, Vector3d angularVelocity, Size size, int timestamp) {
this.type = type;
this.confidence = confidence;
this.sensorId = sensorId;
Expand All @@ -76,6 +78,7 @@ public DetectedObject(DetectionType type, double confidence, String sensorId, St
this.velocity = velocity;
this.angularVelocity = angularVelocity;
this.size = size;
this.timestamp = timestamp;
}

/**
Expand Down Expand Up @@ -248,6 +251,14 @@ public void setSize(Size size) {
this.size = size;
}

public int getTimestamp() {
return timestamp;
}

public void setTimestamp(int timestamp) {
this.timestamp = timestamp;
}

@Override
public int hashCode() {
final int prime = 31;
Expand All @@ -266,6 +277,7 @@ public int hashCode() {
result = prime * result + ((angularVelocity == null) ? 0 : angularVelocity.hashCode());
result = prime * result + Arrays.deepHashCode(angularVelocityCovariance);
result = prime * result + ((size == null) ? 0 : size.hashCode());
result = prime * result + timestamp;
return result;
}

Expand Down Expand Up @@ -323,9 +335,7 @@ public boolean equals(Object obj) {
return false;
} else if (!size.equals(other.size))
return false;
if (timestamp != other.timestamp)
return false;
return true;
}



}
}}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void testDetectObjectJsonSerialization() {
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(0, 0, 0),
new Vector3d(),
new Size(0, 0, 0));
new Size(0, 0, 0),
100);
Double[][] covarianceMatrix = { {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0}};
detectedObject.setPositionCovariance(covarianceMatrix);
detectedObject.setVelocityCovariance(covarianceMatrix);
Expand Down Expand Up @@ -83,11 +84,10 @@ public void testDetectObjectJsonSerialization() {
+ "\"length\":0.0,"
+ "\"height\":0.0,"
+ "\"width\":0.0"
+ "}"
+ "},"
+ "\"timestamp\":100"
+ "}";
assertEquals(json,
json_prediction);
System.out.println(json);
assertEquals(json_prediction,json);
}

@Test
Expand Down Expand Up @@ -125,7 +125,8 @@ public void testDetectObjectJsonDeserialization() {
+ "\"length\":2.0,"
+ "\"height\":1.0,"
+ "\"width\":0.5"
+ "}"
+ "},"
+ "\"timestamp\":100"
+ "}";

DetectedObject detectedObject = gson.fromJson(json, DetectedObject.class);
Expand All @@ -138,7 +139,8 @@ public void testDetectObjectJsonDeserialization() {
CartesianPoint.xyz(-1.1, -2, -3.2),
new Vector3d(1, 1, 1),
new Vector3d(.1, .2, .3),
new Size(2, 1, .5));
new Size(2, 1, .5),
100);
Double[][] covarianceMatrix = { {1.0, 0.0, 0.0} , {1.0, 0.0, 0.0} , {1.0, 0.0, 0.0}};
predictedDetectedObject.setPositionCovariance(covarianceMatrix);
predictedDetectedObject.setVelocityCovariance(covarianceMatrix);
Expand All @@ -159,7 +161,8 @@ public void testGetterSetterConstructor() {
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(2, 3, 4),
new Vector3d(-4.4,-5.5,-6.6),
new Size(3, 4, 5));
new Size(3, 4, 5),
0);
Double[][] covarianceMatrix = { {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0}};
detectedObject.setPositionCovariance(covarianceMatrix);
detectedObject.setVelocityCovariance(covarianceMatrix);
Expand Down Expand Up @@ -192,7 +195,8 @@ public void testEquals() {
CartesianPoint.xyz(1.1, 2, 3.2),
new Vector3d(2, 3, 4),
new Vector3d(-4.4,-5.5,-6.6),
new Size(3, 4, 5));
new Size(3, 4, 5),
100);
Double[][] covarianceMatrix = { {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0} , {0.0, 0.0, 0.0}};
detectedObject.setPositionCovariance(covarianceMatrix);
detectedObject.setVelocityCovariance(covarianceMatrix);
Expand All @@ -207,7 +211,8 @@ public void testEquals() {
null,
null,
null,
null);
null,
100);
DetectedObject detectedObject2 = new DetectedObject(
null,
0.6,
Expand All @@ -217,7 +222,8 @@ public void testEquals() {
null,
null,
null,
null);
null,
100);

assertNotEquals(detectedObject1, detectedObject);
assertEquals(detectedObject2, detectedObject1);
Expand Down

0 comments on commit fcd09a3

Please sign in to comment.