Skip to content

[RSDK-10991] Create Go helpers for implementing GetImage if you have GetImages and vice versa #5055

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

hexbabe
Copy link
Member

@hexbabe hexbabe commented Jun 16, 2025

RSDK-10991

Create Go helpers for implementing GetImage if you have GetImages and vice versa

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

@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 Jun 16, 2025
@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 Jun 16, 2025
@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 Jun 16, 2025
@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 Jun 16, 2025
@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 Jun 16, 2025
@hexbabe hexbabe requested a review from seanavery June 16, 2025 19:31
@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 Jun 17, 2025
@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 Jun 17, 2025
@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 Jun 17, 2025
@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 Jun 17, 2025
@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 Jun 17, 2025
@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 Jun 17, 2025
Comment on lines +216 to +225
resBytes, resMetadata, err := cam.Image(ctx, mimeType, nil)
if err != nil {
return nil, resource.ResponseMetadata{}, fmt.Errorf("could not get image bytes from camera: %w", err)
}
if len(resBytes) == 0 {
return nil, resource.ResponseMetadata{}, errors.New("received empty bytes from camera")
}
if resMetadata.MimeType != mimeType {
logger.Warnf("requested mime type %s, but received %s", mimeType, resMetadata.MimeType)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

essentially the same as DecodeImageFromCamera but added the log

@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 Jun 17, 2025
@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 Jun 17, 2025
@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 Jun 17, 2025
@nicksanford
Copy link
Member

This approach will force us to do decodes and encodes. I agree we need this behavior as a fallback but I'm wondering:

If the method we call returns an image.Image that happens to be a LazyImage can we save ourselves some decodes and encodes?

if len(resBytes) == 0 {
return nil, resource.ResponseMetadata{}, errors.New("received empty bytes from camera")
}
if resMetadata.MimeType != mimeType {
Copy link
Member

Choose a reason for hiding this comment

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

should we strip lazy suffix when doing this comparison?

testImg1 := image.NewRGBA(image.Rect(0, 0, 100, 100))
testImg2 := image.NewRGBA(image.Rect(0, 0, 200, 200))

testCam := inject.NewCamera("test_cam")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
testCam := inject.NewCamera("test_cam")
rgbaCam := inject.NewCamera("rgba_cam")

Comment on lines +337 to +340
t.Run("request empty mime type", func(t *testing.T) {
_, _, err := camera.GetImageFromGetImages(context.Background(), nil, "", testCam)
test.That(t, err, test.ShouldBeError, errors.New("could not encode image: do not know how to encode \"\""))
})
Copy link
Member

Choose a reason for hiding this comment

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

this should default to jpeg

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.

5 participants