-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello_em_current.cpp
61 lines (48 loc) · 1.15 KB
/
hello_em_current.cpp
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
// Study of em current versus input PWM.
// 2024-04-12
#include "tof.h"
#include "rodos.h"
#include "magnet.h"
#include "satellite_config.h"
float pwm = 20; // Start pwm
float delta_pwm = 10; // PWM increments
float max_pwm = 100; // End PWM
int max_count = 5; // Current samples for each PWM
int count = 0;
float current[4] = {0.0};
class magnet_thread : public StaticThread<>
{
private:
int period = 500; // millis
public:
magnet_thread(const char* thread_name) : StaticThread(thread_name){}
void init(void);
void run(void);
};
void magnet_thread::init()
{
magnet::init();
}
void magnet_thread::run(void)
{
while(1)
{
magnet::actuate(MAGNET_IDX_ALL, pwm);
magnet::get_current(current);
PRINTF("%f, %f, %f, %f, %f\n", pwm, current[0], current[1], current[2], current[3]);
count ++;
if(count == max_count)
{
count = 0;
pwm = pwm + delta_pwm;
if(pwm > max_pwm)
{
magnet::stop(MAGNET_IDX_ALL);
PRINTF("Datalog complete!\n");
suspendCallerUntil(END_OF_TIME);
}
}
suspendCallerUntil(NOW() + period * MILLISECONDS);
}
}
magnet_thread test_magnet_thread("magnet_thread");