i2 hold() Function in Maths

Discussion and support for i2 Standard and i2 Pro applications

i2 hold() Function in Maths

Postby MikeWorosz on Tue May 21, 2024 10:50 pm

Hello,
One thing I have always struggled to achieve and curious if there is a way to go about doing this in i2 is to hold a math function's last calculated value. For example, if I had a math expression as follows:

PitLaneRH = choose('Pit' == 1 AND 'LatAccel' [G] < 0.1 AND 'LongAccel' [G] < 0.1, 'RideHeight' [mm], invalid())

I could use this channel to find a 'Pit Lane Zero' value for ride height of the car, but once the conditions to calculate a pitlane trundle value are no longer true, this channel will simply output a value of nothing, hence the invalid(). Ideally in this expression it would be very useful to have a different function of invalid(), such as one called hold('PitLaneZero'), so that once the conditions of the choose function are not met and the expression moves over to the hold() function it will simply output the last calculated value for 'PitLaneZero' at that moment as a constant until conditions to do otherwise are met again. The integrate function in i2 already works in this manner, for example:

TimeInABS = integrate('ABSactive', 'ABSactive' == 1)

This expression will integrate the ABSactive binary channel when ABSactive == 1. Integrating "1" wrt time will simply have this channel work as a counter for when the ABS is active. However, when ABSactive == 0, the expression "TimeInABS" will hold the last calculated value for when ABSactive == 1. If MoTeC were able to implement a hold() function into a future update I think it would make the math expressions a lot more versatile. It would become much simplier to zero channels such as pitlane ride heights, damper positions/forces, anything you can think of on the car that would vary via setup so that when comparing different session's data all the channels are zeroed to a pitlane reference. The only way I could currently think of doing something like this would be using the integrate function, which quickly becomes over complicated for trying to calculate simple things such as ride height. The following expression would do what I am asking for with MoTeC's current functions:

PitLaneRH = integrate(derivative('RideHeight' [mm]), 'Pit' == 1, AND 'LatAccel' [G] < 0.1 AND 'LongAccel' [G] < 0.1) + C

This issue with using this method is the "+ C" at the end. The integration constant would have to be calculated by the user manually and then replace the value of "C" in this expression in order for the expression to read out the correct value for the ride height in pitlane. This function works as a sort of "hold()" function because when the conditions are no longer met, the channel 'PitLaneRH' would equal the last calculated value for the integral of the derivative of ride height, which is equivalent to simply the ride height considering integrating derivatives cancel each other out.

Do you think that potentially in the future we could expect to see some sort of hold() function to be implemented into i2? Or maybe there is already an effective way to go about what I am trying to do here other than using the integrate function that I simply haven't figured out yet?

Cheers,
Mike
MikeWorosz
 
Posts: 1
Joined: Tue May 21, 2024 5:29 am

Re: i2 hold() Function in Maths

Postby adrian on Wed May 22, 2024 6:17 pm

I think 'previous_sample()' should do what you want. First make sure you select "Point Evaluator" from the dropdown on the RHS, it won't work with "Array Evaluator".

You expression becomes something like this:
PitLaneRH = choose('Pit' == 1 AND 'LatAccel' [G] < 0.1 AND 'LongAccel' [G] < 0.1, 'RideHeight' [mm], previous_sample(-1))

You need to pass a default value to the previous_sample function, you could use invalid() here if that works.
adrian
MoTeC
 
Posts: 719
Joined: Mon Apr 13, 2015 5:16 pm


Return to i2 Data Analysis Software

Who is online

Users browsing this forum: No registered users and 4 guests