mykni.cpp
Go to the documentation of this file.
1 // mykni.cpp
3 // demo program training
5 #include "kniBase.h"
6 #include <iostream>
7 #include <cstdio>
8 #include <memory>
9 #include <vector>
10 #include <fstream>
12 #ifdef WIN32
13 # include <conio.h>
14 #else //LINUX
15 #include "keyboard.h"
16 #endif
17 #define LEFT false
18 #define RIGHT true
19 //Katana structs:
21 struct TPoint {
22  double X, Y, Z;
23  double phi, theta, psi;
24 };
25 struct TCurrentMot {
26  int idx;
27  bool running;
28  bool dir;
29 };
30 struct Tpos{
31  static std::vector<int> x,y,z,u,v,w;
32  static const int xArr[], yArr[], zArr[], uArr[], vArr[], wArr[];
33 };
35 //Katana obj.
36 std::unique_ptr<CLMBase> katana;
37 int retVal = 0;
38 const double PI = 3.14159265358979323846;
40 int main(int argc, char *argv[]) {
41  if (argc != 3) {
42  std::cout << "---------------------------------\n";
43  std::cout << "usage for socket connection: socketcontrol CONFIGFILE IP_ADDR\n";
44  std::cout << "---------------------------------\n";
45  return 0;
46  }
47  std::cout << "--------------------------\n";
48  std::cout << "SOCKETCONTROL DEMO STARTED\n";
49  std::cout << "--------------------------\n";
50  std::unique_ptr<CCdlSocket> device;
51  std::unique_ptr<CCplSerialCRC> protocol;
52  try {
53  int port = 5566;
54  device.reset(new CCdlSocket(argv[2], port));
55  std::cout << "-------------------------------------------\n";
56  std::cout << "success: port " << port << " open\n";
57  std::cout << "-------------------------------------------\n";
58  protocol.reset(new CCplSerialCRC());
59  std::cout << "-------------------------------------------\n";
60  std::cout << "success: protocol class instantiated\n";
61  std::cout << "-------------------------------------------\n";
62  protocol->init(device.get()); //fails if no response from Katana
63  std::cout << "-------------------------------------------\n";
64  std::cout << "success: communication with Katana initialized\n";
65  std::cout << "-------------------------------------------\n";
66  katana.reset(new CLMBase());
67  katana->create(argv[1], protocol.get());
68  } catch(Exception &e) {
69  std::cout << "ERROR: " << e.message() << std::endl;
70  return -1;
71  }
72  std::cout << "-------------------------------------------\n";
73  std::cout << "success: katana initialized\n";
74  std::cout << "-------------------------------------------\n";
75  std::vector<int> encoders(katana->getNumberOfMotors(), 0);
76  TCurrentMot mot[6];
77  for (int i = 0; i< 6; i++){
78  mot[i].running = false;
79  mot[i].idx = i;
80  mot[i].dir = true;
81  mot[i].dir = RIGHT;
82  }
83  //set linear velocity to 60
84  try{
85  katana->setMaximumLinearVelocity(60);
86  katana->calibrate();
87  //....continue here
88  }
89  catch(...){
90  std::cout << "-------------------------------------------\n";
91  std::cout << "An exception occurred while communicating with the Katana.\n";
92  std::cout << "-------------------------------------------\n";
93  }
94  return 0;
95 }
static std::unique_ptr< CCdlSocket > device
Definition: kni_wrapper.cpp:23
double Z
Definition: control.cpp:41
static std::unique_ptr< CCplSerialCRC > protocol
Definition: kni_wrapper.cpp:24
std::string message() const
int main(int argc, char *argv[])
Definition: mykni.cpp:40
std::unique_ptr< CLMBase > katana
Definition: mykni.cpp:36
double theta
Definition: control.cpp:42
int retVal
Definition: mykni.cpp:37
Implement the Serial-Zero protocol.
Definition: cplSerial.h:137
double phi
Definition: control.cpp:42
Definition: control.cpp:51
double Y
Definition: control.cpp:41
Encapsulates the socket communication device.
Definition: cdlSocket.h:65
structure for the currently active axis
Definition: control.cpp:45
double psi
Definition: control.cpp:42
Linear movement Class.
Definition: lmBase.h:73
#define RIGHT
Definition: mykni.cpp:18
const double PI
Definition: mykni.cpp:38
bool running
Definition: control.cpp:47
double X
Definition: control.cpp:41
std::vector< int > encoders
Definition: kni_wrapper.cpp:29


kni
Author(s): Martin Günther
autogenerated on Fri Jun 7 2019 22:06:44