1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Question UE4 UDP output string format?

Discussion in 'SimTools Plugins' started by Tim Armstrong, Aug 6, 2017.

  1. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    Hello :)

    I am a UE4 developer that is new to motion sims and the SimTools software. I am in the process of making a vr game that will make use a motion platform and am trying to understand what data needs to be output and in what format.

    I have been looking over the Dirt 2 sample plugin and see the "Process_PacketRecieved(Text As String)" function as well as the "Outsim" structure that gets populated from the UDP string, but I have a few questions...

    1. What would be the IP I would send to to get the packet to SimTools? Would IP just be localhost?

    2. I am a bit confused also on how the UDP string out of UE4 should be structured...
    - Should the time in milliseconds be how long the game has been running? Would that part of the string be something like "000000000255" = 255 milliseconds over four bytes?
    - I am guessing that the rest is just x,y,z info for the object being simulated...is that correct?
    - Any chance you could provide a sample string showing how the data should be formatted?

    Thanks so much for any help you can send my way! Sorry if these are noob questions...just trying to wrap my head around the data format :)
  2. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    @yobuddy Hi buddy!

    I was wondering if you could help me understand getting the data into SimTools plugin?

    I saw on this thread that you mentioned:
    "Send like this Roll,Pitch,Heave,Yaw,Sway,Surge in plain text."

    Then you had a string that had a start, end, and delimiter characters:
    "S:Roll_Value : Pitch_Value:E"

    Were you just taking the roll and pitch and just plugging them in like this to your sample plugin?:

    Code:
    Public Sub Process_PacketRecieved(Text As String) Implements IPlugin_Game.Process_PacketRecieved
            'Convert string to byte and copy to byte array
            Dim ByteArray() As Byte = System.Text.Encoding.Default.GetBytes(Text)
            'Create Gchandle instance and pin variable required
            Dim MyGC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(MyOutsim_Internal, System.Runtime.InteropServices.GCHandleType.Pinned)
            'get address of variable in pointer variable
            Dim AddofLongValue As IntPtr = MyGC.AddrOfPinnedObject()
            'Copy the memory space to my GCHandle
            System.Runtime.InteropServices.Marshal.Copy(ByteArray, 0, AddofLongValue, ByteArray.Length)
            'Direct Cast myGC to my Outsim Object
            MyOutsim_Internal = DirectCast(MyGC.Target, OutSim)
            'Free GChandle to avoid memory leaks
            MyGC.Free()
    
            'Get Proper Data out of UDP Packet
            With MyOutsim_Internal
                Roll_Output = Roll_Value
                Pitch_Output = Pitch_Value
                Heave_Output = (System.Math.Cos(.sngOrientation2) * .sngAcceleration2)
                Yaw_Output = (.sngOrientation0 * 180 / 3.14159)
                Sway_Output = ((System.Math.Cos(.sngOrientation0) * .sngAcceleration0) + (System.Math.Sin(.sngOrientation0) * .sngAcceleration1))
                Surge_Output = ((-System.Math.Sin(.sngOrientation0) * .sngAcceleration0) + (System.Math.Cos(.sngOrientation0) * .sngAcceleration1))
                Extra1_Output = (((System.Math.Sin(.sngOrientation0) * .sngAcceleration0) + (System.Math.Sin(.sngOrientation0) * .sngAcceleration1)) * -1)
            End With
        End Sub
    Thanks in advance! Maybe if I can get this figured out I can make a generic UDP UE4 plugin for the community :)
  3. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,133
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    47,906Coins
    Ratings:
    +5,027 / 16 / -0
    Hi Tim,
    I can help you buddy.
    Does your game already output telemetry?

    Although I plan to post a basic "how to" on adding telemetry on xsimulator too, you can see my post here as it may help you.
    https://forum.il2sturmovik.com/topic/20568-telemetry-data-export/?p=494815

    With this way of outputting telemetry, you just parse the incoming string at the colon's ":" and then assign the correct outputs where needed.

    Yep, this way does not use a pre-constructed structure, just parsing the input string and assigns the values.

    You don't need a structure at all.
    Your process packets received could look like this:

    Private Sub Process_PacketRecieved(Text As String)
    Dim OutputValues() As String = Text.Split(CType(":", Char()))
    Roll_Output = OutputValues(1)
    Pitch_Output = OutputValues(3)
    Heave_Output = OutputValues(5)
    Yaw_Output = OutputValues(7)
    Sway_Output = OutputValues(9)
    Surge_Output = OutputValues(11)
    Extra1_Output = OutputValues(13)
    Extra2_Output = OutputValues(15)
    Extra3_Output = OutputValues(17)​
    End Sub

    I hope this helps.
    - Checking if the packet has the right leading and traing char, helps to make sure it has a full packet (not corrupted or anything)
    - You Can also check how many values OutputValues() has, as it should always be the same amount.
    If you need more help, just ask buddy. :thumbs
    Take care,
    yobuddy
    • Like Like x 1
  4. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    Thanks so much for the reply! :)

    Ok, that sounds easier than I thought it would be then!

    What is the best units to use for those values?

    I see from that link that you suggest degrees for roll, pitch, and yaw....is that good to use?

    How about for heave, sway, and surge? G's acceleration?

    Floats for all those or are integers ok?

    Thanks again!!
  5. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,133
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    47,906Coins
    Ratings:
    +5,027 / 16 / -0
    Hi Tim,
    Here you go buddy,
    Roll = degrees - (-180 to 180)
    Pitch = degrees - (-180 to 180)
    Yaw = degrees - (-180 to 180)
    Vertical = g's acceleration
    Lateral = g's acceleration
    Longitudinal = " g's acceleration

    (If you use these too)
    RollSpeed = (rad/sec)
    PitchSpeed = (rad/sec)
    YawSpeed = (rad/sec)
    • Like Like x 1
  6. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,133
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    47,906Coins
    Ratings:
    +5,027 / 16 / -0
    Yea, once you make a couple it gets easier.

    And now you can see how to also add Dash outputs too.
    Simply add the RPM values to the output string of the game, and assign it to:
    Dash_1_Output = "RPM," & (YourRpmValue)
    (btw, "_Enable_DashBoard" must = true for dash to be enabled)

    I'm around if you have more questions.
    Take care,
    yobuddy
    • Like Like x 1
  7. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    Awesome, thanks!

    Going to give it a go! :)
  8. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    @yobuddy

    Hi, ran into a problem trying to get my test game patched. It is just a simple platform tilting back and forth in UE4 so I can see if SimTools can read it.

    I made the plugin and used the PluginUpdater and tried to patch my exe but I keep getting:

    "You Must first Install and Run the Game Once Prior to Patching"

    Not sure what to do to fix it...looks like in the code it is looking for a config file since I used the Dirt 2 example. Any ideas on how to fix?

    I attached my plugin file if you want to take a look...

    Thanks again!

    Attached Files:

  9. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    @yobuddy

    I think I fixed my patching issue...I hope...

    I just went into the plugin and commented out the lines that referenced the config file so it would patch. I hope that is ok to do since I don't have a config file and I am coding the port and ip directly into the game.

    Also, I am using ip 127.0.0.1 and port 4123 is that the correct info to use to reach SimTools?

    So far I am not having any luck getting the simulator to move. Live for Speed works ok so i know SimTools is running ok and I know I am outputting udp data as I tested it sending to an arduino through udp.

    This is what I am using in the plugin:

    Code:
    Private Sub Process_PacketRecieved(Text As String) Implements IPlugin_Game.Process_PacketRecieved
            Dim OutputValues() As String = Text.Split(CType(":", Char()))
            Roll_Output = CDbl(OutputValues(1))
            Pitch_Output = CDbl(OutputValues(3))
            Heave_Output = CDbl(OutputValues(5))
            Yaw_Output = CDbl(OutputValues(7))
            Sway_Output = CDbl(OutputValues(9))
            Surge_Output = CDbl(OutputValues(11))
            Extra1_Output = CDbl(OutputValues(13))
            Extra2_Output = CDbl(OutputValues(15))
            Extra3_Output = CDbl(OutputValues(17))
        End Sub
    And this is an example of what my string looks like coming out of my game (just using Roll Output):
    -9.47364773:0:0:0:0:0:0:0:0

    Not sure on what next step to take....any advice?

    Thanks in advance!

    -Tim
    Last edited: Aug 8, 2017
  10. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    Here is a pic of what I have going so far.

    I have the same value going into Roll, Pitch, Yaw, Surge, Heave, and Sway (just for testing purposes).

    The game manager seems to show it is connected to the game but no values in tuning window. :(

    myTest.jpg
    • Like Like x 1
  11. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,460
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    144,596Coins
    Ratings:
    +10,741 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    You are definitely getting there :thumbs

    What are your Interface Settings?
  12. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    @noorbeast

    Hi noorbeast ,

    My Interface Settings have the com ports set and 10ms Output Rate with 15000 speed and 750 acceleration for axis 1a and 2a.

    However i don't think that is my issue. I can run Live For Speed without the simulator even connected and still get values being output in the Tuning Center...but i can't for my application.

    I know I am outputing proper udp packets, I checked them out in a couple of different apps and all showed the correct string being sent...I am a bit at a loss for what i am doing wrong.
  13. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    Ok, I think I have it working now! :)

    I added a beginning and ending check character to my udp string and that seemed to do the trick!

    Once I get all the bugs ironed out I will post all my steps for anyone else who wants to make a ue4 game with simtools.

    Thanks to yobuddy for the help!!
    • Winner Winner x 1
    Last edited: Aug 9, 2017
  14. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,460
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    144,596Coins
    Ratings:
    +10,741 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Congrats and thanks, that will be super useful and hopefully encourage Unreal devs to include motion support!

    Once you are done I will link your work in the FAQs, with credit to yourself.

    Work was started on a Unity plugin, but that did not get past proof of concept: https://www.xsimulator.net/community/threads/generic-unity-plugin.7804/
  15. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,133
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    47,906Coins
    Ratings:
    +5,027 / 16 / -0
    Hi Buddy,
    I'll take a look at your plugin tomorrow buddy.
    See if I can be of any help.
    (Just finished a late night of programming on GameVibe)
    yobuddy
    • Friendly Friendly x 1
  16. Tim Armstrong

    Tim Armstrong New Member

    Joined:
    Aug 2, 2017
    Messages:
    19
    Location:
    USA
    Balance:
    295Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino
    @yobuddy

    No worries, I was able to get it working by using your suggestion to add start and end characters to udp ('S:' and ':E'). That seemed to do the trick! :)

    Thank you for the help! :)
    • Like Like x 1
    • Winner Winner x 1
  17. hervetb

    hervetb New Member

    Joined:
    Jul 31, 2017
    Messages:
    1
    Location:
    France
    Balance:
    - 96Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Hey @Tim Armstrong , could you please show us the code you used to send the udp string in Ue4 ? thanks !
  18. DOF_Dex

    DOF_Dex New Member Gold Contributor

    Joined:
    Jan 29, 2024
    Messages:
    17
    Location:
    London
    Balance:
    19Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, 6DOF
    Hey Tim, I hope the UE to simtools project worked out. I'm working on a project similar to yours and I think your previous work on this would really help. Did you post your steps for the community to see? Thanks

    Did
  19. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,460
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    144,596Coins
    Ratings:
    +10,741 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Just so you know @Tim Armstrong has not been active for many years.
  20. DOF_Dex

    DOF_Dex New Member Gold Contributor

    Joined:
    Jan 29, 2024
    Messages:
    17
    Location:
    London
    Balance:
    19Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, 6DOF
    Oh, noorbeast. I've been waiting 4 years for Tim to post all his final steps and now you say he is gone from this thread forever?

    Ok. Time to figure this out myself then....
    :grin

    thanks for pointing out the last post from Tim was a while ago. It’s a shame it would be interesting to know how it went in the end.

    • Like Like x 1
    Last edited: Feb 14, 2024