Skip to content

Commit

Permalink
fixed plot_graph.sh shaper graphs when the filename was not containin…
Browse files Browse the repository at this point in the history
…g only the date
  • Loading branch information
Frix-x committed May 1, 2023
1 parent 512a56d commit f1cf77a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/software/z_calibration.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ switch_xy_position: -1,-1
# Switch offset (default D2F-5: 0.5mm and SSG-5H: 0.7mm)
# Smaller number means higher nozzle to the PEI
switch_offset: 0.50
offset_margins: 0.750
offset_margins: -0.750, 1.0
samples: 3
#samples_tolerance: 0.01
speed: 350 # X,Y movements
Expand Down
39 changes: 30 additions & 9 deletions scripts/plot_graphs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
###### GRAPH PLOTTING SCRIPT ######
###################################
# Written by Frix_x#0161 #
# @version: 1.5
# @version: 1.6

# CHANGELOG:
# v1.6: updated the handling of shaper graph files to be able to optionnaly account for added positions in the filenames and remove them
# v1.5: fixed klipper unnexpected fail at the end of the execution, even if graphs were correctly generated (unicode decode error fixed)
# v1.4: added the ~/klipper dir parameter to the call of graph_vibrations.py for a better user handling (in case user is not "pi")
# v1.3: some documentation improvement regarding the line endings that needs to be LF for this file
Expand Down Expand Up @@ -48,14 +49,26 @@ export LC_ALL=C
function plot_shaper_graph {
local generator filename newfilename date axis
generator="${KLIPPER_FOLDER}/scripts/calibrate_shaper.py"


# For each file
while read filename; do
# We remove the /tmp in front of the filename
newfilename="$(echo ${filename} | sed -e "s/\\/tmp\///")"

# We check if there is the position added by Klipper and remove it
if [[ ${newfilename} =~ ^resonances_[[:alpha:]]_([0-9]*\.)+[0-9]*_ ]]; then
newfilename="$(echo ${newfilename} | sed -E 's/(^resonances_[[:alpha:]])_(([0-9]*\.)+[0-9]*_)+/\1_/')"
fi

# We extract the date and axis name from the filename
date="$(basename "${newfilename}" | cut -d '.' -f1 | awk -F'_' '{print $3"_"$4}')"
axis="$(basename "${newfilename}" | cut -d '_' -f2)"

# Then we move the file to the result folder
mv "${filename}" "${isf}"/inputshaper/"${newfilename}"

sync && sleep 2

# Finally we compute the shaper graphs
"${generator}" "${isf}"/inputshaper/"${newfilename}" -o "${isf}"/inputshaper/resonances_"${axis}"_"${date}".png
done <<< "$(find /tmp -type f -name "resonances_*.csv" 2>&1 | grep -v "Permission")"
}
Expand All @@ -64,29 +77,34 @@ function plot_belts_graph {
local date_ext generator filename belt
date_ext="$(date +%Y%m%d_%H%M%S)"
generator="${KLIPPER_FOLDER}/scripts/graph_accelerometer.py"


# For each file
while read filename; do
# We extract the belt tested from the filename
belt="$(basename "${filename}" | cut -d '_' -f4 | cut -d '.' -f1 | sed -e 's/\(.*\)/\U\1/')"

# And we move it to the result folder while injecting the date and belt inside the filename
mv "${filename}" "${isf}"/belts/belt_"${date_ext}"_"${belt}".csv
done <<< "$(find /tmp -type f -name "raw_data_axis*.csv" 2>&1 | grep -v "Permission")"

sync && sleep 2

# Finally we compute the belts graph
"${generator}" -c "${isf}"/belts/belt_"${date_ext}"_*.csv -o "${isf}"/belts/belts_"${date_ext}".png
}

function plot_vibr_graph {
local date_ext generator filename newfilename
date_ext="$(date +%Y%m%d_%H%M%S)"
generator="${SCRIPTS_FOLDER}/graph_vibrations.py"

while read filename; do
newfilename="$(echo ${filename} | sed -e "s/\\/tmp\/adxl345/vibr_${date_ext}/")"
mv "${filename}" "${isf}"/vibrations/"${newfilename}"
done <<< "$(find /tmp -type f -name "adxl345-*.csv" 2>&1 | grep -v "Permission")"

sync && sleep 2
"${generator}" "${isf}"/vibrations/vibr_"${date_ext}"*.csv -o "${isf}"/vibrations/vibrations_"${date_ext}".png -a "$1" -k "${KLIPPER_FOLDER}"

tar cfz "${isf}"/vibrations/vibrations_"${date_ext}".tar.gz "${isf}"/vibrations/vibr_"${date_ext}"*.csv
rm "${isf}"/vibrations/vibr_"${date_ext}"*.csv
}
Expand All @@ -103,7 +121,7 @@ function clean_files {
old+=("${isf}"/inputshaper/"${csv}".csv)
fi
done <<< "$(find "${isf}"/inputshaper/ -type f -name '*.png' -printf '%T@ %p\n' | sort -k 1 -n -r | sed 's/^[^ ]* //' | tail -n +"${keep2}")"

while read filename; do
if [ ! -z "${filename}" ]; then
old+=("${filename}")
Expand Down Expand Up @@ -144,6 +162,9 @@ fi

isf="${RESULTS_FOLDER//\~/${HOME}}"

# Dirty fix to be sure Klipper has closed the file before doing anything
sync && sleep 5

case ${1} in
SHAPER|shaper)
plot_shaper_graph
Expand Down

0 comments on commit f1cf77a

Please sign in to comment.