Skip to content

Commit 6dcfaee

Browse files
urmahpurfeex
andauthored
Added configuration data to packages parsed from the primary interface (#327)
Co-authored-by: Felix Exner <feex@universal-robots.com>
1 parent ccc2e5a commit 6dcfaee

File tree

10 files changed

+393
-0
lines changed

10 files changed

+393
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_library(urcl
2929
src/primary/robot_message/error_code_message.cpp
3030
src/primary/robot_state/kinematics_info.cpp
3131
src/primary/robot_state/robot_mode_data.cpp
32+
src/primary/robot_state/configuration_data.cpp
3233
src/rtde/control_package_pause.cpp
3334
src/rtde/control_package_setup_inputs.cpp
3435
src/rtde/control_package_setup_outputs.cpp

include/ur_client_library/primary/abstract_primary_consumer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "ur_client_library/primary/robot_message/error_code_message.h"
3636
#include "ur_client_library/primary/robot_state/kinematics_info.h"
3737
#include "ur_client_library/primary/robot_state/robot_mode_data.h"
38+
#include "ur_client_library/primary/robot_state/configuration_data.h"
3839

3940
namespace urcl
4041
{
@@ -77,6 +78,7 @@ class AbstractPrimaryConsumer : public comm::IConsumer<PrimaryPackage>
7778
virtual bool consume(KinematicsInfo& pkg) = 0;
7879
virtual bool consume(ErrorCodeMessage& pkg) = 0;
7980
virtual bool consume(RobotModeData& pkg) = 0;
81+
virtual bool consume(ConfigurationData& pkg) = 0;
8082

8183
private:
8284
/* data */

include/ur_client_library/primary/primary_client.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,25 @@ class PrimaryClient
218218
return robot_mode_data->is_protective_stopped_;
219219
}
220220

221+
/*!
222+
* \brief Get the latest configuration data
223+
*
224+
* The configuration data will be updated in the background. This will always show the latest
225+
* received configuration data independent of the time that has passed since receiving it. If no
226+
* configuration data has been received yet, this will return a nullptr.
227+
*/
228+
std::shared_ptr<ConfigurationData> getConfigurationData()
229+
{
230+
return consumer_->getConfigurationData();
231+
}
232+
233+
/*!
234+
* \brief Get the Robot type
235+
*
236+
* If no robot type data has been received yet, this will return UNDEFINED.
237+
*/
238+
RobotType getRobotType();
239+
221240
private:
222241
/*!
223242
* \brief Reconnects the primary stream used to send program to the robot.

include/ur_client_library/primary/primary_consumer.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ class PrimaryConsumer : public AbstractPrimaryConsumer
170170
return true;
171171
}
172172

173+
virtual bool consume(ConfigurationData& pkg) override
174+
{
175+
std::scoped_lock lock(configuration_data_mutex_);
176+
configuration_data_ = std::make_shared<ConfigurationData>(pkg);
177+
return true;
178+
}
179+
173180
/*!
174181
* \brief Set callback function which will be triggered whenever error code messages are received
175182
*
@@ -216,13 +223,28 @@ class PrimaryConsumer : public AbstractPrimaryConsumer
216223
return version_information_;
217224
}
218225

226+
/*!
227+
* \brief Get the latest configuration data.
228+
*
229+
* The configuration data will be updated in the background. This will always show the latest
230+
* received configuration data independent of the time that has passed since receiving it. If no
231+
* configuration data has been received yet, this will return a nullptr.
232+
*/
233+
std::shared_ptr<ConfigurationData> getConfigurationData()
234+
{
235+
std::scoped_lock lock(configuration_data_mutex_);
236+
return configuration_data_;
237+
}
238+
219239
private:
220240
std::function<void(ErrorCode&)> error_code_message_callback_;
221241
std::shared_ptr<KinematicsInfo> kinematics_info_;
222242
std::mutex robot_mode_mutex_;
223243
std::shared_ptr<RobotModeData> robot_mode_;
224244
std::mutex version_information_mutex_;
225245
std::shared_ptr<VersionInformation> version_information_;
246+
std::shared_ptr<ConfigurationData> configuration_data_;
247+
std::mutex configuration_data_mutex_;
226248
};
227249

228250
} // namespace primary_interface

include/ur_client_library/primary/primary_parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "ur_client_library/primary/robot_message/version_message.h"
3131
#include "ur_client_library/primary/robot_message/error_code_message.h"
3232
#include "ur_client_library/primary/robot_state/robot_mode_data.h"
33+
#include "ur_client_library/primary/robot_state/configuration_data.h"
3334

3435
namespace urcl
3536
{
@@ -159,6 +160,8 @@ class PrimaryParser : public comm::Parser<PrimaryPackage>
159160
// return new MBD;*/
160161
case RobotStateType::KINEMATICS_INFO:
161162
return new KinematicsInfo(type);
163+
case RobotStateType::CONFIGURATION_DATA:
164+
return new ConfigurationData(type);
162165
default:
163166
return new RobotState(type);
164167
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// -- BEGIN LICENSE BLOCK ----------------------------------------------
2+
// Copyright 2025 Universal Robots A/S
3+
//
4+
// Redistribution and use in source and binary forms, with or without
5+
// modification, are permitted provided that the following conditions are met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
//
10+
// * Redistributions in binary form must reproduce the above copyright
11+
// notice, this list of conditions and the following disclaimer in the
12+
// documentation and/or other materials provided with the distribution.
13+
//
14+
// * Neither the name of the {copyright_holder} nor the names of its
15+
// contributors may be used to endorse or promote products derived from
16+
// this software without specific prior written permission.
17+
//
18+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
// POSSIBILITY OF SUCH DAMAGE.
29+
// -- END LICENSE BLOCK ------------------------------------------------
30+
31+
#pragma once
32+
33+
#include "ur_client_library/types.h"
34+
#include "ur_client_library/primary/robot_state.h"
35+
#include <iostream>
36+
37+
namespace urcl
38+
{
39+
namespace primary_interface
40+
{
41+
/*!
42+
* \brief The ConfigurationData class handles the configuration data sent via the primary UR interface.
43+
*/
44+
class ConfigurationData : public RobotState
45+
{
46+
public:
47+
struct JointPositionLimits
48+
{
49+
double joint_min_limit;
50+
double joint_max_limit;
51+
};
52+
53+
struct JointMotionLimits
54+
{
55+
double joint_max_speed;
56+
double joint_max_acceleration;
57+
};
58+
59+
ConfigurationData() = delete;
60+
61+
/*!
62+
* \brief Creates a new ConfigurationData object.
63+
*
64+
* \param type The type of RobotState message received
65+
*/
66+
ConfigurationData(const RobotStateType type) : RobotState(type)
67+
{
68+
}
69+
70+
/*!
71+
* \brief Creates a copy of a ConfigurationData object.
72+
*
73+
* \param pkg The ConfigurationData object to be copied
74+
*/
75+
ConfigurationData(const ConfigurationData& pkg);
76+
77+
virtual ~ConfigurationData() = default;
78+
79+
/*!
80+
* \brief Sets the attributes of the package by parsing a serialized representation of the
81+
* package.
82+
*
83+
* \param bp A parser containing a serialized version of the package
84+
*
85+
* \returns True, if the package was parsed successfully, false otherwise
86+
*/
87+
virtual bool parseWith(comm::BinParser& bp);
88+
89+
/*!
90+
* \brief Consume this package with a specific consumer.
91+
*
92+
* \param consumer Placeholder for the consumer calling this
93+
*
94+
* \returns true on success
95+
*/
96+
virtual bool consumeWith(AbstractPrimaryConsumer& consumer);
97+
98+
/*!
99+
* \brief Produces a human readable representation of the package object.
100+
*
101+
* \returns A string representing the object
102+
*/
103+
virtual std::string toString() const;
104+
105+
std::array<JointPositionLimits, 6> joint_position_limits_;
106+
std::array<JointMotionLimits, 6> joint_motion_limits_;
107+
double v_joint_default_;
108+
double a_joint_default_;
109+
double v_tool_default_;
110+
double a_tool_default_;
111+
double eq_radius_;
112+
urcl::vector6d_t dh_a_;
113+
urcl::vector6d_t dh_d_;
114+
urcl::vector6d_t dh_alpha_;
115+
urcl::vector6d_t dh_theta_;
116+
int32_t masterboard_version_;
117+
int32_t controller_box_type_;
118+
int32_t robot_type_;
119+
int32_t robot_sub_type_;
120+
};
121+
122+
} // namespace primary_interface
123+
} // namespace urcl

include/ur_client_library/ur/datatypes.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#pragma once
3030

3131
#include <ur_client_library/types.h>
32+
#include "ur_client_library/log.h"
3233

3334
namespace urcl
3435
{
@@ -86,6 +87,18 @@ enum class AnalogOutputType : int8_t
8687
VOLTAGE = 1
8788
};
8889

90+
enum class RobotType : int8_t
91+
{
92+
UNDEFINED = -128, // This is not defined by UR but only inside this driver
93+
UR5 = 1,
94+
UR10 = 2,
95+
UR3 = 3,
96+
UR16 = 4,
97+
UR20 = 7,
98+
UR30 = 8,
99+
UR15 = 9
100+
};
101+
89102
inline std::string robotModeString(const RobotMode& mode)
90103
{
91104
switch (mode)
@@ -186,4 +199,31 @@ inline std::string safetyStatusString(const SafetyStatus& status)
186199
throw std::invalid_argument(ss.str());
187200
}
188201
}
202+
203+
inline std::string robotTypeString(const RobotType& type)
204+
{
205+
switch (type)
206+
{
207+
case RobotType::UR3:
208+
return "UR3";
209+
case RobotType::UR5:
210+
return "UR5";
211+
case RobotType::UR10:
212+
return "UR10";
213+
case RobotType::UR15:
214+
return "UR15";
215+
case RobotType::UR16:
216+
return "UR16";
217+
case RobotType::UR20:
218+
return "UR20";
219+
case RobotType::UR30:
220+
return "UR30";
221+
default:
222+
std::stringstream ss;
223+
ss << "Unknown Robot Type: " << static_cast<int>(type);
224+
URCL_LOG_WARN(ss.str().c_str());
225+
return "UNDEFINED";
226+
}
227+
}
228+
189229
} // namespace urcl

src/primary/primary_client.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,15 @@ std::shared_ptr<VersionInformation> PrimaryClient::getRobotVersion(bool blocking
279279
return consumer_->getVersionInformation();
280280
}
281281

282+
RobotType PrimaryClient::getRobotType()
283+
{
284+
std::shared_ptr<ConfigurationData> configuration_data = consumer_->getConfigurationData();
285+
if (configuration_data == nullptr)
286+
{
287+
return RobotType::UNDEFINED;
288+
}
289+
return static_cast<RobotType>(configuration_data->robot_type_);
290+
}
291+
282292
} // namespace primary_interface
283293
} // namespace urcl

0 commit comments

Comments
 (0)