Progressively larger jitters when setting SimObject Lat,Lon,Alt

Hi everyone!

I am working on TerraBuilder’s Kennedy Space Center scenery update, which will feature on-demand rocket launches. Everything is falling into place nicely, except I have an odd problem when I dynamically update and set Lat,Lon,Alt of my rocket. Everything starts nice and smooth on the ground, but as the rocket climbs higher and higher, there are visible an annoying positional shifts and jitters, as if the higher I go, I am losing more and more precision. I’ve made 2 videos to illustrate the problem: In this one, the jitters start at about 1:10 into the launch and get worse and worse (sorry about crappy tracking, it is really hard to do it from the ground straight up)

And this next video (only 10 sec long) shows it more pronounced at higher altitudes: (again, sorry about the tracking all over the place :slight_smile: )

Can anyone explain what is going on here? I am using a fairly simple SimConnect_SetDataOnSimObject call to set the Lat,Lon,Alt (after I compute the velocity vector) and I use doubles everywhere. It looks like a precision problem, but I can’t believe that the sim couldn’t handle a float value that represents values below a 100, and to a precision of a fraction of milimeter. Here are relevant code snippets:

struct Def_SimObject
{
	double  Latitude;
	double  Longitude;
	double  Altitude;

	double	Pitch;
	double	Bank;
	double	Heading;
};
...
	hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE LATITUDE",				"degrees latitude");
	hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE LONGITUDE",				"degrees longitude");
	hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE ALTITUDE",				"meters");

	hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE PITCH DEGREES",			"degrees");
	hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE BANK DEGREES",			"degrees");
	hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE HEADING DEGREES TRUE",	"degrees");
...
				Def_SimObject RocketInit;
				RocketInit.Latitude		= (double);
				RocketInit.Longitude	= (double);
				RocketInit.Altitude		= (double);
				RocketInit.Bank		= (double);
				RocketInit.Heading		= (double);
				RocketInit.Pitch		= (double);
				hr = SimConnect_SetDataOnSimObject(hSimConnect, DEF_SIMOBJECT, LaunchData.LaunchObjectID, 0, 0, sizeof(RocketInit), &RocketInit);

The values I am setting (for example, RocketInit.Altitude) are absolute, not per-frame distance updates. That is, I am not obtaining the current position and attitude of the rocket and adding per-frame distance values. That was going to be the next thing I try, but it requires a bit of code reshuffle, and I thought I ask first, perhaps there is a simple solution. This is all in MSFS2020 (I came across a post that described a similar problem, but it was observed in MSFS2024, while MSFS2020 was working fine).

Oh, and if it matters - the object is viewed from a dev-mode developer camera, not sure if that makes a difference.

Thanks for any and all feedback or suggestions,
Mitch
TerraBuilder

1 Like

You should probably freeze the SimObject before the launch. I suspect there are some body velocities that aren’t being handled, and they show between your Set frames.

1 Like

Thanks, great suggestion, and I just tested it, but it didn’t help - no change.

What are the velocity variables like up there? Are they reasonable our out of hand?

I don’t have (or set) a velocity vector on the object - I have Latitude, Longitude and Altitude variables that start at the current position, and I add a progressively larger increment every frame. then, I set those through SimConnect call. In the launch sequence, there is a roll (Which doesn’t affect the position when the rocket is going straight up), but immediately after the roll, there is also a pitch (into the orbital path), at which point I start computing Lat, Lon components of a vector that no longer points straight up. That’s what I meant by “vector” - just the direction of the flight path.

Yes, I could implement a “real” physics vector, with thrusts, masses, etc to compute the acceleration, then velocity, then position. But this is just for show, so I skipped the acceleration and velocity, and just implemented a simple positional update.

[EDIT] I also added SimConnect_AIReleaseControl, which didn’t change anything. The rocket (shuttle) SimObject is defined as “StaticObject”… not sure if that matters after all the FREEZE calls.

You don’t have to set accurate vector data, simply set all of them to zero to prevent them from affecting the behaviour of the aircraft.

I think I know what is going on. It seems to be my conversion from meters to Latitude/Longitude degrees, which I am doing by “quick and dirty” method, not the haversine.

I did a quick test, I took latitude and longitude steps (in meters) and divided them by 1000000 just to give me a rough conversion to Latitude/Longitude equivalent. It moved upward in a slanted straight line but there was no jitter.

1 Like

depending on your needs, Haversine might still not be accurate enough, because it’s based on a spherical model, so accuracy diverge over longer distances,

Vincenty is more precise, because it uses a spheroid model, but it’s more computationally expensive.

I suggest looking at Karney, which is faster and also based on a spheroid, and there are multiple libraries for all major languages available, like the popular GeographicLib

2 Likes

There’s a lot of good info in the publication links on Karney’s website too https://www.petrel.org/ (use the arXiv links).

I fixed my problem. My math/trig was fine. What happened was the update synch issue. I was obtaining the “previous” position from the SimConnect which returned a position that I set in the same cycle. This caused a timing/synch issue where a few values were oscilating between current and new.

Fix was simple - keep “previous” position as a static, do not obtain it from SimConnect. It is now working as expected, smooth, no jitters. I have no idea what made me go this way, as I know better.

Thanks everyone for chiming in and offering suggestions!