Skip to content

Commit eb108f5

Browse files
committed
Use primary client in UrDriver for checking the calibration checksum
As the primary client already receives the calibration data, we can use it directly to check the checksum.
1 parent c31338e commit eb108f5

File tree

8 files changed

+52
-30
lines changed

8 files changed

+52
-30
lines changed

include/ur_client_library/primary/primary_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class PrimaryClient
8787
*/
8888
bool sendScript(const std::string& program);
8989

90+
bool checkCalibration(const std::string& checksum);
91+
9092
private:
9193
/*!
9294
* \brief Reconnects the primary stream used to send program to the robot.

include/ur_client_library/primary/primary_consumer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class PrimaryConsumer : public AbstractPrimaryConsumer
9797
*/
9898
virtual bool consume(KinematicsInfo& pkg) override
9999
{
100+
URCL_LOG_DEBUG("%s", pkg.toString().c_str());
101+
kinematics_info_ = std::make_shared<KinematicsInfo>(pkg);
100102
return true;
101103
}
102104

@@ -162,8 +164,19 @@ class PrimaryConsumer : public AbstractPrimaryConsumer
162164
error_code_message_callback_ = callback_function;
163165
}
164166

167+
/*!
168+
* \brief Get the kinematics info
169+
*
170+
* \returns Shared pointer to the kinematics info
171+
*/
172+
std::shared_ptr<KinematicsInfo> getKinematicsInfo()
173+
{
174+
return kinematics_info_;
175+
}
176+
165177
private:
166178
std::function<void(ErrorCode&)> error_code_message_callback_;
179+
std::shared_ptr<KinematicsInfo> kinematics_info_;
167180
};
168181

169182
} // namespace primary_interface

include/ur_client_library/primary/robot_state/kinematics_info.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,26 @@ namespace primary_interface
4343
class KinematicsInfo : public RobotState
4444
{
4545
public:
46-
KinematicsInfo() = delete;
46+
KinematicsInfo() : RobotState(RobotStateType::KINEMATICS_INFO)
47+
{
48+
}
4749
/*!
4850
* \brief Creates a new KinematicsInfo object.
4951
*
5052
* \param type The type of RobotState message received
5153
*/
52-
KinematicsInfo(const RobotStateType type) : RobotState(type)
54+
explicit KinematicsInfo(const RobotStateType type) : RobotState(type)
55+
{
56+
}
57+
58+
KinematicsInfo(const KinematicsInfo& other) : RobotState(RobotStateType::KINEMATICS_INFO)
5359
{
60+
checksum_ = other.checksum_;
61+
dh_theta_ = other.dh_theta_;
62+
dh_a_ = other.dh_a_;
63+
dh_d_ = other.dh_d_;
64+
dh_alpha_ = other.dh_alpha_;
65+
calibration_status_ = other.calibration_status_;
5466
}
5567
virtual ~KinematicsInfo() = default;
5668

include/ur_client_library/ur/calibration_checker.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ namespace urcl
3939
* packages. These are then checked against the used kinematics to see if the correct calibration
4040
* is used.
4141
*/
42-
class CalibrationChecker : public comm::IConsumer<primary_interface::PrimaryPackage>
42+
class [[deprecated("Using the standaline CalibrationChecker consumer to compare the kinematics hash is deprecated. "
43+
"Please use the PrimaryClient instead.")]] CalibrationChecker
44+
: public comm::IConsumer<primary_interface::PrimaryPackage>
4345
{
4446
public:
4547
/*!

include/ur_client_library/ur/ur_driver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,6 @@ class UrDriver
903903
std::unique_ptr<control::TrajectoryPointInterface> trajectory_interface_;
904904
std::unique_ptr<control::ScriptCommandInterface> script_command_interface_;
905905
std::unique_ptr<control::ScriptSender> script_sender_;
906-
std::unique_ptr<comm::URStream<primary_interface::PrimaryPackage>> primary_stream_;
907906

908907
size_t socket_connection_attempts_ = 0;
909908
std::chrono::milliseconds socket_reconnection_timeout_ = std::chrono::milliseconds(10000);

src/primary/primary_client.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,19 @@ bool PrimaryClient::reconnectStream()
146146
URCL_LOG_ERROR("Failed to reconnect primary stream!");
147147
return false;
148148
}
149+
150+
bool PrimaryClient::checkCalibration(const std::string& checksum)
151+
{
152+
std::shared_ptr<primary_interface::KinematicsInfo> kin_info;
153+
while (kin_info == nullptr)
154+
{
155+
kin_info = consumer_->getKinematicsInfo();
156+
std::this_thread::sleep_for(std::chrono::seconds(1));
157+
}
158+
URCL_LOG_DEBUG("Got calibration information from robot.");
159+
160+
return kin_info->toHash() == checksum;
161+
}
162+
149163
} // namespace primary_interface
150-
} // namespace urcl
164+
} // namespace urcl

src/ur/ur_driver.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ void UrDriver::init(const UrDriverConfiguration& config)
7070
rtde_client_.reset(
7171
new rtde_interface::RTDEClient(robot_ip_, notifier_, config.output_recipe_file, config.input_recipe_file));
7272

73-
primary_stream_.reset(
74-
new comm::URStream<primary_interface::PrimaryPackage>(robot_ip_, urcl::primary_interface::UR_PRIMARY_PORT));
75-
7673
primary_client_.reset(new urcl::primary_interface::PrimaryClient(robot_ip_, notifier_));
7774

7875
get_packet_timeout_ = non_blocking_read_ ? 0 : 100;
@@ -559,27 +556,7 @@ std::string UrDriver::readScriptFile(const std::string& filename)
559556

560557
bool UrDriver::checkCalibration(const std::string& checksum)
561558
{
562-
if (primary_stream_ == nullptr)
563-
{
564-
throw std::runtime_error("checkCalibration() called without a primary interface connection being established.");
565-
}
566-
primary_interface::PrimaryParser parser;
567-
comm::URProducer<primary_interface::PrimaryPackage> prod(*primary_stream_, parser);
568-
prod.setupProducer();
569-
570-
CalibrationChecker consumer(checksum);
571-
572-
comm::INotifier notifier;
573-
574-
comm::Pipeline<primary_interface::PrimaryPackage> pipeline(prod, &consumer, "Pipeline", notifier);
575-
pipeline.run();
576-
577-
while (!consumer.isChecked())
578-
{
579-
std::this_thread::sleep_for(std::chrono::seconds(1));
580-
}
581-
URCL_LOG_DEBUG("Got calibration information from robot.");
582-
return consumer.checkSuccessful();
559+
return primary_client_->checkCalibration(checksum);
583560
}
584561

585562
rtde_interface::RTDEWriter& UrDriver::getRTDEWriter()
@@ -670,4 +647,4 @@ std::deque<urcl::primary_interface::ErrorCode> UrDriver::getErrorCodes()
670647
{
671648
return primary_client_->getErrorCodes();
672649
}
673-
} // namespace urcl
650+
} // namespace urcl

tests/test_primary_client.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ TEST_F(PrimaryClientTest, start_communication_succeeds)
5757

5858
TEST_F(PrimaryClientTest, add_and_remove_consumer)
5959
{
60+
#pragma GCC diagnostic push
61+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6062
auto calibration_consumer = std::make_shared<urcl::CalibrationChecker>("test");
63+
#pragma GCC diagnostic pop
6164

6265
client_->addPrimaryConsumer(calibration_consumer);
6366

0 commit comments

Comments
 (0)