1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include <AP_Common/AP_Common.h>
- #include <AP_HAL/AP_HAL.h>
- #include "AP_WheelEncoder.h"
- #include "WheelEncoder_Backend.h"
- AP_WheelEncoder_Backend::AP_WheelEncoder_Backend(AP_WheelEncoder &frontend, uint8_t instance, AP_WheelEncoder::WheelEncoder_State &state) :
- _frontend(frontend),
- _state(state)
- {
- state.instance = instance;
- }
- int8_t AP_WheelEncoder_Backend::get_pin_a() const
- {
- if (_state.instance >= WHEELENCODER_MAX_INSTANCES) {
- return -1;
- }
- return _frontend._pina[_state.instance].get();
- }
- int8_t AP_WheelEncoder_Backend::get_pin_b() const
- {
- if (_state.instance >= WHEELENCODER_MAX_INSTANCES) {
- return -1;
- }
- return _frontend._pinb[_state.instance].get();
- }
- void AP_WheelEncoder_Backend::copy_state_to_frontend(int32_t distance_count, uint32_t total_count, uint32_t error_count, uint32_t last_reading_ms)
- {
-
- _state.dt_ms = last_reading_ms - _state.last_reading_ms;
- _state.dist_count_change = distance_count - _state.distance_count;
-
- _state.distance_count = distance_count;
- _state.total_count = total_count;
- _state.error_count = error_count;
- _state.last_reading_ms = last_reading_ms;
- }
|