pulse / vibration motor when abs is active ?

Discussion in 'Plugins' started by Gadget11, Feb 28, 2021.

  1. Gadget11

    Gadget11 Registered

    Joined:
    Jun 17, 2016
    Messages:
    82
    Likes Received:
    14
    Hi guys

    I want to vibrate the brake pedal when the abs of the car is active

    is there a flag or variable that will indicate the abs is active

    how can read this flag and transmit it to a serial port etc so i can drive a dc rumble motor

    I have a background in electronics / software and need a bit of help getting started

    ideally i would like to build a windows app that records the basic things like speed, rpm, gforce etc and use this to send data to a serial port

    Is there an API or anything similar that can be used ?

    any help greatly appreciated
     
  2. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,345
    Likes Received:
    6,572
    You may have luck comparing unfiltered and filtered brake in the plugin interface, but I'm not sure if that'll indicate ABS.
     
  3. davehenrie

    davehenrie Registered

    Joined:
    Jul 6, 2016
    Messages:
    7,453
    Likes Received:
    4,369
    Fanatec v3 wheels can do that already can't they? Gotta be some code leaking out somewhere for that.
     
  4. Seven Smiles

    Seven Smiles Registered

    Joined:
    Oct 5, 2010
    Messages:
    1,099
    Likes Received:
    1,152
    For the "how to read" bit search for @The Iron Wolf 's Shared Memory Plugin
     
  5. Gadget11

    Gadget11 Registered

    Joined:
    Jun 17, 2016
    Messages:
    82
    Likes Received:
    14
    If I can get the wheels speeds and the vehicle speed I should be able to work out when the ABS is active

    I have downloaded the Iron Wolf Plugin - will see what data is available

    I assume the Iron wolf plugin uses the RFactor API

    where is the API ? and is there any documentation ?
     
  6. Seven Smiles

    Seven Smiles Registered

    Joined:
    Oct 5, 2010
    Messages:
    1,099
    Likes Received:
    1,152
  7. Gadget11

    Gadget11 Registered

    Joined:
    Jun 17, 2016
    Messages:
    82
    Likes Received:
    14
    I have found the files at https://www.studio-397.com/modding-resources/

    I can see the filtered and unfiltered brake and also the forces on the wheels etc

    but how do I access these values from a windows forms application - eg visual basic or delphi etc

    (been a while but years ago I would declare a dll and then could access the functions inside it)

    once the dll is recognised can you do stuff like RF2.GetSpeed() etc ?
     
  8. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,345
    Likes Received:
    6,572
    The rF2SharedMemoryMap plugin linked above should help. That way you don't need your own rF2 plugin.
     
  9. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,345
    Likes Received:
    6,572
    @Gadget11 just to explain that a little more:

    Rather than using that plugin's source as an example of how to access rF2, use the plugin itself (install it in your game) and access the memory mapped file it creates to get the data you need. That's what the plugin is for. So then you just need to work out how to access the data with your language, I'm sure Seven Smiles can help with any specifics (though much is probably already covered on github)
     
  10. Gadget11

    Gadget11 Registered

    Joined:
    Jun 17, 2016
    Messages:
    82
    Likes Received:
    14
    Hi Lazza thank you for the advice

    I have a background in software development - just not with C

    is the memory mapped file a text file or similar and you read it like an ini file ?

    what is the name of the file the plugin writes to ?
     
  11. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,345
    Likes Received:
    6,572
    This page has a description https://github.com/TheIronWolfModding/rF2SharedMemoryMapPlugin

    And mentions an example program in C# that should be quite similar to what you'll be using.

    Apologies to @The Iron Wolf , said seven smiles above by accident (though he can probably help too - I haven't used rF2SMMP myself).
     
    The Iron Wolf likes this.
  12. Seven Smiles

    Seven Smiles Registered

    Joined:
    Oct 5, 2010
    Messages:
    1,099
    Likes Received:
    1,152
  13. lagg

    lagg Registered

    Joined:
    Oct 1, 2012
    Messages:
    3,043
    Likes Received:
    1,958
    I don't have used it never but you have the Namespace System.IO.MemoryMappedFiles in Visual Studio
     
    Gadget11 likes this.
  14. Gadget11

    Gadget11 Registered

    Joined:
    Jun 17, 2016
    Messages:
    82
    Likes Received:
    14
    ok - i am making some progress - thank you for the help and support guys - its is very much appreciated !

    I have researched memory maps and found an example -- http://voiceofgeek.blogspot.com/2009/02/memory-mapped-file-in-delphi.html


    i have created a hello world app using Delphi and here is the code

    (I can load the whole project if people want to test it themselves)

    I will write a version in Visual Studio when i can get the software downloaded - (Seven Smiles I upgraded VS to use Python last night and it took hours !! )

    In the example below I am using a memory map called 'MMAP'

    what is the RF2 memory map called ?




    -------------------------------------------------------------------------------------------------------------------------------------------------

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

    type
    TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    private
    { Private declarations }
    public




    { Public declarations }
    end;


    type
    PRecordInfo = ^TRecordInfo;
    TRecordInfo = packed record
    Field1 : ShortString;
    Field2 : Integer;
    Field3 : Integer;
    end; //TInstanceInfo




    var
    Form1: TForm1;

    FMappingHandle : THandle = 0;
    FRecordInfo : PRecordInfo= nil;
    FMappingName : String = 'MMAP';




    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);


    begin





    { To Create a Mapping File }
    FMappingHandle := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(TRecordInfo), @FMappingName[1]);
    FRecordInfo := MapViewOfFile(FMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TRecordInfo));
    FRecordInfo.Field1 := 'Value 1';
    FRecordInfo.Field2 := 0;
    FRecordInfo.Field3 := 1;



    end;

    procedure TForm1.Button2Click(Sender: TObject);

    begin

    { To Open the Memory Map File }
    FMappingName := 'MMAP';
    FMappingHandle := OpenFileMapping(FILE_MAP_ALL_ACCESS, false, @FMappingName[1]);

    { To Read the File Contents}
    FRecordInfo := MapViewOfFile(FMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TRecordInfo));
    edit1.Text := FRecordInfo^.Field1;//Read the Contents
    edit2.Text := inttoStr(FRecordInfo^.Field2);//Read the Contents
    edit3.Text := inttostr(FRecordInfo^.Field3);//Read the Contents


    end;

    end.
     
  15. Seven Smiles

    Seven Smiles Registered

    Joined:
    Oct 5, 2010
    Messages:
    1,099
    Likes Received:
    1,152
    There are several
    Code:
            const string MM_TELEMETRY_FILE_NAME = "$rFactor2SMMP_Telemetry$";
            const string MM_SCORING_FILE_NAME = "$rFactor2SMMP_Scoring$";
            const string MM_RULES_FILE_NAME = "$rFactor2SMMP_Rules$";
            const string MM_FORCE_FEEDBACK_FILE_NAME = "$rFactor2SMMP_ForceFeedback$";
            const string MM_GRAPHICS_FILE_NAME = "$rFactor2SMMP_Graphics$";
            const string MM_PITINFO_FILE_NAME = "$rFactor2SMMP_PitInfo$";
            const string MM_WEATHER_FILE_NAME = "$rFactor2SMMP_Weather$";
            const string MM_EXTENDED_FILE_NAME = "$rFactor2SMMP_Extended$";
            const string MM_HWCONTROL_FILE_NAME = "$rFactor2SMMP_HWControl$";
            const string MM_WEATHER_CONTROL_FILE_NAME = "$rFactor2SMMP_WeatherControl$";
    "$rFactor2SMMP_Telemetry$" is the one you want
     
    Gadget11 likes this.
  16. Gadget11

    Gadget11 Registered

    Joined:
    Jun 17, 2016
    Messages:
    82
    Likes Received:
    14
    Thank you guys - i have managed to read the first 3 items in $rFactor2SMMP_Telemetry$
    i have no idea what they are and what they contain yet - but its some good progress

    do you have to read all the item one by one - or can you specify which item to read

    i will do some research on $rFactor2SMMP_Telemetry$

    very pleased I am making progress :)
     
  17. Dave^

    Dave^ Registered

    Joined:
    Oct 14, 2019
    Messages:
    263
    Likes Received:
    121
    Can this be done within SimHub? (Thinking out loud)
     
  18. Seven Smiles

    Seven Smiles Registered

    Joined:
    Oct 5, 2010
    Messages:
    1,099
    Likes Received:
    1,152
  19. Gadget11

    Gadget11 Registered

    Joined:
    Jun 17, 2016
    Messages:
    82
    Likes Received:
    14
    Hi Dave, I did try simhub first, but it does not have a flag for ABS active
     
    Dave^ likes this.
  20. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    simhub shakeit has ABS effect. I don't know if it works in rF2, but Watever is amazing guy, he would answer your questions about that (try SH Discord). SH uses my plugin. Also, yes, rF2 does not expose ABS active flag, but I suspect you could derive that info (from speed dropping, brake input, wheel rotation speed, assuming rF2 simulates ABS properly). How I would go about it is I would plot wheel RPS using SH and see how graph looks like when ABS is engaged (available properites window).
     
    Last edited: Mar 2, 2021
    Gadget11 and Dave^ like this.

Share This Page