Skip to content

Commit 169cd03

Browse files
authored
Merge pull request #40 from MGBla/fix_combined_speed_scaling_factor
Fixed the calculation of the combined speed scaling factor
2 parents 7162aa7 + 9009d8b commit 169cd03

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
// UR stuff
4444
#include <ur_client_library/ur/ur_driver.h>
4545
#include <ur_robot_driver/dashboard_client_ros.h>
46+
#include <ur_dashboard_msgs/msg/robot_mode.hpp>
4647

4748
// ROS
4849
#include "rclcpp/macros.hpp"
@@ -55,6 +56,13 @@ using hardware_interface::status;
5556

5657
namespace ur_robot_driver
5758
{
59+
enum class PausingState
60+
{
61+
PAUSED,
62+
RUNNING,
63+
RAMPUP
64+
};
65+
5866
/*!
5967
* \brief The HardwareInterface class handles the interface between the ROS system and the main
6068
* driver. It contains the read and write methods of the main control loop and registers various ROS
@@ -113,9 +121,11 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
113121
urcl::vector6d_t urcl_joint_efforts_;
114122
urcl::vector6d_t urcl_ft_sensor_measurements_;
115123
urcl::vector6d_t urcl_tcp_pose_;
124+
116125
bool packet_read_;
117126

118127
uint32_t runtime_state_;
128+
bool controllers_initialized_;
119129

120130
std::bitset<18> actual_dig_out_bits_;
121131
std::bitset<18> actual_dig_in_bits_;
@@ -140,6 +150,9 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
140150
bool non_blocking_read_;
141151
bool position_interface_in_use_;
142152

153+
PausingState pausing_state_;
154+
double pausing_ramp_up_increment_;
155+
143156
std::unique_ptr<urcl::UrDriver> ur_driver_;
144157
};
145158
} // namespace ur_robot_driver

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*
2222
* \author Lovro Ivanov [email protected]
2323
* \author Andy Zelenak [email protected]
24+
* \author Marvin Große Besselmann [email protected]
2425
* \date 2020-11-9
2526
*
2627
*/
@@ -49,6 +50,10 @@ hardware_interface::return_type URPositionHardwareInterface::configure(const Har
4950
urcl_tcp_pose_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
5051
urcl_position_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
5152
urcl_velocity_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
53+
runtime_state_ = static_cast<uint32_t>(rtde::RUNTIME_STATE::STOPPED);
54+
pausing_state_ = PausingState::RUNNING;
55+
pausing_ramp_up_increment_ = 0.01;
56+
controllers_initialized_ = false;
5257

5358
for (const hardware_interface::ComponentInfo& joint : info_.joints)
5459
{
@@ -376,6 +381,41 @@ return_type URPositionHardwareInterface::read()
376381

377382
// TODO logic for sending other stuff to higher level interface
378383

384+
// pausing state follows runtime state when pausing
385+
if (runtime_state_ == static_cast<uint32_t>(rtde::RUNTIME_STATE::PAUSED))
386+
{
387+
pausing_state_ = PausingState::PAUSED;
388+
}
389+
// When the robot resumed program execution and pausing state was PAUSED, we enter RAMPUP
390+
else if (runtime_state_ == static_cast<uint32_t>(rtde::RUNTIME_STATE::PLAYING) &&
391+
pausing_state_ == PausingState::PAUSED)
392+
{
393+
speed_scaling_combined_ = 0.0;
394+
pausing_state_ = PausingState::RAMPUP;
395+
}
396+
397+
if (pausing_state_ == PausingState::RAMPUP)
398+
{
399+
double speed_scaling_ramp = speed_scaling_combined_ + pausing_ramp_up_increment_;
400+
speed_scaling_combined_ = std::min(speed_scaling_ramp, speed_scaling_ * target_speed_fraction_);
401+
402+
if (speed_scaling_ramp > speed_scaling_ * target_speed_fraction_)
403+
{
404+
pausing_state_ = PausingState::RUNNING;
405+
}
406+
}
407+
else if (runtime_state_ == static_cast<uint32_t>(rtde::RUNTIME_STATE::RESUMING))
408+
{
409+
// We have to keep speed scaling on ROS side at 0 during RESUMING to prevent controllers from
410+
// continuing to interpolate
411+
speed_scaling_combined_ = 0.0;
412+
}
413+
else
414+
{
415+
// Normal case
416+
speed_scaling_combined_ = speed_scaling_ * target_speed_fraction_;
417+
}
418+
379419
return return_type::OK;
380420
}
381421

0 commit comments

Comments
 (0)