-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvesc-code.lisp
146 lines (123 loc) · 4.54 KB
/
vesc-code.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
(define launch-line-length 180)
(define min-eight-line-length 200)
(define max-eight-line-length 230)
(define launch-command 0.0)
(define land-command 1.0)
(define launch 0)
(define eight 1)
(define landing 2)
(define final-landing 3)
(define flightmode launch)
(define generatormode 0)
(define motormode 1)
(define mode generatormode)
(define counter 10)
(define max-reel-out-tension 10)
(uart-start 115200)
(define offset (get-dist))
(define arr (array-create 16))
(define array (array-create 16))
(define uart-send-counter 0)
(loopwhile t
(progn
(define counter (- counter 1))
(if (< counter 0) (define counter 0) 0)
(define uart-send-counter (- uart-send-counter 1))
(if (< uart-send-counter 0) (define uart-send-counter 0) 0)
(if (= uart-send-counter 0)
(progn
(define uart-send-counter 20)
(define line-length (- 0 (- (get-dist) offset) ) )
; SEND line-length AND line tension(current)
(bufset-f32 arr 0 1234567.0)
(bufset-f32 arr 4 line-length)
(bufset-f32 arr 8 flightmode)
(bufset-f32 arr 12 -1234567.0)
(uart-write arr)
)
)
; RECEIVE tension-request from kite
(bufclear array)
(define num-bytes-read (uart-read array 16))
;(print num-bytes-read)
(if (> num-bytes-read 15)
(if (and (= (bufget-f32 array 0) 1234567.0) (= (bufget-f32 array 12) -1234567.0))
; received something
(progn
;(print (bufget-f32 array 4))
(if (= (bufget-f32 array 4) land-command)
(progn
(define flightmode final-landing)
(define mode motormode)
)
)
;(if (= (bufget-f32 array 4) launch-command)
; (progn
; (define flightmode launch)
; (define mode generatormode)
; )
;)
)
)
)
(if (= mode generatormode)
(progn
(if (= flightmode launch)
(set-brake 0.1) ; LAUNCHING
(progn
(print "generating")
(set-brake 9) ; GENERATING max-reel-out-tension
)
)
; SWITCHING TO REEL-IN
(if (and (= flightmode eight) (> (get-current) -1) (= counter 0))
(progn
(define mode motormode)
(define counter 100)
)
)
(if (and (= flightmode launch) (> line-length launch-line-length))
(define flightmode eight)
)
(if (and (= flightmode eight) (> line-length max-eight-line-length))
(progn
(define flightmode landing)
(define mode motormode)
)
)
)
(progn
(progn
; REEL-IN WITH LOW TENSION
(if (= flightmode eight)
(progn
(print "REEL IN while Eight")
(set-current 9)
)
; flightmode = landing or final-landing
(if (> line-length 30)
(set-current 3)
(if (> line-length 0)
(progn
(set-current (+ 1.5 (* 0.05 line-length)))
)
)
)
)
(if (and (= flightmode landing) (< line-length min-eight-line-length))
(define flightmode eight)
)
; SWITCHING TO REEL-OUT
(if (and (= flightmode eight) (< (get-duty) 0.1) (= counter 0))
(progn
;(set-current 0)
(define mode generatormode)
(define counter 10)
)
)
)
)
)
(sleep 0.005)
)
)