-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-esc-testing.lisp
187 lines (156 loc) · 6.54 KB
/
main-esc-testing.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
(import "pkg@://vesc_packages/lib_code_server/code_server.vescpkg" 'code-server)
(read-eval-program code-server)
(import "pkg::midi@://vesc_packages/lib_midi/midi.vescpkg" 'midi)
(import "lib/audible-alerts.lisp" 'audible-alerts)
(import "./assets/alerts/startup.mid" 'midi-startup)
(import "./assets/alerts/ascend.mid" 'midi-ascend)
(import "./assets/alerts/descend.mid" 'midi-descend)
(read-eval-program audible-alerts)
(start-code-server)
; NOTE: ADC App? Cruise control test?
;(app-adc-detach 2 1) ; Give LBM control over CC button
;(app-adc-override 3 1) ; Activate CC
;(app-adc-override 3 0) ; Deactivate CC
; ESC
; 20 SOC, Duty, Speed, Current In
; 21 BMS Temp, Mosfet Temp, Motor Temp, Pitch angle
; 22 Wh, Wh Regen, Distance, Fault
; 23 Current Avg, Current Max, Current Now, Batt Ah
; 24 VIN, Odometer, Cruise Control Set Speed
(def buf-canid20 (array-create 8))
(def buf-canid21 (array-create 8))
(def buf-canid22 (array-create 8))
(def buf-canid23 (array-create 8))
(def buf-canid24 (array-create 8))
; IO
; 30 Indicators, High Beam, Cruise Control Active
; 31 Kickstand, Drive Mode, Performance Mode
(def buf-canid30 (array-create 8))
(def buf-canid31 (array-create 8))
; BMS
; 35 Battery A/B SOC, Battery A/B Charge Status
(def buf-canid35 (array-create 8))
@const-start
(spawn (fn ()
(loopwhile t
(progn
(select-motor 1)
(bufset-i16 buf-canid20 0 (* (get-batt) 1000))
(bufset-i16 buf-canid20 2 (* (abs (get-duty)) 1000))
(bufset-i16 buf-canid20 4 (* (abs (get-speed)) 3.6 10))
(bufset-i16 buf-canid20 6 (* (get-current-in) (get-vin) 2 0.1))
(if (> (get-bms-val 'bms-temp-adc-num) 0)
(bufset-i16 buf-canid21 0 (* (get-bms-val 'bms-temps-adc 0) 10))
(bufset-i16 buf-canid21 0 0)
)
(bufset-i16 buf-canid21 2 (* (get-temp-fet) 10))
(bufset-i16 buf-canid21 4 (* (get-temp-mot) 10))
(bufset-i16 buf-canid21 6 (* (ix (get-imu-rpy) 1) 100))
(bufset-u16 buf-canid22 0 (* (get-wh) 10.0))
(bufset-u16 buf-canid22 2 (* (get-wh-chg) 10.0))
(bufset-u16 buf-canid22 4 (* (/ (get-dist-abs) 1000.0) 10))
(bufset-u16 buf-canid22 6 (get-fault))
(bufset-u16 buf-canid23 0 (to-i (stats 'stat-current-avg)))
(bufset-u16 buf-canid23 2 (to-i (stats 'stat-current-max)))
(bufset-i16 buf-canid23 4 (to-i (get-current)))
(bufset-u16 buf-canid23 6 (to-i (conf-get 'si-battery-ah)))
(bufset-u16 buf-canid24 0 (* (get-vin) 10))
(bufset-u16 buf-canid24 2 (* (/ (sysinfo 'odometer) 1000.0) 10))
(bufset-u16 buf-canid24 4 (* (abs (get-speed-set)) 3.6 10))
(sleep 0.1) ; 10 Hz
))))
; TODO: Fake indicator signals, highbeam indicator, cruise control state
(spawn (fn () {
; Sending initial signal that would not have measured the Indicator Duration
(bufset-u8 buf-canid30 0 1) ; L Indicator ON
(bufset-u8 buf-canid30 1 1) ; R Indicator ON
(bufset-u16 buf-canid30 2 0) ; Indicator ON milliseconds
(bufset-u8 buf-canid30 4 0) ; Highbeam OFF
(bufset-u8 buf-canid30 5 0) ; Cruise Control OFF
(bufset-u16 buf-canid30 6 0) ; Cruise Control Speed
(sleep 0.65)
(bufset-u8 buf-canid30 0 0) ; L Indicator OFF
(bufset-u8 buf-canid30 1 0) ; R Indicator OFF
(bufset-u16 buf-canid30 2 0) ; Indicator ON milliseconds
(sleep 0.5)
(var highbeam-active false)
; Sending indicator signals with measured Indicator Duration
(loopwhile t
(progn
(if highbeam-active {
(bufset-u8 buf-canid30 5 0) ; Cruise Control OFF
} {
(bufset-u8 buf-canid30 5 1) ; Cruise Control ON
})
(bufset-u8 buf-canid30 0 1) ; L Indicator ON
(bufset-u8 buf-canid30 1 (if highbeam-active 1 0)) ; R Indicator ON
(bufset-u16 buf-canid30 2 650) ; Indicator ON milliseconds
(if highbeam-active
(bufset-u8 buf-canid30 4 1)
(bufset-u8 buf-canid30 4 0)
)
(sleep 0.65)
(bufset-u8 buf-canid30 0 0) ; L Indicator OFF
(bufset-u8 buf-canid30 1 (if highbeam-active 0 0)) ; R Indicator OFF
(bufset-u16 buf-canid30 2 650) ; Indicator ON milliseconds
(sleep 0.5)
(setq highbeam-active (not highbeam-active))
))
}))
; TODO: Fake kickstand, drive mode, performance mode
(spawn (fn () (loopwhile t
(progn
; Raise kickstand, put in neutral
(bufset-u8 buf-canid31 0 1) ; Kickstand Up
(bufset-u8 buf-canid31 1 0) ; 'neutral
(bufset-u8 buf-canid31 2 0) ; Performance Mode ECO
(sleep 3.0)
; Raise kickstand, Put in Drive
(bufset-u8 buf-canid31 0 1) ; Kickstand Up
(bufset-u8 buf-canid31 1 1) ; 'drive
(bufset-u8 buf-canid31 2 1) ; Performance Mode Normal
(sleep 2.0)
(bufset-u8 buf-canid31 1 2) ; 'reverse
(sleep 2.0)
(bufset-u8 buf-canid31 1 1) ; 'drive
(sleep 2.0)
; Lower kickstand, put in neutral
(bufset-u8 buf-canid31 0 0) ; Kickstand Down
(bufset-u8 buf-canid31 1 0) ; 'neutral
(bufset-u8 buf-canid31 2 2) ; Performance Mode Sport
(sleep 3.0)
))))
; Fake Battery A/B SOC and charge status
@const-end
(def fake-charge-state 0)
(def fake-charge-swap (systime))
(def fake-battery-b-connected true)
@const-start
(spawn (fn () (loopwhile t
(progn
(bufset-i16 buf-canid35 0 (* (get-batt) 1000)) ; Battery A SOC
(bufset-i16 buf-canid35 2 (* (- 1.0 (get-batt)) 1000)) ; Battery B SOC
(bufset-u8 buf-canid35 4 fake-charge-state) ; Battery A Charging
(bufset-u8 buf-canid35 5 (if (eq fake-charge-state 1) 0 1)) ; Battery B Charging
(bufset-u8 buf-canid35 6 (if fake-battery-b-connected 1 0))
(if (> (secs-since fake-charge-swap) 2.0) {
(setq fake-charge-state (if (eq fake-charge-state 1) 0 1))
(def fake-charge-swap (systime))
})
(sleep 0.1)
))))
(spawn (fn () (loopwhile t
(progn
; ESC
(can-send-sid 20 buf-canid20)
(can-send-sid 21 buf-canid21)
(can-send-sid 22 buf-canid22)
(can-send-sid 23 buf-canid23)
(can-send-sid 24 buf-canid24)
; I/O Board
(can-send-sid 30 buf-canid30)
(can-send-sid 31 buf-canid31)
; BMS
(can-send-sid 35 buf-canid35)
(sleep 0.1) ; 10 Hz
))))