Skip to content

Commit 994fa1b

Browse files
committed
setting up new branch
1 parent bce0890 commit 994fa1b

14 files changed

+240
-219
lines changed

mendel/calc.pl

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/perl
2+
3+
my ($ss, $es, $f, $dn, $dt, $a, $n0, $nn, $np, $c0, $cn, $cp, $n, $c, $t, $tp, $v, $vp);
4+
my ($c0_exact, $cn_exact, $v_exact, $t_exact, $vp_exact, $tp_exact);
5+
my ($n_pre);
6+
7+
$ss = 300;
8+
$es = 400;
9+
$f = 16000000;
10+
$dn = 50000;
11+
12+
$ssq = $ss * $ss;
13+
$esq = $es * $es;
14+
$dsq = ($esq - $ssq);
15+
16+
# $a = $dsq / ($dn << 1);
17+
18+
#$n0 = int(($ss * $ss) / (2 * $a));
19+
#$nn = int(($es * $es) / (2 * $a));
20+
# $n0 = int($ssq * $dn / $dsq);
21+
# $nn = int($esq * $dn / $dsq);
22+
23+
$c0 = int($f / $ss);
24+
# $c0_exact = $f * sqrt(2 / abs($a));
25+
26+
27+
# $dt = ($es - $ss) / $a;
28+
29+
# printf "A:\t%d-%d/%g: %d\n", $es, $ss, $dt, $a;
30+
# printf "N:\t%d-%d %d:%d\n", $n0, $nn, $nn - $n0, $dn, $a;
31+
# printf "C:\t%d\t%g\n", $c0, $c0_exact * (sqrt(abs($n0) + 1) - sqrt(abs($n0)));
32+
# $n = $np = $n0;
33+
$c = $cp = int($f / $ss);
34+
$end_c = int($f / $es);
35+
$t = $tp = $t_exact = 0;
36+
# $v = $vp = $ss;
37+
38+
$n_pre = int(4 * $ssq * $dn / $dsq) | 1;
39+
40+
# $cn_exact = $c0_exact * (sqrt(abs($n0) + 1) - sqrt(abs($n0)));
41+
# $v_exact = $vp_exact = $f / $cn_exact;
42+
43+
printf "\tt:i\t\t\tdt\tn\tV\t\ta\n";
44+
for (0..$dn) {
45+
# approximation
46+
# $c = int($c * 1000) / 1000;
47+
printf "Approx:\t%8.6f:%i\t%10d\t%d\t%12.3f\t%12.3f\n", $t, $_, $c, ($n_pre / 4) - 1, $f / $c, ($t > 0)?($v - $ss) / ($t):0;
48+
49+
# $tp = $t;
50+
# $cp = $c;
51+
# $np = $n;
52+
# $vp = $v;
53+
54+
$t += $c / $f;
55+
if (
56+
(($n_pre > 0) && ($c > $end_c)) ||
57+
(($n_pre < 0) && ($c < $end_c))
58+
) {
59+
$c = int($c - ((2 * $c) / $n_pre));
60+
$n_pre += 4;
61+
}
62+
# $v = $f / $c;
63+
64+
# exact
65+
# printf "Exact:\t%8.6f:%i\t%10.3f\t%i\t%12.3f\t%12.3f\n\n", $t_exact, $_, $cn_exact, $n, $v_exact, ($t_exact > 0)?($v_exact - $ss) / ($t_exact):0
66+
# if ($_ % 10 == 0);
67+
#
68+
# $vp_exact = $v_exact;
69+
# $tp_exact = $t_exact;
70+
#
71+
# $t_exact += $cn_exact / $f;
72+
# $cn_exact = $c0_exact * (sqrt(abs($n) + 1) - sqrt(abs($n)));
73+
# $v_exact = $f / $cn_exact;
74+
75+
# loop increment
76+
# if ($nn > $n0) {
77+
# $n++;
78+
$n_pre += 4;
79+
# }
80+
# else {
81+
# $n--;
82+
# $n_pre -= 4;
83+
# }
84+
}
85+
86+
printf "dt:%8.3f\tv:%8.3f\n", int(($f / $es) + 0.5), $f / int(($f / $es) + 0.5);

mendel/dda.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void dda_create(DDA *dda, TARGET *target) {
126126

127127
// initialise DDA to a known state
128128
dda->live = 0;
129-
dda->total_steps = 0;
129+
// dda->total_steps = 0;
130130
dda->waitfor_temp = 0;
131131

132132
if (debug_flags & DEBUG_DDA)
@@ -162,7 +162,7 @@ void dda_create(DDA *dda, TARGET *target) {
162162
serial_writestr_P(PSTR("] ["));
163163
}
164164

165-
if (dda->x_delta > dda->total_steps)
165+
// if (dda->x_delta > dda->total_steps)
166166
dda->total_steps = dda->x_delta;
167167
if (dda->y_delta > dda->total_steps)
168168
dda->total_steps = dda->y_delta;
@@ -449,7 +449,7 @@ void dda_step(DDA *dda) {
449449
// else we are already at target speed
450450
}
451451

452-
if (step_option & DID_STEP) {
452+
if (step_option) {
453453
// we stepped, reset timeout
454454
steptimeout = 0;
455455

mendel/dda_queue.c

+48-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "dda_queue.h"
22

33
#include <string.h>
4+
#include <avr/interrupt.h>
45

56
#include "timer.h"
67
#include "serial.h"
78
#include "sermsg.h"
9+
#include "temp.h"
810

911
uint8_t mb_head = 0;
1012
uint8_t mb_tail = 0;
@@ -18,6 +20,41 @@ uint8_t queue_empty() {
1820
return ((mb_tail == mb_head) && (movebuffer[mb_tail].live == 0))?255:0;
1921
}
2022

23+
void queue_step() {
24+
disableTimerInterrupt();
25+
26+
// do our next step
27+
// NOTE: dda_step makes this interrupt interruptible after steps have been sent but before new speed is calculated.
28+
if (movebuffer[mb_tail].live) {
29+
if (movebuffer[mb_tail].waitfor_temp) {
30+
if (temp_achieved()) {
31+
movebuffer[mb_tail].live = movebuffer[mb_tail].waitfor_temp = 0;
32+
serial_writestr_P(PSTR("Temp achieved\n"));
33+
}
34+
35+
#if STEP_INTERRUPT_INTERRUPTIBLE
36+
sei();
37+
#endif
38+
}
39+
else {
40+
dda_step(&(movebuffer[mb_tail]));
41+
}
42+
}
43+
44+
// serial_writechar('!');
45+
46+
// fall directly into dda_start instead of waiting for another step
47+
if (movebuffer[mb_tail].live == 0)
48+
next_move();
49+
50+
#if STEP_INTERRUPT_INTERRUPTIBLE
51+
cli();
52+
#endif
53+
// check queue, if empty we don't need to interrupt again until re-enabled in dda_create
54+
if (queue_empty() == 0)
55+
enableTimerInterrupt();
56+
}
57+
2158
void enqueue(TARGET *t) {
2259
// don't call this function when the queue is full, but just in case, wait for a move to complete and free up the space for the passed target
2360
while (queue_full())
@@ -47,10 +84,11 @@ void enqueue_temp_wait() {
4784
while (queue_full())
4885
delay(WAITING_DELAY);
4986

50-
uint8_t h = mb_head;
51-
h++;
52-
if (h == MOVEBUFFER_SIZE)
53-
h = 0;
87+
uint8_t h = mb_head + 1;
88+
// h++;
89+
// if (h == MOVEBUFFER_SIZE)
90+
// h = 0;
91+
h &= (MOVEBUFFER_SIZE - 1);
5492

5593
// wait for temp flag
5694
movebuffer[h].waitfor_temp = 1;
@@ -76,16 +114,13 @@ void enqueue_temp_wait() {
76114
}
77115

78116
void next_move() {
79-
if (queue_empty()) {
80-
// memcpy(&startpoint, &current_position, sizeof(TARGET));
81-
startpoint.E = current_position.E = 0;
82-
}
83-
else {
117+
if (queue_empty() == 0) {
84118
// next item
85-
uint8_t t = mb_tail;
86-
t++;
87-
if (t == MOVEBUFFER_SIZE)
88-
t = 0;
119+
uint8_t t = mb_tail + 1;
120+
// t++;
121+
// if (t == MOVEBUFFER_SIZE)
122+
// t = 0;
123+
t &= (MOVEBUFFER_SIZE - 1);
89124
dda_start(&movebuffer[t]);
90125
mb_tail = t;
91126
}

mendel/dda_queue.h

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ extern DDA movebuffer[MOVEBUFFER_SIZE];
2020
uint8_t queue_full(void);
2121
uint8_t queue_empty(void);
2222

23+
// take one step
24+
void queue_step(void);
25+
2326
// add a new target to the queue
2427
void enqueue(TARGET *t);
2528

0 commit comments

Comments
 (0)