PlusToolkit / ndicapi

A common C API for communicating with NDI Polaris and Aurora devices
MIT License
47 stars 31 forks source link

additional details in python example #20

Open spitzbubchen opened 5 years ago

spitzbubchen commented 5 years ago

Sorry, is there a reference doc listing the ndicapi commands for a Polaris camera? Otherwise, would it be possible to add more NDI camera commands in the ndiBasicExample.py example file? Maybe some basic commands as:

I think these two basic commands would meet the requirements for most users.

adamrankin commented 5 years ago

The python API isn't officially supported, but has been worked on by a couple of users. I would recommend reaching out to them to see if they might be willing to implement this.

spitzbubchen commented 5 years ago

Basically, ndiBasicExample.py runs fine. It connects to the camera and I can do tasks such as reading firmware and whatnot. It is the remaining steps that are unclear. I have done the following:

ndiCommand(device, 'PHRQ:********010A**')
port_handle = ndiGetPHRQHandle(device)                            #returns port "1"
ndiPVWRFromFile(device, port_handle, "passive_tool.rom")
ndiCommand(device, 'TSTART:')

for _ in range(5):
    ndiCommand(device, 'BX:0001')
    test = ndiGetBXTransform(device, str(port_handle).encode())
    print(test)
    time.sleep(0.3)

ndiClose(device)

Basically the result that I get from ndiGetBXTransform is "DISABLED". I have the feeling I'm missing a small step somewhere. Please let me know if you have any advice. Once I have this running I can add it to ndiBasicExample.py and submit a PR. Thanks!

lassoan commented 5 years ago

There is a quite complicated protocol to start tracking, for example, you need to explicitly enable each tool you want to use. See implementation in the Plus toolkit (that uses the same ndicapi library but from C++) here: https://github.com/PlusToolkit/PlusLib/blob/master/src/PlusDataCollection/NDICAPITracking/vtkPlusNDITracker.cxx

If you don't want to go into such low-level details then you can download and use PlusToolkit's PlusServer application, which connects to the tracker and broadcasts tracking data via OpenIGTLink. You can receive data in Python using https://github.com/SlicerIGT/pyIGTLink.

spitzbubchen commented 5 years ago

Thanks for the suggestions! Unfortunately, I was never able to get ndicapi to work with my camera so I ended up writing my own python script which seems to work well. This may be due to the fact that my polaris camera is over 10 years old (serial port only) and ndicapi may be compatible only with newer cameras...?

Another question to the experts. My python code currently works well with the BX 0001 command in that it reports the quaternion of the tool. However, I would like to get the 3D positions of the individual IR markers on the tool. I tried the BX 0008 command and it seems to work in the sense it accepts the command and sends back a properly formatted reply, but the first component is "Number of Markers" which is always 0. I believe that is not an interpretation mistake on my end because the reply block length is short, consistent with no actual marker information.

Does anyone have an idea of what I am doing wrong? Looking at the NDI API documentation it seems BX 0008 is the correct command.

Reply Option 0008 : Markers are returned in alphabetical according to how they are labelled in the tool definition file. For example, for a tool with markers labelled A, G, M and S, the system will return the marker positions in the order A G M S. Reply option 0008 only returns data for markers that the system detects. To identify which marker is which, compare the reply option 0008 data to the data returned with reply option 0002. The marker order is the same for both replies; each marker that does not have a status of 0000 (“missing”) in reply option 0002 corresponds to a marker in reply option 0008.

diontan524 commented 3 years ago

@spitzbubchen hey there, i am facing the same issue like you where i encounter DISABLED with ndiGetBXTransform. How do you fix this issue? Do u you mind sharing your python script ?

adamrankin commented 3 years ago

Hi @spitzbubchen,

Sorry I'm not well versed enough in the NDI API protocol to answer about the BX0008 command. You could reach out to NDI support to see if they have any resources you might draw on.