Items with no label
3338 Discussions

How can I add latency to the D435 video stream in Unity?

Ijena
Beginner
2,515 Views

Currently, we have connected the camera to our laptop but in reality the camera will be far away and is connected via internet. We want to simulate the network latency and measure our performance based on the length of latency but don't how. Any guidance is appreciated.

 

Thanks

Iman

0 Kudos
1 Solution
MartyG
Honored Contributor III
1,016 Views

If you are writing your own program in Unity, you could put a Unity instruction called WaitForSeconds in your script at the point where it loops round to start the next frame. WaitForSeconds can be any number you want, such as 0.1 (seconds). Unity does not allow the loop (e.g the next frame) to start again until the period specified in the WaitForSeconds instruction has passed. Here's an example script from my own Unity project:

 

On the last line, change the value in the bracket from 0.1 to whatever pause period you want. Remember to leave the 'f' on the end of the number if its a decimal number.

 

StartCoroutine(PauseTracking());

  }

  IEnumerator PauseTracking()

  {

    yield return new WaitForSeconds(0.1f);

 

View solution in original post

0 Kudos
5 Replies
MartyG
Honored Contributor III
1,016 Views

You could try using Unity's own in-built performance profiling tool, under Window > Analysis > Profiler. If you open the Profiler window whilst the program is running, it gives you extremely detailed feedback about where lag is occurring. Its default mode is a graphical line chart showing the frames per second (FPS) that the program is running at after processing lag is taken into account. You can dig deep into textual information about every aspect of the program's processing activities though.

0 Kudos
Ijena
Beginner
1,016 Views

Thanks for the reply. We don't want to understand current lag in the system. We need to artificially add latency between what the current frame that the camera captures and when the frame is available for processing, so we can simulate what we'll encounter in the real world. Right now we connect the camera to the laptop and do our processing locally but in reality the camera needs to send it's data over internet to a different location. Therefore, there will be a delay between when camera captures a frame and when it is available for processing. How can we simulate such lag?

0 Kudos
MartyG
Honored Contributor III
1,017 Views

If you are writing your own program in Unity, you could put a Unity instruction called WaitForSeconds in your script at the point where it loops round to start the next frame. WaitForSeconds can be any number you want, such as 0.1 (seconds). Unity does not allow the loop (e.g the next frame) to start again until the period specified in the WaitForSeconds instruction has passed. Here's an example script from my own Unity project:

 

On the last line, change the value in the bracket from 0.1 to whatever pause period you want. Remember to leave the 'f' on the end of the number if its a decimal number.

 

StartCoroutine(PauseTracking());

  }

  IEnumerator PauseTracking()

  {

    yield return new WaitForSeconds(0.1f);

 

0 Kudos
Ijena
Beginner
1,016 Views

Wouldn't this lower the frequency as opposed to adding latency? We are also using the sample provided by librealsense in unity. RsDevice object is used to reconstruct the 3D environment.

 

Thanks for your prompt replies MartyG

0 Kudos
MartyG
Honored Contributor III
1,016 Views

WaitForSeconds is not related to frames per second. It is a general 'pause button' for processing that stops a script from running any further past the WaitForSeconds point until the time has elapsed.

 

I understand what you are trying to achieve. It was a good idea to post your question on the GitHub too, as there are highly technical staff there who may be able to offer a cleverer solution than I can think of.

 

0 Kudos
Reply