Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/ur_client_library/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,7 @@ RobotSeries robotSeriesFromTypeAndVersion(const RobotType type, const VersionInf
*/
RobotType robotTypeFromString(const std::string& robot_type_str);

std::string stringFromMotionTarget(const MotionTarget& target);

} // namespace urcl
#endif // ifndef UR_CLIENT_LIBRARY_HELPERS_H_INCLUDED
4 changes: 4 additions & 0 deletions include/ur_client_library/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Q
void setValues(const vector6d_t& values);
void setValues(const std::vector<double>& values);

std::string toString() const;

private:
std::vector<double> values_;
};
Expand Down Expand Up @@ -89,6 +91,8 @@ class Pose

void setPose(const double x, const double y, const double z, const double rx, const double ry, const double rz);

std::string toString() const;

double x;
double y;
double z;
Expand Down
5 changes: 5 additions & 0 deletions src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,9 @@ RobotType robotTypeFromString(const std::string& robot_type_str)
return it->second;
}

std::string stringFromMotionTarget(const MotionTarget& target)
{
return std::visit([](const auto& target) { return target.toString(); }, target);
}

} // namespace urcl
25 changes: 25 additions & 0 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <ur_client_library/types.h>

#include <algorithm>
#include <sstream>

namespace urcl
{
Expand Down Expand Up @@ -71,6 +72,22 @@ bool operator==(const Q& lhs, const Q& rhs)
std::equal(lhs.getValues().begin(), lhs.getValues().end(), rhs.getValues().begin());
}

std::string Q::toString() const
{
std::stringstream ss;
ss << "Q([";
for (size_t i = 0; i < values_.size(); ++i)
{
ss << values_[i];
if (i < values_.size() - 1)
{
ss << ", ";
}
}
ss << "])";
return ss.str();
}

Pose::Pose() : x(0.0), y(0.0), z(0.0), rx(0.0), ry(0.0), rz(0.0), q_near_(std::nullopt)
{
}
Expand Down Expand Up @@ -129,4 +146,12 @@ void Pose::setPose(const double x, const double y, const double z, const double
this->rz = rz;
}

std::string Pose::toString() const
{
std::stringstream ss;
ss << "Pose(x = " << x << ", y = " << y << ", z = " << z << ", rx = " << rx << ", ry = " << ry << ", rz = " << rz
<< ")";
return ss.str();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pose string omits q_near

Low Severity

Pose::toString only formats the Cartesian fields and drops q_near_ when it is set. Equality, constructors, and the trajectory path all treat that hint as part of the pose, so stringFromMotionTarget can hide important IK context in logs and make two unequal poses look identical.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 17f0822. Configure here.


} // namespace urcl
9 changes: 9 additions & 0 deletions tests/test_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,12 @@ TEST(TestHelpers, robotSeriesString)
EXPECT_EQ(robotSeriesString(RobotSeries::UR_SERIES), "UR_SERIES");
EXPECT_EQ(robotSeriesString(RobotSeries::UNDEFINED), "UNDEFINED");
}

TEST(TestHelpers, stringFromMotionTarget)
{
const MotionTarget joint_target = Q{ 0.0, 0.1, 0.2, 0.3, 0.4, 0.5 };
EXPECT_EQ(stringFromMotionTarget(joint_target), "Q([0, 0.1, 0.2, 0.3, 0.4, 0.5])");

const MotionTarget pose_target = Pose{ 1.0, 2.0, 3.0, 0.1, 0.2, 0.3 };
EXPECT_EQ(stringFromMotionTarget(pose_target), "Pose(x = 1, y = 2, z = 3, rx = 0.1, ry = 0.2, rz = 0.3)");
}
Loading