Skip to content

Commit c6a671e

Browse files
authored
Add robotSeriesString function (UniversalRobots#510)
Converts the `RobotSeries` enum value to a `std::string`
1 parent 139fbfc commit c6a671e

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

include/ur_client_library/ur/datatypes.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,31 @@ inline std::string robotTypeString(const RobotType& type)
267267
}
268268
}
269269

270+
/**
271+
* @brief Converts a RobotSeries enum value to its corresponding string representation.
272+
*
273+
* This function takes a RobotSeries enum value and returns a string that represents the robot series.
274+
* If the provided RobotSeries value does not match any known series, it logs a warning and returns "UNDEFINED".
275+
*
276+
* @param series The RobotSeries enum value to convert.
277+
* @return A string representation of the robot series.
278+
*/
279+
inline std::string robotSeriesString(const RobotSeries& series)
280+
{
281+
switch (series)
282+
{
283+
case RobotSeries::CB3:
284+
return "CB3";
285+
case RobotSeries::E_SERIES:
286+
return "E_SERIES";
287+
case RobotSeries::UR_SERIES:
288+
return "UR_SERIES";
289+
default:
290+
std::stringstream ss;
291+
ss << "Unknown Robot Series: " << static_cast<int>(series);
292+
URCL_LOG_WARN(ss.str().c_str());
293+
return "UNDEFINED";
294+
}
295+
}
296+
270297
} // namespace urcl

tests/test_helpers.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,11 @@ TEST(TestHelpers, robotSeriesFromTypeAndVersion)
137137
EXPECT_EQ(robotSeriesFromTypeAndVersion(RobotType::UNDEFINED, cb3_version), RobotSeries::UNDEFINED);
138138
EXPECT_EQ(robotSeriesFromTypeAndVersion(RobotType::UNDEFINED, polyscope_x_version), RobotSeries::UNDEFINED);
139139
}
140+
141+
TEST(TestHelpers, robotSeriesString)
142+
{
143+
EXPECT_EQ(robotSeriesString(RobotSeries::CB3), "CB3");
144+
EXPECT_EQ(robotSeriesString(RobotSeries::E_SERIES), "E_SERIES");
145+
EXPECT_EQ(robotSeriesString(RobotSeries::UR_SERIES), "UR_SERIES");
146+
EXPECT_EQ(robotSeriesString(RobotSeries::UNDEFINED), "UNDEFINED");
147+
}

0 commit comments

Comments
 (0)