[IGSTK-Users] Polaris reference tool

Patrick Cheng cheng at isis.imac.georgetown.edu
Tue Mar 31 12:46:48 EDT 2009


Hi Jayson,

Is there any problem using the IGSTK code?

If you want to use NDI's raw API, here are some reference code from
igstkPolarisTracker.cxx and NDICommandInterpreter.cxx that might help
you debug the issue. I have also attached a picture from NDI
documentation showing the flow chart of the initialization process.

Hope these will help,

Patrick

----------------------------------------------------------------------------
// most SROM files don't contain the whole 1024 bytes, they only
// contain whatever is necessary, so the rest should be filled with zero
    const unsigned int SROM_FILE_DATA_SIZE = 1024;
    char data[SROM_FILE_DATA_SIZE];
    memset( data, 0, SROM_FILE_DATA_SIZE );
    sromFile.read( data, SROM_FILE_DATA_SIZE );
    sromFile.close();

    // request port handle using PHRQ
    commandInterpreter->PHRQ("********", // device number
                               "*",        // TIU or SCU
                               "1",        // wireless
                               "**",       // port
                               "**");      // channel
    if (this->CheckError(commandInterpreter) == FAILURE)
      {
      return FAILURE;
      }

    ph = commandInterpreter->GetPHRQHandle();

    for ( unsigned int i = 0; i < SROM_FILE_DATA_SIZE; i += 64)
      {
      // holds hexidecimal data to be sent to device
      char hexbuffer[129];

      // convert data to hexidecimal and write to virtual SROM in
      // 64-byte chunks
      commandInterpreter->HexEncode(hexbuffer, &data[i], 64);
      commandInterpreter->PVWR(ph, i, hexbuffer);
      }
    }
  else
    {
    // if the tool is not wireless, search ports with
    // uninitialized handles
    ............................
    }

-------------------------------------------------------------------------
/** Encode binary data in to hexidecimal ASCII. */
char* NDICommandInterpreter::HexEncode(char* cp, const void* data, int n)
{
  const unsigned char* bdata;
  int i, c1, c2;
  unsigned int d;
  char* tcp;

  bdata = (const unsigned char* )data;
  tcp = cp;

  for (i = 0; i < n; i++)
    {
    d = bdata[i];
    c1 = (d & 0xf0) >> 4;
    c2 = (d & 0x0f);
    c1 += '0';
    c2 += '0';
    if (c1 > '9')
      {
      c1 += ('A' - '0' - 10);
      }
    if (c2 > '9')
      {
      c2 += ('A' - '0' - 10);
      }
    *tcp++ = c1;
    *tcp++ = c2;
    }

  return cp;
}
-------------------------------------------------------------------------------


Jason YEE wrote:
> 
>  Thank you Ziv,
>  
> I got another problem with the definition file (.rom file), after I used 
> command PINIT to initialize the port handle, polaris spectra returned 
> ERORR40 (file format is invalid or CRC failed).
> But the return of command:PVWR is all okay. I am compused about it now, 
> in order to make sure the file is right, I read the file out and wrote a 
> test program by manually using PVWR assign the definition file one 
> address by one address. But it is still not working. would you please 
> give me some suggestion?
> any help is very much appreciated,
>  
>  
> Below is part of the test program(the rom flie is 8700339.rom which is 
> provided by NDI):
> write(fd,"PHRQ *********1****",20);
> got handle 01;
> then assign the file with 16 addresses
> write(fd, "PVWR 
> 0100004E444900D2110000010000000000000100000000031480345A00000004000000040000000000403F000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 01004000002041000000000000000000000000000000000000000052B8E4417B14244200000000000000000000B04200000000AE4731C2CDCC21420000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 01008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 0100C000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 01010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000803F00000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 010140000000000000803F00000000000000000000803F00000000000000000000803F0000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 01018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 0101C000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 0102000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001F1F1F1F\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 010240090000004E4449000000000000000000383730303333390000000000000000000000000009010101010000000000000000000000000000000001010101000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 010280000000000000000000000000008000290000000000000000000080BF0 
> 00000000000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 0102C000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 01030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 01034000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 01038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r", 
> 140);
> usleep(1000000);
> write(fd, "PVWR 
> 0103C000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 
> 000\r", 140);
> usleep(1000000);
> write(fd,"PINIT 01",9);
> error40...
>  
>  
> regards,
>  
> Jason
>  
>  
>  > Date: Mon, 30 Mar 2009 09:45:34 -0400
>  > From: zivy at isis.imac.georgetown.edu
>  > To: famousyi at hotmail.com
>  > CC: igstk-users at public.kitware.com
>  > Subject: Re: [IGSTK-Users] Polaris reference tool
>  >
>  > Dear Jason YEE,
>  >
>  > To set a tool as a dynamic reference you first initialize the tool as
>  > you would with all tools then attach it to the tracker and finally set
>  > it as a dynamic reference.
>  >
>  > pseudo code:
>  >
>  > Tracker;
>  > Tool;
>  >
>  > Create and initialize tracker;
>  > Create and initialize Tool;
>  >
>  > Tool->RequestAttachToTracker(Tracker);
>  > Tracker->RequestSetReferenceTool(Tool);
>  >
>  >
>  > Once you start tracking the reported transformation will be relative to
>  > the reference frame.
>  >
>  >
>  > If you are looking for generic code that works with all IGSTK supported
>  > trackers please take a look at the TrackerController class and the
>  > tracker configuration and xml file readers. These allow you to specify
>  > the tool configuration in an xml file and you don't have to write the
>  > initialization and setup code as described above. A good example of
>  > using this framework is the Navigator application.
>  >
>  > regards
>  > Ziv
>  >
>  >
>  > Jason YEE wrote:
>  > > greetings,
>  > >
>  > > I am encountering a problem with the reference port handle of the
>  > > polaris currently, I seek your help:
>  > >
>  > > There is no API command for setting the reference port handle (Is it
>  > > right?), so how the position sensor know which tool has been set to be
>  > > the reference?
>  > >
>  > > Could you please tell me a method for setting the reference and 
> getting
>  > > transform with respect to reference?
>  > >
>  > > Any help is very much appreciated,
>  > >
>  > > Regards,
>  > >
>  > > Jason
>  > > 
> ------------------------------------------------------------------------
>  > > See all the ways you can stay connected to friends and family
>  > > <http://www.microsoft.com/windows/windowslive/default.aspx>
>  > >
>  > >
>  > > 
> ------------------------------------------------------------------------
>  > >
>  > > _______________________________________________
>  > > Powered by www.kitware.com
>  > >
>  > > Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
>  > >
>  > > Follow this link to subscribe/unsubscribe:
>  > > http://public.kitware.com/cgi-bin/mailman/listinfo/igstk-users
>  >
>  >
>  > --
>  > Ziv Yaniv, PhD., Research Assistant Professor
>  > Imaging Science and Information Systems (ISIS) Center
>  > Department of Ra diology
>  > Georgetown University Medical Center
>  > 2115 Wisconsin Avenue, Suite 603
>  > Washington, DC, 20007,
>  >
>  > Phone: +1-202-687-7286
>  > Fax: +1-202-784-3479
>  > email: zivy at isis.georgetown.edu
>  > web: http://isiswiki.georgetown.edu/zivy/
> 
> ------------------------------------------------------------------------
> Invite your mail contacts to join your friends list with Windows Live 
> Spaces. It's easy! Try it! 
> <http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/cgi-bin/mailman/listinfo/igstk-users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NDI API -- Flow Chart.png
Type: image/png
Size: 50942 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/igstk-users/attachments/20090331/176e6d89/attachment-0002.png>


More information about the IGSTK-Users mailing list