Revision b033b3ae
unittests/periphery-lld/src/ut_alld_a3906.c | ||
---|---|---|
34 | 34 |
|
35 | 35 |
/** |
36 | 36 |
* @brief Threshold for QEI differences. |
37 |
* @details Differences smaller tahn or equal to this value are neglected (interpreted as zero). |
|
37 |
* @details Differences smaller than or equal to this value are neglected (interpreted as zero). |
|
38 |
* The value can be interpreted as encoder ticks per second (tps). |
|
39 |
* @note The expected value is about 7000 tps and a jitter of up to ±2% is ok. |
|
38 | 40 |
*/ |
39 |
#define QEI_DIFF_THRESHOLD 4
|
|
41 |
#define QEI_DIFF_THRESHOLD (apalQEICount_t)(7000 * 0.02f)
|
|
40 | 42 |
|
41 | 43 |
/** |
42 | 44 |
* @brief Enumerator to distinguish between left and right wheel. |
... | ... | |
145 | 147 |
qei_increments[1] = (direction == DIRECTION_FORWARD) ? |
146 | 148 |
((qei_count[1] > qei_count[0]) ? (qei_count[1] - qei_count[0]) : (qei_count[1] + (qei_range - qei_count[0]))) : |
147 | 149 |
((qei_count[0] > qei_count[1]) ? (qei_count[0] - qei_count[1]) : (qei_count[0] + (qei_range - qei_count[1]))); |
148 |
qei_increments_diff = abs((int32_t)qei_increments[0] - (int32_t)qei_increments[1]); |
|
149 |
stable_counter = (qei_increments[1] != 0 && qei_increments_diff <= QEI_DIFF_THRESHOLD) ? stable_counter+1 : 0; |
|
150 |
qei_increments_diff = abs((int32_t)qei_increments[0] - (int32_t)qei_increments[1]) * ((float)MILLISECONDS_PER_SECOND / (float)QEI_POLL_INTERVAL_MS); |
|
151 |
stable_counter = ((qei_increments[0] != 0 || qei_increments[1] != 0) && qei_increments_diff <= QEI_DIFF_THRESHOLD) ? stable_counter+1 : 0; |
|
152 |
if (qei_increments[0] != 0 && stable_counter == 0) { |
|
153 |
chprintf(stream, "\tunstable speed? jitter of %u tps is above threshold (%u tps).\n", qei_increments_diff, QEI_DIFF_THRESHOLD); |
|
154 |
} |
|
150 | 155 |
} while ((stable_counter* QEI_POLL_INTERVAL_MS < MILLISECONDS_PER_SECOND) && (timeout_counter * MICROSECONDS_PER_MILLISECOND <= data->timeout)); |
151 | 156 |
status |= a3906_lld_set_pwm(data->pwm.driver, (wheel == WHEEL_LEFT) ? |
152 | 157 |
((direction == DIRECTION_FORWARD) ? data->pwm.channel.left_forward : data->pwm.channel.left_backward) : |
Also available in: Unified diff