Python-SimConnect icon indicating copy to clipboard operation
Python-SimConnect copied to clipboard

Increase Data Rate?

Open PowerBroker2 opened this issue 3 years ago • 2 comments
trafficstars

I'm trying to get real-time location and attitude data, but it seems I can only get a ~5Hz data rate using this lib. I'd prefer to stay in Python and not switch to the C++ SDK, so I figure I'd ask here: Is there a way to speed up the data rate?

Here is my current code for reference:

import sys
from os.path import dirname
from pprint import pprint

import numpy as np
from SimConnect import *

SIM_DIR = dirname(__file__)
SRC_DIR = dirname(SIM_DIR)
sys.path.append(SIM_DIR)
sys.path.append(SRC_DIR)

import rotation
import pilotUtils


sm = SimConnect()
aq = AircraftRequests(sm, _time=0)

while not sm.quit:
    lat = aq.PositionandSpeedData.get('PLANE_LATITUDE')
    lon = aq.PositionandSpeedData.get('PLANE_LONGITUDE')
    alt = aq.PositionandSpeedData.get('PLANE_ALTITUDE') 
    
    alt_agl = aq.PositionandSpeedData.get('PLANE_ALT_ABOVE_GROUND')
    
    roll  = aq.PositionandSpeedData.get('PLANE_BANK_DEGREES')
    pitch = aq.PositionandSpeedData.get('PLANE_PITCH_DEGREES')
    yaw   = aq.PositionandSpeedData.get('PLANE_HEADING_DEGREES_TRUE')
    
    airspeed = aq.FlightInstrumentationData.get('AIRSPEED_TRUE')
    
    if None not in [lat, lon, alt, alt_agl, roll, pitch, yaw, airspeed]:
        lla = np.array([lat,           # dd
                        lon,           # dd
                        alt / 3.2808]) # Ft -> m above MSL

        agl = alt_agl / 3.2808 # Ft -> m above AGL

        B_angles_N = np.rad2deg(np.array([-roll,  # Actually radians
                                          -pitch, # Actually radians
                                          yaw]))  # Actually radians
        B_dcm_N = rotation.angle2dcm(B_angles_N,
                                     pilotUtils.DEGREES,
                                     True,
                                     321).squeeze()

        B_airspeed = np.array([airspeed * 0.514444, # Knots -> m/s
                               0,
                               0])
        N_airspeed = B_dcm_N.T @ B_airspeed
        
        pprint(lla)
        pprint(B_angles_N)
        pprint(B_airspeed)
        pprint(N_airspeed)
        print('')

PowerBroker2 avatar Sep 25 '22 02:09 PowerBroker2

Have the same concern. But it seems limited by MSFS; when I set the "GLASS COCKPIT REFRESH RATE" to high in the MSFS setting, the sampling rate is increased. All other factors depend on your CPU, I guess. I don't have a very powerful CPU, I just get ~2hz when I set the refresh rate to high (1hz with medium). MSFS is not well optimized for CPU load. If you wish do some optimization on server and client, WebSocket might be helpful.

TyraelDLee avatar Jun 04 '24 14:06 TyraelDLee

@odwdinc Is this repo abandoned or is it still maintained?

PowerBroker2 avatar Jun 04 '24 21:06 PowerBroker2