forked from UniversalRobots/Universal_Robots_Client_Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.h
More file actions
470 lines (401 loc) · 12.1 KB
/
Copy pathexceptions.h
File metadata and controls
470 lines (401 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2019 FZI Forschungszentrum Informatik
// Created on behalf of Universal Robots A/S
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -- END LICENSE BLOCK ------------------------------------------------
//----------------------------------------------------------------------
/*!\file
*
* \author Felix Exner exner@fzi.de
* \date 2019-06-11
*
*/
//----------------------------------------------------------------------
#ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED
#define UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED
#include <chrono>
#include <optional>
#include <stdexcept>
#include <sstream>
#include <vector>
#include "ur/version_information.h"
#include "ur_client_library/ur/datatypes.h"
#ifdef _WIN32
# define NOMINMAX
# define WIN32_LEAN_AND_MEAN
# include <WinSock2.h>
# ifdef ERROR
# undef ERROR
# endif // ERROR
#else
# include <sys/time.h>
#endif
namespace urcl
{
/*!
* \brief Our base class for exceptions. Specialized exceptions should inherit from those.
*/
class UrException : virtual public std::runtime_error
{
public:
explicit UrException() : std::runtime_error("")
{
}
explicit UrException(const std::string& what_arg) : std::runtime_error(what_arg)
{
}
explicit UrException(const char* what_arg) : std::runtime_error(what_arg)
{
}
virtual ~UrException() = default;
private:
/* data */
};
/*!
* \brief A specialized exception representing detection of a not supported UR control version.
*/
class VersionMismatch : public UrException
{
public:
explicit VersionMismatch() : VersionMismatch("", VersionInformation(), VersionInformation())
{
}
explicit VersionMismatch(const std::string& text, const VersionInformation version_req,
const VersionInformation version_actual)
: std::runtime_error(text)
{
version_required_ = version_req;
version_actual_ = version_actual;
std::stringstream ss;
ss << text << "(Required version: " << version_required_ << ", actual version: " << version_actual_ << ")";
text_ = ss.str();
}
virtual ~VersionMismatch() = default;
virtual const char* what() const noexcept override
{
return text_.c_str();
}
private:
VersionInformation version_required_;
VersionInformation version_actual_;
std::string text_;
};
/*!
* \brief A specialized exception representing that communication to the tool is not possible.
*/
class ToolCommNotAvailable : public VersionMismatch
{
public:
explicit ToolCommNotAvailable() : ToolCommNotAvailable("", VersionInformation(), VersionInformation())
{
}
explicit ToolCommNotAvailable(const std::string& text, const VersionInformation version_req,
const VersionInformation version_actual)
: std::runtime_error(text), VersionMismatch(text, version_req, version_actual)
{
}
};
/*!
* \brief A specialized exception representing that communication to the tool is not possible.
*/
class TimeoutException : public UrException
{
public:
explicit TimeoutException() = delete;
explicit TimeoutException(const std::string& text, std::chrono::milliseconds timeout) : std::runtime_error(text)
{
std::stringstream ss;
ss << text << "(Configured timeout: " << timeout.count() / 1000.0 << " sec)";
text_ = ss.str();
}
explicit TimeoutException(const std::string& text, timeval timeout) : std::runtime_error(text)
{
std::stringstream ss;
ss << text << "(Configured timeout: " << timeout.tv_sec + timeout.tv_usec * 1e-6 << " sec)";
text_ = ss.str();
}
virtual const char* what() const noexcept override
{
return text_.c_str();
}
private:
std::string text_;
};
class IncompatibleRobotVersion : public UrException
{
public:
explicit IncompatibleRobotVersion() = delete;
explicit IncompatibleRobotVersion(const std::string& text, const VersionInformation& minimum_robot_version,
const VersionInformation& actual_robot_version)
: std::runtime_error(text)
{
std::stringstream ss;
ss << text << "\n"
<< "The requested feature is incompatible with the connected robot. Minimum required Polyscope version: "
<< minimum_robot_version << ", actual Polyscope version: " << actual_robot_version;
text_ = ss.str();
}
virtual const char* what() const noexcept override
{
return text_.c_str();
}
private:
std::string text_;
};
class InvalidRange : public UrException
{
private:
std::string text_;
public:
explicit InvalidRange() = delete;
explicit InvalidRange(std::string text) : std::runtime_error(text)
{
text_ = text;
}
virtual const char* what() const noexcept override
{
return text_.c_str();
}
};
class MissingArgument : public UrException
{
private:
std::string text_;
public:
explicit MissingArgument() = delete;
explicit MissingArgument(std::string text, std::string function_name, std::string argument_name, float default_value)
: std::runtime_error("")
{
std::stringstream ss;
ss << text << "\nMissing argument when calling function: " << function_name
<< ". \nArgument missing: " << argument_name
<< ". \nSet to default value if not important, default value is: " << default_value;
text_ = ss.str();
}
virtual const char* what() const noexcept override
{
return text_.c_str();
}
};
class UnsupportedMotionType : public UrException
{
public:
explicit UnsupportedMotionType() : std::runtime_error("Unsupported motion type")
{
}
};
class UnknownVariable : public UrException
{
private:
std::string text_;
public:
explicit UnknownVariable() = delete;
explicit UnknownVariable(const std::string& variable_name) : std::runtime_error("Unknown variable: " + variable_name)
{
}
};
class NotImplementedException : public UrException
{
public:
explicit NotImplementedException() : std::runtime_error("Not implemented")
{
}
explicit NotImplementedException(const std::string& text) : std::runtime_error(text)
{
}
virtual ~NotImplementedException() = default;
virtual const char* what() const noexcept override
{
return std::runtime_error::what();
}
};
class UnexpectedResponse : public UrException
{
public:
explicit UnexpectedResponse() : std::runtime_error("Unexpected response")
{
}
explicit UnexpectedResponse(const std::string& text) : std::runtime_error(text)
{
text_ = text;
}
explicit UnexpectedResponse(const std::string& text, int status) : std::runtime_error(text), status(status)
{
std::stringstream ss;
ss << "Message: " << text << ". \nStatus code: " << status;
text_ = ss.str();
}
virtual ~UnexpectedResponse() = default;
virtual const char* what() const noexcept override
{
return text_.c_str();
}
std::optional<int> status = std::nullopt; // Optional status code, if available
private:
std::string text_;
};
class RTDEInvalidKeyException : public UrException
{
public:
explicit RTDEInvalidKeyException() : std::runtime_error("RTDE Invalid Key Exception")
{
}
explicit RTDEInvalidKeyException(const std::string& text) : std::runtime_error(text)
{
}
virtual ~RTDEInvalidKeyException() = default;
virtual const char* what() const noexcept override
{
return std::runtime_error::what();
}
};
class RTDEInputConflictException : public UrException
{
public:
explicit RTDEInputConflictException() : std::runtime_error("RTDE Output Conflict Exception")
{
}
explicit RTDEInputConflictException(const std::string& key)
: std::runtime_error("RTDE Input Conflict for key: " + key), key_(key)
{
message_ = "Variable '" + key_ +
"' is currently controlled by another RTDE client. The input recipe can't be used as "
"configured. Note: when using a fieldbus (e.g. Ethernet/IP or Modbus), all outputs are claimed by "
"those.";
}
virtual ~RTDEInputConflictException() = default;
virtual const char* what() const noexcept override
{
return message_.c_str();
}
private:
std::string key_;
std::string message_;
};
class ScriptCodeSyntaxException : public UrException
{
public:
explicit ScriptCodeSyntaxException() = delete;
explicit ScriptCodeSyntaxException(const std::string& text) : std::runtime_error(text)
{
}
virtual ~ScriptCodeSyntaxException() = default;
virtual const char* what() const noexcept override
{
return std::runtime_error::what();
}
};
class RobotModeException : public UrException
{
public:
explicit RobotModeException() = delete;
explicit RobotModeException(const std::string& operation, const RobotMode& required, const RobotMode& actual)
: std::runtime_error("Incorrect robot mode: " + robotModeString(actual))
{
std::stringstream ss;
ss << "Robot is in incorrect mode for the requested operation: " << operation << "\n"
<< "Required robot mode: " << urcl::robotModeString(required) << " (" << int(required) << ") \n"
<< "Actual robot mode: " << urcl::robotModeString(actual) << " (" << int(actual) << ")";
text_ = ss.str();
}
virtual ~RobotModeException() = default;
virtual const char* what() const noexcept override
{
return text_.c_str();
}
private:
std::string text_;
};
class SafetyModeException : public UrException
{
public:
explicit SafetyModeException() = delete;
explicit SafetyModeException(const std::string& operation, const std::vector<urcl::SafetyMode>& options,
const urcl::SafetyMode& actual)
: std::runtime_error("Incorrect safety mode: " + safetyModeString(actual))
{
std::stringstream ss;
ss << "Robot is in incorrect safety mode for the requested operation: " << operation << "\n"
<< "Safety mode should be one of: \n";
for (auto mode : options)
{
ss << urcl::safetyModeString(mode) << " (" << int(mode) << ")\n";
}
ss << "\n"
<< "Actual safety mode: " << urcl::safetyModeString(actual) << " (" << int(actual) << ")";
text_ = ss.str();
}
virtual ~SafetyModeException() = default;
virtual const char* what() const noexcept override
{
return text_.c_str();
}
private:
std::string text_;
};
class StreamNotConnectedException : public UrException
{
public:
explicit StreamNotConnectedException() = delete;
explicit StreamNotConnectedException(const std::string& text) : std::runtime_error(text)
{
}
virtual ~StreamNotConnectedException() = default;
virtual const char* what() const noexcept override
{
return std::runtime_error::what();
}
};
class RobotRuntimeException : public UrException
{
public:
explicit RobotRuntimeException() = delete;
explicit RobotRuntimeException(const std::string& text) : std::runtime_error(text)
{
}
virtual ~RobotRuntimeException() = default;
virtual const char* what() const noexcept override
{
return std::runtime_error::what();
}
};
class ReadOnlyInterfaceException : public UrException
{
public:
explicit ReadOnlyInterfaceException() = delete;
explicit ReadOnlyInterfaceException(const std::string& text) : std::runtime_error(text)
{
}
virtual ~ReadOnlyInterfaceException() = default;
virtual const char* what() const noexcept override
{
return std::runtime_error::what();
}
};
class RobotErrorCodeException : public UrException
{
public:
explicit RobotErrorCodeException() = delete;
explicit RobotErrorCodeException(const std::string& text) : std::runtime_error(text)
{
}
virtual ~RobotErrorCodeException() = default;
virtual const char* what() const noexcept override
{
return std::runtime_error::what();
}
};
} // namespace urcl
#endif // ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED