planner-test: $(PLANNER_TEST_SRC)
gcc -o $@ $(PLANNER_TEST_SRC) $(CFLAGS) $(LDFLAGS)
-test: planner-test
- ./$< < test.gc
+%.csv: %.gc planner-test
+ ./planner-test < $< | grep -E '^-?[0-9.]+,'
-csv: planner-test
- @$(MAKE) -s test | grep -E '^-?[0-9.]+,'
+%-test: %.gc planner-test
+ ./planner-test < $<
-plot: planner-test
- @$(MAKE) -s csv | ./plot_velocity.py
+%-plot: %.gc planner-test
+ ./planner-test < $< | grep -E '^-?[0-9.]+,' | ./plot.py
# Clean
tidy:
clean: tidy
rm -rf $(TESTS)
-.PHONY: tidy clean all test csv plot
+.PHONY: tidy clean all
# Dependencies
-include $(shell mkdir -p .dep) $(wildcard .dep/*)
--- /dev/null
+$resume
+
+$0vm=10000
+$1vm=10000
+$2vm=10000
+$0jm=50
+$1jm=50
+$2jm=50
+
+G3 I2 J2 F10000
DEBUG_CALL("%f, (%f, %f, %f, %f)",
time, target[0], target[1], target[2], target[3]);
- for (int i = 0; i < MOTORS; i++)
+ float p[MOTORS] = {0, 0, 0, 0};
+
+ for (int i = 0; i < MOTORS; i++) {
motor_position[i] = target[i];
+ p[i] = target[i] / motor_get_steps_per_unit(i);
+ }
- printf("%0.10f, %0.10f, %0.10f, %0.10f\n",
- time, motor_position[0], motor_position[1], motor_position[2]);
+ printf("%0.10f, %0.10f, %0.10f, %0.10f\n", time, p[0], p[1], p[2]);
return STAT_OK;
}
--- /dev/null
+$resume
+
+$0vm=10000
+$1vm=10000
+$2vm=10000
+$0jm=50
+$1jm=50
+$2jm=50
+
+G0 X500Y500
+G0 X0Y0
+G0 X-500Y0
+G0 X-500Y-500
+
+G0 Z-100
+G0 Z0
#include "axis.h"
#include "machine.h"
#include "command.h"
+#include "plan/arc.h"
#include "plan/planner.h"
#include "plan/exec.h"
#include "plan/state.h"
stat_t status = STAT_OK;
- while (!feof(stdin)) {
- mp_state_callback();
- command_callback();
- }
-
while (true) {
+ mach_arc_callback(); // arc generation runs
+
+ bool reading = !feof(stdin);
+
+ if (reading && mp_queue_get_room()) {
+ mp_state_callback();
+ command_callback();
+
+ if (mp_queue_get_room()) continue;
+ }
+
status = mp_exec_move();
printf("EXEC: %s\n", status_to_pgmstr(status));
printf("ERROR: %s\n", status_to_pgmstr(status));
}
- break;
+ if (!reading) break;
}
printf("STATE: %s\n", mp_get_state_pgmstr(mp_get_state()));
--- /dev/null
+#!/usr/bin/env python3
+
+import sys
+import csv
+import matplotlib.pyplot as plt
+import numpy as np
+import math
+
+
+def compute_velocity(rows):
+ p = [0, 0, 0]
+
+ for row in rows:
+ t = float(row[0])
+ d = 0.0
+
+ for i in range(3):
+ x = float(row[i + 1]) - p[i]
+ d += x * x
+ p[i] = float(row[i + 1])
+
+ d = math.sqrt(d)
+
+ yield d / t
+
+
+time_step = 0.005
+
+data = list(csv.reader(sys.stdin))
+
+velocity = list(compute_velocity(data))
+acceleration = np.diff(velocity)
+jerk = np.diff(acceleration)
+
+t = np.cumsum([float(row[0]) for row in data])
+x = [float(row[1]) for row in data]
+y = [float(row[2]) for row in data]
+z = [float(row[3]) for row in data]
+
+rows = 3
+row = 1
+if np.sum(x): rows += 1
+if np.sum(y): rows += 1
+if np.sum(z): rows += 1
+
+def next_subplot():
+ global row
+ plt.subplot(rows * 100 + 10 + row)
+ row += 1
+
+if np.sum(x):
+ next_subplot()
+ plt.title('X')
+ plt.plot(t, x, 'r')
+ plt.ylabel(r'$mm$')
+
+if np.sum(y):
+ next_subplot()
+ plt.title('X')
+ plt.title('Y')
+ plt.plot(t, [row[2] for row in data], 'g')
+ plt.ylabel(r'$mm$')
+
+if np.sum(z):
+ next_subplot()
+ plt.title('Z')
+ plt.plot(t, [row[3] for row in data], 'b')
+ plt.ylabel(r'$mm$')
+
+next_subplot()
+plt.title('Velocity')
+plt.plot(t, velocity, 'g')
+plt.ylabel(r'$\frac{mm}{min}$')
+
+next_subplot()
+plt.title('Acceleration')
+plt.plot(t[1:], acceleration, 'b')
+plt.ylabel(r'$\frac{mm}{min^2}$')
+
+next_subplot()
+plt.title('Jerk')
+plt.plot(t[2:], jerk, 'r')
+plt.ylabel(r'$\frac{mm}{min^3}$')
+plt.xlabel('Seconds')
+
+plt.tight_layout()
+plt.subplots_adjust(hspace = 0.5)
+mng = plt.get_current_fig_manager()
+mng.resize(*mng.window.maxsize())
+plt.show()
--- /dev/null
+$resume
+
+$0vm=10000
+$1vm=10000
+$2vm=10000
+$0jm=50
+$1jm=50
+$2jm=50
+
+G0 X0.0
+G0 X0.1
+G0 X0.2
+G0 X0.3
+G0 X0.4
+G0 X0.5
+G0 X0.6
+G0 X0.7
+G0 X0.8
+G0 X0.9
+G0 X1.0
+G0 X1.1
+G0 X1.2
+G0 X1.3
+G0 X1.4
+G0 X1.5
+G0 X1.6
+G0 X1.7
+G0 X1.8
+G0 X1.9
+G0 X2.0
+G0 X2.1
+G0 X2.2
+G0 X2.3
+G0 X2.4
+G0 X2.5
+G0 X2.6
+G0 X2.7
+G0 X2.8
+G0 X2.9
+G0 X3.0
+G0 X3.1
+G0 X3.2
+G0 X3.3
+G0 X3.4
+G0 X3.5
+G0 X3.6
+G0 X3.7
+G0 X3.8
+G0 X3.9
+G0 X4.0
+G0 X4.1
+G0 X4.2
+G0 X4.3
+G0 X4.4
+G0 X4.5
+G0 X4.6
+G0 X4.7
+G0 X4.8
+G0 X4.9
+++ /dev/null
-$resume
-
-$0vm=10000
-$1vm=10000
-$2vm=10000
-$0jm=50
-$1jm=50
-$2jm=50
-
-G0 X500Y500
-G0 X0Y0
-G0 X-500Y0
-G0 X-500Y-500
-
-G0 Z-100
-G0 Z0