Skip to content

Commit a7926d4

Browse files
committed
Added UR exceptions InvalidRange and IncompatibleRobotVersion
Added them to the various checks for starting force mode. I created IncompatibleRobotVersion instead of using VersionMismatch, as the VersionMismatch would not give enough information in my opinion.
1 parent 9728732 commit a7926d4

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

include/ur_client_library/exceptions.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,44 @@ class TimeoutException : public UrException
124124
private:
125125
std::string text_;
126126
};
127+
128+
class IncompatibleRobotVersion : public UrException
129+
{
130+
public:
131+
explicit IncompatibleRobotVersion() = delete;
132+
explicit IncompatibleRobotVersion(std::string text, int required_robot_version, int actual_robot_version)
133+
: std::runtime_error(text)
134+
{
135+
std::stringstream ss;
136+
ss << text << "\n"
137+
<< "The requested feature is incompatible with the connected robot. Required Polyscope version: "
138+
<< required_robot_version << ", actual Polyscope version: " << actual_robot_version;
139+
text_ = ss.str();
140+
}
141+
virtual const char* what() const noexcept override
142+
{
143+
return text_.c_str();
144+
}
145+
146+
private:
147+
std::string text_;
148+
};
149+
150+
class InvalidRange : public UrException
151+
{
152+
private:
153+
std::string text_;
154+
155+
public:
156+
explicit InvalidRange() = delete;
157+
explicit InvalidRange(std::string text) : std::runtime_error(text)
158+
{
159+
text_ = text;
160+
}
161+
virtual const char* what() const noexcept override
162+
{
163+
return text_.c_str();
164+
}
165+
};
127166
} // namespace urcl
128167
#endif // ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED

src/ur/ur_driver.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
364364
std::stringstream ss;
365365
ss << "Force mode gain scaling factor cannot be set on a CB3 robot.";
366366
URCL_LOG_ERROR(ss.str().c_str());
367-
throw std::invalid_argument(ss.str().c_str());
367+
throw IncompatibleRobotVersion(ss.str(), 5, robot_version_.major);
368368
}
369369
// Test that the type is either 1, 2 or 3.
370370
switch (type)
@@ -379,7 +379,7 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
379379
std::stringstream ss;
380380
ss << "The type should be 1, 2 or 3. The type is " << type;
381381
URCL_LOG_ERROR(ss.str().c_str());
382-
throw std::invalid_argument(ss.str().c_str());
382+
throw InvalidRange(ss.str().c_str());
383383
}
384384
for (unsigned int i = 0; i < selection_vector.size(); ++i)
385385
{
@@ -388,7 +388,7 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
388388
std::stringstream ss;
389389
ss << "The selection vector should only consist of 0's and 1's";
390390
URCL_LOG_ERROR(ss.str().c_str());
391-
throw std::invalid_argument(ss.str().c_str());
391+
throw InvalidRange(ss.str().c_str());
392392
}
393393
}
394394

@@ -397,15 +397,15 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
397397
std::stringstream ss;
398398
ss << "The force mode damping factor should be between 0 and 1, both inclusive.";
399399
URCL_LOG_ERROR(ss.str().c_str());
400-
throw std::invalid_argument(ss.str().c_str());
400+
throw InvalidRange(ss.str().c_str());
401401
}
402402

403403
if (gain_scaling_factor > 2 || gain_scaling_factor < 0)
404404
{
405405
std::stringstream ss;
406406
ss << "The force mode gain scaling factor should be between 0 and 2, both inclusive.";
407407
URCL_LOG_ERROR(ss.str().c_str());
408-
throw std::invalid_argument(ss.str().c_str());
408+
throw InvalidRange(ss.str().c_str());
409409
}
410410

411411
if (script_command_interface_->clientConnected())
@@ -430,7 +430,7 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
430430
std::stringstream ss;
431431
ss << "You should also specify a force mode gain scaling factor to activate force mode on an e-series robot.";
432432
URCL_LOG_ERROR(ss.str().c_str());
433-
throw std::invalid_argument(ss.str().c_str());
433+
throw IncompatibleRobotVersion(ss.str(), 3, robot_version_.major);
434434
}
435435
// Test that the type is either 1, 2 or 3.
436436
switch (type)
@@ -445,7 +445,7 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
445445
std::stringstream ss;
446446
ss << "The type should be 1, 2 or 3. The type is " << type;
447447
URCL_LOG_ERROR(ss.str().c_str());
448-
throw std::invalid_argument(ss.str().c_str());
448+
throw InvalidRange(ss.str().c_str());
449449
}
450450
for (unsigned int i = 0; i < selection_vector.size(); ++i)
451451
{
@@ -454,7 +454,7 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
454454
std::stringstream ss;
455455
ss << "The selection vector should only consist of 0's and 1's";
456456
URCL_LOG_ERROR(ss.str().c_str());
457-
throw std::invalid_argument(ss.str().c_str());
457+
throw InvalidRange(ss.str().c_str());
458458
}
459459
}
460460

@@ -463,7 +463,7 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
463463
std::stringstream ss;
464464
ss << "The force mode damping factor should be between 0 and 1, both inclusive.";
465465
URCL_LOG_ERROR(ss.str().c_str());
466-
throw std::invalid_argument(ss.str().c_str());
466+
throw InvalidRange(ss.str().c_str());
467467
}
468468

469469
if (script_command_interface_->clientConnected())

0 commit comments

Comments
 (0)