Skip to content

Commit 9728732

Browse files
committed
Invalid_argument exceptions for all input checks in startForceMode.
1 parent 6a37208 commit 9728732

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

examples/force_mode_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ int main(int argc, char* argv[])
194194
{ 0, 0, 0, 0, 0, 0 }, // do not apply any active wrench
195195
2, // do not transform the force frame at all
196196
{ 0.1, 0.1, 1.5, 3.14, 3.14, 0.5 }, // limits
197-
0.025, // damping_factor
197+
0.025, // damping_factor
198198
0.8); // gain_scaling. See ScriptManual for details.
199199
}
200200
if (!success)

src/ur/ur_driver.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,10 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
361361
{
362362
if (robot_version_.major < 5)
363363
{
364-
URCL_LOG_ERROR("Force mode gain scaling factor cannot be set on a CB3 robot.");
365-
return false;
364+
std::stringstream ss;
365+
ss << "Force mode gain scaling factor cannot be set on a CB3 robot.";
366+
URCL_LOG_ERROR(ss.str().c_str());
367+
throw std::invalid_argument(ss.str().c_str());
366368
}
367369
// Test that the type is either 1, 2 or 3.
368370
switch (type)
@@ -383,21 +385,27 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
383385
{
384386
if (selection_vector[i] > 1)
385387
{
386-
URCL_LOG_ERROR("The selection vector should only consist of 0's and 1's");
387-
return false;
388+
std::stringstream ss;
389+
ss << "The selection vector should only consist of 0's and 1's";
390+
URCL_LOG_ERROR(ss.str().c_str());
391+
throw std::invalid_argument(ss.str().c_str());
388392
}
389393
}
390394

391395
if (damping_factor > 1 || damping_factor < 0)
392396
{
393-
URCL_LOG_ERROR("The force mode damping factor should be between 0 and 1, both inclusive.");
394-
return false;
397+
std::stringstream ss;
398+
ss << "The force mode damping factor should be between 0 and 1, both inclusive.";
399+
URCL_LOG_ERROR(ss.str().c_str());
400+
throw std::invalid_argument(ss.str().c_str());
395401
}
396402

397403
if (gain_scaling_factor > 2 || gain_scaling_factor < 0)
398404
{
399-
URCL_LOG_ERROR("The force mode gain scaling factor should be between 0 and 2, both inclusive.");
400-
return false;
405+
std::stringstream ss;
406+
ss << "The force mode gain scaling factor should be between 0 and 2, both inclusive.";
407+
URCL_LOG_ERROR(ss.str().c_str());
408+
throw std::invalid_argument(ss.str().c_str());
401409
}
402410

403411
if (script_command_interface_->clientConnected())
@@ -419,9 +427,10 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
419427
{
420428
if (robot_version_.major >= 5)
421429
{
422-
URCL_LOG_ERROR("You should also specify a force mode gain scaling factor to activate force mode on a e-series "
423-
"robot.");
424-
return false;
430+
std::stringstream ss;
431+
ss << "You should also specify a force mode gain scaling factor to activate force mode on an e-series robot.";
432+
URCL_LOG_ERROR(ss.str().c_str());
433+
throw std::invalid_argument(ss.str().c_str());
425434
}
426435
// Test that the type is either 1, 2 or 3.
427436
switch (type)
@@ -442,15 +451,19 @@ bool UrDriver::startForceMode(const vector6d_t& task_frame, const vector6uint32_
442451
{
443452
if (selection_vector[i] > 1)
444453
{
445-
URCL_LOG_ERROR("The selection vector should only consist of 0's and 1's");
446-
return false;
454+
std::stringstream ss;
455+
ss << "The selection vector should only consist of 0's and 1's";
456+
URCL_LOG_ERROR(ss.str().c_str());
457+
throw std::invalid_argument(ss.str().c_str());
447458
}
448459
}
449460

450461
if (damping_factor > 1 || damping_factor < 0)
451462
{
452-
URCL_LOG_ERROR("The force mode damping factor should be between 0 and 1, both inclusive.");
453-
return false;
463+
std::stringstream ss;
464+
ss << "The force mode damping factor should be between 0 and 1, both inclusive.";
465+
URCL_LOG_ERROR(ss.str().c_str());
466+
throw std::invalid_argument(ss.str().c_str());
454467
}
455468

456469
if (script_command_interface_->clientConnected())

0 commit comments

Comments
 (0)