1. 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 Download Package Now!
  2. 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
  3. 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 here. Do not following these rules will lead to permanent exclusion from this website: Read the forum rules.

Lesson How to add Telemetry output into a game. (Simple Example)

Discussion in 'Tutorials and Tips by the Developer' started by yobuddy, Oct 26, 2017.

  1. yobuddy

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

    Joined:
    Feb 9, 2007
    Messages:
    3,062
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    32,377Coins
    Ratings:
    +3,142 / 10 / -0
    I have been asked a few times on how to add telemetry output into a game.
    So today I thought I would show one way of achieving such a goal.

    Remember that SimTools is designed so it can capture telemetry output from a game no matter how it is outputting telemetry data. In other words, SimTools conforms to the games output method, rather than the game having to do anything special for SimTools.

    I believe the easiest way to output telemetry is thru UDP, so that is the way I’m going to show here. Other ways of outputting telemetry is with the use of Memory Mapped files and even a custom API’s.

    Ok let’s get started!
    First, let’s make the game a settings file to hold the Telemetry settings for the game.
    I’m suggesting a ‘Telemetry.cfg’ file that holds the motion configuration for the game.

    You may already have a configuration file for the game that you want to put these settings in, this is just an example. (This also gives SimTools a file to patch for motion, and allows the telemetry outputting to be on or off as needed.)

    The Telemetry.cfg file holds these 4 settings:
    - Enable_Telemitry = False
    - IpAddress = 127.0.0.1
    - Port = 4123
    - MS_OutputRate = 10

    I wrote the following example code in VB.net, as its dead simple to read and see what I’m doing.
    Basically thou, I’m creating a looping background thread that builds and sends the needed output with UDP.
    Once you have ‘something like’ this code in the game, all you have to do is:
    Call ‘Start_Telemetry_Output()’ when the game starts up.
    And ‘Stop_Telemety_Output()’ when the game shuts down.

    Ok, now some code:
    Private Telemetry_Sender As New UdpClient
    Private Telemetry_Loop_ms As Integer
    Private
    Telemetry_Running As Boolean = False
    Private
    Telemetry_Thread As Threading.Thread

    'Starts up the Telemetry Sender.
    Private Sub Start_Telemetry_Output()
    'only startup if not already started.
    If Telemetry_Running = False Then
    'read from Telemtry cfg file.
    Dim Telemitry_Enabled AsString = "Get Enabled_Telemetry value from the Telemetry.cfg file"
    Dim IpAddress AsString = "Get IpAddress value from the Telemetry.cfg file"
    Dim Port AsString = "Get Port value from the Telemetry.cfg file"
    Dim MS_OutputRate AsString = "Get MS_OutputRate value from the Telemetry.cfg file"

    If CBool(Telemitry_Enabled) = True Then
    Try
    'startup a new client.
    Telemetry_Sender = New UdpClient
    Telemetry_Sender.Connect(IpAddress, CInt(Port))

    'set loop speed & start sending data.
    Telemetry_Loop_ms = CInt(MS_OutputRate)
    Telemetry_Running = True
    Telemetry_Thread = New Threading.Thread(AddressOf Telemetry_Loop)
    Telemetry_Thread.IsBackground = True
    Telemetry_Thread.Start()
    Catch ex As Exception
    'Could not create the UDP sender, no need to do anything.
    End Try
    End If
    End If
    End Sub

    'Send Telemetry
    Public Sub SendTelemetry()
    Try
    'Collect the data.
    Dim Roll As String = ""
    Dim Pitch As String = ""
    Dim Yaw As String = ""
    Dim RollSpeed As String = ""
    Dim PitchSpeed As String = ""
    Dim YawSpeed As String = ""
    Dim Vertical As String = ""
    Dim Lateral As String = ""
    Dim Longitudinal As String = ""
    'add anything else you want to add, its easy now!
    'Dim Rpm As String = ""
    'Dim Speed As String = ""


    'check the status to see if the game is being played (In Game, In Menus, Paused).
    Dim Game_Is_Playing As Boolean = 'Get if the game is being played)

    'game is actually being played check.
    If Game_Is_Playing = True Then

    'If game is actually being played (not in menus or paused).
    Roll = "Get value from your game" 'in degrees - (-180 to 180)
    Pitch = "Get value from your game" 'in degrees - (-180 to 180)
    Yaw = "Get value from your game" 'in degrees - (-180 to 180)
    RollSpeed = "Get value from your game" 'in (rad/sec)
    PitchSpeed = "Get value from your game" 'in (rad/sec)
    YawSpeed = "Get value from your game" 'in (rad/sec)
    Vertical = "Get value from your game" 'in g's acceleration
    Lateral = "Get value from your game" 'in g's acceleration
    Longitudinal = "Get value from your game" 'in g's acceleration
    Else
    'If the game is paused or in the menus. (not actually being played)
    Roll = "0" 'in degrees - (-180 to 180)
    Pitch = "0" 'in degrees - (-180 to 180)
    Yaw = "0" 'in degrees - (-180 to 180)
    RollSpeed = "0" 'in (rad/sec)
    PitchSpeed = "0" 'in (rad/sec)
    YawSpeed = "0" 'in (rad/sec)
    Vertical = "0" 'in g's acceleration
    Lateral = "0" 'in g's acceleration
    Longitudinal = "0" 'in g's acceleration
    End If

    'Build the output string. (The 'S~' and the '~E' is so the user can see if they have a complete string of inputs)
    Dim WhatToSend As String = "S~Roll:" & Roll & "Pitch:" & Pitch & ":Yaw:" & Yaw & "RollSpeed:" & RollSpeed & "PitchSpeed:" & PitchSpeed & ":YawSpeed:" & YawSpeed & "Vertical:" & Vertical & ":Lateral:" & Lateral & ":Longitudinal:" & Longitudinal & "~E"

    'Send the string
    Dim bytCommand As Byte() = NewByte() {}
    bytCommand = Encoding.ASCII.GetBytes(WhatToSend)
    Telemetry_Sender.Send(bytCommand, bytCommand.Length)​
    Catch ex As Exception
    'something went wrong, turn off telemetry output.
    Stop_Telemity_Output()​
    End Try
    End Sub

    'Stop Telemetry Output
    Public Sub Stop_Telemetry_Output()
    'only shutdown if already started.
    If Telemetry_Running = True Then
    'turn output off.
    Telemetry_Running = False
    'let it finish what its doing.
    Threading.Thread.Sleep(100)
    'Close Client.
    Telemetry_Sender.Close()​
    End If
    End Sub

    'Send Telemetry Loop
    Private Sub Telemetry_Loop()
    'Send Telemetry.
    SendTelemetry()
    'pause till next packet is needed.
    Threading.Thread.Sleep(Telemetry_Loop_ms)
    'loop again if needed.
    If Telemetry_Running = True Then
    Telemetry_Thread = New Threading.Thread(AddressOf Telemetry_Loop)
    Telemetry_Thread.IsBackground = True
    Telemetry_Thread.Start()​
    End If
    End Sub

    That’s all there is to it!
    I hope this example is helpful.
    Let me know if I can be of any help!
    Take Care,
    yobuddy

    Source code of the example above:

    Attached Files:

    • Like Like x 2
    • Winner Winner x 2
    • Informative Informative x 1
    Last edited: Oct 26, 2017
  2. noorbeast

    noorbeast VR - The Next Generation Staff Member Moderator SimTools 2.0 Beta Tester

    Joined:
    Jul 13, 2014
    Messages:
    11,763
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    91,407Coins
    Ratings:
    +7,686 / 37 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    • Like Like x 2
  3. noorbeast

    noorbeast VR - The Next Generation Staff Member Moderator SimTools 2.0 Beta Tester

    Joined:
    Jul 13, 2014
    Messages:
    11,763
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    91,407Coins
    Ratings:
    +7,686 / 37 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
  4. yobuddy

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

    Joined:
    Feb 9, 2007
    Messages:
    3,062
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    32,377Coins
    Ratings:
    +3,142 / 10 / -0
    • Like Like x 1
    • Agree Agree x 1
  5. Gadget999

    Gadget999 Active Member

    Joined:
    Dec 27, 2015
    Messages:
    560
    Location:
    London
    Balance:
    4,257Coins
    Ratings:
    +104 / 4 / -0
    My Motion Simulator:
    2DOF, Arduino
    awesome !

    can you recommend a tool to read the telemetry - i guess excel would do the job
  6. yobuddy

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

    Joined:
    Feb 9, 2007
    Messages:
    3,062
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    32,377Coins
    Ratings:
    +3,142 / 10 / -0
    Anything that can catch and make use of UDP packets really.
    Take care,
    yobuddy