Skip to content
Snippets Groups Projects
Commit d80dc606 authored by VulcanixFR's avatar VulcanixFR
Browse files

Add Comments to Trace

parent d5d26822
No related merge requests found
...@@ -10,10 +10,18 @@ from pathlib import Path ...@@ -10,10 +10,18 @@ from pathlib import Path
import pandas as pd import pandas as pd
class DatFile: class DatFile:
"""This class represents the contents of a .dat file"""
# The sampling rate of the .r64 file
sampling: float = 0 sampling: float = 0
# The scale coefficient for each variable
col241: List[float] = [] col241: List[float] = []
traces: List[float] = []
# The names of the variables
traces: List[str] = []
# The number of samples in the file
length: float = 0 length: float = 0
def __init__(self) -> None: def __init__(self) -> None:
...@@ -178,12 +186,15 @@ class KUKA_Trace: ...@@ -178,12 +186,15 @@ class KUKA_Trace:
return None return None
def translate (self, value: str) -> str: def translate (self, value: str) -> str:
"""Translates a varaible name from German to English"""
if value in self.translations: if value in self.translations:
return self.translations[value] return self.translations[value]
return value return value
def copy_to_local (self, pairs: List[List[Path]], name: str): def copy_to_local (self, pairs: List[List[Path]], name: str):
"""Copies a file pair form the robot to the ./temp folder"""
src_folder = None src_folder = None
if type (self.trace_root) == str : if type (self.trace_root) == str :
...@@ -232,7 +243,8 @@ class KUKA_Trace: ...@@ -232,7 +243,8 @@ class KUKA_Trace:
return files return files
def read_dat (self, dat: Path, suffix: str = "") -> DatFile: def read_dat (self, dat: Path, suffix: str = "") -> DatFile:
"""Reads the contents of a .dat file"""
out = DatFile() out = DatFile()
with open(dat, "r") as dat_file: with open(dat, "r") as dat_file:
...@@ -282,6 +294,7 @@ class KUKA_Trace: ...@@ -282,6 +294,7 @@ class KUKA_Trace:
return out return out
def convert_r64 (self, r64: Path, dat: DatFile) -> Dict[str, List[float]]: def convert_r64 (self, r64: Path, dat: DatFile) -> Dict[str, List[float]]:
"""Converts a .r64 file to a dictionnary based on the .dat file contents"""
out: Dict[str, List[float]] = {} out: Dict[str, List[float]] = {}
...@@ -303,6 +316,9 @@ class KUKA_Trace: ...@@ -303,6 +316,9 @@ class KUKA_Trace:
return out return out
def linear_interpolation (self, data: List[float], ratio: int = 1): def linear_interpolation (self, data: List[float], ratio: int = 1):
"""Basic linear interpolation to "upsample" traces with lower
sampling rate than the main ones"""
if ratio == 1: if ratio == 1:
return data return data
...@@ -330,6 +346,8 @@ class KUKA_Trace: ...@@ -330,6 +346,8 @@ class KUKA_Trace:
return neo return neo
def read_traces (self, name: str): def read_traces (self, name: str):
"""Copies and reads the trace files and returns the contents
as a DataFrame"""
pairs = self.find_pairs(name) pairs = self.find_pairs(name)
self.copy_to_local(pairs, name) self.copy_to_local(pairs, name)
...@@ -376,6 +394,7 @@ class KUKA_Trace: ...@@ -376,6 +394,7 @@ class KUKA_Trace:
if ratio > 1: if ratio > 1:
# This variable has descrete values
if "AnalogOut" in col: if "AnalogOut" in col:
# Step interpolation # Step interpolation
temp = np.zeros(len(values[col]) * ratio) temp = np.zeros(len(values[col]) * ratio)
......
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