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-7335] Remove Close() from and Add Write() to Analog interface in board #3809

Merged
merged 6 commits into from
Apr 18, 2024

Conversation

randhid
Copy link
Member

@randhid randhid commented Apr 16, 2024

Removes the Close function from the analog interface, changes implementation of the raspberry pi to directly use the analog smoother rather than store it as a board.Analog in its struct.

Note: I have only implemented the Write method on the interface in the analog struct in board.go. This function does not yet go through the server or client in th main board file, which was ticketed separately. That will need to go over the wire using the WriteAnalog rpc.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Apr 16, 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

@randhid randhid changed the title [RSDK-XXXX] Remove Close() from Analog interface in board [RSDK-7335] Remove Close() from Analog interface in board Apr 16, 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 16, 2024
@@ -360,16 +360,16 @@ type analog struct {
pin string
}

func (ar *analog) Read(ctx context.Context, extra map[string]interface{}) (int, error) {
res, err := ar.b.doSendReceive(ctx, fmt.Sprintf("adc read %s", ar.pin))
func (a *analog) Read(ctx context.Context, extra map[string]interface{}) (int, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I think the numato code can either not use the analog smoother or implement a Close more gracefully. We'll handle this driver in our next bug bash.

@@ -65,3 +66,7 @@ func (mar *MCP3008AnalogReader) Read(ctx context.Context, extra map[string]inter
func (mar *MCP3008AnalogReader) Close(ctx context.Context) error {
return nil
}

func (mar *MCP3008AnalogReader) Write(ctx context.Context, value int, extra map[string]interface{}) error {
Copy link
Member Author

Choose a reason for hiding this comment

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

The current flow for the pi/generic linux:

  • make a MCP3008 analog helper,
  • pass that into AnalogSMoother, it needs Close function implemented.
  • use that analog smoother to fulfill the Read and Write methods in analog for board's Analog struct.

This can probably be better. Probably by obliterating it.

@randhid randhid changed the title [RSDK-7335] Remove Close() from Analog interface in board [RSDK-7335] Remove Close() from and Add Write() to Analog interface in board Apr 16, 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 16, 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.

I think it's important to continue storing the interface instead of a specific implementation of it. The rest LGTM

components/board/pi/impl/board.go Show resolved Hide resolved
testutils/inject/analog.go Outdated Show resolved Hide resolved

// Write calls the injected Write or the real version.
func (a *Analog) Write(ctx context.Context, value int, extra map[string]interface{}) error {
a.readCap = []interface{}{ctx}
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the documentation you left for WriteCap, I suspect we should also store the value here.

...though TBH I don't understand when you'd ever need to call WriteCap() or ReadCap() and don't really get why this code exists at all. The one use of ReadCap in our codebase is used to assert that the context passed into a function really is the context passed in, which seems like kind of a useless test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not going to change the pattern of inject implementations as part of this pr. They could probably be better, but they do their job of injecting interfaces for testing, and I'm happy with that.

Copy link
Member

Choose a reason for hiding this comment

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

I did not mean to change the pattern; I don't think you're following the pre-existing pattern here. For example, in testutils/inject/gpio_pin.go, the captures store all of the arguments except extra, which would include storing value here.

I wonder if there's some other reason not to store value and to set things up the way you did, but I don't see that reason myself, partly because I don't understand why the pattern has been set up this way in the first place.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I see, no you're right, we should store value here. tbh I do think our injects could be better. The Cap functions are usually to capture the input arguments to the injected function to be checked against in server-client code tests. But to be frank our team almost never has a need to use the Cap functions in testing the drivers, because we care about testing the behaviour of inputs not validating that we've sent the inputs. The Cap functions are usually used in server tests for resource APIs.

... the inject package could be better and lessconfusing overall, maybe one day.

components/board/numato/board.go Show resolved Hide resolved
components/board/client.go Show resolved Hide resolved
testutils/inject/analog.go Outdated Show resolved Hide resolved
testutils/inject/analog.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 17, 2024
@randhid randhid requested a review from penguinland April 17, 2024 23:31
testutils/inject/analog.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 18, 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!

@randhid randhid merged commit 8e74013 into viamrobotics:main Apr 18, 2024
16 checks passed
vijayvuyyuru pushed a commit to vijayvuyyuru/rdk that referenced this pull request Apr 22, 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