• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

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! 

 

michaelmongin_1-1683553123517.png

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

 

michaelmongin_2-1683553380358.png

 

TOPICS
Experiment , Expressions , Scripting

Views

686

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 08, 2023 May 08, 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];

Votes

Translate

Translate
LEGEND ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

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];

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

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! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines