|
| 1 | + |
| 2 | +""" |
| 3 | + result = SensorResult(; object, objectOrigin, objectCoordinateRef, objectObserveRef) |
| 4 | +
|
| 5 | +Return a `result` providing kinematic measurements of |
| 6 | +`object::`[`Object3D`](@ref) relative to |
| 7 | +`objectOrigin::`[`Object3D`](@ref), resolved in coordinates of |
| 8 | +`objectCoordinateRef::`[`Object3D`](@ref) and observed in |
| 9 | +`objectObserveRef::`[`Object3D`](@ref). |
| 10 | +
|
| 11 | +In case of `objectOrigin` is undefined, world is used as sensor |
| 12 | +origin, i.e. results are absolute measurements. In case of |
| 13 | +`objectCoordinateRef` is undefined, `objectOrigin` is used as coordinate |
| 14 | +reference frame. In case of `objectObserveRef = nothing`, |
| 15 | +`objectCoordinateRef` is used as observer reference frame (so that |
| 16 | +velocity and acceleration results are consistent time derivatives of |
| 17 | +position results). |
| 18 | +
|
| 19 | +# Results |
| 20 | +- `translation` is the position vector from `objectOrigin` to `object`. |
| 21 | +- `velocity` is the translational velocity vector from `objectOrigin` to `object`, observed in `objectObserveRef`. |
| 22 | +- `acceleration` is the translational acceleration vector from `objectOrigin` to `object`, observed in `objectObserveRef`. |
| 23 | +- `rotation` contains the [Cardan (Tait–Bryan) angles](https://en.wikipedia.org/wiki/Euler_angles#Chained_rotations_equivalence) (rotation sequence x-y-z) from `objectOrigin` to `object`. |
| 24 | +- `angularVelocity` is the rotational velocity vector from `objectOrigin` to `object`. |
| 25 | +- `angularAcceleration` is the rotational acceleration vector from `objectOrigin` to `object`, observed in `objectObserveRef`. |
| 26 | +- `distance` is the point-to-point distance between `objectOrigin` and `object`. |
| 27 | +- `distanceVelocity` is the point-to-point velocity between `objectOrigin` and `object`. |
| 28 | +- `distanceAcceleration` is the point-to-point acceleration between `objectOrigin` and `object`. |
| 29 | +""" |
| 30 | +mutable struct SensorResult{F <: Modia3D.VarFloatType} <: Modia3D.AbstractResultElement |
| 31 | + |
| 32 | + path::String |
| 33 | + |
| 34 | + object::Object3D{F} |
| 35 | + objectOrigin::Union{Object3D{F}, Nothing} |
| 36 | + objectCoordinateRef::Union{Object3D{F}, Nothing} |
| 37 | + objectObserveRef::Union{Object3D{F}, Nothing} |
| 38 | + |
| 39 | + translationResultIndex::Int |
| 40 | + velocityResultIndex::Int |
| 41 | + accelerationResultIndex::Int |
| 42 | + rotationResultIndex::Int |
| 43 | + angularVelocityResultIndex::Int |
| 44 | + angularAccelerationResultIndex::Int |
| 45 | + distanceResultIndex::Int |
| 46 | + distanceVelocityResultIndex::Int |
| 47 | + distanceAccelerationResultIndex::Int |
| 48 | + |
| 49 | + function SensorResult{F}(; path::String = "", |
| 50 | + object::Object3D{F}, |
| 51 | + objectOrigin::Union{Object3D{F}, Nothing}=nothing, |
| 52 | + objectCoordinateRef::Union{Object3D{F}, Nothing}=objectOrigin, |
| 53 | + objectObserveRef::Union{Object3D{F}, Nothing}=objectCoordinateRef ) where F <: Modia3D.VarFloatType |
| 54 | + return new(path, object, objectOrigin, objectCoordinateRef, objectObserveRef) |
| 55 | + end |
| 56 | +end |
| 57 | +SensorResult(; kwargs...) = SensorResult{Float64}(; kwargs...) |
| 58 | + |
| 59 | + |
| 60 | +function initializeResultElement(model::Modia.InstantiatedModel{F,TimeType}, result::SensorResult{F}) where {F <: Modia3D.VarFloatType, TimeType <: AbstractFloat} |
| 61 | + result.object.computeAcceleration = true |
| 62 | + if (!isnothing(result.objectOrigin)) |
| 63 | + result.objectOrigin.computeAcceleration = true |
| 64 | + end |
| 65 | + if (!isnothing(result.objectObserveRef)) |
| 66 | + result.objectObserveRef.computeAcceleration = true |
| 67 | + end |
| 68 | + |
| 69 | + result.translationResultIndex = Modia.new_w_segmented_variable!(model, result.path*".translation" , SVector{3,F}(0, 0, 0), "m") |
| 70 | + result.velocityResultIndex = Modia.new_w_segmented_variable!(model, result.path*".velocity" , SVector{3,F}(0, 0, 0), "m/s") |
| 71 | + result.accelerationResultIndex = Modia.new_w_segmented_variable!(model, result.path*".acceleration" , SVector{3,F}(0, 0, 0), "m/s^2") |
| 72 | + result.rotationResultIndex = Modia.new_w_segmented_variable!(model, result.path*".rotation" , SVector{3,F}(0, 0, 0), "rad") |
| 73 | + result.angularVelocityResultIndex = Modia.new_w_segmented_variable!(model, result.path*".angularVelocity" , SVector{3,F}(0, 0, 0), "rad/s") |
| 74 | + result.angularAccelerationResultIndex = Modia.new_w_segmented_variable!(model, result.path*".angularAcceleration" , SVector{3,F}(0, 0, 0), "rad/s^2") |
| 75 | + result.distanceResultIndex = Modia.new_w_segmented_variable!(model, result.path*".distance" , F(0) , "m") |
| 76 | + result.distanceVelocityResultIndex = Modia.new_w_segmented_variable!(model, result.path*".distanceVelocity" , F(0) , "m/s") |
| 77 | + result.distanceAccelerationResultIndex = Modia.new_w_segmented_variable!(model, result.path*".distanceAcceleration" , F(0) , "m/s^2") |
| 78 | + |
| 79 | + return nothing |
| 80 | +end |
| 81 | + |
| 82 | +function evaluateResultElement(model::Modia.InstantiatedModel{F,TimeType}, scene::Modia3D.Composition.Scene{F}, result::SensorResult{F}, time::TimeType) where {F <: Modia3D.VarFloatType, TimeType <: AbstractFloat} |
| 83 | + |
| 84 | + translation = measFramePosition(result.object; frameOrig=result.objectOrigin, frameCoord=result.objectCoordinateRef) |
| 85 | + velocity = measFrameTransVelocity(result.object; frameOrig=result.objectOrigin, frameCoord=result.objectCoordinateRef, frameObsrv=result.objectObserveRef) |
| 86 | + acceleration = measFrameTransAcceleration(result.object; frameOrig=result.objectOrigin, frameCoord=result.objectCoordinateRef, frameObsrv=result.objectObserveRef) |
| 87 | + rotationMatrix = measFrameRotation(result.object; frameOrig=result.objectOrigin) |
| 88 | + rotation = rot123fromR(rotationMatrix) |
| 89 | + angularVelocity = measFrameRotVelocity(result.object; frameOrig=result.objectOrigin, frameCoord=result.objectCoordinateRef) |
| 90 | + angularAcceleration = measFrameRotAcceleration(result.object; frameOrig=result.objectOrigin, frameCoord=result.objectCoordinateRef, frameObsrv=result.objectObserveRef) |
| 91 | + (distance, dir) = measFrameDistance(result.object; frameOrig=result.objectOrigin) |
| 92 | + distanceVelocity = measFrameDistVelocity(result.object; frameOrig=result.objectOrigin) |
| 93 | + distanceAcceleration = measFrameDistAcceleration(result.object; frameOrig=result.objectOrigin) |
| 94 | + |
| 95 | + Modia.copy_w_segmented_value_to_result(model, result.translationResultIndex, translation) |
| 96 | + Modia.copy_w_segmented_value_to_result(model, result.velocityResultIndex, velocity) |
| 97 | + Modia.copy_w_segmented_value_to_result(model, result.accelerationResultIndex, acceleration) |
| 98 | + Modia.copy_w_segmented_value_to_result(model, result.rotationResultIndex, rotation) |
| 99 | + Modia.copy_w_segmented_value_to_result(model, result.angularVelocityResultIndex, angularVelocity) |
| 100 | + Modia.copy_w_segmented_value_to_result(model, result.angularAccelerationResultIndex, angularAcceleration) |
| 101 | + Modia.copy_w_segmented_value_to_result(model, result.distanceResultIndex, distance) |
| 102 | + Modia.copy_w_segmented_value_to_result(model, result.distanceVelocityResultIndex, distanceVelocity) |
| 103 | + Modia.copy_w_segmented_value_to_result(model, result.distanceAccelerationResultIndex, distanceAcceleration) |
| 104 | + |
| 105 | + return nothing |
| 106 | +end |
| 107 | + |
| 108 | +function terminateResultElement(result::SensorResult{F}) where F <: Modia3D.VarFloatType |
| 109 | + return nothing |
| 110 | +end |
0 commit comments