PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
CivcoBrachyStepperTest.cxx
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2  Program: Plus
3  Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4  See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #include "PlusConfigure.h"
8 #include "vtksys/CommandLineArguments.hxx"
9 #include "PlusBrachyStepper.h"
10 #include "PlusCivcoBrachyStepper.h"
11 #include <stdlib.h>
12 #include <iostream>
13 
14 int main (int argc, char* argv[])
15 {
16  bool printHelp(false);
17  bool resetStepper(false);
18  int inputComPort(2);
19  int inputNumberOfTrials(20);
20  int samplingTimeMs(50);
21 
22  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
23 
24  vtksys::CommandLineArguments args;
25  args.Initialize(argc, argv);
26 
27  args.AddArgument("--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help.");
28  args.AddArgument("--reset", vtksys::CommandLineArguments::NO_ARGUMENT, &resetStepper, "Reset the stepper.");
29  args.AddArgument("--com-port", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputComPort, "Com port number (Default: 2)." );
30  args.AddArgument("--number-of-trials", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputNumberOfTrials, "Number of trials (Default: 20)." );
31  args.AddArgument("--sampling-time", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &samplingTimeMs, "Sampling time in milliseconds (Default: 20)." );
32  args.AddArgument("--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
33 
34  if ( !args.Parse() )
35  {
36  std::cerr << "Problem parsing arguments" << std::endl;
37  std::cout << "\n\nCivcoBrachyStepperTest help:" << args.GetHelp() << std::endl;
38  exit(EXIT_FAILURE);
39  }
40 
41  vtkPlusLogger::Instance()->SetLogLevel(verboseLevel);
42 
43  if ( printHelp )
44  {
45  std::cout << "\n\nCivcoBrachyStepperTest help:" << args.GetHelp() << std::endl;
46  exit(EXIT_SUCCESS);
47 
48  }
49 
50  for ( int reconnect = 0; reconnect < 5; reconnect++ )
51  {
52  LOG_INFO("Starting test " << reconnect + 1 );
53 
54  PlusCivcoBrachyStepper *myStepper = new PlusCivcoBrachyStepper(inputComPort, 19200);
55 
56  if ( myStepper->Connect() != PLUS_SUCCESS )
57  {
58  LOG_ERROR("Couldn't connect to tracker!");
59  return EXIT_FAILURE;
60  }
61 
62 
63  if ( resetStepper && reconnect == 0)
64  {
65  LOG_INFO( "Resetting stepper...");
66  if (!myStepper->ResetStepper())
67  {
68  resetStepper = false;
69  LOG_ERROR("Wrong answer received!");
70  return EXIT_FAILURE;
71  }
72  }
73 
74  LOG_INFO( "Getting stepper's device info...");
75 
76  std::string version;
77  std::string model;
78  std::string serial;
79  if (myStepper->GetDeviceModelInfo(version, model, serial) == PLUS_SUCCESS )
80  {
81  LOG_INFO("Version = " << version << "\tModel = " << model << "\tSerial = " << serial );
82  }
83  else
84  {
85  LOG_ERROR("Wrong answer received!");
86  return EXIT_FAILURE;
87  }
88 
89 
90  LOG_INFO( "Getting stepper's encoder values...");
91  for (int i = 0; i<inputNumberOfTrials; i++)
92  {
93  double pposition=0, gposition=0, rposition=0;
94  unsigned long positionRequestNumber(0);
95  if (myStepper->GetEncoderValues(pposition, gposition, rposition, positionRequestNumber))
96  {
97  LOG_INFO("Probe = " << pposition << " mm\tGrid = " << gposition << " mm\tRotate = " << rposition << " deg\tRequestNumber = " << positionRequestNumber);
98  }
99  else
100  {
101  LOG_ERROR("Wrong answer received!");
102  //return EXIT_FAILURE;
103  }
104 
105  vtkIGSIOAccurateTimer::Delay(0.001*samplingTimeMs);
106  }
107 
108  LOG_INFO( "Stopping stepper...\n");
109  myStepper->Disconnect();
110  }
111 
112  LOG_INFO( "Exit successfully...");
113 
114  return EXIT_SUCCESS;
115 }
virtual PlusStatus ResetStepper()
virtual PlusStatus Disconnect()
for i
virtual PlusStatus GetEncoderValues(double &PPosition, double &GPosition, double &RPosition, unsigned long &PositionRequestNumber)
virtual PlusStatus GetDeviceModelInfo(std::string &version, std::string &model, std::string &serial)
int main(int argc, char *argv[])
virtual PlusStatus Connect()
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
static vtkIGSIOLogger * Instance()