Thursday, June 10, 2010

Read Position + Quaternion from Polhemus Fastrak with Boost Asio

How to get data from a polhemus fastrak via the serial port (USB Serial adapter) with Boost. It is necessary to create an IOService object to that reads data from the serial port. Upon receipt of the data in a buffer, a solution would be to memcpy each float based on an index number (since the floats all come packed next to each other). So by preparing an array of 7 floats then doing a for loop on every element of that array we can copy the floats from our buffer with a memcpy:

//function to memcopy from a boost asio buffer containing polhemus floats
getFloat(int index) {
float temp = 0.0;
memcpy(&temp,buffer+3*sizeof(char)+index*sizeof(float),sizeof(float));
return temp;
}

In the case of linux if minicom is showing "Offline" even though you know you are connected to the right port and the right DIP settings (baud, width, parity, data stop bits etc) then disabling hardware flow control in minicom port settings might do the trick.

No comments:

Post a Comment