Skip to content

Commit 6cc351e

Browse files
committed
Add parsing support for RobotModeData
1 parent ee46144 commit 6cc351e

File tree

4 files changed

+229
-5
lines changed

4 files changed

+229
-5
lines changed

CMakeLists.txt

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

include/ur_client_library/primary/primary_parser.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "ur_client_library/primary/robot_state/kinematics_info.h"
3030
#include "ur_client_library/primary/robot_message/version_message.h"
3131
#include "ur_client_library/primary/robot_message/error_code_message.h"
32+
#include "ur_client_library/primary/robot_state/robot_mode_data.h"
3233

3334
namespace urcl
3435
{
@@ -150,12 +151,12 @@ class PrimaryParser : public comm::Parser<PrimaryPackage>
150151
{
151152
switch (type)
152153
{
153-
/*case robot_state_type::ROBOT_MODE_DATA:
154-
// SharedRobotModeData* rmd = new SharedRobotModeData();
154+
case RobotStateType::ROBOT_MODE_DATA:
155+
return new RobotModeData(type);
155156

156-
//return new rmd;
157-
case robot_state_type::MASTERBOARD_DATA:
158-
return new MBD;*/
157+
// return new rmd;
158+
// case robot_state_type::MASTERBOARD_DATA:
159+
// return new MBD;*/
159160
case RobotStateType::KINEMATICS_INFO:
160161
return new KinematicsInfo(type);
161162
default:
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
#ifndef UR_CLIENT_LIBRARY_ROBOT_MODE_DATA_H_INCLUDED
32+
#define UR_CLIENT_LIBRARY_ROBOT_MODE_DATA_H_INCLUDED
33+
34+
#include <stdexcept>
35+
#include "ur_client_library/types.h"
36+
#include "ur_client_library/primary/robot_state.h"
37+
namespace urcl
38+
{
39+
namespace primary_interface
40+
{
41+
42+
/*!
43+
* \brief This messages contains data about the mode of the robot.
44+
*/
45+
class RobotModeData : public RobotState
46+
{
47+
public:
48+
RobotModeData() = delete;
49+
/*!
50+
* \brief Creates a new RobotModeData object.
51+
*
52+
* \param type The type of RobotState message received
53+
*/
54+
RobotModeData(const RobotStateType type) : RobotState(type)
55+
{
56+
}
57+
58+
/*!
59+
* \brief Creates a copy of a RobotModeData object.
60+
*
61+
* \param pkg The RobotModeData object to be copied
62+
*/
63+
RobotModeData(const RobotModeData& pkg);
64+
65+
virtual ~RobotModeData() = default;
66+
67+
/*!
68+
* \brief Sets the attributes of the package by parsing a serialized representation of the
69+
* package.
70+
*
71+
* \param bp A parser containing a serialized version of the package
72+
*
73+
* \returns True, if the package was parsed successfully, false otherwise
74+
*/
75+
virtual bool parseWith(comm::BinParser& bp);
76+
77+
/*!
78+
* \brief Consume this specific package with a specific consumer.
79+
*
80+
* \param consumer Placeholder for the consumer calling this
81+
*
82+
* \returns true on success
83+
*/
84+
virtual bool consumeWith(AbstractPrimaryConsumer& consumer);
85+
86+
/*!
87+
* \brief Produces a human readable representation of the package object.
88+
*
89+
* \returns A string representing the object
90+
*/
91+
virtual std::string toString() const;
92+
93+
uint64_t timestamp_;
94+
bool is_real_robot_connected_;
95+
bool is_real_robot_enabled_;
96+
bool is_robot_power_on_;
97+
bool is_emergency_stopped_;
98+
bool is_protective_stopped_;
99+
bool is_program_running_;
100+
bool is_program_paused_;
101+
int8_t robot_mode_;
102+
uint8_t control_mode_;
103+
double target_speed_fraction_;
104+
double speed_scaling_;
105+
double target_speed_fraction_limit_;
106+
std::string reserved_;
107+
};
108+
109+
} // namespace primary_interface
110+
} // namespace urcl
111+
112+
#endif // ifndef UR_CLIENT_LIBRARY_ROBOT_MODE_DATA_H_INCLUDED
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
#include "ur_client_library/primary/robot_state/robot_mode_data.h"
32+
#include "ur_client_library/primary/abstract_primary_consumer.h"
33+
34+
#include <iomanip>
35+
36+
namespace urcl
37+
{
38+
namespace primary_interface
39+
{
40+
RobotModeData::RobotModeData(const RobotModeData& pkg) : RobotState(RobotStateType::ROBOT_MODE_DATA)
41+
{
42+
timestamp_ = pkg.timestamp_;
43+
is_real_robot_connected_ = pkg.is_real_robot_connected_;
44+
is_real_robot_enabled_ = pkg.is_real_robot_enabled_;
45+
is_robot_power_on_ = pkg.is_robot_power_on_;
46+
is_emergency_stopped_ = pkg.is_emergency_stopped_;
47+
is_protective_stopped_ = pkg.is_protective_stopped_;
48+
is_program_running_ = pkg.is_program_running_;
49+
is_program_paused_ = pkg.is_program_paused_;
50+
robot_mode_ = pkg.robot_mode_;
51+
control_mode_ = pkg.control_mode_;
52+
target_speed_fraction_ = pkg.target_speed_fraction_;
53+
speed_scaling_ = pkg.speed_scaling_;
54+
target_speed_fraction_limit_ = pkg.target_speed_fraction_limit_;
55+
reserved_ = pkg.reserved_;
56+
}
57+
58+
bool RobotModeData::parseWith(comm::BinParser& bp)
59+
{
60+
bp.parse(timestamp_);
61+
bp.parse(is_real_robot_connected_);
62+
bp.parse(is_real_robot_enabled_);
63+
bp.parse(is_robot_power_on_);
64+
bp.parse(is_emergency_stopped_);
65+
bp.parse(is_protective_stopped_);
66+
bp.parse(is_program_running_);
67+
bp.parse(is_program_paused_);
68+
bp.parse(robot_mode_);
69+
bp.parse(control_mode_);
70+
bp.parse(target_speed_fraction_);
71+
bp.parse(speed_scaling_);
72+
bp.parse(target_speed_fraction_limit_);
73+
bp.parseRemainder(reserved_);
74+
75+
return true;
76+
}
77+
78+
bool RobotModeData::consumeWith(AbstractPrimaryConsumer& consumer)
79+
{
80+
return consumer.consume(*this);
81+
}
82+
83+
std::string RobotModeData::toString() const
84+
{
85+
std::stringstream os;
86+
os << "Timestamp: " << timestamp_ << std::endl;
87+
os << "Is real robot connected: " << is_real_robot_connected_ << std::endl;
88+
os << "Is real robot enabled: " << is_real_robot_enabled_ << std::endl;
89+
os << "Is robot power on: " << is_robot_power_on_ << std::endl;
90+
os << "Is emergency stopped: " << is_emergency_stopped_ << std::endl;
91+
os << "Is protective stopped: " << is_protective_stopped_ << std::endl;
92+
os << "Is program running: " << is_program_running_ << std::endl;
93+
os << "Is program paused: " << is_program_paused_ << std::endl;
94+
os << "Robot mode: " << unsigned(robot_mode_) << std::endl;
95+
os << "Control mode: " << unsigned(control_mode_) << std::endl;
96+
os << "Target speed fraction: " << target_speed_fraction_ << std::endl;
97+
os << "Speed scaling: " << speed_scaling_ << std::endl;
98+
os << "Target speed fraction limit: " << target_speed_fraction_limit_ << std::endl;
99+
os << "Reserved: ( " << reserved_.length() << ")";
100+
for (const char& c : reserved_)
101+
{
102+
os << std::hex << static_cast<int>(c) << ", ";
103+
}
104+
os << std::endl;
105+
106+
return os.str();
107+
}
108+
109+
} // namespace primary_interface
110+
} // namespace urcl

0 commit comments

Comments
 (0)