Skip to content

Commit b710249

Browse files
committed
WIP: Move primary interface logic to primary client
1 parent d41a48b commit b710249

File tree

10 files changed

+367
-113
lines changed

10 files changed

+367
-113
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2+
//
3+
// -- BEGIN LICENSE BLOCK ----------------------------------------------
4+
// Copyright 2020 FZI Forschungszentrum Informatik
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// -- END LICENSE BLOCK ------------------------------------------------
18+
19+
//----------------------------------------------------------------------
20+
/*!\file
21+
*
22+
* \author Felix Exner exner@fzi.de
23+
* \date 2020-04-30
24+
*
25+
*/
26+
//----------------------------------------------------------------------
27+
28+
#ifndef UR_ROBOT_DRIVER_KEY_MESSAGE_HANDLER_H_INCLUDED
29+
#define UR_ROBOT_DRIVER_KEY_MESSAGE_HANDLER_H_INCLUDED
30+
31+
#include <ur_robot_driver/log.h>
32+
#include <ur_robot_driver/primary/primary_package_handler.h>
33+
#include <ur_robot_driver/primary/robot_message/key_message.h>
34+
35+
namespace ur_driver
36+
{
37+
namespace primary_interface
38+
{
39+
class KeyMessageHandler : public IPrimaryPackageHandler<KeyMessage>
40+
{
41+
public:
42+
KeyMessageHandler() = default;
43+
virtual ~KeyMessageHandler() = default;
44+
45+
/*!
46+
* \brief Actual worker function
47+
*
48+
* \param pkg package that should be handled
49+
*/
50+
virtual void handle(KeyMessage& pkg) override
51+
{
52+
LOG_INFO("%s", pkg.toString().c_str());
53+
}
54+
55+
private:
56+
/* data */
57+
};
58+
} // namespace primary_interface
59+
} // namespace ur_driver
60+
#endif // ifndef UR_ROBOT_DRIVER_KEY_MESSAGE_HANDLER_H_INCLUDED

ur_robot_driver/include/ur_robot_driver/primary/primary_client.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <ur_robot_driver/comm/producer.h>
3232
#include <ur_robot_driver/comm/stream.h>
3333
#include <ur_robot_driver/comm/pipeline.h>
34+
#include <ur_robot_driver/ur/calibration_checker.h>
35+
#include <ur_robot_driver/primary/primary_consumer.h>
3436

3537
namespace ur_driver
3638
{
@@ -40,13 +42,31 @@ class PrimaryClient
4042
{
4143
public:
4244
PrimaryClient() = delete;
43-
PrimaryClient(const std::string& robot_ip);
45+
PrimaryClient(const std::string& robot_ip, const std::string& calibration_checksum);
4446
virtual ~PrimaryClient() = default;
4547

48+
/*!
49+
* \brief Sends a custom script program to the robot.
50+
*
51+
* The given code must be valid according the UR Scripting Manual.
52+
*
53+
* \param script_code URScript code that shall be executed by the robot.
54+
*
55+
* \returns true on successful upload, false otherwise.
56+
*/
57+
bool sendScript(const std::string& script_code);
58+
59+
/*!
60+
* \brief Checks if the kinematics information in the used model fits the actual robot.
61+
*
62+
* \param checksum Hash of the used kinematics information
63+
*/
64+
void checkCalibration(const std::string& checksum);
65+
4666
private:
4767
std::string robot_ip_;
4868
PrimaryParser parser_;
49-
std::unique_ptr<comm::IConsumer<PrimaryPackage>> consumer_;
69+
std::unique_ptr<PrimaryConsumer> consumer_;
5070
comm::INotifier notifier_;
5171
std::unique_ptr<comm::URProducer<PrimaryPackage>> producer_;
5272
std::unique_ptr<comm::URStream<PrimaryPackage>> stream_;
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2+
//
3+
// -- BEGIN LICENSE BLOCK ----------------------------------------------
4+
// Copyright 2020 FZI Forschungszentrum Informatik
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// -- END LICENSE BLOCK ------------------------------------------------
18+
19+
//----------------------------------------------------------------------
20+
/*!\file
21+
*
22+
* \author Felix Exner exner@fzi.de
23+
* \date 2020-04-30
24+
*
25+
*/
26+
//----------------------------------------------------------------------
27+
28+
#ifndef UR_ROBOT_DRIVER_PRIMARY_CONSUMER_H_INCLUDED
29+
#define UR_ROBOT_DRIVER_PRIMARY_CONSUMER_H_INCLUDED
30+
31+
#include "ur_robot_driver/log.h"
32+
#include "ur_robot_driver/comm/pipeline.h"
33+
#include "ur_robot_driver/primary/primary_package_handler.h"
34+
#include "ur_robot_driver/primary/abstract_primary_consumer.h"
35+
#include "ur_robot_driver/primary/key_message_handler.h"
36+
#include "ur_robot_driver/primary/robot_message/error_code_message.h"
37+
#include "ur_robot_driver/primary/robot_message/key_message.h"
38+
#include "ur_robot_driver/primary/robot_message/runtime_exception_message.h"
39+
#include "ur_robot_driver/primary/robot_message/text_message.h"
40+
#include "ur_robot_driver/primary/robot_message/version_message.h"
41+
#include "ur_robot_driver/primary/robot_state/kinematics_info.h"
42+
43+
namespace ur_driver
44+
{
45+
namespace primary_interface
46+
{
47+
/*!
48+
* \brief Primary consumer implementation
49+
*
50+
* This class implements am AbstractPrimaryConsumer such that it can consume all incoming primary
51+
* messages. However, actual work will be done by workers for each specific type.
52+
*/
53+
class PrimaryConsumer : public AbstractPrimaryConsumer
54+
{
55+
public:
56+
PrimaryConsumer()
57+
{
58+
LOG_INFO("Constructing primary consumer");
59+
key_message_worker_.reset(new KeyMessageHandler());
60+
LOG_INFO("Constructed primary consumer");
61+
}
62+
virtual ~PrimaryConsumer() = default;
63+
64+
virtual bool consume(RobotMessage& msg) override
65+
{
66+
LOG_INFO("---RobotMessage:---\n%s", msg.toString().c_str());
67+
return true;
68+
}
69+
virtual bool consume(RobotState& msg) override
70+
{
71+
// LOG_INFO("---RobotState:---\n%s", msg.toString().c_str());
72+
return true;
73+
}
74+
virtual bool consume(ErrorCodeMessage& msg) override
75+
{
76+
LOG_INFO("---ErrorCodeMessage---\n%s", msg.toString().c_str());
77+
return true;
78+
}
79+
virtual bool consume(RuntimeExceptionMessage& msg) override
80+
{
81+
LOG_INFO("---RuntimeExceptionMessage---\n%s", msg.toString().c_str());
82+
return true;
83+
}
84+
virtual bool consume(TextMessage& msg) override
85+
{
86+
LOG_INFO("---TextMessage---\n%s", msg.toString().c_str());
87+
return true;
88+
}
89+
virtual bool consume(VersionMessage& msg) override
90+
{
91+
LOG_INFO("---VersionMessage---\n%s", msg.toString().c_str());
92+
return true;
93+
}
94+
95+
/*!
96+
* \brief Handle a KinematicsInfo
97+
*
98+
* \returns True if there's a handler for this message type registered. False otherwise.
99+
*/
100+
virtual bool consume(KinematicsInfo& pkg) override
101+
{
102+
if (kinematics_info_message_worker_ != nullptr)
103+
{
104+
kinematics_info_message_worker_->handle(pkg);
105+
return true;
106+
}
107+
return false;
108+
}
109+
110+
/*!
111+
* \brief Handle a KeyMessage
112+
*
113+
* \returns True if there's a handler for this message type registered. False otherwise.
114+
*/
115+
virtual bool consume(KeyMessage& pkg) override
116+
{
117+
if (key_message_worker_ != nullptr)
118+
{
119+
key_message_worker_->handle(pkg);
120+
return true;
121+
}
122+
return false;
123+
}
124+
125+
void setKinematicsInfoHandler(const std::shared_ptr<IPrimaryPackageHandler<KinematicsInfo>>& handler)
126+
{
127+
kinematics_info_message_worker_ = handler;
128+
}
129+
130+
private:
131+
std::shared_ptr<IPrimaryPackageHandler<KeyMessage>> key_message_worker_;
132+
std::shared_ptr<IPrimaryPackageHandler<KinematicsInfo>> kinematics_info_message_worker_;
133+
};
134+
} // namespace primary_interface
135+
} // namespace ur_driver
136+
137+
#endif // ifndef UR_ROBOT_DRIVER_PRIMARY_CONSUMER_H_INCLUDED
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2+
//
3+
// -- BEGIN LICENSE BLOCK ----------------------------------------------
4+
// Copyright 2020 FZI Forschungszentrum Informatik
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// -- END LICENSE BLOCK ------------------------------------------------
18+
19+
//----------------------------------------------------------------------
20+
/*!\file
21+
*
22+
* \author Felix Exner exner@fzi.de
23+
* \date 2020-04-30
24+
*
25+
*/
26+
//----------------------------------------------------------------------
27+
28+
#ifndef UR_ROBOT_DRIVER_PRIMARY_PACKAGE_HANDLER_H_INCLUDED
29+
#define UR_ROBOT_DRIVER_PRIMARY_PACKAGE_HANDLER_H_INCLUDED
30+
31+
namespace ur_driver
32+
{
33+
namespace primary_interface
34+
{
35+
/*!
36+
* \brief Interface for a class handling a primary interface package. Classes that implement this
37+
* interface with a specific package type will be able to handle packages of this type.
38+
*/
39+
template <typename PackageT>
40+
class IPrimaryPackageHandler
41+
{
42+
public:
43+
IPrimaryPackageHandler() = default;
44+
virtual ~IPrimaryPackageHandler() = default;
45+
46+
/*!
47+
* \brief Actual worker function
48+
*
49+
* \param pkg package that should be handled
50+
*/
51+
virtual void handle(PackageT& pkg) = 0;
52+
53+
private:
54+
/* data */
55+
};
56+
} // namespace primary_interface
57+
} // namespace ur_driver
58+
#endif // ifndef UR_ROBOT_DRIVER_PRIMARY_PACKAGE_HANDLER_H_INCLUDED

ur_robot_driver/include/ur_robot_driver/primary/primary_shell_consumer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class PrimaryShellConsumer : public AbstractPrimaryConsumer
4949
}
5050
virtual bool consume(RobotState& msg) override
5151
{
52-
LOG_INFO("---RobotState:---\n%s", msg.toString().c_str());
52+
//LOG_INFO("---RobotState:---\n%s", msg.toString().c_str());
5353
return true;
5454
}
5555
virtual bool consume(ErrorCodeMessage& msg) override

ur_robot_driver/include/ur_robot_driver/ur/calibration_checker.h

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@
2727
#ifndef UR_RTDE_DRIVER_UR_CALIBRATION_CHECKER_H_INCLUDED
2828
#define UR_RTDE_DRIVER_UR_CALIBRATION_CHECKER_H_INCLUDED
2929

30-
#include <ur_robot_driver/comm/pipeline.h>
31-
30+
#include <ur_robot_driver/primary/primary_package_handler.h>
3231
#include <ur_robot_driver/primary/robot_state/kinematics_info.h>
3332

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

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

8862
/*!
8963
* \brief Used to make sure the calibration check is not performed several times.

0 commit comments

Comments
 (0)