Skip to content

Commit 535b083

Browse files
committed
Bug fixes and updates to tests
1 parent e1797f3 commit 535b083

File tree

4 files changed

+60
-26
lines changed

4 files changed

+60
-26
lines changed

examples/force_mode_example.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,25 @@ int main(int argc, char* argv[])
149149
}
150150
// Task frame at the robot's base with limits being large enough to cover the whole workspace
151151
// Compliance in z axis and rotation around z axis
152-
153-
bool success = g_my_driver->startForceMode({ 0, 0, 0, 0, 0, 0 }, // Task frame at the robot's base
154-
{ 0, 0, 1, 0, 0, 1 }, // Compliance in z axis and rotation around z axis
155-
{ 0, 0, 0, 0, 0, 0 }, // do not apply any active wrench
156-
2, // do not transform the force frame at all
157-
{ 0.1, 0.1, 1.5, 3.14, 3.14, 0.5 } // limits. See ScriptManual
158-
,
159-
0.8, 0.8); // for details.
152+
bool success;
153+
if (g_my_driver->getVersion().major < 5)
154+
success = g_my_driver->startForceMode({ 0, 0, 0, 0, 0, 0 }, // Task frame at the robot's base
155+
{ 0, 0, 1, 0, 0, 1 }, // Compliance in z axis and rotation around z axis
156+
{ 0, 0, 0, 0, 0, 0 }, // do not apply any active wrench
157+
2, // do not transform the force frame at all
158+
{ 0.1, 0.1, 1.5, 3.14, 3.14, 0.5 } // limits. See ScriptManual
159+
,
160+
0.8); // for details.
161+
else
162+
{
163+
success = g_my_driver->startForceMode({ 0, 0, 0, 0, 0, 0 }, // Task frame at the robot's base
164+
{ 0, 0, 1, 0, 0, 1 }, // Compliance in z axis and rotation around z axis
165+
{ 0, 0, 0, 0, 0, 0 }, // do not apply any active wrench
166+
2, // do not transform the force frame at all
167+
{ 0.1, 0.1, 1.5, 3.14, 3.14, 0.5 } // limits. See ScriptManual
168+
,
169+
0.8, 0.8); // for details.
170+
}
160171
if (!success)
161172
{
162173
URCL_LOG_ERROR("Failed to start force mode.");

include/ur_client_library/ur/ur_driver.h

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,25 @@ class UrDriver
128128
* \param force_mode_damping The damping parameter used when the robot is in force mode, range [0,1]
129129
* \param force_mode_gain_scaling Scales the gain used when the robot is in force mode, range [0,2] (only e-series)
130130
*/
131-
[[deprecated("Specifying the force mode damping factor and the force mode gain scaling factor at driver creation has "
132-
"been deprecated. Force mode parameters should be specified with each activiation of force mode, and "
133-
"can be set in the function call to start force mode.")]]
134-
UrDriver(const std::string& robot_ip, const std::string& script_file, const std::string& output_recipe_file,
135-
const std::string& input_recipe_file, std::function<void(bool)> handle_program_state, bool headless_mode,
136-
std::unique_ptr<ToolCommSetup> tool_comm_setup, const uint32_t reverse_port,
137-
const uint32_t script_sender_port, int servoj_gain, double servoj_lookahead_time, bool non_blocking_read,
138-
const std::string& reverse_ip, const uint32_t trajectory_port, const uint32_t script_command_port,
139-
double force_mode_damping, double force_mode_gain_scaling = 0.5);
131+
[[deprecated(
132+
"Specifying the force mode damping factor and the force mode gain scaling factor at driver creation has "
133+
"been deprecated. Force mode parameters should be specified with each activiation of force mode, and "
134+
"can be set in the function call to start force mode.")]] UrDriver(const std::string& robot_ip,
135+
const std::string& script_file,
136+
const std::string& output_recipe_file,
137+
const std::string& input_recipe_file,
138+
std::function<void(bool)> handle_program_state,
139+
bool headless_mode,
140+
std::unique_ptr<ToolCommSetup> tool_comm_setup,
141+
const uint32_t reverse_port,
142+
const uint32_t script_sender_port,
143+
int servoj_gain, double servoj_lookahead_time,
144+
bool non_blocking_read,
145+
const std::string& reverse_ip,
146+
const uint32_t trajectory_port,
147+
const uint32_t script_command_port,
148+
double force_mode_damping,
149+
double force_mode_gain_scaling = 0.5);
140150

141151
/*!
142152
* \brief Constructs a new UrDriver object.
@@ -439,9 +449,9 @@ class UrDriver
439449
* \returns True, if the write was performed successfully, false otherwise.
440450
*/
441451
[[deprecated("Starting force mode without specifying the force mode damping factor and gain scale factor has been "
442-
"deprecated. These values should be given with each function call.")]]
443-
bool startForceMode(const vector6d_t& task_frame, const vector6uint32_t& selection_vector, const vector6d_t& wrench,
444-
const unsigned int type, const vector6d_t& limits);
452+
"deprecated. These values should be given with each function call.")]] bool
453+
startForceMode(const vector6d_t& task_frame, const vector6uint32_t& selection_vector, const vector6d_t& wrench,
454+
const unsigned int type, const vector6d_t& limits);
445455

446456
/*!
447457
* \brief Stop force mode and put the robot into normal operation mode.

src/ur/ur_driver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ urcl::UrDriver::UrDriver(const std::string& robot_ip, const std::string& script_
142142
}
143143
begin_replace << "set_tool_voltage("
144144
<< static_cast<std::underlying_type<ToolVoltage>::type>(tool_comm_setup->getToolVoltage()) << ")\n";
145-
begin_replace << "set_tool_communication(" << "True" << ", " << tool_comm_setup->getBaudRate() << ", "
145+
begin_replace << "set_tool_communication("
146+
<< "True"
147+
<< ", " << tool_comm_setup->getBaudRate() << ", "
146148
<< static_cast<std::underlying_type<Parity>::type>(tool_comm_setup->getParity()) << ", "
147149
<< tool_comm_setup->getStopBits() << ", " << tool_comm_setup->getRxIdleChars() << ", "
148150
<< tool_comm_setup->getTxIdleChars() << ")";

tests/test_script_command_interface.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ class ScriptCommandInterfaceTest : public ::testing::Test
6464

6565
void readMessage(int32_t& command, std::vector<int32_t>& message)
6666
{
67-
// Max message length is 26
68-
uint8_t buf[sizeof(int32_t) * 26];
67+
// Max message length is 28
68+
uint8_t buf[sizeof(int32_t) * 28];
6969
uint8_t* b_pos = buf;
7070
size_t read = 0;
71-
size_t remainder = sizeof(int32_t) * 26;
71+
size_t remainder = sizeof(int32_t) * 28;
7272
while (remainder > 0)
7373
{
7474
if (!TCPSocket::read(b_pos, remainder, read))
@@ -252,7 +252,10 @@ TEST_F(ScriptCommandInterfaceTest, test_force_mode)
252252
urcl::vector6d_t wrench = { 20, 0, 40, 0, 0, 0 };
253253
int32_t force_mode_type = 2;
254254
urcl::vector6d_t limits = { 0.1, 0.1, 0.1, 0.785, 0.785, 1.57 };
255-
script_command_interface_->startForceMode(&task_frame, &selection_vector, &wrench, force_mode_type, &limits);
255+
double damping = 0.8;
256+
double gain_scaling = 0.8;
257+
script_command_interface_->startForceMode(&task_frame, &selection_vector, &wrench, force_mode_type, &limits, damping,
258+
gain_scaling);
256259

257260
int32_t command;
258261
std::vector<int32_t> message;
@@ -298,8 +301,16 @@ TEST_F(ScriptCommandInterfaceTest, test_force_mode)
298301
EXPECT_EQ(received_limits[i], limits[i]);
299302
}
300303

304+
// Test damping return
305+
double received_damping = (double)message[25] / script_command_interface_->MULT_JOINTSTATE;
306+
EXPECT_EQ(received_damping, damping);
307+
308+
// Test Gain scaling return
309+
double received_gain = (double)message[26] / script_command_interface_->MULT_JOINTSTATE;
310+
EXPECT_EQ(received_gain, gain_scaling);
311+
301312
// The rest of the message should be zero
302-
int32_t message_sum = std::accumulate(std::begin(message) + 25, std::end(message), 0);
313+
int32_t message_sum = std::accumulate(std::begin(message) + 27, std::end(message), 0);
303314
int32_t expected_message_sum = 0;
304315
EXPECT_EQ(message_sum, expected_message_sum);
305316

0 commit comments

Comments
 (0)