From 89d56e256fb03e5e34b4bd7f4bdd81a6d9605f59 Mon Sep 17 00:00:00 2001 From: Philipp Kramer Date: Tue, 23 Aug 2022 14:56:15 +0200 Subject: [PATCH] add receive tests --- tests/rtde_receive_actualq.py | 80 +++++++++++++++++++++++++++++++++++ tests/rtde_record_example.py | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 tests/rtde_receive_actualq.py create mode 100644 tests/rtde_record_example.py diff --git a/tests/rtde_receive_actualq.py b/tests/rtde_receive_actualq.py new file mode 100644 index 0000000..bcf7265 --- /dev/null +++ b/tests/rtde_receive_actualq.py @@ -0,0 +1,80 @@ +from rtde_receive import RTDEReceiveInterface as RTDEReceive +import time +import argparse +import sys + + +def parse_args(args): + """Parse command line parameters + + Args: + args ([str]): command line parameters as list of strings + + Returns: + :obj:`argparse.Namespace`: command line parameters namespace + """ + parser = argparse.ArgumentParser( + description="Record data example") + parser.add_argument( + "-ip", + "--robot_ip", + dest="ip", + help="IP address of the UR robot", + type=str, + default='localhost', + metavar="") + parser.add_argument( + "-o", + "--output", + dest="output", + help="data output (.csv) file to write to (default is \"robot_data.csv\"", + type=str, + default="robot_data.csv", + metavar="") + parser.add_argument( + "-f", + "--frequency", + dest="frequency", + help="the frequency at which the data is recorded (default is 500Hz)", + type=float, + default=500.0, + metavar="") + + return parser.parse_args(args) + + +def main(args): + """Main entry point allowing external calls + + Args: + args ([str]): command line parameter list + """ + args = parse_args(args) + dt = 1 / args.frequency + rtde_r = RTDEReceive(args.ip, args.frequency) + + + i = 0 + try: + while True: + start = time.time() + + q=rtde_r.getActualQ() + print(q) + #sys.stdout.write("\r") + #sys.stdout.write("{:3d} samples.".format(i)) + #sys.stdout.flush() + end = time.time() + duration = end - start + + if duration < dt: + time.sleep(dt - duration) + i += 1 + + except KeyboardInterrupt: + + print("\nData recording stopped.") + + +if __name__ == "__main__": + main(sys.argv[1:]) \ No newline at end of file diff --git a/tests/rtde_record_example.py b/tests/rtde_record_example.py new file mode 100644 index 0000000..5a8797d --- /dev/null +++ b/tests/rtde_record_example.py @@ -0,0 +1,78 @@ +from rtde_receive import RTDEReceiveInterface as RTDEReceive +import time +import argparse +import sys + + +def parse_args(args): + """Parse command line parameters + + Args: + args ([str]): command line parameters as list of strings + + Returns: + :obj:`argparse.Namespace`: command line parameters namespace + """ + parser = argparse.ArgumentParser( + description="Record data example") + parser.add_argument( + "-ip", + "--robot_ip", + dest="ip", + help="IP address of the UR robot", + type=str, + default='localhost', + metavar="") + parser.add_argument( + "-o", + "--output", + dest="output", + help="data output (.csv) file to write to (default is \"robot_data.csv\"", + type=str, + default="robot_data.csv", + metavar="") + parser.add_argument( + "-f", + "--frequency", + dest="frequency", + help="the frequency at which the data is recorded (default is 500Hz)", + type=float, + default=500.0, + metavar="") + + return parser.parse_args(args) + + +def main(args): + """Main entry point allowing external calls + + Args: + args ([str]): command line parameter list + """ + args = parse_args(args) + dt = 1 / args.frequency + rtde_r = RTDEReceive(args.ip, args.frequency) + rtde_r.startFileRecording(args.output) + print("Data recording started, press [Ctrl-C] to end recording.") + i = 0 + try: + while True: + start = time.time() + if i % 10 == 0: + sys.stdout.write("\r") + sys.stdout.write("{:3d} samples.".format(i)) + sys.stdout.flush() + end = time.time() + duration = end - start + + if duration < dt: + time.sleep(dt - duration) + i += 1 + + except KeyboardInterrupt: + rtde_r.stopFileRecording() + print("\nData recording stopped.") + + +if __name__ == "__main__": + main(sys.argv[1:]) \ No newline at end of file