-
Notifications
You must be signed in to change notification settings - Fork 3
SNS - Wheel Encoder #117
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
base: master
Are you sure you want to change the base?
SNS - Wheel Encoder #117
Changes from all commits
7318a5b
9de728f
00f8235
8114a74
d8fb711
4ca3cac
cc85041
27ff71a
7ccc237
2872091
924ac3f
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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include "wheel_encoder.hpp" | ||
|
|
||
| namespace hyped::sensors { | ||
|
|
||
| WheelEncoder::WheelEncoder(core::ILogger &logger, std::shared_ptr<io::IAdc> adc) | ||
| : logger_(logger), | ||
| adc_(adc), | ||
| count_(0), | ||
| previous_voltage_(0) | ||
| { | ||
| } | ||
|
|
||
| std::uint64_t WheelEncoder::getCount() | ||
| { | ||
| return count_; | ||
| } | ||
|
|
||
| core::Result WheelEncoder::updateCount() | ||
| { | ||
| const auto optional_voltage = adc_->readValue(); | ||
| if (!optional_voltage) { | ||
| logger_.log(core::LogLevel::kFatal, "Failed to read wheel encoder value from ADC"); | ||
| return core::Result::kFailure; | ||
| } | ||
| const core::Float voltage = *optional_voltage; | ||
| if (voltage > kVoltageThreshold && previous_voltage_ < kVoltageThreshold) { count_++; } | ||
| previous_voltage_ = voltage; | ||
| return core::Result::kSuccess; | ||
|
Comment on lines
+26
to
+28
Contributor
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. If we keep getting a value over the thresh, at what point do we think the encoders aren't working. Ik nav pays a lot of attention to these so want to make sure we report any possible failure asap.
Member
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. Yeah these are our singular most accurate sensor I think. If these give faulty data, we'll only spot it if it's disagreeing with our other data but this data being unreliable could potentially leave us without a ground truth
Contributor
Author
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. it depends on velocity. we can probably calculate a maximum high period before we stop trusting it based off of minimum velocity we expect to hold |
||
| } | ||
|
|
||
| void WheelEncoder::resetCount() | ||
| { | ||
| count_ = 0; | ||
| } | ||
|
|
||
| } // namespace hyped::sensors | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #pragma once | ||
| #include <memory> | ||
| #include <optional> | ||
|
Member
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.
|
||
|
|
||
| #include <core/logger.hpp> | ||
| #include <core/types.hpp> | ||
| #include <io/adc.hpp> | ||
|
|
||
| namespace hyped::sensors { | ||
| class WheelEncoder { | ||
| public: | ||
| WheelEncoder(core::ILogger &logger, std::shared_ptr<io::IAdc> adc); | ||
| std::uint64_t getCount(); | ||
| core::Result updateCount(); | ||
| void resetCount(); | ||
|
|
||
| private: | ||
| static constexpr core::Float kVoltageThreshold = 1.7; | ||
| core::ILogger &logger_; | ||
| std::shared_ptr<io::IAdc> adc_; | ||
| std::uint64_t count_; | ||
| core::Float previous_voltage_; | ||
| }; | ||
| } // namespace hyped::sensors | ||
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.
++count_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.
will fix this, however can you remind me what the reason for this is