Getting Rotation2d from Pose2d in NetworkTables

Language: Javascript

NetworkTables.addKeyListener('/common/Odometry/odometryPose', (_, value, __) => {
    console.log(value);
});

This prints

Pose2d(Translation2d(X: 2.03, Y: 0.05), Rotation2d(Rads: 0.05, Deg: 2.64))

How would I go about getting the degrees from inside the Rotation2d?

You need to use .getDegrees() on the Rotation2d (at least in Java/C++ WPILib).

Is the actual value in NT a string? If so, you’ll need to parse it. But you’d be better off changing the sending code to put the value into an array of double.

I am using Javascript for this, sorry for not including that originally (I have updated)

Im not a javascript expert, but from what im reading it looks like that is just a string. You can do some string manipulation to get the rotation?

value = "Pose2d(Translation2d(X: 2.03, Y: 0.05), Rotation2d(Rads: 0.05, Deg: 2.64))"
start = value.search("Deg:") + 5
value = value.substring(start)
end = value.search(")")
degrees = parcefloat(value.substring(0, end))

Thanks, I never thought of that. Perfect solution :smiley:

I haven’t tested that since I solved it with Peter_Johnson’s answer, but that also looks like a good solution!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.