Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/ur_client_library/control/reverse_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "ur_client_library/types.h"
#include "ur_client_library/log.h"
#include "ur_client_library/ur/robot_receive_timeout.h"
#include "ur_client_library/ur/version_information.h"
#include <cstring>
#include <endian.h>
#include <condition_variable>
Expand Down Expand Up @@ -62,6 +63,17 @@ enum class FreedriveControlMessage : int32_t
FREEDRIVE_START = 1, ///< Represents command to start freedrive mode.
};

struct ReverseInterfaceConfig
{
uint32_t port = 50001; //!< Port the server is started on
std::function<void(bool)> handle_program_state = [](bool) {
return;
}; //!< Function handle to a callback on program state changes.
std::chrono::milliseconds step_time = std::chrono::milliseconds(8); //!< The robots step time
uint32_t keepalive_count = 0; //!< Number of allowed timeout reads on the robot.
VersionInformation robot_software_version = VersionInformation(); //!< The robot software version.
};

/*!
* \brief The ReverseInterface class handles communication to the robot. It starts a server and
* waits for the robot to connect via its URCaps program.
Expand All @@ -79,9 +91,12 @@ class ReverseInterface
* \param handle_program_state Function handle to a callback on program state changes.
* \param step_time The robots step time
*/
[[deprecated("Use ReverseInterfaceConfig instead of port, handle_program_state and step_time parameters")]]
ReverseInterface(uint32_t port, std::function<void(bool)> handle_program_state,
std::chrono::milliseconds step_time = std::chrono::milliseconds(8));

ReverseInterface(const ReverseInterfaceConfig& config);

/*!
* \brief Disconnects possible clients so the reverse interface object can be safely destroyed.
*/
Expand Down Expand Up @@ -167,6 +182,8 @@ class ReverseInterface
socket_t client_fd_;
comm::TCPServer server_;

VersionInformation robot_software_version_;

template <typename T>
size_t append(uint8_t* buffer, T& val)
{
Expand Down
11 changes: 10 additions & 1 deletion include/ur_client_library/control/script_command_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ class ScriptCommandInterface : public ReverseInterface
*
* \param port Port to start the server on
*/
[[deprecated("Use ReverseInterfaceConfig instead of port, handle_program_state and step_time parameters")]]
ScriptCommandInterface(uint32_t port);

/*!
* \brief Creates a ScriptCommandInterface object, including a new TCPServer
*
* \param config Configuration for the ReverseInterface, including the port to start the server
* on.
*/
ScriptCommandInterface(const ReverseInterfaceConfig& config);

/*!
* \brief Zero the force torque sensor
*
Expand Down Expand Up @@ -195,4 +204,4 @@ class ScriptCommandInterface : public ReverseInterface
} // namespace control
} // namespace urcl

#endif // UR_CLIENT_LIBRARY_SCRIPT_COMMAND_INTERFACE_H_INCLUDED
#endif // UR_CLIENT_LIBRARY_SCRIPT_COMMAND_INTERFACE_H_INCLUDED
12 changes: 9 additions & 3 deletions src/control/reverse_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@
{
ReverseInterface::ReverseInterface(uint32_t port, std::function<void(bool)> handle_program_state,
std::chrono::milliseconds step_time)
: ReverseInterface(ReverseInterfaceConfig{ port, handle_program_state, step_time })

Check warning on line 38 in src/control/reverse_interface.cpp

View check run for this annotation

Codecov / codecov/patch

src/control/reverse_interface.cpp#L38

Added line #L38 was not covered by tests
{
}

ReverseInterface::ReverseInterface(const ReverseInterfaceConfig& config)
: client_fd_(INVALID_SOCKET)
, server_(port)
, handle_program_state_(handle_program_state)
, step_time_(step_time)
, server_(config.port)
, robot_software_version_(config.robot_software_version)
, handle_program_state_(config.handle_program_state)
, step_time_(config.step_time)
, keep_alive_count_modified_deprecated_(false)
{
handle_program_state_(false);
Expand Down
6 changes: 5 additions & 1 deletion src/control/script_command_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
{
namespace control
{
ScriptCommandInterface::ScriptCommandInterface(uint32_t port) : ReverseInterface(port, [](bool foo) { return foo; })
ScriptCommandInterface::ScriptCommandInterface(uint32_t port) : ScriptCommandInterface(ReverseInterfaceConfig{ port })

Check warning on line 36 in src/control/script_command_interface.cpp

View check run for this annotation

Codecov / codecov/patch

src/control/script_command_interface.cpp#L36

Added line #L36 was not covered by tests
{
}

ScriptCommandInterface::ScriptCommandInterface(const ReverseInterfaceConfig& config) : ReverseInterface(config)
{
client_connected_ = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/control/trajectory_point_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::string trajectoryResultToString(const TrajectoryResult result)
}
}

TrajectoryPointInterface::TrajectoryPointInterface(uint32_t port) : ReverseInterface(port, [](bool foo) { return foo; })
TrajectoryPointInterface::TrajectoryPointInterface(uint32_t port) : ReverseInterface(ReverseInterfaceConfig{ port })
{
}

Expand Down
12 changes: 10 additions & 2 deletions src/ur/ur_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ void UrDriver::init(const UrDriverConfiguration& config)
std::string local_ip = config.reverse_ip.empty() ? rtde_client_->getIP() : config.reverse_ip;

trajectory_interface_.reset(new control::TrajectoryPointInterface(config.trajectory_port));
script_command_interface_.reset(new control::ScriptCommandInterface(config.script_command_port));
control::ReverseInterfaceConfig script_command_config;
script_command_config.port = config.script_command_port;
script_command_config.robot_software_version = rtde_client_->getVersion();
script_command_interface_.reset(new control::ScriptCommandInterface(script_command_config));

startPrimaryClientCommunication();

Expand Down Expand Up @@ -622,7 +625,12 @@ void UrDriver::setupReverseInterface(const uint32_t reverse_port)
{
auto rtde_frequency = rtde_client_->getTargetFrequency();
auto step_time = std::chrono::milliseconds(static_cast<int>(1000 / rtde_frequency));
reverse_interface_.reset(new control::ReverseInterface(reverse_port, handle_program_state_, step_time));
control::ReverseInterfaceConfig config;
config.step_time = step_time;
config.port = reverse_port;
config.handle_program_state = handle_program_state_;
config.robot_software_version = robot_version_;
reverse_interface_.reset(new control::ReverseInterface(config));
}

void UrDriver::startPrimaryClientCommunication()
Expand Down
6 changes: 4 additions & 2 deletions tests/test_reverse_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ class ReverseIntefaceTest : public ::testing::Test

void SetUp()
{
reverse_interface_.reset(new control::ReverseInterface(
50001, std::bind(&ReverseIntefaceTest::handleProgramState, this, std::placeholders::_1)));
control::ReverseInterfaceConfig config;
config.port = 50001;
config.handle_program_state = std::bind(&ReverseIntefaceTest::handleProgramState, this, std::placeholders::_1);
reverse_interface_.reset(new control::ReverseInterface(config));
client_.reset(new Client(50001));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_script_command_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ScriptCommandInterfaceTest : public ::testing::Test

void SetUp()
{
script_command_interface_.reset(new control::ScriptCommandInterface(50004));
script_command_interface_.reset(new control::ScriptCommandInterface(control::ReverseInterfaceConfig{ 50004 }));
client_.reset(new Client(50004));
}

Expand Down
Loading