forked from sensiasoft/sensorhub
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v2' of https://github.com/opensensorhub/osh-core into v2
- Loading branch information
Showing
11 changed files
with
297 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
sensorhub-core/src/main/java/org/sensorhub/impl/sensor/DefaultOrientationOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/***************************** BEGIN LICENSE BLOCK *************************** | ||
The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
If a copy of the MPL was not distributed with this file, You can obtain one | ||
at http://mozilla.org/MPL/2.0/. | ||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
for the specific language governing rights and limitations under the License. | ||
Copyright (C) 2024 Botts Innovative Research Inc. All Rights Reserved. | ||
******************************* END LICENSE BLOCK ***************************/ | ||
package org.sensorhub.impl.sensor; | ||
|
||
import net.opengis.swe.v20.DataComponent; | ||
import net.opengis.swe.v20.DataEncoding; | ||
import org.sensorhub.api.sensor.ISensorDriver; | ||
|
||
/** | ||
* Default orientation output for sensor drivers outputting their own orientation. | ||
*/ | ||
public abstract class DefaultOrientationOutput extends AbstractSensorOutput<ISensorDriver> { | ||
protected DataComponent outputStruct; | ||
DataEncoding outputEncoding; | ||
protected double updatePeriod; | ||
|
||
protected DefaultOrientationOutput(ISensorDriver parentSensor, double updatePeriod) { | ||
super(AbstractSensorModule.ORIENTATION_OUTPUT_NAME, parentSensor); | ||
this.updatePeriod = updatePeriod; | ||
} | ||
|
||
@Override | ||
public DataComponent getRecordDescription() { | ||
return outputStruct; | ||
} | ||
|
||
@Override | ||
public DataEncoding getRecommendedEncoding() { | ||
return outputEncoding; | ||
} | ||
|
||
@Override | ||
public double getAverageSamplingPeriod() { | ||
return updatePeriod; | ||
} | ||
|
||
/** | ||
* Update the orientation output with the given heading, pitch, and roll angles. | ||
* | ||
* @param time The time of the orientation update. | ||
* @param heading The heading angle in degrees. | ||
* @param pitch The pitch angle in degrees. | ||
* @param roll The roll angle in degrees. | ||
* @param forceUpdate If true, the orientation will be updated even if the angles have not changed. | ||
*/ | ||
public abstract void updateOrientation(double time, double heading, double pitch, double roll, boolean forceUpdate); | ||
} |
63 changes: 63 additions & 0 deletions
63
sensorhub-core/src/main/java/org/sensorhub/impl/sensor/DefaultOrientationOutputEuler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/***************************** BEGIN LICENSE BLOCK *************************** | ||
The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
If a copy of the MPL was not distributed with this file, You can obtain one | ||
at http://mozilla.org/MPL/2.0/. | ||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
for the specific language governing rights and limitations under the License. | ||
Copyright (C) 2012-2015 Sensia Software LLC. All Rights Reserved. | ||
******************************* END LICENSE BLOCK ***************************/ | ||
package org.sensorhub.impl.sensor; | ||
|
||
import net.opengis.swe.v20.DataBlock; | ||
import org.sensorhub.api.data.DataEvent; | ||
import org.sensorhub.api.sensor.ISensorDriver; | ||
import org.vast.swe.SWEConstants; | ||
import org.vast.swe.helper.GeoPosHelper; | ||
|
||
/** | ||
* Default orientation output with heading, pitch, and roll angles. | ||
*/ | ||
public class DefaultOrientationOutputEuler extends DefaultOrientationOutput { | ||
public DefaultOrientationOutputEuler(ISensorDriver parentSensor, String sensorFrameID, double updatePeriod) { | ||
super(parentSensor, updatePeriod); | ||
|
||
GeoPosHelper fac = new GeoPosHelper(); | ||
|
||
outputStruct = fac.createRecord() | ||
.label("Sensor Orientation") | ||
.addSamplingTimeIsoUTC("time") | ||
.addField("orientation", fac.createVector() | ||
.from(fac.newEulerOrientationNED(SWEConstants.DEF_SENSOR_ORIENT)) | ||
.localFrame('#' + sensorFrameID)) | ||
.build(); | ||
|
||
outputStruct.setName(getName()); | ||
outputStruct.setId(AbstractSensorModule.ORIENTATION_OUTPUT_ID); | ||
outputEncoding = fac.newTextEncoding(); | ||
} | ||
|
||
@Override | ||
public void updateOrientation(double time, double heading, double pitch, double roll, boolean forceUpdate) { | ||
// Build new DataBlock | ||
DataBlock dataBlock = (latestRecord == null) ? outputStruct.createDataBlock() : latestRecord.renew(); | ||
dataBlock.setDoubleValue(0, time); | ||
dataBlock.setDoubleValue(1, heading); | ||
dataBlock.setDoubleValue(2, pitch); | ||
dataBlock.setDoubleValue(3, roll); | ||
|
||
var changed = forceUpdate || latestRecord == null || | ||
latestRecord.getDoubleValue(1) != dataBlock.getDoubleValue(1) || | ||
latestRecord.getDoubleValue(2) != dataBlock.getDoubleValue(2) || | ||
latestRecord.getDoubleValue(3) != dataBlock.getDoubleValue(3); | ||
|
||
// If the location has actually changed, update the latest record and send event | ||
if (changed) { | ||
latestRecord = dataBlock; | ||
latestRecordTime = System.currentTimeMillis(); | ||
eventHandler.publish(new DataEvent(latestRecordTime, this, dataBlock)); | ||
} | ||
} | ||
} |
Oops, something went wrong.