Skip to content

Instantly share code, notes, and snippets.

@defunctzombie
Created April 1, 2022 15:00
Show Gist options
  • Select an option

  • Save defunctzombie/aa18ae159c1c078e23ef34198d80f6e1 to your computer and use it in GitHub Desktop.

Select an option

Save defunctzombie/aa18ae159c1c078e23ef34198d80f6e1 to your computer and use it in GitHub Desktop.

Revisions

  1. defunctzombie created this gist Apr 1, 2022.
    32 changes: 32 additions & 0 deletions node.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    // The ./types module provides helper types for your Input events and messages.
    import { Input, Message } from "./types";

    // Your node can output well-known message types, any of your custom message types, or
    // complete custom message types.
    //
    // Use `Message` to access your data source types or well-known types:
    // type Twist = Message<"geometry_msgs/Twist">;
    //
    // Conventionally, it's common to make a _type alias_ for your node's output type
    // and use that type name as the return type for your node function.
    // Here we've called the type `Output` but you can pick any type name.
    type PolygonStamped = Message<"geometry_msgs/PolygonStamped">

    // These are the topics your node "subscribes" to. Studio will invoke your node function
    // when any message is received on one of these topics.
    export const inputs = ["/SampleInputTopic"];

    // Any output your node produces is "published" to this topic. Published messages are only visible within Studio, not to your original data source.
    export const output = "/studio_node/SampleOutputTopic";

    // This function is called with messages from your input topics.
    // The first argument is an event with the topic, receive time, and message.
    // Use the `Input<...>` helper to get the correct event type for your input topic messages.
    export default function node(event: Input<"/SampleInputTopic">): PolygonStamped {
    const msg = event.message;

    return {
    header: msg.header,
    polygon: msg.custom_field_name_array[0].to_be_visualized_polygon,
    };
    };