Skip to content

Commit 92eb009

Browse files
committed
Added the new primary client. The primary client can through its consumer get the message handlers and from the message handlers get the latest message of each type.
The primary client checks whether the robot is in remote control or not, as it should not be able to send script if the robot is not in remote control. This is not true if the robot is simulated. Therefore, when constructing a primary client instance it is needed to specify if the robot is simulated or real. I was not able to find a way for the primary client to check whether it was real or simulated automatically. The primary client now automatically checks whether the checksum is correct when starting.
1 parent 91b4f27 commit 92eb009

File tree

3 files changed

+464
-0
lines changed

3 files changed

+464
-0
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,24 @@ add_library(urcl SHARED
2323
src/control/script_sender.cpp
2424
src/control/trajectory_point_interface.cpp
2525
src/control/script_command_interface.cpp
26+
src/primary/primary_client.cpp
2627
src/primary/primary_package.cpp
28+
src/primary/program_state_message.cpp
2729
src/primary/robot_message.cpp
2830
src/primary/robot_state.cpp
31+
src/primary/program_state_message/global_variables_update_message.cpp
32+
src/primary/program_state_message/global_variables_setup_message.cpp
33+
src/primary/robot_message/error_code_message.cpp
34+
src/primary/robot_message/runtime_exception_message.cpp
2935
src/primary/robot_message/version_message.cpp
36+
src/primary/robot_message/text_message.cpp
37+
src/primary/robot_message/key_message.cpp
3038
src/primary/robot_state/kinematics_info.cpp
39+
src/primary/robot_state/robot_mode_data.cpp
40+
src/primary/robot_state/joint_data.cpp
41+
src/primary/robot_state/cartesian_info.cpp
42+
src/primary/robot_state/force_mode_data.cpp
43+
src/primary/robot_state/additional_info.cpp
3144
src/rtde/control_package_pause.cpp
3245
src/rtde/control_package_setup_inputs.cpp
3346
src/rtde/control_package_setup_outputs.cpp
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2+
3+
// -- BEGIN LICENSE BLOCK ----------------------------------------------
4+
// Copyright 2019 FZI Forschungszentrum Informatik
5+
//
6+
// Licensed under the Apache License, Text 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+
#ifndef UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED
28+
#define UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED
29+
30+
#include <ur_client_library/primary/primary_parser.h>
31+
#include <ur_client_library/comm/producer.h>
32+
#include <ur_client_library/comm/stream.h>
33+
#include <ur_client_library/comm/pipeline.h>
34+
#include <ur_client_library/ur/calibration_checker.h>
35+
#include <ur_client_library/primary/primary_consumer.h>
36+
#include <ur_client_library/ur/dashboard_client.h>
37+
38+
namespace urcl
39+
{
40+
namespace primary_interface
41+
{
42+
class PrimaryClient
43+
{
44+
public:
45+
PrimaryClient() = delete;
46+
PrimaryClient(const std::string& robot_ip, const std::string& calibration_checksum);
47+
// virtual ~PrimaryClient() = default;
48+
virtual ~PrimaryClient();
49+
50+
/*!
51+
* \brief Sends a custom script program to the robot.
52+
*
53+
* The given code must be valid according the UR Scripting Manual.
54+
*
55+
* \param script_code URScript code that shall be executed by the robot.
56+
*
57+
* \returns true on successful upload, false otherwise.
58+
*/
59+
bool sendScript(const std::string& script_code);
60+
61+
/*!
62+
* \brief Configures the primary client
63+
*
64+
* Creates a connection to the stream and sets up producer, consumer and pipeline
65+
*/
66+
bool configure();
67+
68+
/*!
69+
* \brief Checks if the robot is in local or remote control
70+
*
71+
* Checks for package with error code determining if robot is in remote or local control
72+
*/
73+
void checkRemoteLocalControl();
74+
75+
/*!
76+
* \brief Stops the primary client
77+
*
78+
* Closes the thread checking for remote or local control
79+
*/
80+
void stop();
81+
82+
/*!
83+
* \brief Returns whether the robot is in remote or local control
84+
*
85+
* Returns whether the robot is in remote or local control
86+
*/
87+
bool isInRemoteControl();
88+
89+
/*!
90+
* \brief Returns latest AdditionalInfo message
91+
*
92+
* Returns latest AdditionalInfo message
93+
*/
94+
std::shared_ptr<AdditionalInfo> getAdditionalInfo();
95+
96+
/*!
97+
* \brief Returns latest CartesianInfo message
98+
*
99+
* Returns latest CartesianInfo message
100+
*/
101+
std::shared_ptr<CartesianInfo> getCartesianInfo();
102+
103+
/*!
104+
* \brief Returns latest ForceModeData message
105+
*
106+
* Returns latest ForceModeData message
107+
*/
108+
std::shared_ptr<ForceModeData> getForceModeData();
109+
110+
/*!
111+
* \brief Returns latest JointData message
112+
*
113+
* Returns latest JointData message
114+
*/
115+
std::shared_ptr<JointData> getJointData();
116+
117+
/*!
118+
* \brief Returns latest RobotModeData message
119+
*
120+
* Returns latest RobotModeData message
121+
*/
122+
std::shared_ptr<RobotModeData> getRobotModeData();
123+
124+
/*!
125+
* \brief Returns latest KeyMessage message
126+
*
127+
* Returns latest KeyMessage message
128+
*/
129+
std::shared_ptr<KeyMessage> getKeyMessage();
130+
131+
/*!
132+
* \brief Returns latest ErrorCodeMessage message
133+
*
134+
* Returns latest ErrorCodeMessage message
135+
*/
136+
std::shared_ptr<ErrorCodeMessage> getErrorCodeMessage();
137+
138+
/*!
139+
* \brief Returns latest RuntimeExceptionMessage message
140+
*
141+
* Returns latest RuntimeExceptionMessage message
142+
*/
143+
std::shared_ptr<RuntimeExceptionMessage> getRuntimeExceptionMessage();
144+
145+
/*!
146+
* \brief Returns latest TextMessage message
147+
*
148+
* Returns latest TextMessage message
149+
*/
150+
std::shared_ptr<TextMessage> getTextMessage();
151+
152+
/*!
153+
* \brief Returns latest VersionMessage message
154+
*
155+
* Returns latest VersionMessage message
156+
*/
157+
std::shared_ptr<VersionMessage> getVersionMessage();
158+
159+
/*!
160+
* \brief Returns latest GlobalVariablesSetupMessage message
161+
*
162+
* Returns latest GlobalVariablesSetupMessage message
163+
*/
164+
std::shared_ptr<GlobalVariablesSetupMessage> getGlobalVariablesSetupMessage();
165+
166+
/*!
167+
* \brief Returns Calibration checker
168+
*
169+
* Returns Calibration checker
170+
*/
171+
std::shared_ptr<CalibrationChecker> getCalibrationChecker();
172+
173+
/*!
174+
* \brief Set whether the robot is simulated or real
175+
*/
176+
void setSimulated(bool value);
177+
178+
/*!
179+
* \brief Check if the robot is simulated or real
180+
*
181+
* \returns true if robot is simulated, false otherwise.
182+
*/
183+
bool getSimulated();
184+
185+
private:
186+
std::string robot_ip_;
187+
int port_;
188+
PrimaryParser parser_;
189+
comm::INotifier notifier_;
190+
bool connected_;
191+
bool simulated_;
192+
std::atomic<bool> running_, in_remote_control_;
193+
std::unique_ptr<PrimaryConsumer> consumer_;
194+
std::unique_ptr<comm::URProducer<PrimaryPackage>> producer_;
195+
std::unique_ptr<comm::URStream<PrimaryPackage>> stream_;
196+
std::unique_ptr<comm::Pipeline<PrimaryPackage>> pipeline_;
197+
std::unique_ptr<urcl::DashboardClient> dashboard_client_;
198+
std::shared_ptr<CalibrationChecker> calibration_checker_;
199+
std::thread rc_thread_;
200+
};
201+
202+
} // namespace primary_interface
203+
} // namespace urcl
204+
205+
#endif // ifndef UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED

0 commit comments

Comments
 (0)