Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BENB scale endless velocity to its previous range #145

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/host_based_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
./host_fuzz.sh

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: always()
with:
name: Fuzzing Binary
Expand Down
29 changes: 14 additions & 15 deletions grid_common/grid_ui_endless.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,20 @@ void grid_ui_element_endless_page_change_cb(struct grid_ui_element* ele, uint8_t
// }
}

uint8_t grid_ui_endless_update_trigger(struct grid_ui_element* ele, int stabilized, int16_t delta, uint64_t* endless_last_real_time, double* delta_vel_frac) {
uint8_t grid_ui_endless_update_trigger(struct grid_ui_element* ele, int stabilized, int16_t delta, uint64_t* endless_last_real_time, double* delta_frac) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Complex Method
grid_ui_endless_update_trigger decreases in cyclomatic complexity from 21 to 20, threshold = 9

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Overall Code Complexity
The mean cyclomatic complexity decreases from 6.43 to 6.14, threshold = 4


uint32_t encoder_elapsed_time = grid_platform_rtc_get_elapsed_time(*endless_last_real_time);
if (GRID_PARAMETER_ELAPSED_LIMIT * MS_TO_US < grid_platform_rtc_get_elapsed_time(*endless_last_real_time)) {
*endless_last_real_time = grid_platform_rtc_get_micros() - GRID_PARAMETER_ELAPSED_LIMIT * MS_TO_US;
encoder_elapsed_time = GRID_PARAMETER_ELAPSED_LIMIT * MS_TO_US;
}

/*
if (delta == 0) {
// nothing left to do
return 0; // did not trigger
}
*/

// update lastrealtime
*endless_last_real_time = grid_platform_rtc_get_micros();
Expand Down Expand Up @@ -137,27 +139,26 @@ uint8_t grid_ui_endless_update_trigger(struct grid_ui_element* ele, int stabiliz
elapsed_ms = 1;
}

double minmaxscale = (max - min) / 16384.0;
double minmaxscale = (max - min) / 3600.0;

double velocityparam = template_parameter_list[GRID_LUA_FNC_EP_ENDLESS_VELOCITY_index] / 100.0;
double sensitivityparam = template_parameter_list[GRID_LUA_FNC_EP_ENDLESS_SENSITIVITY_index] / 100.0;
double vel_param = template_parameter_list[GRID_LUA_FNC_EP_ENDLESS_VELOCITY_index] / 100.0;
double sen_param = template_parameter_list[GRID_LUA_FNC_EP_ENDLESS_SENSITIVITY_index] / 100.0;

double rate_of_change = abs(delta) / elapsed_ms;
double vel_comp = ((rate_of_change * rate_of_change * 28.125) / 2000.0) * vel_param;
double sen_comp = sen_param;
double factor = (vel_comp + sen_comp) * minmaxscale;

// implement configurable velocity parameters here
double velocityfactor = (((rate_of_change * rate_of_change) / 2000.0) * velocityparam + (5.0 * sensitivityparam)) * minmaxscale;
double delta_full = delta * factor + *delta_frac;

double delta_velocity_full = delta * velocityfactor + *delta_vel_frac;
int32_t delta_velocity = ((delta_full > 0) * 2 - 1) * (int32_t)fabs(delta_full);

int32_t delta_velocity = delta_velocity_full;
*delta_frac = delta_full - delta_velocity;

if (delta_velocity == 0) {
return 0; // did not trigger
}

// store the fraction of the delta that cannot be emitted as part of the trigger
*delta_vel_frac = delta_velocity_full - delta_velocity;

int32_t old_value = template_parameter_list[GRID_LUA_FNC_EP_ENDLESS_VALUE_index];

template_parameter_list[GRID_LUA_FNC_EP_ENDLESS_STATE_index] += delta_velocity;
Expand Down Expand Up @@ -341,10 +342,8 @@ void grid_ui_endless_store_input(uint8_t input_channel, uint8_t adc_bit_depth, s
int stabilized = grid_ain_stabilized(&grid_ain_state, input_channel);
uint8_t update = grid_ui_endless_update_trigger(ele, stabilized, delta, &old_value->encoder_last_real_time, &old_value->delta_vel_frac);

if (update) {
old_value->phase_a = new_value->phase_a;
old_value->phase_b = new_value->phase_b;
}
Comment on lines -344 to -347

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No longer an issue: Complex Method
grid_ui_endless_store_input is no longer above the threshold for cyclomatic complexity

Comment on lines -344 to -347

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No longer an issue: Bumpy Road Ahead
grid_ui_endless_store_input is no longer above the threshold for logical blocks with deeply nested code

old_value->phase_a = new_value->phase_a;
old_value->phase_b = new_value->phase_b;
}
}
}
3 changes: 2 additions & 1 deletion grid_common/grid_ui_endless.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define GRID_UI_ENDLESS_H_INCLUDED

#include "grid_ui.h"
#include <math.h>
#include <stdint.h>

struct grid_ui_endless_state {
Expand All @@ -23,7 +24,7 @@ void grid_ui_element_endless_page_change_cb(struct grid_ui_element* ele, uint8_t

void grid_ui_endless_store_input(uint8_t input_channel, uint8_t adc_bit_depth, struct grid_ui_endless_state* new_value, struct grid_ui_endless_state* old_value);

uint8_t grid_ui_endless_update_trigger(struct grid_ui_element* ele, int stabilized, int16_t delta, uint64_t* endless_last_real_time, double* delta_vel_frac);
uint8_t grid_ui_endless_update_trigger(struct grid_ui_element* ele, int stabilized, int16_t delta, uint64_t* endless_last_real_time, double* delta_frac);

// ========================= ENDLESS POTEMETER =========================== //

Expand Down
Loading