-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic.cpp
78 lines (59 loc) · 1.86 KB
/
basic.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "DShotRMT.h"
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#include "esp_log.h"
static const char *TAG = "dshot-example";
#define DSHOT_RMT_CHANNEL RMT_CHANNEL_0
#define DSHOT_GPIO GPIO_NUM_25
#define MIN_THROTTLE 48
#define FULL_THROTTLE 2047
DShotRMT esc;
static void rampThrottle(int start, int stop, int step)
{
if (step == 0)
return;
for (int i = start; step > 0 ? i < stop : i > stop; i += step)
{
esc.sendThrottle(i);
vTaskDelay(1);
}
esc.sendThrottle(stop);
}
extern "C" void app_main(void)
{
ESP_LOGI(TAG, "Initializing DShot RMT");
ESP_ERROR_CHECK(esc.install(DSHOT_GPIO, DSHOT_RMT_CHANNEL));
ESP_ERROR_CHECK(esc.init());
ESP_LOGW(TAG, "Reversing");
ESP_ERROR_CHECK(esc.setReversed(true));
{
ESP_LOGI(TAG, "Ramping throttle");
rampThrottle(MIN_THROTTLE, FULL_THROTTLE, 20);
ESP_LOGI(TAG, "Full throttle");
const TickType_t holdStop = xTaskGetTickCount() + (3000 / portTICK_PERIOD_MS);
while (xTaskGetTickCount() < holdStop)
{
esc.sendThrottle(FULL_THROTTLE);
vTaskDelay(1);
}
ESP_LOGI(TAG, "Ramping down");
rampThrottle(FULL_THROTTLE, MIN_THROTTLE, -20);
}
ESP_LOGW(TAG, "Normal direction");
ESP_ERROR_CHECK(esc.setReversed(false));
{
ESP_LOGI(TAG, "Ramping throttle");
rampThrottle(MIN_THROTTLE, FULL_THROTTLE, 20);
ESP_LOGI(TAG, "Full throttle");
const TickType_t holdStop = xTaskGetTickCount() + (3000 / portTICK_PERIOD_MS);
while (xTaskGetTickCount() < holdStop)
{
esc.sendThrottle(FULL_THROTTLE);
vTaskDelay(1);
}
ESP_LOGI(TAG, "Ramping down");
rampThrottle(FULL_THROTTLE, MIN_THROTTLE, -20);
}
ESP_LOGW(TAG, "Exiting");
}