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

DOCS-1527,DOCS-1594: Refactor Module create page #2401

Merged

Conversation

andf-viam
Copy link
Contributor

@andf-viam andf-viam commented Jan 17, 2024

Refactor Create a Module page based on user feedback from several sources:

  • Apply feedback from three discrete sources, listed below, plus my own awareness of "what's changed since" (example: second object in object triplet has changed context)
  • Expanded seealso: examples section
  • IA considerations, including:
    • Valid APIs to implement moved off-page, to parent /registry/ overview page for now.
    • Naming your model moved off-page, to parent /registry/ overview page for now.
    • (Work on find/search/add/configure a module is for a different PR where I will quite possibly revisit placement of the above two.)

Feedback addressed in this PR:

  • (no need to read this section unless interested in what specifically was implemented, or if you were a provider of feedback and want to make sure I captured your sentiments!)
  • DOCS-1527: C++ SDK team desire to focus on extend existing API, using base API as example
    • client/server language removed.
    • all examples standardized on base example, no "your module here" or other placeholders.
  • DOCS-1527: Hazal's feedback:
    • Where to add your model triplet now explicit, per language
    • Valid API moved off-page, unique cases removed from middle of procedure, and only mentioned briefly in intro.
    • Refactored headers so that steps to perform are clearer, without duplicating concepts (create > create > create)
    • Significant clarifications to creating your model triplet, thank you Hazal, great points!!
      • Matt: this changed: Viam used to desire that the second object in the triplet was a conceptual representation of the common ground between your one (or more) models (like yahboom for both yahboom gripper and yahboom arm), but eng has recently landed on repo name instead. I removed all "like concept" stuff and focused only on repo name.
    • Links to off-docs repos as code examples now much simplified, so as to not hint that repo readmes are part of the module creation process. Hazal: you right!
    • Updated comment to go resource path go.viam.com/rdk/examples/customresources/models/mybase to better reflect what we're doing here. Thanks!
    • Now mentioning go.mod and go.sum with some minimal context. They are not part of module (Viam-module not Go-module) development directly, but will be seen by those inspecting other, published Go Viam modules (Go Viam!!). Good idea to include, thanks!
    • Confusion around what to do with module addressed with new Deploy section: local for Hazal's use, upload for Registry use. We should not detail meta.json or executable path here, that's for the linked pages which provide that info in full context to its usage.
  • DOCS-1594: Nick's feedback:
    • Constituent project files laid out directly, in intro. Right on, solid feedback Nick, thank you!
    • As with Hazal's comment on this topic: valid APIs to implement moved off-page for now. Does not belong mid-procedure. Will find the right place for it when I refactor find/search/add/configure a module section next.
    • Create a custom module now the first actionable step after intro. Bolded instruction to this affect warranted, this is a big one, agreed. Thank you!
    • HOWEVER: opted not to use generic as example because:
      • We don't yet have a generic service, Zach on it.
      • Most users, per eng SDK devs I talked to, are expected to desire to extend Viam support to new hardware that relatively closely matches an existing conceptual component.
      • if we showcase generic only, users will implement dupe functionality when they go to use generic to describe their own new gripper, when they could save time and effort by re-using most existing upstream gripper methods and just adding the new one they need, or the specific driver implementation for the new hardware they're plugging in -- which likely only needs exactly the same methods as provided upstream in the built-in gripper API for example.
      • However however, we definitely need a robust generic API example workflow as well, agreed (not in replacement though). So, when we have a generic service live, I will return to this and see if I can add a full Create a Module > Using the Generic API walkthrough, so users can select the best fit for them. I will indeed use it as teaching opportunity for "a module, all modules, include these basic building blocks" because you are correct generic you'd have to code them all, and therefore learn their utility in context to their use. Spot on, for the next effort -- will do & thank you!
      • Standardized filenames throughout for all languages
      • Clarified model namespace triplet design to land on repo-name over "conceptual parent concept", c.f. Hazal's feedback regarding same.
      • Standardized entry point file and main program, unfortunately, as both: Entry point (main program) file because users might be looking for either: Literal main.cpp program file with main() program (it's in the name) vs. entry point (for the module, from perspective of viam-server), common phrasing for, say, NPM. Subsequent references within-same-section use shortened entry point file. Open to feedback if both is too much, ofc.
      • Better phrasing around next steps: add a module via registry | local, right on!
      • Greatly expanded python virtual env three options with considerations of why you might want to pick one over the other, thank you!
      • Better clarity around: test your module via local (by way of Next Steps), or upload to the registry for all users.
      • Logs section moved to between model definition and main program sections. Rationale:
        • Useable in either, so between them (feedback was: after both, too far from shown example code that uses)
        • Demonstrated in sample code for model definition already, so should be placed right after.
        • New tip to indicate that said code is already included in model definition code samples above.
      • Added a link to the boost trivial logger docs, thanks!

Questions:

  • Did I get 'method' v 'function', and 'class' v 'package' correct per language (I think so!)

TODO:

@viambot viambot added the safe to build This pull request is marked safe to build from a trusted zone label Jan 17, 2024
@viambot
Copy link
Member

viambot commented Jan 17, 2024

Overall readability score: 55.83 (🟢 +0.01)

File Readability
model-namespace-triplet.md 25.51 (🟢 +0)
model.md 31.71 (🟢 +0)
resource.md 6.36 (🟢 +0)
cli.md 63.96 (🟢 +0)
_index.md 44.6 (🟢 +1.62)
create-subtype.md 61.23 (🟢 +0)
custom-components-remotes.md 56.48 (🟢 +0)
configure.md 65.81 (🟢 +0)
_index.md 53.19 (🟢 +2.22)
custom-arm.md 51.87 (🟢 +0)
_index.md 64.87 (🟢 +0.49)
pet-photographer.md 59.74 (🟢 +0.17)
controlling-an-intermode-rover-canbus.md 56.21 (🟢 +0)
View detailed metrics

🟢 - Shows an increase in readability
🔴 - Shows a decrease in readability

File Readability FRE GF ARI CLI DCRS
model-namespace-triplet.md 25.51 22.07 11.37 17.1 18.39 10.75
  🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0
model.md 31.71 23.02 12.84 15.6 15.71 9.94
  🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0
resource.md 6.36 0 16 22 19 10.62
  🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0
cli.md 63.96 42.61 9.44 13.1 11.26 5.81
  🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0
_index.md 44.6 28.03 10.43 16.6 15.19 7.25
  🟢 +1.62 🟢 +1.02 🟢 +0.56 🟢 +0.2 🔴 -0.22 🟢 +0.16
create-subtype.md 61.23 40.24 8.38 12.5 12.52 6.82
  🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0
custom-components-remotes.md 56.48 49.45 11.84 13.4 10.79 7.28
  🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0
configure.md 65.81 45.46 8.42 12.8 12.06 5.71
  🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0
_index.md 53.19 38.25 11.33 15.9 12.54 6.1
  🟢 +2.22 🟢 +5.72 🔴 -0.89 🟢 +0.7 🟢 +1.04 🟢 +0.1
custom-arm.md 51.87 40.89 11.99 14.7 11.78 7.17
  🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0
_index.md 64.87 43.73 9.25 12.2 11.31 6.07
  🟢 +0.49 🔴 -0.51 🔴 -0.1 🟢 +0.1 🟢 +0.29 🟢 +0.06
pet-photographer.md 59.74 43.53 9.65 13.9 12.53 6.14
  🟢 +0.17 🟢 +0 🟢 +0.03 🟢 +0 🟢 +0.06 🟢 +0.01
controlling-an-intermode-rover-canbus.md 56.21 41.6 11.25 13.5 11.49 6.92
  🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0 🟢 +0

Averages:

  Readability FRE GF ARI CLI DCRS
Average 55.83 47.72 10.58 13.14 12.1 7.61
  🟢 +0.01 🟢 +0.02 🟢 +0 🟢 +0 🟢 +0 🟢 +0
View metric targets
Metric Range Ideal score
Flesch Reading Ease 100 (very easy read) to 0 (extremely difficult read) 60
Gunning Fog 6 (very easy read) to 17 (extremely difficult read) 8 or less
Auto. Read. Index 6 (very easy read) to 14 (extremely difficult read) 8 or less
Coleman Liau Index 6 (very easy read) to 17 (extremely difficult read) 8 or less
Dale-Chall Readability 4.9 (very easy read) to 9.9 (extremely difficult read) 6.9 or less

@andf-viam andf-viam force-pushed the DOCS-1527-refactor-create-module branch 9 times, most recently from 71740a2 to b6acca3 Compare January 19, 2024 18:17
@andf-viam andf-viam marked this pull request as ready for review January 19, 2024 18:19
@andf-viam andf-viam force-pushed the DOCS-1527-refactor-create-module branch from b6acca3 to e841a65 Compare January 19, 2024 18:21
@andf-viam andf-viam force-pushed the DOCS-1527-refactor-create-module branch from e841a65 to d0f8b25 Compare January 19, 2024 19:31
Copy link
Collaborator

@npentrel npentrel left a comment

Choose a reason for hiding this comment

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

This looks good to me but I suggest you get Nick's and Hazal's review


For example:

- The `rand:yahboom:arm` model and the `rand:yahboom:gripper` model uses the repository name [yahboom](https://github.com/viam-labs/yahboom).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- The `rand:yahboom:arm` model and the `rand:yahboom:gripper` model uses the repository name [yahboom](https://github.com/viam-labs/yahboom).
- The `rand:yahboom:arm` model and the `rand:yahboom:gripper` model use the repository name [yahboom](https://github.com/viam-labs/yahboom).

}
```

- The `viam-labs:audioout:pygame` model uses the repository name [audioout](https://github.com/viam-labs/audioout)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- The `viam-labs:audioout:pygame` model uses the repository name [audioout](https://github.com/viam-labs/audioout)
- The `viam-labs:audioout:pygame` model uses the repository name [audioout](https://github.com/viam-labs/audioout).

]
description: "Use the Viam module system to implement modular resources that can be included in any Viam-powered machine."
description: "Create a module to provide a new modular resource to your Viam machine."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
description: "Create a module to provide a new modular resource to your Viam machine."
description: "Create a module to provide a new modular resource to your machine."

aliases:
- "/extend/modular-resources/create/"
- "/modular-resources/create/"
no_list: true
---

Viam provides built-in support for a variety of different {{< glossary_tooltip term_id="component" text="components" >}} and {{< glossary_tooltip term_id="service" text="services" >}}, but you can also add support for unsupported resources by creating a module.
A _module_ provides one or more {{< glossary_tooltip term_id="modular-resource" text="modular resources" >}}, which add support for {{< glossary_tooltip term_id="resource" text="resource" >}} {{< glossary_tooltip term_id="type" text="types" >}} or {{< glossary_tooltip term_id="model" text="models" >}} that are not built into Viam.
Viam provides built-in support for a variety of different {{< glossary_tooltip term_id="component" text="components" >}} and {{< glossary_tooltip term_id="service" text="services" >}} -- collectively called {{< glossary_tooltip term_id="resource" text="resources" >}} -- but you might want to use Viam with a new component type or service model that isn't currently supported.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not a huge fan of the interjecting additional information with dashes thing. I think that's generally frowned upon. Maybe we can split it into 2 sentences instead?

Viam provides built-in support for a variety of different {{< glossary_tooltip term_id="component" text="components" >}} and {{< glossary_tooltip term_id="service" text="services" >}}, but you can also add support for unsupported resources by creating a module.
A _module_ provides one or more {{< glossary_tooltip term_id="modular-resource" text="modular resources" >}}, which add support for {{< glossary_tooltip term_id="resource" text="resource" >}} {{< glossary_tooltip term_id="type" text="types" >}} or {{< glossary_tooltip term_id="model" text="models" >}} that are not built into Viam.
Viam provides built-in support for a variety of different {{< glossary_tooltip term_id="component" text="components" >}} and {{< glossary_tooltip term_id="service" text="services" >}} -- collectively called {{< glossary_tooltip term_id="resource" text="resources" >}} -- but you might want to use Viam with a new component type or service model that isn't currently supported.
To extend support to these resources, you can create a {{< glossary_tooltip term_id="module" text="module" >}}.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know what this sentence is supposed to mean. Maybe?

Suggested change
To extend support to these resources, you can create a {{< glossary_tooltip term_id="module" text="module" >}}.
If the existing resources do not support your hardware or service requirements, you can create a {{< glossary_tooltip term_id="module" text="module" >}}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying something different, LMK what you think.


Find the subtype API as defined in the relevant <file>components/\<resource-name\>/\<resource-name>\.hpp</file> or <file>services/\<resource-name\>/<resource-name>.hpp</file> implementation (header) file in the [C++ SDK](https://github.com/viamrobotics/viam-cpp-sdk/).
{{% alert title=Note color="note" %}}
If you want to write a module to extend support to a new type of component that is relatively unique, and doesn't readily correspond to an existing [built-in component API](/build/program/apis/#component-apis), you may want to consider using the [generic API](/components/generic/) with your module instead of extending an existing API.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
If you want to write a module to extend support to a new type of component that is relatively unique, and doesn't readily correspond to an existing [built-in component API](/build/program/apis/#component-apis), you may want to consider using the [generic API](/components/generic/) with your module instead of extending an existing API.
If you want to write a module to extend support to a new type of component that is relatively unique, and doesn't readily correspond to an existing [built-in component API](/build/program/apis/#component-apis), consider using the [generic API](/components/generic/) with your module instead of extending an existing API.


Use the naming schema: `namespace:repo-name:name`.
For example, if you want to add support for a new [base component](/components/base/) to Viam, you would start by looking at the built-in base component class.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Grammar: If sentences that use conditional clauses must use past tense (simple past or past perfect) in the if-clause of the sentence


Create a folder for your module and save your code as a file named <file>my_modular_resource.go</file> inside.
For example, if you want to add support for a new [base component](/components/base/) to Viam, you would start by looking at the built-in base component package.
Copy link
Collaborator

Choose a reason for hiding this comment

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

grammar (see above)

@andf-viam
Copy link
Contributor Author

andf-viam commented Jan 19, 2024

Hi @mestcihazal and @HipsterBrown -- I've refactored our module creation documentation based on yours and others' feedback -- I'd love a quick read-through from one of you to confirm that this addressed your points! Happy to hear any feedback, and make changes as needed! Thanks so much!

And thanks so much, both of you, for the great feedback that spurred this effort on!

Copy link
Contributor

@HipsterBrown HipsterBrown left a comment

Choose a reason for hiding this comment

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

One non-blocking open question, otherwise this is a great improvement over the current "Create" docs. Thanks for the awesome refactor! 👏


{{< tabs >}}
{{% tab name="Python" %}}
While you can certainly combine the resource model definition and the main program code into a single file if desired (for example, a single `main.py` program that includes both the model definition and the `main()` program that uses it), this guide will use separate files for each.
Copy link
Contributor

Choose a reason for hiding this comment

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

this guide will use separate files for each

Do we have a reason for this that we can share? Is it for clarity or separation of concerns?

Copy link
Contributor Author

@andf-viam andf-viam Jan 22, 2024

Choose a reason for hiding this comment

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

Theory: The latter, great insight. My thinking:

  • Keeping a clear path forward from concept to concept, as much as we can here.
  • While some of our most simple examples across our repos do use one file for both 1 and 2, all of the more complicated ones use two. Starting with this file structure from the beginning might set users up for success when they later transition to module design that accomplishes more complicated tasks, like a component and a service working together.
  • This also helps us to demonstrate including other files and referencing the methods/functions contained within them.

Practice: But, mostly, at the end of the day: our existing sample code for all three languages was split in this fashion. Refactoring to a single file for each would be much work, and for minimal gain.

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

Two small notes, nothing that need be blocking on merging!

Comment on lines 553 to 554
| [components/base/base.cpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/base/base.cpp) | Defines the specific functionality of the built-in `Base` class. |
| [components/base/base.hpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/base/base.hpp) | Defines the implementation of functionality defined in `base.cpp`, which includes the declaration of several built-in functions such as `move_straight()`. |
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
| [components/base/base.cpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/base/base.cpp) | Defines the specific functionality of the built-in `Base` class. |
| [components/base/base.hpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/base/base.hpp) | Defines the implementation of functionality defined in `base.cpp`, which includes the declaration of several built-in functions such as `move_straight()`. |
| [components/base/base.hpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/base/base.hpp) | Defines the API of the built-in `Base` class, which includes the declaration of several purely virtual built-in functions such as `move_straight()`. |
| [components/base/base.cpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/base/base.cpp) | Provides implementations of the non-purely virtual functionality defined in `base.hpp`. |


{{% alert title="Tip" color="tip" %}}
You can view the other built-in component classes in similar fashion.
For example, the `Camera` class is defined in [camera.cpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/camera/camera.cpp) and its functions declared in [camera.hpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/camera/camera.hpp), while the `Sensor` class is defined in [sensor.cpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/sensor/sensor.cpp) and its functions declared in [sensor.hpp](https://github.com/viamrobotics/viam-cpp-sdk/blob/main/src/viam/sdk/components/sensor/sensor.hpp).
Copy link
Member

Choose a reason for hiding this comment

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

(minor) I think it would help to be slightly more explicit about the fact that resource base classes are all abstract, and the resource-y methods (stop(), get_image(), etc.) are not defined in, e.g., camera.cpp.

@viambot
Copy link
Member

viambot commented Jan 25, 2024

You can view a rendered version of the docs from this PR at https://docs-test.viam.dev/2401

@andf-viam andf-viam merged commit 097d34b into viamrobotics:main Jan 25, 2024
11 checks passed
@andf-viam andf-viam deleted the DOCS-1527-refactor-create-module branch January 25, 2024 17:55
sguequierre pushed a commit to sguequierre/docs that referenced this pull request Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to build This pull request is marked safe to build from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants