Skip to content
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

RSDK-7268 RSDK-7329 Make StreamTicks take in a list of DigitalInterrupts #3816

Merged
merged 16 commits into from
Apr 22, 2024

Conversation

oliviamiller
Copy link
Member

@oliviamiller oliviamiller commented Apr 17, 2024

This covers changing the StreamTicks and RemoveCallback functions to take in a list of interrupts instead of a list of strings, as well as adding the Name function to the digitialInterrupt interface.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Apr 17, 2024
Copy link
Contributor

Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!

component function
base IsMoving
board GPIOPinByName
camera Properties
encoder Properties
motor IsMoving
sensor Readings
servo Position
arm EndPosition
audio MediaProperties
gantry Lengths
gripper IsMoving
input_controller Controls
movement_sensor LinearAcceleration
power_sensor Power
pose_tracker Poses
motion GetPose
vision ClassificationsFromCamera

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 17, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 17, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 17, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 17, 2024
@oliviamiller oliviamiller changed the title Make Stream Ticks take a list of interrupts RSDK-7268 RSDK-7329 Make StreamTicks take in a list of DigitalInterrupts Apr 17, 2024
@oliviamiller oliviamiller marked this pull request as ready for review April 17, 2024 19:06
Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits, but looking really good.

For the server/client implementation, is there any way we could pass in nil objects to the digital interrupt client? By the time we get to stream ticks, the request should have given us all the info for the helper function to populate the struct with everything for value and Name?

Can we add tests for Name in the client/server files, since it is new and introduces a new workflow for using the apis.

@@ -98,6 +98,11 @@ func (i *BasicDigitalInterrupt) RemoveCallback(c chan board.Tick) {
}
}

// Name returns the name of the digital interrupt.
func (i *BasicDigitalInterrupt) Name() string {
return i.cfg.Name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question for the pinwrappers on nil-ness of the config.

@@ -229,7 +238,7 @@ func (s *serviceServer) StreamTicks(
return err
}

defer utils.UncheckedErrorFunc(func() error { return RemoveCallbacks(b, req.PinNames, ticksChan) })
defer utils.UncheckedErrorFunc(func() error { return RemoveCallbacks(b, dis, ticksChan) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! I'm glad this was so changeable.

@@ -229,7 +228,7 @@ func (e *Encoder) Start(ctx context.Context, b board.Board, interrupts []string)

utils.ManagedGo(func() {
// Remove the callbacks added by the interrupt stream.
defer utils.UncheckedErrorFunc(func() error { return board.RemoveCallbacks(b, interrupts, ch) })
defer utils.UncheckedErrorFunc(func() error { return board.RemoveCallbacks(b, []board.DigitalInterrupt{e.A, e.B}, ch) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we now use the Name() function further down in this code instead of also storing the encAName in the encoder struct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure if we can stop storing the encAName due to how its being used in reconfigure. We use the encAName and compare it to the name in the config to check if the name has changed. the Name() function returns the name in the config so we would have no way to know if the name changed without storing it in the struct.

Copy link
Member

@randhid randhid Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets leave it for another pr. Can we compare the config name with the stored pin's name in Reconfigure directly?

Copy link
Member

@penguinland penguinland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! I made these comments yesterday but didn't finish reviewing the rest of the files until this morning.

components/board/board.go Outdated Show resolved Hide resolved
testutils/inject/board.go Show resolved Hide resolved
components/sensor/ultrasonic/ultrasonic.go Outdated Show resolved Hide resolved
components/input/gpio/gpio.go Outdated Show resolved Hide resolved
components/encoder/single/single_encoder.go Outdated Show resolved Hide resolved
components/board/server.go Outdated Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 19, 2024
if err != nil {
return errors.Wrap(err, "error getting digital interrupt ticks")
}

c.activeBackgroundWorkers.Add(1)
utils.ManagedGo(func() {
// Remove the callbacks added by the interrupt stream once we are done.
defer utils.UncheckedErrorFunc(func() error { return board.RemoveCallbacks(brd, []string{intName}, tickChan) })
defer interrupt.RemoveCallback(tickChan)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember we're goign to remove these functions from the digital interrupt interface as per the scope doc, so we shouldn't increase use of them from the main digital interrupt interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rand is right, but removing their use is a separate task for a separate PR. If it's a lot of work right now to fix this, just leave it as-is and fix it later.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 19, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 19, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 19, 2024
Copy link
Member

@penguinland penguinland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

if err != nil {
return errors.Wrap(err, "error getting digital interrupt ticks")
}

c.activeBackgroundWorkers.Add(1)
utils.ManagedGo(func() {
// Remove the callbacks added by the interrupt stream once we are done.
defer utils.UncheckedErrorFunc(func() error { return board.RemoveCallbacks(brd, []string{intName}, tickChan) })
defer interrupt.RemoveCallback(tickChan)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rand is right, but removing their use is a separate task for a separate PR. If it's a lot of work right now to fix this, just leave it as-is and fix it later.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 22, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 22, 2024
@oliviamiller oliviamiller merged commit 961b4a4 into viamrobotics:main Apr 22, 2024
17 checks passed
vijayvuyyuru pushed a commit to vijayvuyyuru/rdk that referenced this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants