-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
b98bb49
4d486ad
ad8b475
4bb56c5
a2ef3fa
6179c27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Getting better: Overall Code Complexity |
||
|
||
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(); | ||
|
@@ -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; | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ No longer an issue: Complex Method
Comment on lines
-344
to
-347
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ No longer an issue: Bumpy Road Ahead |
||
old_value->phase_a = new_value->phase_a; | ||
old_value->phase_b = new_value->phase_b; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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