Code Monkey home page Code Monkey logo

gizmo's Introduction

VIAM Custom Module/Resource Example

This example goes through how to create custom modular resources using Viam's python SDK, and how to connect it to a Robot.

This is a limited document. For a more in-depth understanding of modules, see the documentation.

Purpose

Modular resources allows you to define custom components and services, and add them to your robot. Viam ships with many component types, but you're not limited to only using those types -- you can create your own using modules.

For more information, see the documentation.

Project structure

The definition of the new resource is in the src directory. Within this directory are the proto and gizmo subdirectories.

The proto directory contains the gizmo.proto definition of all the message types and calls that can be made to the Gizmo component. It also has the compiled python output of the protobuf definition.

The gizmo directory contains all the necessary definitions for creating a custom Gizmo component type. The api.py file defines what a Gizmo can do (mirroring the proto definition), implements the gRPC GizmoService for receiving calls, and the gRPC GizmoClient for making calls. See the API docs for more info. The my_gizmo.py file in contains the unique implementation of a Gizmo. This is defined as a specific Model. See the Model docs for more info. This implementation uses the validate_config function to specify an implicit dependency on a arg1 parameter by default and throw an error if there is an invalid attribute.

There is also a main.py file, which creates a module, adds the desired resources, and starts the module. This file is called by the run.sh script, which is the entrypoint for this module. Read further to learn how to connect this module to your robot.

Outside the src directory, there is the client.py file. This can be used to test the module once it's connected to the robot. You will have to update the credentials and robot address in that file.

How to use

These steps assume that you have a robot available at app.viam.com.

The run.sh script is the entrypoint for this module. To connect this module with your robot, you must add this module's entrypoint to the robot's config. For example, this could be /home/viam-python-sdk/examples/module/run.sh. See the documentation for more details.

alt text

Once the module has been added to your robot, you will then need to add a component that uses the MyGizmo model. See the documentation for more details. You can add a service in a similar manner.

An example configuration for a Gizmo component could look like this:

{
  "components": [
    {
      "name": "gizmo1",
      "type": "gizmo",
      "namespace": "acme",
      "model": "acme:demo:mygizmo",
      "attributes": {
        "arg1": "arg1",
      },
      "depends_on": []
    }
  ],
  "modules": [
    {
      "name": "gizmo",
      "executable_path": "/github/gizmo/run.sh"
    }
  ]
}

alt text

After the robot has started and connected to the module, you can use the provided client.py to connect to your robot and make calls to your custom, modular resources.

gizmo's People

Contributors

felixreichenbach avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.