Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to choose output precision in echo #377

Merged
merged 2 commits into from Apr 30, 2019
Merged
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
28 changes: 20 additions & 8 deletions tf2_tools/scripts/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import math
import numpy
import rospy
# import sys
import sys
import tf2_py as tf2
import tf2_ros

Expand Down Expand Up @@ -184,18 +184,18 @@ def lookup(self, event):
# will be identical.
msg = "At time {}, (current time {})".format(ts.header.stamp.to_sec(), cur_time.to_sec())
xyz = ts.transform.translation
msg += "\n- Translation: [{:.3f}, {:.3f}, {:.3f}]\n".format(xyz.x, xyz.y, xyz.z)
msg += "\n- Translation: [{:.{p}f}, {:.{p}f}, {:.{p}f}]\n".format(xyz.x, xyz.y, xyz.z, p=self.args.precision)
quat = ts.transform.rotation
msg += "- Rotation: in Quaternion [{:.3f}, {:.3f}, {:.3f}, {:.3f}]\n".format(quat.x, quat.y, quat.z, quat.w)
msg += "- Rotation: in Quaternion [{:.{p}f}, {:.{p}f}, {:.{p}f}, {:.{p}f}]\n".format(quat.x, quat.y, quat.z, quat.w, p=self.args.precision)
# TODO(lucasw) need to get quaternion to euler from somewhere, but not tf1
# or a dependency that isn't in Ubuntu or ros repos
euler = _euler_from_quaternion_msg(quat)
msg += " in RPY (radian) "
msg += "[{:.3f}, {:.3f}, {:.3f}]\n".format(euler[0], euler[1], euler[2])
msg += "[{:.{p}f}, {:.{p}f}, {:.{p}f}]\n".format(euler[0], euler[1], euler[2], p=self.args.precision)
msg += " in RPY (degree) "
msg += "[{:.3f}, {:.3f}, {:.3f}]".format(math.degrees(euler[0]),
msg += "[{:.{p}f}, {:.{p}f}, {:.{p}f}]".format(math.degrees(euler[0]),
math.degrees(euler[1]),
math.degrees(euler[2]))
math.degrees(euler[2]), p=self.args.precision)
print(msg)

def positive_float(x):
Expand All @@ -212,6 +212,15 @@ def positive_int(x):

if __name__ == '__main__':
rospy.init_node("echo")

other_args = rospy.myargv(argv=sys.argv)
precision=3
try:
precision = rospy.get_param('~precision')
rospy.loginfo("Precision default value was overriden, new value: %d", precision)
except KeyError:
pass

parser = argparse.ArgumentParser()
parser.add_argument("source_frame") # parent
parser.add_argument("target_frame") # child
Expand All @@ -231,7 +240,10 @@ def positive_int(x):
parser.add_argument("-l", "--limit",
help="lookup fixed number of times",
type=positive_int)
args = parser.parse_args()

parser.add_argument("-p", "--precision",
help="output precision",
default=precision,
type=positive_int)
args = parser.parse_args(other_args[1:]) # Remove first arg
echo = Echo(args)
rospy.spin()