Commit 10fbbc58 authored by Claudio Gomes's avatar Claudio Gomes
Browse files

specify overwrite

parent 20118d07
......@@ -49,7 +49,7 @@ class RobotLiveTests(unittest.TestCase):
def test_debug_first_startrecord_only(self):
"""
THis test shows the importantance of reverting the global state of the RobotConnection.
THis test shows the importance of reverting the global state of the RobotConnection.
"""
# logging.basicConfig(level=logging.DEBUG, filename="test_debug_first_startrecord_only.log") # enables logging
......
import logging
import os
import socket
import sys
import threading
import time
from queue import Queue
......@@ -92,15 +94,23 @@ class RobotConnection:
self._send_ascii_bytes("stop\n", self.dashboard_socket)
return self.dashboard_socket.recv(1024).decode() == "Stopped"
def record_samples(self, config_file='resources/record_configuration.xml', filename='robotdata.csv', frequency=500, samples=10, rtde_port=30004, RtdeConstructor=rtde.RTDE):
def record_samples(self, config_file='resources/record_configuration.xml', filename='robotdata.csv', overwrite=False,
frequency=500, samples=10, rtde_port=30004, RtdeConstructor=rtde.RTDE):
assert samples>0, "Expected positive number of samples. Use start_recording for samples=0."
self.start_recording(config_file, filename, frequency, samples, rtde_port, RtdeConstructor)
self.start_recording(config_file, filename, overwrite, frequency, samples, rtde_port, RtdeConstructor)
self.stop_recording()
def start_recording(self, config_file='resources/record_configuration.xml', filename='robotdata.csv', frequency=500, samples=0, rtde_port=30004, RtdeConstructor=rtde.RTDE):
def start_recording(self, config_file='resources/record_configuration.xml', filename='robotdata.csv', overwrite=False,
frequency=500, samples=0, rtde_port=30004, RtdeConstructor=rtde.RTDE):
# TODO Check that the filename does not exist and give error in case it does.
assert self.recording_thread is None, "Already logging."
# check for overwrite
if os.path.isfile(filename) and not overwrite:
_log.error(
f"Output file {filename} already exists. If you wish to overwrite, use that parameter. Exiting...")
sys.exit(1)
connection = RtdeConstructor(self.ip_adr, rtde_port)
self.recording_thread = threading.Thread(target=_recording_thread,
......
......@@ -12,14 +12,14 @@ class RobotConnectionTests(unittest.TestCase):
ur5e = RobotConnection("192.168.56.101",
controller_socket=DummySocket(),
dashboard_socket=DummyDashboardSocket())
ur5e.record_samples(config_file="resources/record_configuration.xml", frequency=100, samples=10,
ur5e.record_samples(config_file="resources/record_configuration.xml", overwrite=True, frequency=100, samples=10,
RtdeConstructor=DummyRTDE)
def test_dummy_start_stop_record(self):
ur5e = RobotConnection("192.168.56.101",
controller_socket=DummySocket(),
dashboard_socket=DummyDashboardSocket())
ur5e.start_recording(config_file="resources/record_configuration.xml", frequency=100, samples=0,
ur5e.start_recording(config_file="resources/record_configuration.xml", overwrite=True, frequency=100, samples=0,
RtdeConstructor=DummyRTDE)
time.sleep(3.0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment