Volker Franz, University of Tübingen, Germany
Each example shows first
the Matlab-code and second the
code you would need to perform the same actions using the
C-programming language. You can see two things: (a) the Matlab code
using the Optotrak Toolbox is much shorter and more efficient than C
(b) it is nevertheless a 1-to-1 translation of the relevant
C-commands. Please select the sample you want to view:
|
Matlab-code for sample1:
%Name: SAMPLE1.M
%Description:
% OPTOTRAK Sample Program #1.
% 1. Load the system of transputers with the appropriate
% transputer programs.
% 2. Initiate communications with the transputer system.
% 3. Load the appropriate camera parameters.
% 4. Request/receive/display the current OPTOTRAK system status.
% Pass NULL for those status variables that are not
% requested.
% 5. Disconnect the PC application program from the transputer
% system.
%Just to be on the save side, we first reset all Matlab functions:
clear functions
%Load the system of transputers.
optotrak('TransputerLoadSystem','system');
%Wait one second to let the system finish loading.
pause(1);
%Initialize the transputer system.
optotrak('TransputerInitializeSystem',{'OPTO_LOG_ERRORS_FLAG'})
%Load the standard camera parameters.
optotrak('OptotrakLoadCameraParameters','standard')
%Request and print the OPTOTRAK status.
optotrak('OptotrakPrintStatus')
%%Shutdown the transputer message passing system.
optotrak('TransputerShutdownSystem')
%Exit the program.
fprintf('\nProgram execution complete.\n');
|
|
Corresponding C-code for sample1:
/*****************************************************************
Name: SAMPLE1.C
Description:
OPTOTRAK Sample Program #1.
1. Load the system of transputers with the appropriate
transputer programs.
2. Initiate communications with the transputer system.
3. Load the appropriate camera parameters.
4. Request/receive/display the current OPTOTRAK system status.
Pass NULL for those status variables that are not
requested.
5. Disconnect the PC application program from the transputer
system.
*****************************************************************/
/*****************************************************************
C Library Files Included
*****************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef _MSC_VER
void sleep( unsigned int uSec );
#elif __BORLANDC__
#include <dos.h>
#elif __WATCOMC__
#include <dos.h>
#endif
/*****************************************************************
ND Library Files Included
*****************************************************************/
#include "ndtypes.h"
#include "ndpack.h"
#include "ndopto.h"
/*****************************************************************
Name: main
Input Values:
int
argc :Number of command line parameters.
unsigned char
*argv[] :Pointer array to each parameter.
Output Values:
None.
Return Value:
None.
Description:
Main program routine performs all steps listed in the above
program description.
*****************************************************************/
void main( int argc, unsigned char *argv[] )
{
int
nNumSensors,
nNumOdaus,
nMarkers;
char
szNDErrorString[MAX_ERROR_STRING_LENGTH + 1];
/*
* Load the system of transputers.
*/
if( TransputerLoadSystem( "system" ) )
{
goto ERROR_EXIT;
} /* if */
/*
* Wait one second to let the system finish loading.
*/
sleep( 1 );
/*
* Initialize the transputer system.
*/
if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG ))
{
goto ERROR_EXIT;
} /* if */
/*
* Load the standard camera parameters.
*/
if( OptotrakLoadCameraParameters( "standard" ) )
{
goto ERROR_EXIT;
} /* if */
/*
* Request and receive the OPTOTRAK status.
*/
if( OptotrakGetStatus(
&nNumSensors, /* Number of sensors in the OPTOTRAK system. */
&nNumOdaus, /* Number of ODAUs in the OPTOTRAK system. */
NULL, /* Number of rigid bodies being tracked by the O/T. */
&nMarkers, /* Number of markers in the collection. */
NULL, /* Frequency that data frames are being collected. */
NULL, /* Marker firing frequency. */
NULL, /* Dynamic or Static Threshold value being used. */
NULL, /* Minimum gain code amplification being used. */
NULL, /* Stream mode indication for the data buffers */
NULL, /* Marker Duty Cycle being used. */
NULL, /* Voltage being used when turning on markers. */
NULL, /* Number of seconds data is being collected. */
NULL, /* Number of seconds data is being pre-triggered. */
NULL ) ) /* Configuration flags. */
{
goto ERROR_EXIT;
} /* if */
/*
* Display elements of the status received.
*/
fprintf( stdout, "Sensors in system :%3d\n", nNumSensors );
fprintf( stdout, "ODAUs in system :%3d\n", nNumOdaus );
fprintf( stdout, "Default OPTOTRAK Markers:%3d\n", nMarkers );
/*
* Shutdown the transputer message passing system.
*/
if( TransputerShutdownSystem() )
{
goto ERROR_EXIT;
} /* if */
/*
* Exit the program.
*/
fprintf( stdout, "\nProgram execution complete.\n" );
exit( 0 );
ERROR_EXIT:
if( OptotrakGetErrorString( szNDErrorString,
MAX_ERROR_STRING_LENGTH + 1 ) == 0 )
{
fprintf( stdout, szNDErrorString );
} /* if */
TransputerShutdownSystem();
exit( 1 );
} /* main */
|