Move an entity smoothly using socket data

Hello I am working on visualize data that come from socket. I want to move entity smoothly to new positions. I tried to use Cesium.SampledPositionProperty and add samples when data came from socket. When I did this entity moves smoothly but lags behind the actual position over time. How can I fix this issue ?

1 Like

Hi @ismail_ferdi_alaca,

It sounds like you may need to use the Clock to update the current simulation time.

If you’re doing that and still seeing an issue, it would help if you could share a Sandcastle example with your code. That would help us troubleshoot.

Thanks!
Gabby

Hi @Gabby_Getz thanks for your reply.
I use Cesium.JulianDate.now() when adding instance to PositionProperty.
As data comes from the socket
positionProperty.addSample(Cesium.JulianDate.now(), position); By doing this, I aim for the entity to move smoothly between locations. But when I do it this way, the entity is created late and starts from the first sample in positionProperty. That’s why it always lags behind the last position in the socket. Instead, when I add positionProperty.addSample(viewer.clock.currentTime, position) using viewer.clock.currentTime, the entity is created immediately and moves in line with the last position in the socket, but in this case, it moves by jumping to the new position instead of fluent transition.

It could be possible to use a CallbackProperty in addition to the SampledPositionProperty to ensure for smooth updates.

If you could share a Sandcastle example with your code, that could help us troubleshoot what you are seeing.

Sandcastle example

The base logic on project can be found in sandcastle example. I add samples with time when data came from socket. Logically, the time difference between the last sample and the location of the vehicle should always be equal, but as far as I can see, this difference is around 3-4 seconds when the first data comes from the socket, and can increase to 60-70 seconds until the last data comes from the socket. What could be the reason for the wide difference in seconds?

The sandcastle does not work, because socket is not defined…

Beyond that, I think that the goal right now might be a bit underspecified. Let’s ignore the clock, sockets, callbacks, entities, and properties for now, and pretend that there’s an object that is just supposed to move along the x-axis, based on x-values that are obtained at time stamps t from a an arbitrary source.

The object starts at time t=0.0 and position x=0.0.
At time stamp t=1.0, the source provides x=1.0.
What should happen now? It sounds like the object should move from 0.0 to 1.0, and this should take 1.0 seconds. But I’m not sure about that. If this is correct: Imagine that during these 1.0 seconds, the source provides new data - for example
At t=1.1, it provides x=2.0
At t=1.2, it provides x=3.0
At t=1.3, it provides x=4.0
…
The object is still busy with its initial move, and the new positions are piling up. A SampledPositionProperty could not rely on the now() time here, because when it receives the entry with t=1.0, x=1.0, this time stamp has already passed.


However, my :crystal_ball: told me that these updates should be put into some sort of “queue”, and the proessed “as-if” they were happening in real-time … but later.

The following Sandcastle defines a class DynamicPositionProperty. This is a Property that provides a position, based on the positions that have been passed to some enqueueNewPosition function. The positions and the time stamps at which they have been enqueued are stored, and processed according to the time that is passed to the getValue function.

The Sandcastle contains some dummy functionality in a function called emulateSocketUpdates that just emulates some update calls that might otherwise come from some socket. The object is moving between two consecutive positions, and the movement takes as long as the time between the update calls.

https://sandcastle.cesium.com/#c=rVhtb9s2EP4rRL5UxlzZbtduc+Jgm5MB3dIXLGuDoukHRjpHXGXS5YvdrMh/35EUJUqWE6co0BQhdffc23NHMpngSpM1gw1IMiMcNmQOipll+s7tJZcHmVvPBdeUcZCXB4PDS+410qwU2adUFcKU+W+cLakGRNHSAMpc8qykSpGTG06XLHsjFNNM8DdSrEDqG/L1khOSWQekybSQycBu2U1CRiPyYrkqYQlo1moRsSCPguoj4qV0wVTK1NxiUK7R9IKWytquv+awYNzZnReUX0PejvJ0jQaSQaUR6X02YCAPPivU+vDxcOv7P2wJ55ouV9sCKwlrJox6u8oxKwEIxQx3PkG+W7qG3RK/9QnC9Jxy5wKhLpxVwNeCXAEWFJeQW1Hwcq9gE3xIePP7wFehqgPhYoMmq9z8aUpG+Qn6k+K+S1JdnIsCuPOc4D9dAFkwifrBjSH51+DSKCBMk5xJyHR547XZgiR9KU5L4Ne6ILPZjIxrv/rLka6MKlpxHPaIN9Wp5MUmyN0SQKI0RrohcaF7w9JWCMkmdaS5FGvGrzH1Gypzmw6qW0VJHxxKBP5i0cqzAqxU3utR8OPV64ugv0+un0S53pG+D+OPtm3Eps7ybcvHeQHZJ1IgeZYmK4hGRVJQRVbY/thxivEMnPeB5sQ4ng8jDIpR0Tz3wSKLW+IOUVlfgobnq8+GOrcG3rRaqJfGlfgJWyxAAuokTeAY3bCThh1NGaQaznlngnjUvffltZ+sVXEek8nHjgks8zXoeDxsB4lJPPdxRtFt+Rb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