add fixed time for spice translations, update insight asset to use (#1614)

* add fixed time for spice translations, update insight asset to use

* review cleanup
This commit is contained in:
Micah Acinapura
2021-05-30 13:09:58 -04:00
committed by GitHub
parent 8c870384fc
commit 6fc0a598e7
7 changed files with 258 additions and 98 deletions
@@ -60,33 +60,118 @@ local legDeployTime = "2018 NOV 26 19:43:06.68" -- entry + 243s
local landerSeperationTime = "2018 NOV 26 19:44:51.68" -- entry + 348s
local touchdownTime = "2018 NOV 26 19:45:32.68" -- entry + 389s
local panelDeployTime = "2018 NOV 26 19:45:33.68" -- entry + 390s
local foreverTime = "2018 NOV 26 20:17:50.68" -- entry + 2327s
local kernelTouchdownTime = "2018 NOV 26 19:45:32.3"
local spiceRotationEndTime = "2018 NOV 26 19:51:39"
local InsightParent = {
Identifier = "InsightParent",
Parent = "MarsBarycenter",
Transform = {
Translation = {
local TranslationKeyframes = {
['1850 JAN 01 00:00:00'] = {
Type = "SpiceTranslation",
Target = "INSIGHT",
Observer = "MARS",
Frame = "GALACTIC",
Kernels = iKernels
Frame = "IAU_MARS",
Kernels = iKernels,
FixedDate = '2018 NOV 26 19:39:03'
},
['2018 NOV 26 19:39:02'] = {
Type = "SpiceTranslation",
Target = "INSIGHT",
Observer = "MARS",
Frame = "IAU_MARS",
Kernels = iKernels,
FixedDate = '2018 NOV 26 19:39:03'
},
['2018 NOV 26 19:39:03'] = {
Type = "SpiceTranslation",
Target = "INSIGHT",
Observer = "MARS",
Frame = "IAU_MARS",
Kernels = iKernels
},
['2018 NOV 26 19:39:04'] = {
Type = "SpiceTranslation",
Target = "INSIGHT",
Observer = "MARS",
Frame = "IAU_MARS",
Kernels = iKernels
},
['2018 NOV 26 19:45:34'] = {
Type = "SpiceTranslation",
Target = "INSIGHT",
Observer = "MARS",
Frame = "IAU_MARS",
Kernels = iKernels
},
['2018 NOV 26 19:45:35'] = {
Type = "SpiceTranslation",
Target = "INSIGHT",
Observer = "MARS",
Frame = "IAU_MARS",
Kernels = iKernels,
FixedDate = '2018 NOV 26 19:45:34'
},
}
local RotationKeyframes = {
['1850 JAN 01 00:00:00'] = {
Type = "SpiceRotation",
SourceFrame = "INSIGHT_LANDER_CRUISE",
DestinationFrame = "IAU_MARS",
FixedDate = '2018 NOV 26 19:39:02',
Kernels = iKernels
},
['2018 NOV 26 19:39:02'] = {
Type = "SpiceRotation",
SourceFrame = "INSIGHT_LANDER_CRUISE",
DestinationFrame = "IAU_MARS",
FixedDate = '2018 NOV 26 19:39:02',
Kernels = iKernels
},
['2018 NOV 26 19:39:03'] = {
Type = "SpiceRotation",
SourceFrame = "INSIGHT_LANDER_CRUISE",
DestinationFrame = "IAU_MARS",
Kernels = iKernels
},
['2018 NOV 26 19:39:04'] = {
Type = "SpiceRotation",
SourceFrame = "INSIGHT_LANDER_CRUISE",
DestinationFrame = "IAU_MARS",
Kernels = iKernels
},
['2018 NOV 26 19:45:34'] = {
Type = "SpiceRotation",
SourceFrame = "INSIGHT_LANDER_CRUISE",
DestinationFrame = "IAU_MARS",
Kernels = iKernels
},
['2018 NOV 26 19:45:35'] = {
Type = "SpiceRotation",
SourceFrame = "INSIGHT_LANDER_CRUISE",
DestinationFrame = "IAU_MARS",
FixedDate = '2018 NOV 26 19:45:34'
},
}
local InsightParent = {
Identifier = "InsightParent",
Parent = "Mars",
Transform = {
Translation ={
Type = "TimelineTranslation",
Keyframes = TranslationKeyframes,
},
Rotation = {
Type = "SpiceRotation",
SourceFrame = "INSIGHT_LANDER_CRUISE",
DestinationFrame = "GALACTIC"
Type = "TimelineRotation",
Keyframes = RotationKeyframes,
}
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = spiceRotationEndTime
},
-- TimeFrame = {
-- Type = "TimeFrameInterval",
-- Start = entryTimeStart,
-- End = spiceRotationEndTime
-- },
GUI = {
Hidden = true,
Name = "InsightParent",
@@ -121,7 +206,6 @@ local Insight_Entry_CapsuleA = {
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = landerSeperationTime
},
GUI = {
@@ -142,7 +226,6 @@ local Insight_Entry_Capsule_Ring = {
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = landerSeperationTime
},
GUI = {
@@ -163,7 +246,6 @@ local Insight_Entry_Capsule_Plugs = {
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = landerSeperationTime
},
GUI = {
@@ -184,7 +266,6 @@ local Insight_Entry_Heatshield = {
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = heatShieldSeperationTime
},
GUI = {
@@ -329,11 +410,6 @@ local Insight_Lander_A001 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander A001",
@@ -350,11 +426,6 @@ local Insight_Lander_A002 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander A002",
@@ -371,11 +442,6 @@ local Insight_Lander_A003 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander A003",
@@ -392,11 +458,6 @@ local Insight_Lander_A004 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander A004",
@@ -413,11 +474,6 @@ local Insight_Lander_A005 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander A005",
@@ -434,11 +490,6 @@ local Insight_Lander_A006 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander A006",
@@ -455,11 +506,6 @@ local Insight_Lander_A007 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander A007",
@@ -476,11 +522,6 @@ local Insight_Lander_A008 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander A008",
@@ -497,11 +538,6 @@ local Insight_Lander_foil1 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander foil",
@@ -518,11 +554,6 @@ local Insight_Lander_Tex01 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander Tex01",
@@ -539,11 +570,6 @@ local Insight_Lander_Tex02 = {
ModelTransform = RotationMatrix,
LightSources = LightSources,
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight Lander Tex02",
@@ -605,7 +631,6 @@ local Insight_Legs_Deployed_tex = {
TimeFrame = {
Type = "TimeFrameInterval",
Start = legDeployTime,
End = foreverTime
},
GUI = {
Hidden = true,
@@ -626,7 +651,6 @@ local Insight_Legs_Deployed_AO06 = {
TimeFrame = {
Type = "TimeFrameInterval",
Start = legDeployTime,
End = foreverTime
},
GUI = {
Hidden = true,
@@ -644,11 +668,6 @@ local Insight_Panels_Stowed_tex = {
ModelTransform = RotationMatrix,
LightSources = LightSources
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight panels_stow_tex",
@@ -665,11 +684,6 @@ local Insight_Panels_Stowed_tex2 = {
ModelTransform = RotationMatrix,
LightSources = LightSources
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight panels_stow_tex2",
@@ -686,11 +700,6 @@ local Insight_Panels_Stowed_AO01 = {
ModelTransform = RotationMatrix,
LightSources = LightSources
},
TimeFrame = {
Type = "TimeFrameInterval",
Start = entryTimeStart,
End = foreverTime
},
GUI = {
Hidden = true,
Name = "Insight panels_stow_AO",
@@ -710,7 +719,6 @@ local Insight_Panels_Deployed_tex = {
TimeFrame = {
Type = "TimeFrameInterval",
Start = panelDeployTime,
End = foreverTime
},
GUI = {
Hidden = true,
@@ -731,7 +739,6 @@ local Insight_Panels_Deployed_tex2 = {
TimeFrame = {
Type = "TimeFrameInterval",
Start = panelDeployTime,
End = foreverTime
},
GUI = {
Hidden = true,
@@ -752,7 +759,6 @@ local Insight_Panels_Deployed_AO06 = {
TimeFrame = {
Type = "TimeFrameInterval",
Start = panelDeployTime,
End = foreverTime
},
GUI = {
Hidden = true,
+29 -1
View File
@@ -52,6 +52,13 @@ namespace {
"The time frame in which the spice kernels are valid."
};
constexpr openspace::properties::Property::PropertyInfo FixedDateInfo = {
"FixedDate",
"Fixed Date",
"A time to lock the rotation to. Setting this to an empty string will "
"unlock the time and return to rotation based on current simulation time."
};
struct [[codegen::Dictionary(SpiceRotation)]] Parameters {
// [[codegen::verbatim(SourceInfo.description)]]
std::string sourceFrame
@@ -66,6 +73,10 @@ namespace {
// [[codegen::verbatim(TimeFrameInfo.description)]]
std::optional<ghoul::Dictionary> timeFrame
[[codegen::reference("core_time_frame")]];
// [[codegen::verbatim(FixedDateInfo.description)]]
std::optional<std::string> fixedDate
[[codegen::annotation("A time to lock the rotation to")]];
};
#include "spicerotation_codegen.cpp"
} // namespace
@@ -79,6 +90,7 @@ documentation::Documentation SpiceRotation::Documentation() {
SpiceRotation::SpiceRotation(const ghoul::Dictionary& dictionary)
: _sourceFrame(SourceInfo)
, _destinationFrame(DestinationInfo)
, _fixedDate(FixedDateInfo)
{
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -96,6 +108,17 @@ SpiceRotation::SpiceRotation(const ghoul::Dictionary& dictionary)
}
}
_fixedDate.onChange([this]() {
if (_fixedDate.value().empty()) {
_fixedEphemerisTime = std::nullopt;
}
else {
_fixedEphemerisTime = SpiceManager::ref().ephemerisTimeFromDate(_fixedDate);
}
});
_fixedDate = p.fixedDate.value_or(_fixedDate);
addProperty(_fixedDate);
if (dictionary.hasKey(TimeFrameInfo.identifier)) {
ghoul::Dictionary timeFrameDictionary =
dictionary.value<ghoul::Dictionary>(TimeFrameInfo.identifier);
@@ -111,16 +134,21 @@ SpiceRotation::SpiceRotation(const ghoul::Dictionary& dictionary)
_sourceFrame.onChange([this]() { requireUpdate(); });
_destinationFrame.onChange([this]() { requireUpdate(); });
}
glm::dmat3 SpiceRotation::matrix(const UpdateData& data) const {
if (_timeFrame && !_timeFrame->isActive(data.time)) {
return glm::dmat3(1.0);
}
double time = data.time.j2000Seconds();
if (_fixedEphemerisTime.has_value()) {
time = *_fixedEphemerisTime;
}
return SpiceManager::ref().positionTransformMatrix(
_sourceFrame,
_destinationFrame,
data.time.j2000Seconds()
time
);
}
+4
View File
@@ -29,6 +29,7 @@
#include <openspace/properties/stringproperty.h>
#include <openspace/scene/timeframe.h>
#include <optional>
namespace openspace {
@@ -46,7 +47,10 @@ public:
private:
properties::StringProperty _sourceFrame;
properties::StringProperty _destinationFrame;
properties::StringProperty _fixedDate;
ghoul::mm_unique_ptr<TimeFrame> _timeFrame;
std::optional<double> _fixedEphemerisTime;
};
} // namespace openspace
+28 -1
View File
@@ -62,6 +62,13 @@ namespace {
"should be retrieved. The default value is GALACTIC."
};
constexpr openspace::properties::Property::PropertyInfo FixedDateInfo = {
"FixedDate",
"Fixed Date",
"A time to lock the position to. Setting this to an empty string will "
"unlock the time and return to position based on current simulation time."
};
struct [[codegen::Dictionary(SpiceTranslation)]] Parameters {
// [[codegen::verbatim(TargetInfo.description)]]
std::string target
@@ -74,6 +81,9 @@ namespace {
std::optional<std::string> frame
[[codegen::annotation("A valid SPICE NAIF name for a reference frame")]];
std::optional<std::string> fixedDate
[[codegen::annotation("A date to lock the position to")]];
// A single kernel or list of kernels that this SpiceTranslation depends on. All
// provided kernels will be loaded before any other operation is performed
std::optional<std::variant<std::vector<std::string>, std::string>> kernels;
@@ -92,6 +102,7 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary)
, _observer(ObserverInfo)
, _frame(FrameInfo, DefaultReferenceFrame)
, _cachedFrame(DefaultReferenceFrame)
, _fixedDate(FixedDateInfo)
{
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -142,6 +153,17 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary)
});
addProperty(_frame);
_fixedDate.onChange([this]() {
if (_fixedDate.value().empty()) {
_fixedEphemerisTime = std::nullopt;
}
else {
_fixedEphemerisTime = SpiceManager::ref().ephemerisTimeFromDate(_fixedDate);
}
});
_fixedDate = p.fixedDate.value_or(_fixedDate);
addProperty(_fixedDate);
_target = p.target;
_observer = p.observer;
_frame = p.frame.value_or(_frame);
@@ -149,12 +171,17 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary)
glm::dvec3 SpiceTranslation::position(const UpdateData& data) const {
double lightTime = 0.0;
double time = data.time.j2000Seconds();
if (_fixedEphemerisTime.has_value()) {
time = *_fixedEphemerisTime;
}
return SpiceManager::ref().targetPosition(
_cachedTarget,
_cachedObserver,
_cachedFrame,
{},
data.time.j2000Seconds(),
time,
lightTime
) * 1000.0;
}
@@ -28,6 +28,7 @@
#include <openspace/scene/translation.h>
#include <openspace/properties/stringproperty.h>
#include <optional>
namespace openspace {
@@ -43,6 +44,7 @@ private:
properties::StringProperty _target;
properties::StringProperty _observer;
properties::StringProperty _frame;
properties::StringProperty _fixedDate;
// We are accessing these values every frame and when retrieving a string from the
// StringProperty, it allocates some new memory, which we want to prevent. Until the
@@ -51,6 +53,7 @@ private:
std::string _cachedTarget;
std::string _cachedObserver;
std::string _cachedFrame;
std::optional<double> _fixedEphemerisTime;
glm::dvec3 _position = glm::dvec3(0.0);
};
+21 -1
View File
@@ -1362,11 +1362,31 @@ scripting::LuaLibrary SpiceManager::luaLibrary() {
},
{
"getCkCoverage",
& luascriptfunctions::ckCoverage,
&luascriptfunctions::ckCoverage,
{},
"{string [, printValues]}",
"Returns a list of CK coverage intervals for the target."
},
{
"rotationMatrix",
&luascriptfunctions::rotationMatrix,
{},
"{string, string, string}",
"Returns the rotationMatrix for a given body in a frame of reference at a specific"
"time. The first agument is the target body, the second is the frame of reference,"
" the third is the time. Example: openspace.spice.rotationMatrix('"
"INSIGHT_LANDER_CRUISE','MARS', '2018 NOV 26 19:45:34')."
},
{
"position",
&luascriptfunctions::position,
{},
"{string, string, string, string}",
"Returns the position for a target by an observer in a frame of reference at a specific"
"time. The first agument is the target body, the second is the observer body, the third"
"is the frame of reference, and the fourth is the time. Example: openspace.spice."
"position('INSIGHT','MARS','GALACTIC', '2018 NOV 26 19:45:34')."
},
{
"getSpiceBodies",
&luascriptfunctions::spiceBodies,
+72
View File
@@ -231,4 +231,76 @@ int ckCoverage(lua_State* L) {
return 1;
}
/**
* rotationMatrix({string, string, string}):
* Returns the rotationMatrix for a given body in a frame of reference
* at a specific time.
*/
int rotationMatrix(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::rotationMatrix");
const bool isString = (lua_isstring(L, 1) == 1) &&
(lua_isstring(L, 2) == 1) && (lua_isstring(L, 3) == 1);
if (!isString) {
LERRORC(
"rotationMatrix",
fmt::format(
"{}: Expected argument of type 'string' for all three agruments",
ghoul::lua::errorLocation(L)
)
);
lua_settop(L, 0);
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
}
std::string body = ghoul::lua::value<std::string>(L, 1);
std::string frame = ghoul::lua::value<std::string>(L, 2);
std::string date = ghoul::lua::value<std::string>(L, 3);
const double ephemerisTime = SpiceManager::ref().ephemerisTimeFromDate(date);
glm::dmat3 rotationMatrix = SpiceManager::ref().frameTransformationMatrix
(body, frame, ephemerisTime);
ghoul::lua::push(L, 1, rotationMatrix);
return 1;
}
/**
* position({string, string, string, string}):
* Returns the position for a given body relative to another body,
* in a given frame of reference, at a specific time.
*/
int position(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 4, "lua::position");
const bool isString = (lua_isstring(L, 1) == 1) &&
(lua_isstring(L, 2) == 1) &&
(lua_isstring(L, 3) == 1) &&
(lua_isstring(L, 4) == 1);
if (!isString) {
LERRORC(
"position",
fmt::format(
"{}: Expected argument of type 'string' for all four agruments",
ghoul::lua::errorLocation(L)
)
);
lua_settop(L, 0);
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
}
std::string target = ghoul::lua::value<std::string>(L, 1);
std::string observer = ghoul::lua::value<std::string>(L, 2);
std::string frame = ghoul::lua::value<std::string>(L, 3);
std::string date = ghoul::lua::value<std::string>(L, 4);
const double ephemerisTime = SpiceManager::ref().ephemerisTimeFromDate(date);
glm::dvec3 postion = SpiceManager::ref().targetPosition(target, observer, frame, {}, ephemerisTime);
ghoul::lua::push(L, 1, postion);
return 1;
}
} // namespace openspace::luascriptfunctions