KNI.net.cpp
Go to the documentation of this file.
1 // This is the main DLL file.
2 
3 #include "stdafx.h"
4 
5 #include "KNI.net.h"
6 
7 #include<vcclr.h>
8 #include <string>
9 #include <exception>
10 
11 namespace KNInet {
12 
13  bool To_string( System::String^ source, std::string &target ) {
14  int len = (( source->Length+1) * 2);
15  char *ch = new char[ len ];
16  bool result ;
17  {
18  pin_ptr<const wchar_t> wch = PtrToStringChars( source );
19  result = wcstombs( ch, wch, len ) != -1;
20  }
21  target = ch;
22  delete ch;
23  return result ;
24  }
27  if(katana) delete katana;
28  if(proto) delete proto;
29  if(comm) delete comm;
30  if(socket) delete socket;
31  }
33  Katana::Katana(System::String ^ipAddress, System::String ^configurationFile) :
34  katana(0), socket(0), proto(0) {
35  std::string ip, portno, configFile;
36  To_string(ipAddress, ip);
37  //To_string(port, portno);
38  To_string(configurationFile, configFile);
39  try {
40  socket = new CCdlSocket(const_cast<char*>(ip.c_str()), atoi("5566"));
41  proto = new CCplSerialCRC();
42  proto->init(socket);
43 
44  katana = new CLMBase();
45  katana->create(configFile.c_str(), proto);
46  } catch(std::exception &e) {
47  throw gcnew System::Exception(gcnew System::String(e.what()));
48  }
49  }
51  //Katana::Katana(System::String ^connectionString, System::String ^configurationFile) :
52  // katana(0), comm(0), proto(0) {
53  // std::string connString, configFile;
54  // To_string(connectionString, connString);
55  // To_string(configurationFile, configFile);
56 
57  // try {
58  // TCdlCOMDesc ccd = {atoi(connString.c_str()), 57600, 8, 'N', 1, 300, 0};
59  // comm = new CCdlCOM(ccd);
60 
61  // proto = new CCplSerialCRC();
62  // proto->init(comm);
63 
64  // katana = new CLMBase();
65  // katana->create(configFile.c_str(), proto);
66  // } catch(std::exception &e) {
67  // throw gcnew System::Exception(gcnew System::String(e.what()));
68  // }
69  //}
71  void Katana::calibrate(void) {
72  try {
73  katana->calibrate();
74  } catch(std::exception &e) {
75  throw gcnew System::Exception(gcnew System::String(e.what()));
76  }
77  }
79  array<int>^ Katana::getRobotEncoders(bool refreshEncoders) {
80  std::vector<int> encodersVec(katana->getNumberOfMotors(), 0);
81  array<int> ^encoders = gcnew array<int>(encodersVec.size());
82  try {
83  katana->getRobotEncoders(encodersVec.begin(), encodersVec.end(), refreshEncoders);
84  } catch(std::exception &e) {
85  throw gcnew System::Exception(gcnew System::String(e.what()));
86  }
87  for(unsigned int i = 0; i < encodersVec.size(); ++i) {
88  encoders[i] = encodersVec[i];
89  }
90  return encoders;
91  }
93  void Katana::moveRobotToEnc(array<int> ^encoders, bool waitUntilReached, int waitTimeout) {
94  std::vector<int> encoderVector(katana->getNumberOfMotors(), 0);
95  for(int i = 0; i < katana->getNumberOfMotors(); ++i) {
96  encoderVector[i] = encoders[i];
97  }
98  try {
99  katana->moveRobotToEnc(encoderVector, waitUntilReached, waitTimeout);
100  } catch(std::exception &e) {
101  throw gcnew System::Exception(gcnew System::String(e.what()));
102  }
103  }
105  void Katana::moveMotorToEnc(int motor, int encoder, bool waitUntilReached, int waitTimeout){
106  try {
107  katana->moveMotorToEnc(motor, encoder, waitUntilReached, waitTimeout);
108  } catch(std::exception &e) {
109  throw gcnew System::Exception(gcnew System::String(e.what()));
110  }
111  }
113  array<double>^ Katana::getCoordinates(bool refreshEncoders) {
114  std::vector<double> coordinateVector(6,0);
115  try {
117  coordinateVector[0],
118  coordinateVector[1],
119  coordinateVector[2],
120  coordinateVector[3],
121  coordinateVector[4],
122  coordinateVector[5],
123  refreshEncoders);
124  } catch(Exception &e) {
125  throw gcnew System::Exception(gcnew System::String(e.what()));
126  }
127 
128  array<double> ^coordinates = gcnew array<double>(6);
129  for(unsigned int i = 0; i < 6; ++i) {
130  coordinates[i] = coordinateVector[i];
131  }
132  return coordinates;
133  }
135  void Katana::moveRobotTo(array<double> ^coordinates, bool waitUntilReached, int waitTimeout) {
136  std::vector<double> coordinateVector(6, 0);
137  for(unsigned int i = 0; i < 6; ++i) {
138  coordinateVector[i] = coordinates[i];
139  }
140  try {
141  katana->moveRobotTo(coordinateVector, waitUntilReached, waitTimeout);
142  } catch(std::exception &e) {
143  throw gcnew System::Exception(gcnew System::String(e.what()));
144  }
145  }
147  void Katana::moveRobotLinearTo(array<double> ^coordinates, bool waitUntilReached, int waitTimeout) {
148  std::vector<double> coordinateVector(6, 0);
149  for(unsigned int i = 0; i < 6; ++i) {
150  coordinateVector[i] = coordinates[i];
151  }
152  try {
153  katana->moveRobotLinearTo(coordinateVector, waitUntilReached, waitTimeout);
154  } catch(std::exception &e) {
155  throw gcnew System::Exception(gcnew System::String(e.what()));
156  }
157  }
159  void Katana::setMaximumLinearVelocity(double maximumVelocity) {
160  katana->setMaximumLinearVelocity(maximumVelocity);
161  }
165  }
169  }
173  }
176  try {
178  } catch(std::exception &e) {
179  throw gcnew System::Exception(gcnew System::String(e.what()));
180  }
181  }
184  try {
186  } catch(std::exception &e) {
187  throw gcnew System::Exception(gcnew System::String(e.what()));
188  }
189  }
192  try {
193  katana->unBlock();
194  } catch(std::exception &e) {
195  throw gcnew System::Exception(gcnew System::String(e.what()));
196  }
197  }
198  void Katana::setCollisionLimit(int number, int limit) {
199  try {
200  katana->setCrashLimit(number, limit);
201  } catch(std::exception &e) {
202  throw gcnew System::Exception(gcnew System::String(e.what()));
203  }
204  }
207  return katana->getNumberOfMotors();
208  }
210  int Katana::getMotorEncoders(int number, bool refreshEncoders) {
211  try {
212  return katana->getMotorEncoders(number, refreshEncoders);
213  } catch(std::exception &e) {
214  throw gcnew System::Exception(gcnew System::String(e.what()));
215  }
216  }
219  return katana->getMotorVelocityLimit(number);
220  }
223  return katana->getMotorAccelerationLimit(number);
224  }
226  void Katana::setMotorVelocityLimit(int number, int velocity) {
227  katana->setMotorVelocityLimit(number, velocity);
228  }
231  katana->setMotorAccelerationLimit(number, acceleration);
232  }
234  void Katana::openGripper(bool waitUntilReached, int waitTimeout) {
235  try {
236  katana->openGripper(waitUntilReached, waitTimeout);
237  } catch(std::exception &e) {
238  throw gcnew System::Exception(gcnew System::String(e.what()));
239  }
240  }
242  void Katana::closeGripper(bool waitUntilReached, int waitTimeout) {
243  try {
244  katana->closeGripper(waitUntilReached, waitTimeout);
245  } catch(std::exception &e) {
246  throw gcnew System::Exception(gcnew System::String(e.what()));
247  }
248  }
251  try {
252  katana->freezeRobot();
253  } catch(std::exception &e) {
254  throw gcnew System::Exception(gcnew System::String(e.what()));
255  }
256  }
258  void Katana::freezeMotor(int number) {
259  try {
260  katana->freezeMotor(number);
261  } catch(std::exception &e) {
262  throw gcnew System::Exception(gcnew System::String(e.what()));
263  }
264  }
267  try {
269  } catch(std::exception &e) {
270  throw gcnew System::Exception(gcnew System::String(e.what()));
271  }
272  }
275  try {
277  } catch(std::exception &e) {
278  throw gcnew System::Exception(gcnew System::String(e.what()));
279  }
280  }
282  void Katana::switchMotorOn(int number) {
283  try {
284  katana->switchMotorOn(number);
285  } catch(std::exception &e) {
286  throw gcnew System::Exception(gcnew System::String(e.what()));
287  }
288  }
290  void Katana::switchMotorOff(int number) {
291  try {
292  katana->switchMotorOff(number);
293  } catch(std::exception &e) {
294  throw gcnew System::Exception(gcnew System::String(e.what()));
295  }
296  }
298 }
void switchMotorOff(int number)
Definition: KNI.net.cpp:290
int acceleration
void switchRobotOff()
Definition: KNI.net.cpp:274
int getNumberOfMotors()
Definition: KNI.net.cpp:206
void freezeMotor(short number)
Definition: kmlExt.cpp:571
void moveRobotToEnc(array< int >^encoders, bool waitUntilReached, int waitTimeout)
Definition: KNI.net.cpp:93
void setCrashLimit(long idx, int limit)
unblock robot after a crash
Definition: kmlExt.cpp:301
bool To_string(System::String^source, std::string &target)
Definition: KNI.net.cpp:13
void moveRobotLinearTo(double x, double y, double z, double phi, double theta, double psi, bool waitUntilReached=true, int waitTimeout=TM_ENDLESS)
Definition: lmBase.cpp:869
void setMotorVelocityLimit(int number, int velocity)
Definition: KNI.net.cpp:226
Implement the Serial-Zero protocol.
Definition: cplSerial.h:137
void freezeMotor(int number)
Definition: KNI.net.cpp:258
void openGripper(bool waitUntilReached=false, int waitTimeout=100)
Definition: kmlExt.cpp:551
void switchRobotOn()
Definition: kmlExt.cpp:578
void switchMotorOff(short number)
Definition: kmlExt.cpp:596
void openGripper(bool waitUntilReached, int waitTimeout)
Definition: KNI.net.cpp:234
void setActivatePositionController(bool activate)
Definition: KNI.net.cpp:167
BaseException Exception
Definition: myexcept.h:98
array< double > getCoordinates(bool refreshEncoders)
Definition: KNI.net.cpp:113
void switchMotorOn(int number)
Definition: KNI.net.cpp:282
void switchRobotOff()
Definition: kmlExt.cpp:584
void getCoordinates(double &x, double &y, double &z, double &phi, double &theta, double &psi, bool refreshEncoders=true)
Definition: ikBase.cpp:349
void setActivatePositionController(bool activate)
Definition: lmBase.cpp:911
bool getActivatePositionController()
Check if the position controller will be activated after the linear movement.
Definition: lmBase.cpp:914
CCplSerialCRC * proto
Definition: KNI.net.h:15
int getMotorEncoders(short number, bool refreshEncoders=true) const
Definition: kmlExt.cpp:362
void switchRobotOn()
Definition: KNI.net.cpp:266
void disableCollisionLimits()
Definition: KNI.net.cpp:183
CCdlCOM * comm
Definition: KNI.net.h:13
void freezeRobot()
Definition: KNI.net.cpp:250
void setMaximumLinearVelocity(double maximumVelocity)
Definition: lmBase.cpp:900
void moveMotorToEnc(int motor, int encoder, bool waitUntilReached, int waitTimeout)
Definition: KNI.net.cpp:105
void setCollisionLimit(int number, int limit)
Definition: KNI.net.cpp:198
Encapsulates the socket communication device.
Definition: cdlSocket.h:65
Katana(System::String^ipAddress, System::String^configurationFile)
Definition: KNI.net.cpp:33
void moveRobotLinearTo(array< double >^coordinates, bool waitUntilReached, int waitTimeout)
Definition: KNI.net.cpp:147
void enableCollisionLimits()
Definition: KNI.net.cpp:175
array< int > getRobotEncoders(bool refreshEncoders)
Definition: KNI.net.cpp:79
int getMotorAccelerationLimit(int number)
Definition: KNI.net.cpp:222
short getMotorVelocityLimit(short number) const
Definition: kmlExt.cpp:390
void setMaximumLinearVelocity(double maximumVelocity)
Definition: KNI.net.cpp:159
Linear movement Class.
Definition: lmBase.h:73
void calibrate()
Definition: kmlExt.cpp:115
std::vector< int >::iterator getRobotEncoders(std::vector< int >::iterator start, std::vector< int >::const_iterator end, bool refreshEncoders=true) const
Definition: kmlExt.cpp:369
int getMotorEncoders(int number, bool refreshEncoders)
Definition: KNI.net.cpp:210
void unBlock()
unblock robot after a crash
Definition: kmlExt.cpp:291
void closeGripper(bool waitUntilReached=false, int waitTimeout=100)
Definition: kmlExt.cpp:558
void switchMotorOn(short number)
Definition: kmlExt.cpp:589
void closeGripper(bool waitUntilReached, int waitTimeout)
Definition: KNI.net.cpp:242
void setMotorAccelerationLimit(short number, short acceleration)
Definition: kmlExt.cpp:411
void create(const char *configurationFile, CCplBase *protocol)
Create routine.
Definition: kmlExt.cpp:65
double getMaximumLinearVelocity() const
Definition: lmBase.cpp:907
void setMotorVelocityLimit(short number, short velocity)
Definition: kmlExt.cpp:399
void calibrate(void)
Definition: KNI.net.cpp:71
void moveRobotTo(double x, double y, double z, double phi, double theta, double psi, bool waitUntilReached=true, int waitTimeout=TM_ENDLESS)
Definition: lmBase.cpp:880
const char * what() const
int velocity
short getNumberOfMotors() const
Definition: kmlExt.cpp:357
bool getActivatePositionController()
Definition: KNI.net.cpp:171
void setMotorAccelerationLimit(int number, int acceleration)
Definition: KNI.net.cpp:230
void freezeRobot()
Definition: kmlExt.cpp:566
void moveRobotTo(array< double >^coordinates, bool waitUntilReached, int waitTimeout)
Definition: KNI.net.cpp:135
double getMaximumLinearVelocity()
Definition: KNI.net.cpp:163
void moveRobotToEnc(std::vector< int >::const_iterator start, std::vector< int >::const_iterator end, bool waitUntilReached=false, int encTolerance=100, int waitTimeout=0)
Definition: kmlExt.cpp:463
CLMBase * katana
Definition: KNI.net.h:12
void enableCrashLimits()
crash limits enable
Definition: kmlExt.cpp:281
CCdlSocket * socket
Definition: KNI.net.h:14
std::vector< int > encoders
Definition: kni_wrapper.cpp:29
void disableCrashLimits()
crash limits disable
Definition: kmlExt.cpp:286
int getMotorVelocityLimit(int number)
Definition: KNI.net.cpp:218
void unBlock()
Definition: KNI.net.cpp:191
void moveMotorToEnc(short number, int encoders, bool waitUntilReached=false, int encTolerance=100, int waitTimeout=0)
Definition: kmlExt.cpp:438
short getMotorAccelerationLimit(short number) const
Definition: kmlExt.cpp:394


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