1 Motion Tracking Polhemus Liberty Latus References 1
1. Motion Tracking - Polhemus Liberty Latus References: 1. Liberty Latus Manual, Polhemus, 2005 2. G. Burdea and P. Coiffet, Virtual Reality Technology 2 nd Ed. , Wiley, New Jersey, 2003, Ch. 2 3. J. M. Hart, Windows System Programming, 3 rd Ed. , Addison-Wesley, 2005, Ch. 12 Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 1
Motion Tracking Systems l l A motion tracking system is often the most important I/O Devices of a Virtual Reality system It detects the position and orientation (P&O) of multiple objects in the 3 D space and feeds into the VR Engine Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 2
3 -D System of Coordinates of Objects l 3 D objects have 6 degrees of freedom (D. O. Fs) of movement: l l three translations – (x, y, z); three rotations – (Azimuth (az), Elevation (el) and Roll (ro)). Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 3
Tracking Technologies l Trackers measure the motion of “objects” such as user’s wrist or his head vs. a fixed system of coordinates. l Technologies to perform this task: l Magnetic (prevalent, less expensive) l l l Ultrasonic (less used, low resolution) Mechanical (special cases, only when size and weight are not matter) l l E. g. Fakespace’s Push 1280 Vision-based (expensive, high accuracy) l l E. g. Polhemus’s Liberty Latus, Ascension’s FOB E. g. A. R. T. Gmb. H’s ARTrack Inertial/Vision-based (cheap but limited functionality) l E. g. WII of Nintendo Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 4
Characteristics of Trackers l Different tracking systems have different characteristics l Measurement rate – Readings/sec; l Sensing latency; l Sensor noise and drift; l Measurement accuracy (errors); l Measurement repeatability; l Tethered or wireless; l Sensing degradation; l Restriction on the working environment; l Cost l To build a VR system using a particular tracking system, good understanding of its technology and limitations is required Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 5
Magnetic Tracking Systems l Definition: A magnetic tracker is a noncontact position measurement device that uses a magnetic field produced by a stationary TRANSMITTER to determine the real-time position of a moving RECEIVER element Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 6
Working principle l l Magnetic field picked up by an antenna can be converted into electrical signal The electric power induced depends on the magnetic field strength l l The strength of magnetic field follows inverse square law l l The longer is the distance between the transmitter and antenna, the lower is the power Magnitude decreases as the square of the distance Magnetic field is directional l E. g. vertical magnetic field can only be picked up by antenna placed vertically Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 7
Working Principle l l When the object is moving or rotating, voltage of different magnitude will be generated in its three antennas based on the distance moved and the rotation angle Receiver antenna (stationary) Such information will be sent to the computer for analyzing the P&O information of the moving object Magnetic wave Transmitter antenna (moving) Tx G Tx B Tx R Rx B Rx R Rx G Send back to the computer for further analysis Time 8
Limitations l Performance will be significantly degraded if there is ferromagnetic material nearby the transmitter or receiver Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 9
Case study – Polhemus’s Liberty Latus l l l The LIBERTY LATUS (Large Area Tracking Untethered System) is a magnetic based motion tracking system Design to track the position and orientation (P&O) of multiple objects in the 3 D space Comprise 3 major components: l SEU – System Electronic Unit l Receptors l Wireless Markers Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 10
Working Principle Signals of multiple frequencies are sent back to SEU for analysis Markers/Transmitters (moving) Magnetic wave of different frequencies Receptor / Receiver (stationary) 11
Characteristics l l l Each transmitter “marker” position is measured by a receiver “receptor” within 8 ft. One receiver can track 4 markers. l In practice, inaccurate data will be received if the distance between marker and receptor is larger than 1 m The system can have up to 12 markers and up to 16 receptors l In DE 505 a, 8 markers and 4 receptors are installed Sampling rate is 188 Hz up to 8 markers and drops to 94 Hz from 9 to 12 markers Markers are battery powered up to 2. 5 hours and weigh 2 ounces each l Battery life can be shorter when using for long time For one marker and one receptor accuracy is 0. 04 mm and 0. 0012 degree at 1 ft range and drops afterwards Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 12
Precautions When Using the System 1. 2. 3. 4. 5. Never put metallic objects near the receptors or markers. Wrong data will be generated Never put receptors and markers on the ground in DE 505 a since there are many metallic conduits laid under the ground Whenever a marker is switched on, there is a possibility that the phase of the data is wrong (from +ve to –ve or vice versa). It will also happen when the marker is moving too far away from the receptors. Switch the marker off and on again to obtain a correct phase When a marker is moved outside 1. 5 m from the receptors, the data received will have much noise. Denoising technique should be implemented in order to use the data in your game A marker should be moved too close (e. g. < 10 cm) to the receptor. Wrong data will be generated Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 13
More Precautions l l The floor of DE 505 a is not leveled. Some parts may be slightly higher than the other parts Try not to use the absolute values of the received data to determine the exact 3 D coordinates of a marker in the room, as the values can drift in time Use the relative difference between measures as much as possible The battery of the marker can be exhausted much earlier than expected. Replace the battery once noticing that there is abnormality in the received data Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 14
Software Architecture l For easy access of the data generated by Liberty Latus, a simple network server is installed that accepts clients’ connection thru Winsock Network backbone receptor Marker receptor SEU Motion Tracking Server receptor Windows Socket Server IP: 158. 132. 148. 212 Port: 8888 Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 15
Motion Tracking Server l l The server accepts string commands and replies different string for different requests Some commands are particularly important: 1. “hello” – When the user program sends a string “hello” to the server, the server will return a string “Hello client, have a nice day!” 2. “Q” – For closing a Winsock connection. 3. “P” – Return a string that contains the P&O data of all markers and the status of the markers Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 16
Retrieve the P&O Data l When the string of the P&O data is received, the function memcpy() has to be used to convert the string into an array of the structure Marker. Data: #define NMarker 8 //There are 8 markers in DE 505 a struct Marker. Data //Structure of marker data { float x, y, z, az, el, ro; //6 DOF of a marker bool status; //Status of a marker }; Marker. Data marker[NMarker]; //Define an array of 8 markers memcpy(marker, string. From. Server, sizeof(marker)); //string. From. Server is the string received from server 17 //Must use this command to convert between data type
Socket API and Socket l l l • • • The socket API is an Interprocess Communication (IPC) programming interface originally provided as part of the Berkeley UNIX OS Ported to all modern operating systems, including Sun Solaris and Windows systems It is a de facto standard for programming IPC, and is the basis of more sophisticated IPC interface such as remote procedure call and remote method invocation A socket API provides a programming construct termed a socket Process A Process B A process wishing to communicate with another process must instantiate such a construct The two processes then issue operations provided by the API to send and receive data. a socket Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 18
Connection-oriented stream socket A socket programming construct can make use of either the UDP or TCP protocol l Sockets that use UDP for transport are known as datagram sockets, while sockets that use TCP are termed stream sockets l Socket APIs can support both connectionless and connection -oriented communication at the application layer l For the Motion Tracking Server, it uses stream socket and works in connection-oriented mode, i. e. a connection has to be made before data can be sent or received l socket API runtime support Process A Process B socket API runtime support transport layer software connection-oriented datagram socket 19
Windows Sockets API l l An extension of the Berkeley Sockets API used in the Windows environment Porting of code already written for Berkeley Sockets l l l Windows stations easily integrated into TCP/IP networks Winsock API is supported by a DLL (ws 2_32. dll) that can be accessed by linking ws 2_32. lib with your project Include <winsock. h> as well for the definition of some names Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 20
General Procedure for Connecting to a Server l Just follow the procedure below and fill in the required information: WSAStartup(. . . ); //1. Initialize socket (. . . ); //2. Create a socket connect (. . . ); //3. Connect to the server send (. . . ); / recv (. . . ); //4. Send or receive data : closesocket (. . . ); //5. After using the socket, // close it. WSACleanup (. . . ); //6. Allow the system to 21 // free resource allocated
Winsock Initialization l l To initialize, a nonstandard Winsock-specific function WSAStartup must be the first function a program calls For example, WORD w. Version. Required; WSADATA wsa. Data; //Store the socket version //Store socket info w. Version. Required =. . . ; //Input the version number int error = WSAStartup( // Return non-zero if error w. Version. Required, (LPWSADATA)&wsa. Data); 22
WSAStartup() Parameters l w. Version. Required l l l Indicates the highest version of the Win. Sock DLL you need Returns a non-zero value if the DLL cannot support the version you want Can use a macro MAKEWORD to generate the number w. Version. Required = MAKEWORD(2, 2); //version 2. 2 lp. WSAData points to a WSADATA structure that returns information on the configuration of the DLL To obtain the error number, the function WSAGet. Last. Error() Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 23
Create a Socket l Call socket() to create (or open) a socket l For example, typedef unsigned int SOCKET; //Should have been included in <winsock. h> int af =. . . ; int type =. . . ; int protocol =. . . ; SOCKET the. Socket = socket(af, type, protocol); Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 24
socket() parameter l Input parameters include l l af denotes the address family. PF_INET designates the Internet protocol (IP) type specifies connection-oriented (SOCK_STREAM) or datagram communications (SOCK_DGRAM) protocol – unnecessary if using TCP/IP l Use IPPROTO_TCP socket returns SOCKET_ERROR upon failure Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 25
Connect to a Server l l To connect to the Motion Tracking Server, a client program can call the function connect() if it has a socket For example, SOCKET s =. . . ; SOCKADDR_IN server. Info =. . . ; int n. Name. Len =. . . ; int connect. Result = connect(s, (LPSOCKADDR)&server. Info, n. Name. Len); 26
connect Parameters l Input parameters: l l s – a socket created by socket() function &server. Info – a LPSOCKADDR pointer that points to a SOCKADDR_IN structure designating the server machine name and port address n. Name. Len – should give the size of SOCKADDR_IN l Use sizeof() Return 0 indicates a successful connection, otherwise SOCKET_ERROR indicate failure l Possibly due to the server socket is not listening to clients’ request Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 27
SOCKADDR_IN Structure l The structure SOCKADDR_IN is protocol dependent. For TCP/IP, it is defined as struct sockaddr_in { short sin_family; // PF_INET u_short sin_port; struct sin_addr; //4 -byte IP addr char sin_zero [8]; }; typedef struct sockaddr_in SOCKADDR_IN //Should have been defined in //<winsock. h> 28
Parameters of SOCKADDR_IN l sin_family l l Address family, should be the same as the parameter af when calling socket(), i. e. PR_INET, e. g. server. Info. sin_family = PF_INET; sin_port l l Specify port number of the server Should call the function htons() to enter this value. E. g. int port. No = …; //Specify the port number server. Info. sin_port = htons(port. No); 29
Parameters of SOCKADDR_IN l sin_addr l l sin_addr is a structure that has a sub-member s_addr. Should be filled with server’s IP address The function inet_addr() can be used as follows: std: : string ip. Address; // Assume ip. Address contains // the IP address of the server SOCKADDR_IN sa; //Define an instance of the structure sa. sin_addr. s_addr = inet_addr(ip. Address. c_str()); //Set the IP address of server l sin_zeros l Just to pad enough zeros to make the structure the same size as SOCKADDR. No need to initialize it 30
Send or Receive Data l l l After the connection is made, the client can send or receive data to or from the server Partner stations exchange data using send() and recv() have identical arguments: int send ( int recv ( SOCKET s, LPSTR lp. Buffer, int n. Buffer. Len, int n. Flags); Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 31
send / recv Parameters l l lp. Buffer l send: the string to be sent l recv: keep the received string n. Buffer. Len l send: the length of the string l recv: the size of the buffer used to keep the string n. Flags l Can be used to indicate urgency l Can also be used to allow reading the data but not removing it l In general, use 0 Return the actual number of bytes transmitted or received. An error is indicated by the value SOCKET_ERROR Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 32
When Finish … l l When finish transmitting or receiving data, remember to destroy the socket and release the resource Use closesocket() and WSACleanup() as follows: SOCKET s; : //After finish using the socket. . . : closesocket(s); //The name of the socket is s WSACleanup(); //Release the resource acquired 33
System Software Architecture Windows Socket Server IP: 158. 132. 148. 212 Port: 8888 Network backbone Motion Tracking Server Client Windows Socket Your Client Program Window. Socket Motion Tracking Server Simulator Windows Socket Server IP: 158. 132. 148. 218 Port: 8889 Latus Ogre Graphics Engine m. Marker[8] Should be used to keeping the current markers’ data 34
Responses of the Servers String sent from the client “hello” Response of the server “Q” The Winsock connection will be terminated Return a string that contains the P&O data of all markers and the status of the markers “P” “Hello client, have a nice day!” Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 35
Structure of the Client Program Window. Socket -m. Socket : SOCKET -m. Connect : bool +Connect. To. Host(. . . ) +Close. Connection(. . . ) +Send. Msg(. . . ) +Receive. Msg(. . . ) +Is. Connect(. . . ) Latus Window. Socket is the base class for realizing Windows Sockets -m. Marker[NMARKER] : Marker. Data +Initialize(. . . ) +Update. PO(. . . ) +Get. X(. . . ) +Get. Y(. . . ) +Get. Z(. . . ) +Get. AZ(. . . ) +Get. EL(. . . ) +Get. RO(. . . ) +Get. Status(. . . ) Latus is derived from Window. Socket that extends its function to obtain markers’ data on the network 36
Things to be done in Lab 1 l l Construct a basic Ogre game Implement the class Window. Socket Implement the class Latus Apply the markers’ data obtained using the Latus class to the movement of Ogre objects Department of ELECTRONIC AND INFORMATION ENGINEERING 1. Motion Tracking – Polhemus Liberty Latus by Dr Daniel Lun 37
- Slides: 37