Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleIselLinearControlTwoAxis.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /** @example ExampleIselLinearControlTwoAxis.cpp
26  @relates IselLinearControlTwoAxis
27  @ingroup g_examples
28  @brief Example for using the Isel iMC-S8 linear controller,
29  defines a command line interface
30  @author MIP
31 */
32 
33 #include <PanTilt/IselLinearControlTwoAxis.hh>
34 
35 using namespace BIAS;
36 using namespace std;
37 
38 int main(int argc, char *argv[])
39 {
40  char menuChoice;
41  int input, input2;
42  float f, f2;
43  string s;
45 
46 
47  if(argc != 2) {
48  cout << "Usage: ./ExampleIselLinearControlTwoAxis <PortName>" << endl;
49  return -1;
50  }
51 
52  if (control.Init(argv[1]) != 0) {
53  cout << "Initialising IGOR unit on serial port x failed!" << endl;
54  return -1;
55  }
56 
57  control.SetSpeed(1, 1);
58 
59  cout << "bla" << endl;
60 
61  while(true) {
62  cout << "============================" << endl;
63  cout << "(1) move x-axis" << endl;
64  cout << "(2) move y-axis" << endl;
65  cout << "(3) status output" << endl;
66  cout << "(4) set speed" << endl;
67  cout << "(5) reference movement" << endl;
68  cout << "(6) move free" << endl;
69  cout << "(7) position output" << endl;
70  cout << "(8) set position" << endl;
71  cout << "(9) send command" << endl;
72  cout << "(Q) quit" << endl;
73 
74  cin >> menuChoice;
75  switch (menuChoice) {
76  case '1':
77  cout << "move distance (mm):" << endl;
78  cin >> input;
79  control.Move(input,0);
80  break;
81  case '2':
82  cout << "move distance (mm):" << endl;
83  cin >> input;
84  control.Move(0,input);
85  break;
86  case '3':
87  control.SendRawCommand("@0h\r");
88  while (control.ReadRawLine(s) == 0) {}
89  cout << s << endl;
90  break;
91  case '4':
92  cout << "set speed on x-axis (mm/sec) to:" << endl;
93  cin >> input;
94  cout << "set speed on y-axis (mm/sec) to:" << endl;
95  cin >> input2;
96  control.SetSpeed(input, input2);
97  break;
98  case '5':
99  control.Reset();
100  break;
101  case '6':
102  control.SendRawCommand("@0F1\r");
103  control.SendRawCommand("@03\r");
104  break;
105  case '7':
106  control.GetCurrentPosition(f, f2);
107  cout << "position (mm): " << f <<", " << f2 << endl;
108  break;
109  case '8':
110  cout << "set position on x-axis (mm) to:" << endl;
111  cin >> input;
112  cout << "set position on y-axis (mm) to:" << endl;
113  cin >> input2;
114  control.SetPosition(input, input2);
115  break;
116  case '9':
117  cout << "enter command:" << endl;
118  cin >> s;
119  control.SendRawCommand(s + "\r");
120  while (control.ReadRawLine(s) == 0) {}
121  cout << "return: " << s << endl;
122  break;
123  case 'Q':
124  case 'q':
125  return 0;
126  default:
127  cout << "unknown input!" << endl;
128  }
129  }
130 }
This class controls the Isel iMC-S8 Linear Unit (two axis controll)
void SendRawCommand(const std::string cmd)
Send a command string, terminated by &lt;cr&gt; character.
void GetCurrentPosition(float &millimetersX, float &millimetersY)
int Init(const int nCOMportNumber)
opens the serial port and initialises unit
int SetSpeed(const float speedX, const float speedY)
sets the maximum/desired speed for all movements in millimeter per second
int SetPosition(const float millimetersX, const float millimetersY, const bool bWaitComplete=true)
int Reset(const int axis=3)
Start Reference Tour on given axis (1-x, 2-y, or 3 x+y)
int Move(const float millimetersX, const float millimetersY)
move millimeters in directions
int ReadRawLine(std::string &cmd)
Read a line from the serial port, returns length of read string, zero on nothing to read...