-
Notifications
You must be signed in to change notification settings - Fork 108
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
APP-4940 - Update fake encoder config to have ticks_per_sec
parameter
#3976
APP-4940 - Update fake encoder config to have ticks_per_sec
parameter
#3976
Conversation
components/encoder/fake/encoder.go
Outdated
@@ -69,7 +71,8 @@ func (e *fakeEncoder) Reconfigure( | |||
|
|||
// Config describes the configuration of a fake encoder. | |||
type Config struct { | |||
UpdateRate int64 `json:"update_rate_msec,omitempty"` | |||
UpdateRate int64 `json:"update_rate_msec,omitempty"` | |||
Speed float64 `json:"speed,omitempty"` |
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.
Should this have units? If so, what would they be?
I was thinking about:
Speed float64 `json:"speed,omitempty"` | |
Speed float64 `json:"speed_tpm,omitempty"` |
where tpm means ticks per minute, but I'm not sure if that is clear? (or because it is fake, if speed
is fine)
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.
maybe just ticks_per_sec
, since that kinda matches the guidelines
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.
tpm
wouldn't be obvious to me. I think because it's fake, speed
is fine, in the way that, when you're playing a board game, the units on the currency are often just called "money" ("I will pay 3 money to buy that potion").
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.
Oh, I like John's suggestion! ticks_per_sec
or ticks_per_min
is clearer than tps
or tpm
. My main problem is that ticks
is such a rare unit that I couldn't tell what the t
stood for.
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.
Oh, I really like ticks_per_sec
@JohnN193 . That makes sense to me. Will swap to that (might involve a few other code changes because the rest of this logic is measured in ticks per minute)
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.
Updated in 773457b to ticks_per_sec.
I also changed Speed to ticksPerSec in a few other places
components/encoder/fake/encoder.go
Outdated
@@ -69,7 +71,8 @@ func (e *fakeEncoder) Reconfigure( | |||
|
|||
// Config describes the configuration of a fake encoder. | |||
type Config struct { | |||
UpdateRate int64 `json:"update_rate_msec,omitempty"` | |||
UpdateRate int64 `json:"update_rate_msec,omitempty"` | |||
Speed float64 `json:"speed,omitempty"` |
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.
maybe just ticks_per_sec
, since that kinda matches the guidelines
components/encoder/fake/encoder.go
Outdated
@@ -69,7 +71,8 @@ func (e *fakeEncoder) Reconfigure( | |||
|
|||
// Config describes the configuration of a fake encoder. | |||
type Config struct { | |||
UpdateRate int64 `json:"update_rate_msec,omitempty"` | |||
UpdateRate int64 `json:"update_rate_msec,omitempty"` | |||
Speed float64 `json:"speed,omitempty"` |
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.
Oh, I like John's suggestion! ticks_per_sec
or ticks_per_min
is clearer than tps
or tpm
. My main problem is that ticks
is such a rare unit that I couldn't tell what the t
stood for.
|
||
e.start(ctx) |
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.
Dang, I think this just fixed a bug! ctx
was an argument to this function, and would likely be cancelled by the end of reconfiguration. By switching to a StoppableWorkers
, the context used in the start
function won't be cancelled until someone calls Close
on the component. Thanks!
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.
heh, the two bugs canceled each other out: our background goroutine would shut down unexpectedly early, and then when we don't shut it down during Close
, we don't leak goroutines. Thanks for fixing both these issues! 😂
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.
Agreed -- When I saw these issues, StoppableWorkers
is the first thing that came to mind. Thanks for making it!
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.
I can't look at this today, so requesting changes until I can since I noticed John approved.
Typically attribute additions also go through a scope doc review.
The failed test is an unrelated flaky one. Ping the Jira ticket in the hopes that someone looks at it soon, and retry the tests. |
speed
parameterticks_per_second
parameter
ticks_per_second
parameterticks_per_sec
parameter
components/encoder/fake/encoder.go
Outdated
} | ||
|
||
e.mu.Lock() | ||
e.position += int64(e.ticksPerSec / float64(1000/updateRate)) |
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.
This thing can never go backwards, and would need a dependency on motor to figure out if it would have to. Needs a bit of thought.
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.
this is the same behavior as speed
from before though right? we can pass in a negative ticksPerSec
as well. Additionally this is still a fake encoder, not intended to be used with a real motor iirc
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.
They used to be. Right now, we can do this since we needed the fake encoder from gpio motor's encoded_motor_tests; it used to be that the tests called SetSpeed
directly use the encoder in tests. I think if we're going to add functionality, we should think a bit more about this, maybe migrate the SetSpeed and SetPosition to DoCommands to be cleaner? That we it's more representative of an actual encoder.
components/encoder/fake/encoder.go
Outdated
@@ -69,7 +71,8 @@ func (e *fakeEncoder) Reconfigure( | |||
|
|||
// Config describes the configuration of a fake encoder. | |||
type Config struct { | |||
UpdateRate int64 `json:"update_rate_msec,omitempty"` | |||
UpdateRate int64 `json:"update_rate_msec,omitempty"` | |||
TicksPerSec float64 `json:"ticks_per_sec,omitempty"` |
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.
Instead of this - and dealing with the zero default value that will have the driver stall, let's do a non-user facing default speed value at the top of this file.
You can also use the update rate multiplied by a default constant if you prefer.
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.
I don't think this pr should change the default behavior of fake encoders, that would require changing more of the tests.
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.
I don't think the tests are testing with any encoder functionality from a cursory look, so it can just be changed in the fake motor and gpio motor tests to injects.
@zaporter-work, if you need a fake encoder, I can make and upload one to my fake modules module, as an alternative to more work on this one. |
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.
Okay, @JohnN193 convinced me - add a warning in Reconfigure to tell you that the encoder will do nothing if the speed is 0, and counts up if the speed is positive, counts down if the speed is negative.
(rand and I talked a bit offline -- deleted speed. Plan to wait for at least tomorrow to let this sit and we can ponder if we like this idea) |
// Close safely shuts down the fake encoder. | ||
func (e *fakeEncoder) Close(ctx context.Context) error { | ||
e.mu.Lock() | ||
defer e.mu.Unlock() |
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.
No need to lock the mutex: it protects the position, updateRate, and similar things, but we're not using any of those. e.workers.Stop()
is already atomic, protected by its own internal mutex.
After talking with my team a bit more, I think I've come to realize that the viz team goals might not be aligned with the goals of the fakes. I've realized that we also probably want fake encoder to support position in degrees and probably have 1-2 other config params. As it is, I am opposed to merging this because I don't think it solves a concrete problem (because we still need more params) and it changes the behavior of the fake motor & leaves the user with no way to stop the encoder from ticking upwards. I think it makes a lot more sense for us to independently develop some stub components in a module that fit our needs and then in a few months, we can decide if we (as a company) want to incorporate those changes back into the fakes. Thank you everyone for your time. I really deeply appreciate it. If anyone wants to take any of this code and use it in a future PR, please don't let me closing this discourage that. I am closing this partially because I am not confident that I am the right person to be making these changes. |
Useful for viz team config testing: https://viam.atlassian.net/browse/APP-4940
New proposed config for a fake encoder:
I also changed this to use a StoppableWorkers group because there was a subtle bug with the context being canceled too early