Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
testing steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Wurstnase committed Jan 2, 2017
1 parent b66e194 commit 51090b1
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile-SIM
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SIM_SOURCES = $(subst $(SIM_PATH)/,,$(wildcard $(SIM_PATH)/*.c))
SOURCES := $(filter-out $(subst _sim.c,.c,$(SIM_SOURCES)),$(SOURCES)) $(SIM_SOURCES)

CFLAGS = $(EXTRA_CFLAGS)
CFLAGS += -g -Wall -Wstrict-prototypes -Wno-format -Os $(DEFS) -std=gnu99
CFLAGS += -g -Wall -Wstrict-prototypes -Wno-format -O0 $(DEFS) -std=gnu99
CFLAGS += -funsigned-char -funsigned-bitfields -fshort-enums -I.. -I.
CFLAGS += -DSIMULATOR -Wno-format -Wno-format-security
#CFLAGS += -dM -E # To list all predefined macros into the .o file.
Expand Down
31 changes: 20 additions & 11 deletions dda.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ static const axes_uint32_t PROGMEM steps_per_m_P = {
STEPS_PER_M_E
};

axes_int32_t BSS debug_axis;
TARGET BSS debug_position;

/// \var maximum_feedrate_P
/// \brief maximum allowed feedrate on each axis
static const axes_uint32_t PROGMEM maximum_feedrate_P = {
Expand Down Expand Up @@ -309,7 +312,7 @@ void dda_create(DDA *dda, const TARGET *target) {
else
distance = approx_distance_3(delta_um[X], delta_um[Y], delta_um[Z]);

if (distance < 2)
if (distance < 1)

This comment has been minimized.

Copy link
@phord

phord Jan 3, 2017

Collaborator

This is the same as if (distance == 0) since distance is unsigned int. I assume this is the change that fixed a DIV0 error you saw. But the original code is mysterious to me. It has never been clear why we would switch to E-axis only when our head moves less than 2um. I assume this is only needed to allow us to extrude without movement, but it seems suspicious to me that we treat E special. Isn't it reasonable for E to be treated like any other moving axis?

I'm not blaming you for this code, but I am wondering if you have any insight about this.

This comment has been minimized.

Copy link
@Wurstnase

Wurstnase Jan 5, 2017

Author Collaborator

Yes, if (distance == 0) or if (!distance).

Just took a look into Marlin. They throw away any move with less then 5 steps and only move then E. But there must be an E or we have a nullmove.

The idea behind this is, that we want a smooth axis movement. E-independent.

distance = delta_um[E];

if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
Expand Down Expand Up @@ -574,40 +577,44 @@ void dda_start(DDA *dda) {
*/
void dda_step(DDA *dda) {

#if ! defined ACCELERATION_TEMPORAL
#if ! defined ACCELERATION_TEMPORAL
if (move_state.steps[X]) {
move_state.counter[X] -= dda->delta[X];
if (move_state.counter[X] < 0) {
x_step();
x_step();
move_state.steps[X]--;
move_state.counter[X] += dda->total_steps;
}
debug_axis[X] += get_direction(dda, X);
}
}
if (move_state.steps[Y]) {
move_state.counter[Y] -= dda->delta[Y];
if (move_state.counter[Y] < 0) {
y_step();
y_step();
move_state.steps[Y]--;
move_state.counter[Y] += dda->total_steps;
}
debug_axis[Y] += get_direction(dda, Y);
}
}
if (move_state.steps[Z]) {
move_state.counter[Z] -= dda->delta[Z];
if (move_state.counter[Z] < 0) {
z_step();
z_step();
move_state.steps[Z]--;
move_state.counter[Z] += dda->total_steps;
}
debug_axis[Z] += get_direction(dda, Z);
}
}
if (move_state.steps[E]) {
move_state.counter[E] -= dda->delta[E];
if (move_state.counter[E] < 0) {
e_step();
e_step();
move_state.steps[E]--;
move_state.counter[E] += dda->total_steps;
}
debug_axis[E] += get_direction(dda, E);
}
}
#endif
#endif

#ifdef ACCELERATION_REPRAP
// linear acceleration magic, courtesy of http://www.embedded.com/design/mcus-processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time
Expand Down Expand Up @@ -970,6 +977,7 @@ void update_current_position() {
if (queue_empty()) {
for (i = X; i < AXIS_COUNT; i++) {
current_position.axis[i] = startpoint.axis[i];
debug_position.axis[i] = muldiv(debug_axis[i], 1000000, pgm_read_dword(&steps_per_m_P[i]));
}
}
else if (dda->live) {
Expand All @@ -981,6 +989,7 @@ void update_current_position() {
// Unfortunately, using muldiv() overwhelms the compiler.
// Also keep the parens around this term, else results go wrong.
((move_state.steps[i] * 1000) / pgm_read_dword(&steps_per_mm_P[i]));
debug_position.axis[i] = muldiv(debug_axis[i], 1000000, pgm_read_dword(&steps_per_m_P[i]));
}

if (dda->endpoint.e_relative)
Expand Down
3 changes: 3 additions & 0 deletions dda.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ extern TARGET startpoint_steps;
/// current_position holds the machine's current position. this is only updated when we step, or when G92 (set home) is received.
extern TARGET current_position;

extern axes_int32_t debug_axis;
extern TARGET debug_position;

/*
methods
*/
Expand Down
4 changes: 4 additions & 0 deletions gcode_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ void process_gcode_command() {
current_position.axis[X], current_position.axis[Y],
current_position.axis[Z], current_position.axis[E],
current_position.F);
sersendf_P(PSTR("X:%lq,Y:%lq,Z:%lq,E:%lq,F:%lu\n"),
debug_position.axis[X], debug_position.axis[Y],
debug_position.axis[Z], debug_position.axis[E],
current_position.F);

if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION)) {
sersendf_P(PSTR("Endpoint: X:%ld,Y:%ld,Z:%ld,E:%ld,F:%lu,c:%lu}\n"),
Expand Down
40 changes: 40 additions & 0 deletions parse_clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
if [ $1 ]
then
drwnumber="$1"
else
drwnumber="000"
fi

echo "${drwnumber}"

if [ -z "$2" ]
then
test_it=false
else
test_it=true
fi

if $test_it
then
make -f Makefile-SIM clean
make -f Makefile-SIM
./sim -t0 -g testcases/swan4.gcode -o
fi

grep '#' datalog.out > datalog.out2
grep '[^[:blank:]]' datalog.out2 > datalog.out3

grep '# X:' datalog.out3 > datalog.out4

python3 parse_datalog.py 'datalog.out4' 'swan.log'

gnuplot <<__EOF
set term png size 1024,768
set output "swan-diff-${drwnumber}.png"
plot 'swan.log' u 1:4 with lines
set yrange [80:120]
set output "swan-reference-${drwnumber}.png"
plot 'swan.log' u 1:2 with lines
set output "swan-current-${drwnumber}.png"
plot 'swan.log' u 1:3 with lines
__EOF
58 changes: 58 additions & 0 deletions parse_datalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import sys

in_file = sys.argv[1]
out_file = sys.argv[2]

diff_list = list()
diff_list.clear()

with open(in_file, 'r') as file:
data = file.readlines()

def get_line(text):
temp = text
temp = temp[temp.find('X:')+2:]
X = temp[:temp.find(',')]
temp = temp[temp.find('Y:')+2:]
Y = temp[:temp.find(',')]
temp = temp[temp.find('Z:')+2:]
Z = temp[:temp.find(',')]
temp = temp[temp.find('E:')+2:]
E = temp[:temp.find(',')]
X = float(X)
Y = float(Y)
Z = float(Z)
E = float(E)
return X, Y, Z, E


for i, line in enumerate(data):
if not (i % 2):
x1, y1, z1, e1 = get_line(line)
else:
x2, y2, z2, e2 = get_line(line)
x = x2 - x1
y = y2 - y1
z = z2 - z1
e = e2 - e1
# diff_list.append('- X:{}\t\t\t,Y:{}\t\t\t,Z:{}\n'.format(x1, y1, z1))
# diff_list.append('# X:{}\t\t\t,Y:{}\t\t\t,Z:{}\n'.format(x, y, z))
diff_list.append('{}\t\t\t{}\t\t\t{}\t\t\t{}\n'.format(i//2, x1, x2, x))
# try:
# x3 = x/x2
# except ZeroDivisionError:
# x3 = 0
# try:
# y3 = x/y2
# except ZeroDivisionError:
# y3 = 0
# try:
# z3 = z/z2
# except ZeroDivisionError:
# z3 = 0

# diff_list.append('# X:{}\t,Y:{}\t,Z:{}\n'.format(x3, y3, z3))


with open(out_file, 'w') as file:
file.writelines(diff_list)

0 comments on commit 51090b1

Please sign in to comment.