Skip to content

Commit 91b4f27

Browse files
committed
Updated calibration checker to double as both the message handler for the kinematics info message type and a calibration checker. It is still possible to add a separate calibration checker, if that is desired.
1 parent be9a694 commit 91b4f27

File tree

2 files changed

+46
-43
lines changed

2 files changed

+46
-43
lines changed

include/ur_client_library/ur/calibration_checker.h

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@
2828
#ifndef UR_CLIENT_LIBRARY_UR_CALIBRATION_CHECKER_H_INCLUDED
2929
#define UR_CLIENT_LIBRARY_UR_CALIBRATION_CHECKER_H_INCLUDED
3030

31-
#include <ur_client_library/comm/pipeline.h>
32-
31+
#include <ur_client_library/primary/primary_package_handler.h>
3332
#include <ur_client_library/primary/robot_state/kinematics_info.h>
3433

3534
namespace urcl
3635
{
3736
/*!
38-
* \brief The CalibrationChecker class consumes primary packages ignoring all but KinematicsInfo
39-
* packages. These are then checked against the used kinematics to see if the correct calibration
40-
* is used.
37+
* \brief The CalibrationChecker checks a received KinematicsInfo package against a registered calibration hash
38+
* value. This way we know whether the robot that sent the KinematicsInfo package matches the
39+
* expected calibration.
4140
*/
42-
class CalibrationChecker : public comm::IConsumer<primary_interface::PrimaryPackage>
41+
class CalibrationChecker : public primary_interface::IPrimaryPackageHandler<primary_interface::KinematicsInfo>
4342
{
4443
public:
4544
/*!
@@ -51,40 +50,15 @@ class CalibrationChecker : public comm::IConsumer<primary_interface::PrimaryPack
5150
CalibrationChecker(const std::string& expected_hash);
5251
virtual ~CalibrationChecker() = default;
5352

54-
/*!
55-
* \brief Empty setup function, as no setup is needed.
56-
*/
57-
virtual void setupConsumer()
58-
{
59-
}
60-
/*!
61-
* \brief Tears down the consumer.
62-
*/
63-
virtual void teardownConsumer()
64-
{
65-
}
66-
/*!
67-
* \brief Stops the consumer.
68-
*/
69-
virtual void stopConsumer()
70-
{
71-
}
72-
/*!
73-
* \brief Handles timeouts.
74-
*/
75-
virtual void onTimeout()
76-
{
77-
}
78-
7953
/*!
8054
* \brief Consumes a package, checking its hash if it is a KinematicsInfo package. If the hash
8155
* does not match the expected hash, an error is logged.
8256
*
83-
* \param product The package to consume
57+
* \param kin_info The package to consume
8458
*
8559
* \returns True, if the package was consumed correctly
8660
*/
87-
virtual bool consume(std::shared_ptr<primary_interface::PrimaryPackage> product);
61+
virtual void handle(primary_interface::KinematicsInfo& kin_info) override;
8862

8963
/*!
9064
* \brief Used to make sure the calibration check is not performed several times.
@@ -107,10 +81,33 @@ class CalibrationChecker : public comm::IConsumer<primary_interface::PrimaryPack
10781
return matches_;
10882
}
10983

84+
/*!
85+
* \brief Get latest KinematicsInfo
86+
*
87+
* \return latest KinematicsInfo
88+
*/
89+
virtual std::shared_ptr<primary_interface::KinematicsInfo> getData()
90+
{
91+
if (data_ == nullptr)
92+
throw UrException("A KinematicsInfo package has not been received yet");
93+
return data_;
94+
}
95+
96+
/*!
97+
* \brief Returns whether the calibration check was successful.
98+
*
99+
* \param expected_hash The hash expected to match the hash on the robot
100+
*
101+
* \returns True if the robot's expected_hash matches the one given to the checker. False
102+
* if it doesn't match or the check was not yet performed.
103+
*/
104+
bool checkCalibration(const std::string& expected_hash);
105+
110106
private:
111107
std::string expected_hash_;
112108
bool checked_;
113109
bool matches_;
110+
std::shared_ptr<primary_interface::KinematicsInfo> data_;
114111
};
115112
} // namespace urcl
116113

src/ur/calibration_checker.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,24 @@ CalibrationChecker::CalibrationChecker(const std::string& expected_hash)
3434
: expected_hash_(expected_hash), checked_(false), matches_(false)
3535
{
3636
}
37-
bool CalibrationChecker::consume(std::shared_ptr<primary_interface::PrimaryPackage> product)
37+
38+
void CalibrationChecker::handle(primary_interface::KinematicsInfo& kin_info)
39+
{
40+
// URCL_LOG_INFO("%s", kin_info.toString().c_str());
41+
//
42+
matches_ = kin_info.toHash() == expected_hash_;
43+
44+
checked_ = true;
45+
46+
data_.reset(new primary_interface::KinematicsInfo(kin_info));
47+
}
48+
49+
bool CalibrationChecker::checkCalibration(const std::string& expected_hash)
3850
{
39-
auto kin_info = std::dynamic_pointer_cast<primary_interface::KinematicsInfo>(product);
40-
if (kin_info != nullptr)
41-
{
42-
// URCL_LOG_INFO("%s", product->toString().c_str());
43-
//
44-
matches_ = kin_info->toHash() == expected_hash_;
51+
matches_ = expected_hash == expected_hash_;
4552

46-
checked_ = true;
47-
}
53+
checked_ = true;
4854

49-
return true;
55+
return matches_;
5056
}
5157
} // namespace urcl

0 commit comments

Comments
 (0)