Skip to content

Commit 8ff93ae

Browse files
committed
Created new exception MissingArgument
After further thought, I dont think the Incompatible version exception is appropriate for one of the exception calls, as the robot is not actually incompatible, the function just needs more information. The new exception conveys that, i think. I can't quite make my mind up about whether it should mention that this is due to the robot version, though, so I have left it out for now.
1 parent 060a493 commit 8ff93ae

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

include/ur_client_library/exceptions.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <chrono>
3333
#include <stdexcept>
3434
#include <sstream>
35+
#include "ur/version_information.h"
3536

3637
namespace urcl
3738
{
@@ -129,13 +130,14 @@ class IncompatibleRobotVersion : public UrException
129130
{
130131
public:
131132
explicit IncompatibleRobotVersion() = delete;
132-
explicit IncompatibleRobotVersion(const std::string& text, const VersionInformation& minimum_robot_version, const VersionInformation& actual_robot_version)
133+
explicit IncompatibleRobotVersion(const std::string& text, const VersionInformation& minimum_robot_version,
134+
const VersionInformation& actual_robot_version)
133135
: std::runtime_error(text)
134136
{
135137
std::stringstream ss;
136138
ss << text << "\n"
137139
<< "The requested feature is incompatible with the connected robot. Minimum required Polyscope version: "
138-
<< required_robot_version << ", actual Polyscope version: " << actual_robot_version;
140+
<< minimum_robot_version << ", actual Polyscope version: " << actual_robot_version;
139141
text_ = ss.str();
140142
}
141143
virtual const char* what() const noexcept override
@@ -163,5 +165,27 @@ class InvalidRange : public UrException
163165
return text_.c_str();
164166
}
165167
};
168+
169+
class MissingArgument : public UrException
170+
{
171+
private:
172+
std::string text_;
173+
174+
public:
175+
explicit MissingArgument() = delete;
176+
explicit MissingArgument(std::string text, std::string function_name, std::string argument_name, float default_value)
177+
: std::runtime_error("")
178+
{
179+
std::stringstream ss;
180+
ss << text << "\nMissing argument when calling function: " << function_name
181+
<< ". \nArgument missing: " << argument_name
182+
<< ". \nSet to default value if not important, default value is: " << default_value;
183+
text_ = ss.str();
184+
}
185+
virtual const char* what() const noexcept override
186+
{
187+
return text_.c_str();
188+
}
189+
};
166190
} // namespace urcl
167191
#endif // ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED

src/ur/ur_driver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ 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 IncompatibleRobotVersion(ss.str(), 5, robot_version_.major);
367+
VersionInformation req_version = VersionInformation::fromString("5.0.0.0");
368+
throw IncompatibleRobotVersion(ss.str(), req_version, robot_version_);
368369
}
369370
// Test that the type is either 1, 2 or 3.
370371
switch (type)
@@ -430,7 +431,7 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
430431
std::stringstream ss;
431432
ss << "You should also specify a force mode gain scaling factor to activate force mode on an e-series robot.";
432433
URCL_LOG_ERROR(ss.str().c_str());
433-
throw IncompatibleRobotVersion(ss.str(), 3, robot_version_.major);
434+
throw MissingArgument(ss.str(), "startForceMode", "gain_scaling_factor", 0.5);
434435
}
435436
// Test that the type is either 1, 2 or 3.
436437
switch (type)

0 commit comments

Comments
 (0)