From b076b77d09f64581f48d28a03126b68d65e9639b Mon Sep 17 00:00:00 2001 From: sky leilani <45158875+skyleilani@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:09:21 -0400 Subject: [PATCH 1/6] Add camera, gantry, and encoder snippets --- components/camera/camera.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/components/camera/camera.go b/components/camera/camera.go index f59861c136a..f2f48970fbf 100644 --- a/components/camera/camera.go +++ b/components/camera/camera.go @@ -88,17 +88,45 @@ type VideoSource interface { projectorProvider // Images is used for getting simultaneous images from different imagers, // along with associated metadata (just timestamp for now). It's not for getting a time series of images from the same imager. + // + // myCamera, err := camera.FromRobot(robot, "my_camera") + // + // images, metadata, err := myCamera.Images(context.Background()) Images(ctx context.Context) ([]NamedImage, resource.ResponseMetadata, error) // Stream returns a stream that makes a best effort to return consecutive images // that may have a MIME type hint dictated in the context via gostream.WithMIMETypeHint. + // + // myCamera, err := camera.FromRobot(robot, "my_camera") + // + // // gets the stream from a camera + // stream, err := myCamera.Stream(context.Background()) + // + // // gets an image from the camera stream + // img, release, err := stream.Next(context.Background()) + // defer release() Stream(ctx context.Context, errHandlers ...gostream.ErrorHandler) (gostream.VideoStream, error) // NextPointCloud returns the next immediately available point cloud, not necessarily one // a part of a sequence. In the future, there could be streaming of point clouds. + // + // myCamera, err := camera.FromRobot(robot, "my_camera") + // + // pointCloud, err := myCamera.NextPointCloud(context.Background()) NextPointCloud(ctx context.Context) (pointcloud.PointCloud, error) // Properties returns properties that are intrinsic to the particular // implementation of a camera + // + // myCamera, err := camera.FromRobot(robot, "my_camera") + // + // // gets the properties from a camera + // properties, err := myCamera.Properties(context.Background()) Properties(ctx context.Context) (Properties, error) + + // Close shuts down the resource and prevents further use + // + // myCamera, err := camera.FromRobot(robot, "my_camera") + // + // err := myCamera.Close(ctx) Close(ctx context.Context) error } From 304b201c8ad6417db3f2a7aee3c2f970164f0ce9 Mon Sep 17 00:00:00 2001 From: sky leilani <45158875+skyleilani@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:12:48 -0400 Subject: [PATCH 2/6] Add gantry --- components/gantry/gantry.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/components/gantry/gantry.go b/components/gantry/gantry.go index de2eee803ab..e879472455d 100644 --- a/components/gantry/gantry.go +++ b/components/gantry/gantry.go @@ -48,16 +48,40 @@ type Gantry interface { referenceframe.InputEnabled // Position returns the position in meters + // + // myGantry, err := gantry.FromRobot(robot, "my_gantry") + // + // // Get the current positions of the axes of the gantry in millimeters. + // position, err := myGantry.Position(context.Background(), nil) Position(ctx context.Context, extra map[string]interface{}) ([]float64, error) // MoveToPosition is in meters // This will block until done or a new operation cancels this one + // + // myGantry, err := gantry.FromRobot(robot, "my_gantry") + // + // // Create a list of positions for the axes of the gantry to move to. Assume in this example that the gantry is multi-axis, with 3 axes. + // examplePositions = []float64{1, 2, 3} + // + // exampleSpeeds = []float64{3, 9, 12} + // + // // Move the axes of the gantry to the positions specified. + // myGantry.MoveToPosition(context.Background(), examplePositions, exampleSpeeds, nil) MoveToPosition(ctx context.Context, positionsMm, speedsMmPerSec []float64, extra map[string]interface{}) error // Lengths is the length of gantries in meters + // + // myGantry, err := gantry.FromRobot(robot, "my_gantry") + // + // // Get the lengths of the axes of the gantry in millimeters. + // lengths_mm, err := myGantry.Lengths(context.Background(), nil) Lengths(ctx context.Context, extra map[string]interface{}) ([]float64, error) // Home runs the homing sequence of the gantry and returns true once completed + // + // myGantry, err := gantry.FromRobot(robot, "my_gantry") + // + // myGantry.Home(context.Background(), nil) Home(ctx context.Context, extra map[string]interface{}) (bool, error) } From 15835d0228930dae2bee4363488aee4067dd98dd Mon Sep 17 00:00:00 2001 From: sky leilani <45158875+skyleilani@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:16:05 -0400 Subject: [PATCH 3/6] Add encoder code snippet --- components/encoder/encoder.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/encoder/encoder.go b/components/encoder/encoder.go index 46e49863f94..157e7ae6861 100644 --- a/components/encoder/encoder.go +++ b/components/encoder/encoder.go @@ -62,12 +62,32 @@ type Encoder interface { resource.Resource // Position returns the current position in terms of ticks or degrees, and whether it is a relative or absolute position. + // + // myEncoder, err := encoder.FromRobot(robot, "my_encoder") + // if err != nil { + // logger.Fatalf("cannot get encoder: %v", err) + // } + // + // // Get the position of the encoder in ticks + // position, posType, err := myEncoder.Position(context.Background(), encoder.PositionTypeTicks, nil) Position(ctx context.Context, positionType PositionType, extra map[string]interface{}) (float64, PositionType, error) // ResetPosition sets the current position of the motor to be its new zero position. + // + // myEncoder, err := encoder.FromRobot(robot, "my_encoder") + // if err != nil { + // logger.Fatalf("cannot get encoder: %v", err) + // } + // + // err := myEncoder.ResetPosition(context.Background(), nil) ResetPosition(ctx context.Context, extra map[string]interface{}) error // Properties returns a list of all the position types that are supported by a given encoder + // + // myEncoder, err := encoder.FromRobot(robot, "my_encoder") + // + // // Get whether the encoder returns position in ticks or degrees. + // properties, err := myEncoder.Properties(context.Background(), nil) Properties(ctx context.Context, extra map[string]interface{}) (Properties, error) } From dbebc006d28afbc8a0115ab9bcbcf5ea09ced3bb Mon Sep 17 00:00:00 2001 From: sky leilani <45158875+skyleilani@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:29:28 -0400 Subject: [PATCH 4/6] fix formatting --- components/gantry/gantry.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/gantry/gantry.go b/components/gantry/gantry.go index e879472455d..a50ead4c6e6 100644 --- a/components/gantry/gantry.go +++ b/components/gantry/gantry.go @@ -60,7 +60,8 @@ type Gantry interface { // // myGantry, err := gantry.FromRobot(robot, "my_gantry") // - // // Create a list of positions for the axes of the gantry to move to. Assume in this example that the gantry is multi-axis, with 3 axes. + // // Create a list of positions for the axes of the gantry to move to. + // // Assume in this example that the gantry is multi-axis, with 3 axes. // examplePositions = []float64{1, 2, 3} // // exampleSpeeds = []float64{3, 9, 12} From cf8805196ded31b865ae220a06f813dca63299aa Mon Sep 17 00:00:00 2001 From: sky leilani <45158875+skyleilani@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:45:06 -0400 Subject: [PATCH 5/6] fix whitespace --- components/gantry/gantry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/gantry/gantry.go b/components/gantry/gantry.go index a50ead4c6e6..149486e8cc5 100644 --- a/components/gantry/gantry.go +++ b/components/gantry/gantry.go @@ -67,7 +67,7 @@ type Gantry interface { // exampleSpeeds = []float64{3, 9, 12} // // // Move the axes of the gantry to the positions specified. - // myGantry.MoveToPosition(context.Background(), examplePositions, exampleSpeeds, nil) + // myGantry.MoveToPosition(context.Background(), examplePositions, exampleSpeeds, nil) MoveToPosition(ctx context.Context, positionsMm, speedsMmPerSec []float64, extra map[string]interface{}) error // Lengths is the length of gantries in meters From 83656a204050c1dc4f6b5000b9c47815e3d9ede9 Mon Sep 17 00:00:00 2001 From: sky leilani <45158875+skyleilani@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:46:05 -0400 Subject: [PATCH 6/6] review code snippets --- components/camera/camera.go | 12 ++++++------ components/encoder/encoder.go | 8 ++++---- components/gantry/gantry.go | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/camera/camera.go b/components/camera/camera.go index f2f48970fbf..d2a3eb9cfb8 100644 --- a/components/camera/camera.go +++ b/components/camera/camera.go @@ -89,14 +89,14 @@ type VideoSource interface { // Images is used for getting simultaneous images from different imagers, // along with associated metadata (just timestamp for now). It's not for getting a time series of images from the same imager. // - // myCamera, err := camera.FromRobot(robot, "my_camera") + // myCamera, err := camera.FromRobot(machine, "my_camera") // // images, metadata, err := myCamera.Images(context.Background()) Images(ctx context.Context) ([]NamedImage, resource.ResponseMetadata, error) // Stream returns a stream that makes a best effort to return consecutive images // that may have a MIME type hint dictated in the context via gostream.WithMIMETypeHint. // - // myCamera, err := camera.FromRobot(robot, "my_camera") + // myCamera, err := camera.FromRobot(machine, "my_camera") // // // gets the stream from a camera // stream, err := myCamera.Stream(context.Background()) @@ -109,14 +109,14 @@ type VideoSource interface { // NextPointCloud returns the next immediately available point cloud, not necessarily one // a part of a sequence. In the future, there could be streaming of point clouds. // - // myCamera, err := camera.FromRobot(robot, "my_camera") + // myCamera, err := camera.FromRobot(machine, "my_camera") // // pointCloud, err := myCamera.NextPointCloud(context.Background()) NextPointCloud(ctx context.Context) (pointcloud.PointCloud, error) // Properties returns properties that are intrinsic to the particular // implementation of a camera // - // myCamera, err := camera.FromRobot(robot, "my_camera") + // myCamera, err := camera.FromRobot(machine, "my_camera") // // // gets the properties from a camera // properties, err := myCamera.Properties(context.Background()) @@ -124,9 +124,9 @@ type VideoSource interface { // Close shuts down the resource and prevents further use // - // myCamera, err := camera.FromRobot(robot, "my_camera") + // myCamera, err := camera.FromRobot(machine, "my_camera") // - // err := myCamera.Close(ctx) + // err = myCamera.Close(ctx) Close(ctx context.Context) error } diff --git a/components/encoder/encoder.go b/components/encoder/encoder.go index 157e7ae6861..bbf5d4708e9 100644 --- a/components/encoder/encoder.go +++ b/components/encoder/encoder.go @@ -63,7 +63,7 @@ type Encoder interface { // Position returns the current position in terms of ticks or degrees, and whether it is a relative or absolute position. // - // myEncoder, err := encoder.FromRobot(robot, "my_encoder") + // myEncoder, err := encoder.FromRobot(machine, "my_encoder") // if err != nil { // logger.Fatalf("cannot get encoder: %v", err) // } @@ -74,17 +74,17 @@ type Encoder interface { // ResetPosition sets the current position of the motor to be its new zero position. // - // myEncoder, err := encoder.FromRobot(robot, "my_encoder") + // myEncoder, err := encoder.FromRobot(machine, "my_encoder") // if err != nil { // logger.Fatalf("cannot get encoder: %v", err) // } // - // err := myEncoder.ResetPosition(context.Background(), nil) + // err = myEncoder.ResetPosition(context.Background(), nil) ResetPosition(ctx context.Context, extra map[string]interface{}) error // Properties returns a list of all the position types that are supported by a given encoder // - // myEncoder, err := encoder.FromRobot(robot, "my_encoder") + // myEncoder, err := encoder.FromRobot(machine, "my_encoder") // // // Get whether the encoder returns position in ticks or degrees. // properties, err := myEncoder.Properties(context.Background(), nil) diff --git a/components/gantry/gantry.go b/components/gantry/gantry.go index 149486e8cc5..2eba1026638 100644 --- a/components/gantry/gantry.go +++ b/components/gantry/gantry.go @@ -49,7 +49,7 @@ type Gantry interface { // Position returns the position in meters // - // myGantry, err := gantry.FromRobot(robot, "my_gantry") + // myGantry, err := gantry.FromRobot(machine, "my_gantry") // // // Get the current positions of the axes of the gantry in millimeters. // position, err := myGantry.Position(context.Background(), nil) @@ -58,13 +58,13 @@ type Gantry interface { // MoveToPosition is in meters // This will block until done or a new operation cancels this one // - // myGantry, err := gantry.FromRobot(robot, "my_gantry") + // myGantry, err := gantry.FromRobot(machine, "my_gantry") // // // Create a list of positions for the axes of the gantry to move to. // // Assume in this example that the gantry is multi-axis, with 3 axes. - // examplePositions = []float64{1, 2, 3} + // examplePositions := []float64{1, 2, 3} // - // exampleSpeeds = []float64{3, 9, 12} + // exampleSpeeds := []float64{3, 9, 12} // // // Move the axes of the gantry to the positions specified. // myGantry.MoveToPosition(context.Background(), examplePositions, exampleSpeeds, nil) @@ -72,7 +72,7 @@ type Gantry interface { // Lengths is the length of gantries in meters // - // myGantry, err := gantry.FromRobot(robot, "my_gantry") + // myGantry, err := gantry.FromRobot(machine, "my_gantry") // // // Get the lengths of the axes of the gantry in millimeters. // lengths_mm, err := myGantry.Lengths(context.Background(), nil) @@ -80,7 +80,7 @@ type Gantry interface { // Home runs the homing sequence of the gantry and returns true once completed // - // myGantry, err := gantry.FromRobot(robot, "my_gantry") + // myGantry, err := gantry.FromRobot(machine, "my_gantry") // // myGantry.Home(context.Background(), nil) Home(ctx context.Context, extra map[string]interface{}) (bool, error)