-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
; PlatformIO Project Configuration File | ||
; Copyright 2023 Ryotaro Onuki <kerikun11+gituhb@gmail.com> | ||
; https://docs.platformio.org/page/projectconf.html | ||
|
||
[platformio] | ||
src_dir = . | ||
|
||
[env] | ||
framework = arduino | ||
build_src_filter = | ||
+<src> | ||
+<platformio> | ||
build_flags = | ||
-O2 | ||
-std=gnu++17 ; to avoid error https://github.com/espressif/esp-idf/issues/5897 | ||
-DCORE_DEBUG_LEVEL=3 ; 5: verbose, 4: debug, 3: info, 2: warn, 1:error | ||
-DCONFIG_ARDUHAL_LOG_COLORS=1 | ||
build_src_flags = ${env.build_flags} | ||
|
||
[env:esp32dev] | ||
platform = espressif32 ; https://github.com/platformio/platform-espressif32 | ||
board = esp32dev | ||
board_build.partitions = no_ota.csv | ||
board_build.f_cpu = 240000000L | ||
upload_speed = 2000000 | ||
monitor_speed = 115200 | ||
monitor_filters = log2file, esp32_exception_decoder | ||
|
||
; upload_port = /dev/ttyUSB0 | ||
; monitor_port = /dev/ttyUSB0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @brief accel designer test | ||
* @author Ryotaro Onuki <kerikun11+github@gmail.com> | ||
* @date 2023-07-01 | ||
* @copyright Copyright 2023 Ryotaro Onuki <kerikun11+github@gmail.com> | ||
*/ | ||
#include <Arduino.h> | ||
#include <ctrl/accel_designer.h> | ||
|
||
#include <chrono> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
void app_ctrl_accel() { | ||
ctrl::AccelDesigner ad; | ||
const std::vector<std::vector<float>> params = { | ||
{100, 10, 4, 0, 2, 4}, //< vs -> vm -> vt, tm1>0, tm2>0 | ||
{100, 10, 4, 0, 3, 4}, //< vs -> vm -> vt, tm1>0, tm2<0 | ||
{100, 10, 4, 3, 0, 4}, //< vs -> vm -> vt, tm1<0, tm2>0 | ||
{100, 10, 8, 0, 2, 4}, //< vs -> vr -> vt, vr<vm, tm1>0, tm2>0 | ||
{100, 10, 8, 0, 6, 4}, //< vs -> vr -> vt, vr<vm, tm1>0, tm2<0 | ||
{100, 10, 8, 0, 0.5, 0.2}, //< vs -> vr -> vt, vr<vm, tm1<0, tm2<0 | ||
{100, 10, 6, 0, 3, 1}, //< vs -> vr -> vt, vr<vm, tm1>0, tm2<0 | ||
{100, 10, 6, 0, 4, 1}, //< ve == vt, tm > 0 just | ||
{100, 10, 8, 0, 6, 1}, //< ve != vt, tm > 0, accel | ||
{100, 10, 8, 4, 0, 1}, //< ve != vt, tm > 0, decel | ||
{100, 10, 4, 0, 4, 0.1}, //< ve != vt, tm < 0, accel | ||
{100, 10, 4, 4, 0, 0.1}, //< ve != vt, tm < 0, decel | ||
}; | ||
std::cout << std::endl; | ||
float sum = 0; | ||
for (const auto &ps : params) { | ||
const int n = 10000; | ||
#if 0 | ||
const auto ts = std::chrono::steady_clock::now(); | ||
for (int i = 0; i < n; ++i) { | ||
ad.reset(ps[0], ps[1], ps[2], ps[3], ps[4], ps[5]); | ||
sum += ad.t_end(); | ||
} | ||
const auto te = std::chrono::steady_clock::now(); | ||
const auto dur = | ||
std::chrono::duration_cast<std::chrono::nanoseconds>(te - ts); | ||
std::cout << "Average Time: " << dur.count() / n << " [ns]" << std::endl; | ||
#else // arduino | ||
const auto ts = micros(); | ||
for (int i = 0; i < n; ++i) { | ||
ad.reset(ps[0], ps[1], ps[2], ps[3], ps[4], ps[5]); | ||
sum += ad.t_end(); | ||
} | ||
const auto te = micros(); | ||
std::cout << "Average Time: " << (te - ts) / n << " [us]" << std::endl; | ||
#endif | ||
} | ||
std::cout << sum << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @brief slalom test | ||
* @author Ryotaro Onuki <kerikun11+github@gmail.com> | ||
* @date 2023-07-01 | ||
* @copyright Copyright 2023 Ryotaro Onuki <kerikun11+github@gmail.com> | ||
*/ | ||
#include <ctrl/slalom/trajectory.h> | ||
#include <ctrl/trajectory_tracker.h> | ||
|
||
#include <chrono> | ||
#include <cmath> | ||
#include <vector> | ||
|
||
using namespace ctrl; | ||
|
||
static constexpr auto pi = M_PI; | ||
static constexpr auto sqrt_2 = std::sqrt(2); | ||
|
||
std::vector<std::pair<std::string, slalom::Shape>> shapes = {{ | ||
{"SS_S90 ", slalom::Shape(Pose(45, 45, pi / 2), 44)}, | ||
{"SS_F45 ", slalom::Shape(Pose(90, 45, pi / 4), 30)}, | ||
{"SS_F90 ", slalom::Shape(Pose(90, 90, pi / 2), 70)}, | ||
{"SS_F135", slalom::Shape(Pose(45, 90, pi * 3 / 4), 80)}, | ||
{"SS_F180", slalom::Shape(Pose(0, 90, pi), 90, 24)}, | ||
{"SS_FV90", slalom::Shape(Pose(45 * sqrt_2, 45 * sqrt_2, pi / 2), 48)}, | ||
{"SS_FS90", slalom::Shape(Pose(45, 45, pi / 2), 44)}, | ||
}}; | ||
|
||
int app_ctrl_slalom() { | ||
std::cout << std::endl; | ||
float dummy = 0; | ||
for (const auto shape : shapes) { | ||
std::chrono::nanoseconds sum{0}; | ||
const int n = 10000; | ||
for (int i = 0; i < n; ++i) { | ||
const auto t_s = std::chrono::system_clock().now(); | ||
slalom::Trajectory st(shape.second); | ||
st.reset(1200); | ||
const auto t_e = std::chrono::system_clock().now(); | ||
dummy += st.getAccelDesigner().t_end(); | ||
const auto us = | ||
std::chrono::duration_cast<std::chrono::nanoseconds>(t_e - t_s); | ||
sum += us; | ||
} | ||
std::cout << shape.first << "\t" << sum.count() / n << "\t[ns]" | ||
<< std::endl; | ||
} | ||
std::cout << dummy << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @file app_main.cpp | ||
* @brief MicroMouse Control MOdule Test App | ||
* @author Ryotaro Onuki <kerikun11+github@gmail.com> | ||
* @date 2021-01-25 | ||
* @copyright Copyright 2021 Ryotaro Onuki <kerikun11+github@gmail.com> | ||
*/ | ||
#include <esp_app_format.h> | ||
#include <esp_ota_ops.h> | ||
#include <freertos/FreeRTOS.h> | ||
#include <freertos/task.h> //< for vTaskDelay | ||
#include <soc/rtc.h> | ||
|
||
#include <iostream> | ||
|
||
static int get_cpu_freq_in_mhz() { | ||
rtc_cpu_freq_config_t conf; | ||
rtc_clk_cpu_freq_get_config(&conf); | ||
return conf.freq_mhz; | ||
} | ||
static char* get_app_version() { | ||
static esp_app_desc_t app_desc; | ||
const esp_partition_t* running = esp_ota_get_running_partition(); | ||
ESP_ERROR_CHECK(esp_ota_get_partition_description(running, &app_desc)); | ||
return app_desc.version; | ||
} | ||
|
||
static void measurement_task(void* arg) { | ||
/* accel */ | ||
void app_ctrl_accel(); | ||
app_ctrl_accel(); | ||
/* end */ | ||
vTaskDelete(NULL); | ||
} | ||
static void serial_control_task(void* arg) { | ||
while (1) { | ||
vTaskDelay(pdMS_TO_TICKS(10)); | ||
char c = getc(stdin); | ||
switch (c) { | ||
case 'r': | ||
esp_restart(); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
/* called by arduino */ | ||
void setup() { | ||
vTaskDelay(pdMS_TO_TICKS(3000)); | ||
std::cout << "Hello, this is ESP32." << std::endl; | ||
std::cout << "CPU Freq: " << get_cpu_freq_in_mhz() << " MHz" << std::endl; | ||
std::cout << "Build Timestamp: " << __DATE__ << " " << __TIME__ << std::endl; | ||
std::cout << "Version: " << get_app_version() << std::endl; | ||
/* measurement task */ | ||
xTaskCreatePinnedToCore(measurement_task, "meas", 4096, NULL, | ||
configMAX_PRIORITIES, NULL, APP_CPU_NUM); | ||
/* serial control task */ | ||
xTaskCreatePinnedToCore(serial_control_task, "serial", 4096, NULL, | ||
configMAX_PRIORITIES, NULL, PRO_CPU_NUM); | ||
} | ||
void loop() { vTaskDelay(portMAX_DELAY); } | ||
|
||
/* called by esp-idf */ | ||
#if 0 | ||
extern "C" __attribute__((weak)) int app_main() { | ||
setup(); | ||
while (1) { | ||
loop(); | ||
vPortYield(); | ||
} | ||
} | ||
#endif |