SpectacularAI / sdk

Spectacular AI SDK
https://www.spectacularai.com/
71 stars 12 forks source link

Documentation for Session.addAbsolutePose() #21

Closed mgagvani closed 9 months ago

mgagvani commented 9 months ago

I am a bit confused at the documentation for addAbsolutePose(): https://spectacularai.github.io/docs/sdk/wrappers/oak.html#spectacularAI.depthai.Session.addAbsolutePose

It takes in a Pose object, 3x3 matrix, and a float value. What should each of these 3 arguments be?

kaatrasa commented 9 months ago

That part of the documentation is indeed very unclear at the moment (we will try to improve that when we have the time). However, if you check the C++ documentation for that part, it is a lot better.

Basically, the second argument is a 3x3 covariance matrix for the position and third argument is orientation variance: image

kaatrasa commented 9 months ago

Here is an example in Python:

# This timestamp should be in sync with OAK-D device clock, you can see example of
# obtaining the host monotonic time to device time offset from the gnns example:
# https://github.com/SpectacularAI/sdk-examples/blob/main/python/oak/vio_gnss.py
timeOfThePose = ...

# Using same uncertainty value for position/orientation for simplicity
simpleUncertainty = 0.00001

# Row major transformation matrix
pose = spectacularAI.Pose.fromMatrix(timeOfThePose, [
  [1.0, 0.0, 0.0, 2.0], # x position = 2.0
  [0.0, 1.0, 0.0, 0.0],
  [0.0, 0.0, 1.0, 0.0],
  [0.0, 0.0, 0.0, 0.0]
])
positionUncertainty = [
  [simpleUncertainty, 0.0, 0.0],
  [0.0, simpleUncertainty, 0.0],
  [0.0, 0.0, simpleUncertainty]
]
orientationUncertainty = simpleUncertainty
vio_session.addAbsolutePose(
  pose,
  positionUncertainty,
  orientationUncertainty
)

Note that you might need to tune the position covariance and orientation variance scales until the absolute poses work as expected.

mgagvani commented 9 months ago

Thanks for your help. When you say the timestamp should be in-sync with the OAK-D device clock, would it be sufficient to read the OAK-D device clock when the external measurement is gathered and input that into addAbsolutePose, or is there something more complex with the host clock I need to take into account?

kaatrasa commented 9 months ago

That should work fine, or if the external measurement is computed from DepthAI ImgFrame, then you should use ImgFrame::getTimestampDevice().