forked from uLipe/foc_rtthread_sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
46 lines (37 loc) · 932 Bytes
/
main.c
File metadata and controls
46 lines (37 loc) · 932 Bytes
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
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "include/esp_foc/esp_foc.h"
#include "esp_foc_devices.h"
static esp_foc_inverter_t *inverter;
static esp_foc_rotor_sensor_t *sensor;
static esp_foc_axis_t axis;
static float now = 0;
static esp_foc_d_voltage vd;
static esp_foc_q_voltage vq;
int main(void)
{
/* initialize rtthread specific devices */
devices_rtthread_init();
inverter = inverter_rtthread_new();
sensor = rotor_sensor_rtthread_new();
esp_foc_initialize_axis(&axis, inverter, sensor, 8);
esp_foc_align_axis(&axis);
vd.raw = 0.0f;
vq.raw = 4.0f;
esp_foc_set_target_voltage(&axis, &vq, &vd);
while (1)
{
float now = ((float)rt_tick_get_millisecond()) * 0.001f;
esp_foc_run(&axis, now);
rt_thread_mdelay(1);
}
return RT_EOK;
}