Skip to content

Commit 1b8fa36

Browse files
committed
Add warnings when calling functions on non-supported PolyScope versions
1 parent 0df9d30 commit 1b8fa36

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

include/ur_client_library/control/reverse_interface.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "ur_client_library/types.h"
3535
#include "ur_client_library/log.h"
3636
#include "ur_client_library/ur/robot_receive_timeout.h"
37+
#include "ur_client_library/ur/version_information.h"
3738
#include <cstring>
3839
#include <endian.h>
3940
#include <condition_variable>
@@ -62,6 +63,17 @@ enum class FreedriveControlMessage : int32_t
6263
FREEDRIVE_START = 1, ///< Represents command to start freedrive mode.
6364
};
6465

66+
struct ReverseInterfaceConfig
67+
{
68+
uint32_t port = 50001; //!< Port the server is started on
69+
std::function<void(bool)> handle_program_state = [](bool) {
70+
return;
71+
}; //!< Function handle to a callback on program state changes.
72+
std::chrono::milliseconds step_time = std::chrono::milliseconds(8); //!< The robots step time
73+
uint32_t keepalive_count = 0; //!< Number of allowed timeout reads on the robot.
74+
VersionInformation robot_software_version = VersionInformation(); //!< The robot software version.
75+
};
76+
6577
/*!
6678
* \brief The ReverseInterface class handles communication to the robot. It starts a server and
6779
* waits for the robot to connect via its URCaps program.
@@ -82,6 +94,8 @@ class ReverseInterface
8294
ReverseInterface(uint32_t port, std::function<void(bool)> handle_program_state,
8395
std::chrono::milliseconds step_time = std::chrono::milliseconds(8));
8496

97+
ReverseInterface(const ReverseInterfaceConfig& config);
98+
8599
/*!
86100
* \brief Disconnects possible clients so the reverse interface object can be safely destroyed.
87101
*/
@@ -167,6 +181,8 @@ class ReverseInterface
167181
socket_t client_fd_;
168182
comm::TCPServer server_;
169183

184+
VersionInformation robot_software_version_;
185+
170186
template <typename T>
171187
size_t append(uint8_t* buffer, T& val)
172188
{

include/ur_client_library/control/script_command_interface.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "ur_client_library/control/reverse_interface.h"
3333
#include "ur_client_library/ur/tool_communication.h"
34+
#include "ur_client_library/ur/version_information.h"
3435

3536
namespace urcl
3637
{
@@ -63,6 +64,11 @@ class ScriptCommandInterface : public ReverseInterface
6364
*/
6465
ScriptCommandInterface(uint32_t port);
6566

67+
ScriptCommandInterface(const ReverseInterfaceConfig& config) : ReverseInterface(config)
68+
{
69+
client_connected_ = false;
70+
}
71+
6672
/*!
6773
* \brief Zero the force torque sensor
6874
*
@@ -226,6 +232,19 @@ class ScriptCommandInterface : public ReverseInterface
226232
SET_MAX_JOINT_TORQUES = 9, ///< Set max joint torques
227233
};
228234

235+
void warnIfNotSupported(const VersionInformation& min_polyscope5, const VersionInformation& min_polyscopeX,
236+
const std::string& command_name)
237+
{
238+
if (robot_software_version_ < min_polyscope5 ||
239+
(robot_software_version_.major > 5 && robot_software_version_ < min_polyscopeX))
240+
{
241+
URCL_LOG_WARN("%s is only available for robots with PolyScope %s / %s or "
242+
"later. This robot's version is %s. This command will have no effect.",
243+
command_name.c_str(), min_polyscope5.toString().c_str(), min_polyscopeX.toString().c_str(),
244+
robot_software_version_.toString().c_str());
245+
}
246+
}
247+
229248
bool client_connected_;
230249
static const int MAX_MESSAGE_LENGTH = 28;
231250

@@ -235,4 +254,4 @@ class ScriptCommandInterface : public ReverseInterface
235254
} // namespace control
236255
} // namespace urcl
237256

238-
#endif // UR_CLIENT_LIBRARY_SCRIPT_COMMAND_INTERFACE_H_INCLUDED
257+
#endif // UR_CLIENT_LIBRARY_SCRIPT_COMMAND_INTERFACE_H_INCLUDED

src/control/reverse_interface.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ namespace control
3535
{
3636
ReverseInterface::ReverseInterface(uint32_t port, std::function<void(bool)> handle_program_state,
3737
std::chrono::milliseconds step_time)
38+
: ReverseInterface(ReverseInterfaceConfig{ port, handle_program_state, step_time })
39+
{
40+
}
41+
42+
ReverseInterface::ReverseInterface(const ReverseInterfaceConfig& config)
3843
: client_fd_(INVALID_SOCKET)
39-
, server_(port)
40-
, handle_program_state_(handle_program_state)
41-
, step_time_(step_time)
44+
, server_(config.port)
45+
, robot_software_version_(config.robot_software_version)
46+
, handle_program_state_(config.handle_program_state)
47+
, step_time_(config.step_time)
4248
, keep_alive_count_modified_deprecated_(false)
4349
{
4450
handle_program_state_(false);

src/control/script_command_interface.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ bool ScriptCommandInterface::endToolContact()
224224

225225
bool ScriptCommandInterface::setFrictionCompensation(const bool friction_compensation_enabled)
226226
{
227+
warnIfNotSupported(urcl::VersionInformation::fromString("5.23.0"), urcl::VersionInformation::fromString("10.10.0"),
228+
__func__);
227229
const int message_length = 2;
228230
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
229231
uint8_t* b_pos = buffer;
@@ -247,6 +249,8 @@ bool ScriptCommandInterface::setFrictionCompensation(const bool friction_compens
247249

248250
bool ScriptCommandInterface::setPDControllerGains(const urcl::vector6d_t* kp, const urcl::vector6d_t* kd)
249251
{
252+
warnIfNotSupported(urcl::VersionInformation::fromString("5.23.0"), urcl::VersionInformation::fromString("10.10.0"),
253+
__func__);
250254
const int message_length = 13;
251255
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
252256
uint8_t* b_pos = buffer;
@@ -279,6 +283,8 @@ bool ScriptCommandInterface::setPDControllerGains(const urcl::vector6d_t* kp, co
279283

280284
bool ScriptCommandInterface::setMaxJointTorques(const urcl::vector6d_t* max_joint_torques)
281285
{
286+
warnIfNotSupported(urcl::VersionInformation::fromString("5.23.0"), urcl::VersionInformation::fromString("10.10.0"),
287+
__func__);
282288
const int message_length = 7;
283289
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
284290
uint8_t* b_pos = buffer;
@@ -354,4 +360,4 @@ void ScriptCommandInterface::messageCallback(const socket_t filedescriptor, char
354360
}
355361

356362
} // namespace control
357-
} // namespace urcl
363+
} // namespace urcl

src/ur/ur_driver.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ void UrDriver::init(const UrDriverConfiguration& config)
9393
std::string local_ip = config.reverse_ip.empty() ? rtde_client_->getIP() : config.reverse_ip;
9494

9595
trajectory_interface_.reset(new control::TrajectoryPointInterface(config.trajectory_port));
96-
script_command_interface_.reset(new control::ScriptCommandInterface(config.script_command_port));
96+
control::ReverseInterfaceConfig script_command_config;
97+
script_command_config.port = config.script_command_port;
98+
script_command_config.robot_software_version = rtde_client_->getVersion();
99+
script_command_interface_.reset(new control::ScriptCommandInterface(script_command_config));
97100

98101
startPrimaryClientCommunication();
99102

@@ -720,7 +723,12 @@ void UrDriver::setupReverseInterface(const uint32_t reverse_port)
720723
{
721724
auto rtde_frequency = rtde_client_->getTargetFrequency();
722725
auto step_time = std::chrono::milliseconds(static_cast<int>(1000 / rtde_frequency));
723-
reverse_interface_.reset(new control::ReverseInterface(reverse_port, handle_program_state_, step_time));
726+
control::ReverseInterfaceConfig config;
727+
config.step_time = step_time;
728+
config.port = reverse_port;
729+
config.handle_program_state = handle_program_state_;
730+
config.robot_software_version = robot_version_;
731+
reverse_interface_.reset(new control::ReverseInterface(config));
724732
}
725733

726734
void UrDriver::startPrimaryClientCommunication()

0 commit comments

Comments
 (0)