Skip to main content
michaelmongin
Participant
May 8, 2023
Answered

Trying to use After Effects Expressions and a Telemetry File From a Pixhawk Flight Controller

  • May 8, 2023
  • 2 replies
  • 1218 views

Hello, I am trying to write an expression to read in a data file from a flight controller (Pixhawk) with time stamps for different points of data. The format of the JSON is shown below with there being time data (PitotTimeS) and speed data (PitotSpeedMpS). The expression I have written will not work and gives me the error shown in the last image. The issue is I cannot simply frame through the data without refferencing the specific time it was recorded if I want everything to align properly. In addition, I have other sensors running at different rates and will need those aligned as well (if this indexed time method works that would be fine!). I am also open to formatting this in any other way that might work if there are reccomendations! 

 

Thanks! 

 

var PixhawkData = footage("AEData.json").sourceData;
var t = time;
var tround = t.toFixed(2);
var TimeIndex = PixhawkData.PitotTimeS.findIndex(tround);
PixhawkData.PitotSpeedMpS[TimeIndex];

 

 

This topic has been closed for replies.
Correct answer Dan Ebberts

Try it this way:

function getIndex(element){
  return element >= time;
}
var PixhawkData = footage("AEData.json").sourceData;
var t = time;
var TimeIndex = PixhawkData.PitotTimeS.findIndex(getIndex);
if (PixhawkData.PitotTimeS > time && TimeIndex > 0) TimeIndex--;
PixhawkData.PitotSpeedMpS[TimeIndex];

2 replies

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
May 8, 2023

Try it this way:

function getIndex(element){
  return element >= time;
}
var PixhawkData = footage("AEData.json").sourceData;
var t = time;
var TimeIndex = PixhawkData.PitotTimeS.findIndex(getIndex);
if (PixhawkData.PitotTimeS > time && TimeIndex > 0) TimeIndex--;
PixhawkData.PitotSpeedMpS[TimeIndex];
michaelmongin
Participant
May 8, 2023

This worked increibly! Thank you so much Dan! 

 

For clarification (because my coding skills are limited to MatLAB and I want to make sure I understand whats taking place):

The first three lines setup the function that will search the input for an element of greater or equal value to the current time,

line 4 is the data reference, line 5 is now technically unused, and line 6 is where the magic happens with the getIndex function now pointing the findIndex to an element comparison to time? Line 7 is still a little fuzzy to me, the if is checking that all of the values of PitotTimeS are greater than time and that the time index is greater than 0 then returns the previous value, what does this acomplish? 

 

Again, I appreciate your quick response and avid skill in coding this up! Thanks again! 

Dan Ebberts
Community Expert
Community Expert
May 8, 2023

Your observations are pretty much all correct. Line 7 makes sure we're picking up the index for the most recent time data that's prior (or equal) to the current time. Otherwise you end up with the index for next time coming up.

Mylenium
Legend
May 8, 2023

Indices need to be plain integers. You have to use Math.round(), not toFixed(). Probably doesn't realyl make a lot of sense in your case, though, since no doubt there will be fractional frames, so may be actually timeToFrames() is the answer. Impossible to tell, since you haven't provided any example of the actual data.

 

Mylenium

michaelmongin
Participant
May 8, 2023

Hi Mylenium, that portion of the expression is actually working and I am able to print the rounded time on screen. I believe the primary issue is with the findIndex portion of the code where I am trying to locate the index within the data that corresponds with the rounded time. I have atatched the JSON with the .txt extension since the adobe website doesnt allow JSON format files. Thanks!