Le-Guily
Firmware du robot auto-équilibré (Zephyr, STM32WB55)
Chargement...
Recherche...
Aucune correspondance
safety.c
Aller à la documentation de ce fichier.
1
11
12
#include <zephyr/kernel.h>
13
#include <zephyr/sys/printk.h>
14
#include "
priorities.h
"
15
#include "
include.h
"
16
17
static
float
buffer
[10];
18
static
int
index
= 0;
19
static
int
count
= 0;
20
static
float
sum
= 0.0f;
21
static
float
moyenne
;
22
23
static
float
moving_average
(
float
new_value) {
24
25
if
(
count
== 10) {
26
27
sum
-=
buffer
[
index
];
28
29
}
else
{
30
31
count
++;
32
}
33
buffer
[
index
] = new_value;
34
35
sum
+= new_value;
36
37
index
= (
index
+ 1) % 10;
38
39
moyenne
=
sum
/
count
;
40
41
return
moyenne
;
42
}
43
44
static
void
thread_safety
(
void
*p1,
void
*p2,
void
*p3)
45
{
46
47
static
uint32_t compteur;
48
49
static
int32_t mvs = 1500;
50
51
while
(1) {
52
53
54
if
((compteur % 10) == 0){
55
56
if
(
battery_read_mv
(&mvs) == 0) {
57
58
moving_average
(mvs);
59
60
printk(
"VBAT = %d mV\n"
, (
int
)
moyenne
);
61
compteur = 0;
62
}
63
}
64
65
compteur++;
66
67
k_msleep(50);
68
}
69
}
70
71
K_THREAD_DEFINE
(thread_safety_id,
STACK_SIZE
,
thread_safety
, NULL, NULL, NULL,
72
PRIORITY_SAFETY
, 0, 0);
73
battery_read_mv
int battery_read_mv(int32_t *mv)
Definition
battery.c:53
include.h
En-tête de regroupement.
priorities.h
Priorités des threads Zephyr et taille de leur pile (plus le nombre est petit, plus le thread est pri...
STACK_SIZE
#define STACK_SIZE
Definition
priorities.h:15
PRIORITY_SAFETY
#define PRIORITY_SAFETY
Definition
priorities.h:11
thread_safety
static void thread_safety(void *p1, void *p2, void *p3)
Definition
safety.c:44
moyenne
static float moyenne
Definition
safety.c:21
index
static int index
Definition
safety.c:18
K_THREAD_DEFINE
K_THREAD_DEFINE(thread_safety_id, STACK_SIZE, thread_safety, NULL, NULL, NULL, PRIORITY_SAFETY, 0, 0)
moving_average
static float moving_average(float new_value)
Definition
safety.c:23
buffer
static float buffer[10]
Definition
safety.c:17
count
static int count
Definition
safety.c:19
sum
static float sum
Definition
safety.c:20
src
app
safety
safety.c
Généré par
1.15.0