-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add support for sensor polling at a specific frequency #38
base: master
Are you sure you want to change the base?
Conversation
Current pull request right now has the frequency as a constant once per second, but we're supposed to make it so that each sensor can get polled at different rates right? |
Would having a polling frequency being added into the constructor of Sensor make more sense so it can be variable for each sensor? |
Hi, sorry for the late response. I assumed it was supposed to be a
universal polling frequency that can be called by any sensor.
I set the const long frequency to 1000, which I think is supposed to be
compared to the values in getMillis.
I haven't gone back and fixed the code yet. The current code is calling the
wrong boundary and is crashing. Feel free to make whatever corrections or
changes that you see fit. Although we should clarify the first point with
Kevin.
…On Thu, Dec 3, 2020 at 6:14 PM Matthew Nieva ***@***.***> wrote:
Would having a polling frequency being added into the constructor of
Sensor make more sense so it can be variable for each sensor?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#38 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOJCHDZZNDB4IUZWSY6TV33STBAY5ANCNFSM4T6K5LXA>
.
|
I see that you have updated it with Kevin! Thanks so much for the changes.
Hope everything is resolved now
…On Mon, Dec 7, 2020 at 2:10 PM YuChen Chen ***@***.***> wrote:
Hi, sorry for the late response. I assumed it was supposed to be a
universal polling frequency that can be called by any sensor.
I set the const long frequency to 1000, which I think is supposed to be
compared to the values in getMillis.
I haven't gone back and fixed the code yet. The current code is calling
the wrong boundary and is crashing. Feel free to make whatever corrections
or changes that you see fit. Although we should clarify the first point
with Kevin.
On Thu, Dec 3, 2020 at 6:14 PM Matthew Nieva ***@***.***>
wrote:
> Would having a polling frequency being added into the constructor of
> Sensor make more sense so it can be variable for each sensor?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#38 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AOJCHDZZNDB4IUZWSY6TV33STBAY5ANCNFSM4T6K5LXA>
> .
>
|
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.
A good start! See below:
@@ -29,6 +31,7 @@ namespace spartan { | |||
// Data getters | |||
int getBusID() const; | |||
int getInstance() const; | |||
const long frequency = 1000; |
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.
Just a styling/lint issue: try to keep the indentation the same if possible!
#include "utilis.h" | ||
// Constructor |
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.
Just a styling/lint issue: adding a newline between the include directives and the rest of the source code helps keep the file more readable.
virtual long last_polled() = 0; | ||
virtual unsigned long poll_correct_frequency(); |
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.
Just a styling/lint issue: try to keep the indentation the same if possible!
unsigned long spartan::Sensor::poll_correct_frequency() { | ||
if (getTimeMillis() > last_polled + frequency) { | ||
last_polled = getTimeMillis(); | ||
} | ||
} |
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.
Based on what is shown here, I presume this method is meant to provide the Sensor
child class with the ability to check if it should poll
during this invocation by checking if enough time has passed since the last time it poll
ed the sensor.
This is good! This is needed in some fashion in order to implement the functionality we desire: polling at different frequencies.
Currently, however, there's a few problems:
- I don't seem to see the
last_polled
variable defined anywhere at all in theSensor
abstract based class... this should be resulting in a compilation/build error right now. Perhaps add a private member variable that holds that information? Maybe namedm_last_poll
or something along those lines? - The current name for this method
poll_correct_frequency
I don't think properly reflects the intent of the function in my eyes. If the method's intent is as what I outlined above, then I would think something likeis_poll_ready
... or something along those lines (I actually don't like my name here, so maybe something else 😄 ). - The use of
frequency
might be a bit ambiguous, as we are using it as a "period" of time instead of a "number of polls per unit of time". Perhaps change this name to something likepolling_period
? - This method doesn't actually return any value (needs to return of type
unsigned long
). This should be causing a compilation error.
@@ -29,6 +31,7 @@ namespace spartan { | |||
// Data getters | |||
int getBusID() const; | |||
int getInstance() const; | |||
const long frequency = 1000; |
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.
Specifying this variable that represents the frequency/period of polling should likely not be something we want to be in the public
access section of our base Sensor
class. By doing so, we allow any other portion of the FSW outside of the class to freely modify this frequency for any of the instantiated Sensor
child objects. This could be error-prone, as we expect only the Sensor
class and (potentially) its derived classes to modify this frequency
variable.
In other words, this is something that should only be handled by the internal methods of the Sensor
base class, since we want to ensure that we're manipulating this frequency in an expected and safe manner. At this point, we expect this frequency to be defined by compile-time, and it should be used when instantiating a new object for a Sensor
-derived class. If we want to support run-time frequency changes, we should only allow access of this private member variable through a protected
"setter" method that can be exclusively accessed by Sensor
and its derived classes.
Here's my quick thoughts:
- Move this
frequency
variable frompublic
toprivate
. - Add some accessor functions (you might not even need these depending on how you implement/what we want), including a "getter" and a "setter". Let's just start with the "getter" as
public
, and the "setter" as aprotected
method (this will support potential dynamic frequencies in the future!). - Rename this
frequency
variable to more accurately represent the data it represents (refer to previous comment I made on this review).
@@ -29,6 +31,7 @@ namespace spartan { | |||
// Data getters | |||
int getBusID() const; | |||
int getInstance() const; | |||
const long frequency = 1000; |
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.
Is there a particular reason why we have our "default" value as 1000
milliseconds?
When making some of the other changes I mentioned in this review, remember that we want our Sensor
-derived classes to themselves define their own frequencies... using an initializer list for this would probably be the best option.
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.
Also, the current changes seem to mostly aim to address the first part of what Issue #29's description mentions. Don't forget to take a look at the other portions too!
In summary, this is to properly update the main flight loop in main.cpp
to actually poll the sensors at these desired frequencies, as well as updating the Sensor
-derived classes to obey the new functionality/interface.
Closes #29.