Results 1 to 8 of 8

Thread: Segment top speed

  1. #1
    Tuner in Training
    Join Date
    Sep 2015
    Posts
    43

    Segment top speed

    Is there a way to display the partial maximum speed at the top of the speed gauge, when above a certain threshold?
    For example, in turn 2 we ride at a speed of 60mph, then 70mph or more, then back to 50mph exiting the turn. We want to display the top T2 speed of 75.4mph for a second.
    I imagine this could be done with the scripting language, but is there a property in the designer ready to use?

  2. #2
    HPT Employee Weston@HPTuners's Avatar
    Join Date
    Jul 2014
    Location
    39.735034, -103.894459
    Posts
    868
    It can be done with the Enhanced Display Object scripting capability, and there is already a "Maximum" display like this included, however you would need to implement your desired way to reset it after each turn or sector... In RaceRender 3.4 (just released), you are able to use the new GetDataValue() function to look at other data channels, so that may be a way to do it. Updated documentation on that is here: http://RaceRender.com/RR3/docs/DispObjEnhanced.html

  3. #3
    Tuner in Training
    Join Date
    Sep 2015
    Posts
    43
    I have a first version of the algorithm but I need help with some of the instructions, please see my comments. For simplicity I switched to max lean angle after each turn (I have a field called bike_angle in my data file, when abs(bike_angle) > 25 we assume we're in a corner).

    Code:
    // How can I define global variables that retain their value across script calls?
    sectorType = STRAIGHT;
    maxLeanAngle = 0;
    
    //
    // Foreground Script
    //
    bikeAngle = abs(GetDataValue(bike_angle));
    
    if( sectorType == STRAIGHT && bikeAngle > 25 ) {
      // begin corner
      sectorType = CORNER;
      maxLeanAngle = bikeAngle;
    } else if( sectorType == CORNER && bikeAngle <= 25 ) {
      // end corner
      sectorType = STRAIGHT;
      // How to hide number after 2 seconds?
      DrawNumber(maxLeanAngle, 0, 100, 100, "red", 10, AlignH_Center);
    } else if( sectorType == CORNER && bikeAngle > 25 ) {
      // cont corner
      maxLeanAngle = max(maxLeanAngle, bikeAngle); 
    }

  4. #4
    HPT Employee Weston@HPTuners's Avatar
    Join Date
    Jul 2014
    Location
    39.735034, -103.894459
    Posts
    868
    // How can I define global variables that retain their value across script calls?
    For your constants, you would put them in the Background script like so:
    Code:
    STRAIGHT = 0;
    CORNER = 1;
    If you are setting a value in the Foreground script and want to retain its value for use in future calls, then enable the "Persistent Script Variables" option.


    bikeAngle = abs(GetDataValue(bike_angle));
    This should work as long as your Background script sets your bike_angle variable to the channel index...
    Code:
    bike_angle = GetDataIndex("bike_angle");

    // How to hide number after 2 seconds?
    You can use the SampleTime system variable to get the time (in seconds) of the current frame you are rendering, and when used in conjunction with the "Persistent Script Variables" option, you can remember the first time you did something. So, then the Foreground script for any subsequent frames could calculate how long it has been since that point and apply logic based on that. Note that these get reset (and the Background Script gets re-run) if you seek backwards or make a change to the display object's configuration or scripts.

    Something like this... (with Persistent Script Variables enabled)

    Background Script:
    Code:
    FirstDisplayTime = -1; //Initialization
    DisplayDuration = 2; //Seconds
    Foreground Script:
    Code:
    if(SomeCondition == true)
    {
        //Triggered to display something
        DoDisplay = true;
    
        if(FirstDisplayTime < 0)
        {
            //Not already displaying it
            FirstDisplayTime = SampleTime;
        }
        else
        {
            //We're already displaying this
            if(SampleTime >= FirstDisplayTime + DisplayDuration)
                DoDisplay = false; //DisplayDuration has already elapsed
        }
    
        if(DoDisplay)
        {
            //Render the display here 
        }
    }
    else
    {
        //Not triggered
        FirstDisplayTime = -1; //Reset for next trigger
    }

    DrawNumber(maxLeanAngle, 0, 100, 100, "red", 10, AlignH_Center);
    Remove the quotes on "red" here, and that should work. It's a constant value that equates to 0xFF0000.


    else if
    Just a heads up about this... The scripting engine doesn't support a direct "else if" at this time (that annoys me too), so you'd just need to format that if() inside of an else { } block, like so:
    Code:
    if(Condition == true)
    {
    }
    else //Condition != true
    {
        if(SomethingElse == true)
        {
            
        }
    }

  5. #5
    Tuner in Training
    Join Date
    Sep 2015
    Posts
    43
    This should work as long as your Background script sets your bike_angle variable to the channel index...
    Code:
    bike_angle = GetDataIndex("bike_angle")
    I'm not clear, bike_angle is a different variable than my bikeAngle and it contains the data field index? Why the field index must be persisted in a global variable?

    By the way, I noticed the speedometer has an indicator with two needles, one with the current values and another with the maximum value over a certain time frame which does exactly what I'm looking for. Except I haven't found a way to print the max needle value. Only the current speed value is displayed.

  6. #6
    HPT Employee Weston@HPTuners's Avatar
    Join Date
    Jul 2014
    Location
    39.735034, -103.894459
    Posts
    868
    Quote Originally Posted by Spaghetti View Post
    Code:
    bike_angle = GetDataIndex("bike_angle")
    I'm not clear, bike_angle is a different variable than my bikeAngle and it contains the data field index? Why the field index must be persisted in a global variable?
    The data file is loaded into memory as a two-dimensional array of data channels (columns) and data samples (rows). GetDataIndex("channel name") is the function that searches the channel names and returns the numerical index of the desired channel / field, so that we know which column in the array to use. That result is what you'd use as the parameter to GetDataValue() (or you can use one of the DFT_* constants instead if it's a common field). For the sake of demonstration (ie this works, but you don't want to actually do it this way), if you were to combine it, you'd get the actual value from the "bike_angle" data field by doing this: GetDataValue(GetDataIndex("bike_angle"))

    This process is split into two separate functions for efficiency, because we don't need to repeat that channel name search for every new frame... That index will always be the same, so it's better to do that in the Background script and put the resulting channel index into a variable, which you can then use with GetDataValue() in the Foreground script. It's not a big difference in performance in this case, but every little bit helps. This fits right into the overall distinction between the Background and Foreground scripts... The Background script is only executed once (and reinitializes when you seek backwards or make a change to the display object), while the Foreground script is executed for each and every frame. Therefore, you want to lighten the load for that Foreground script as much as possible, and do as much of the work as you can in the Background script.

    By the way, I noticed the speedometer has an indicator with two needles, one with the current values and another with the maximum value over a certain time frame which does exactly what I'm looking for. Except I haven't found a way to print the max needle value. Only the current speed value is displayed.
    If I'm understanding correctly, you're talking about "Needle + Peak" mode, which is useful for indicating RPM shift points or other observed maximums. A good starting point for that would be to look at the "Maximum" style under the Enhanced Display Objects... That's a similar effect, but just doesn't automatically reset. Here's a quick and simple modification that would turn it into a Peak value, resetting whenever the max value hasn't increased for 5 seconds... New code is in bold.

    Background Script
    Code:
    //This display requires "Persistent Script Variables" to be enabled
    
    NumberColor = ColorA;
    FontSize = 52;
    Decimals = 2;
    OffsetX = 170;
    
    DefaultValue = -999999999; //Lower than any expected data value
    MaxValue = DefaultValue;
    
    HoldDuration = 5.0; //Seconds to hold the max display before resetting
    MaxTime = -HoldDuration;
    Foreground Script
    Code:
    if(DataValue > MaxValue || SampleTime > MaxTime + HoldDuration)
    {
    	//Got a new maximum value, or it is time to reset it
    	MaxValue = DataValue;
    	MaxTime = SampleTime;
    }
    
    DrawNumber(MaxValue, Decimals, OffsetX, 0, NumberColor, FontSize, 0);

    You could also take that further, like maybe displaying nothing until the DataValue starts increasing again by at least a certain amount, or incorporating DataTrigger to filter out low values, etc. Lots of possibilities to experiment with.

    Here's a copy of that object you can download: Peak.rro

  7. #7
    Tuner in Training
    Join Date
    Sep 2015
    Posts
    43
    I'm almost done with my first template version that includes the max segment speed and lean angle, but I can't get rid of the decimal digits from the enhanced peak object. Also can't change the size and attributes of the fonts (it's only enabled for the label).

  8. #8
    HPT Employee Weston@HPTuners's Avatar
    Join Date
    Jul 2014
    Location
    39.735034, -103.894459
    Posts
    868
    To get rid of the decimals, look at the 2nd parameter to the DrawNumber() function. You just need to set that to zero. In the example above, it is a variable called "Decimals", which is set in the Background script, so in that case, you should only need to go in there and change it to zero.

    As for the font used for text and numbers drawn by the script, the font itself can be set on the "Object Parameters" tab, using the "Drawing Font" setting. Its size is dynamic, depending on what the script tells it to do... It's the 6th parameter to the DrawNumber() function. In the example, it's a variable called "FontSize" that is set in the Background script. At this time, bold/italic/underline/etc attributes are not configurable.