Skip to content

Hunk86/ros-typescript-generator

 
 

Repository files navigation

Ros Typescript Generator

CircleCI

A CLI for generating typescript interfaces and enums from ros msg files.

Features

  • ROS1 and ROS2 support
  • Generate ts types from ROS msgs
  • Generate ts enums from ROS msgs
  • Configurable type prefix, eg) IRosType or Ros
  • Works with custom msgs
  • No runtime dependencies
  • Advanced multi-enum support
# example_msgs/example.msg
uint8 STATUS_DISABLED = 0 
uint8 STATUS_ENABLED = 1

uint8 OTHER_THING_1 = 1
uint8 OTHER_THING_2 = 2

uint8 status
uint8 other
uint8 more

Should become:

export enum IRosTypeExampleStatus {
  "STATUS_DISABLED" = 0,
  "STATUS_ENABLED" = 1,
}
export enum IRosTypeExampleOther {
  "OTHER_THING_1" = 1,
  "OTHER_THING_2" = 2
}
export interface IRosTypeExampleOther {
  status: IRosTypeExampleStatus
  other: IRosTypeExampleOther
  more: number
}

Comparison to rclnodejs / rostsd-gen

Unlike rostsd-gen, this ONLY generates ts types and enums. This means the output does not include any nodejs dependencies. In fact, it has no runtime dependencies at all. It uses interfaces rather than classes 🙂. This makes it good option for any frontend project.

Usage

  • Add a ros-ts-generator-config.json file to your project root. For example:
{
  "output": "./generated/ros_msgs.ts",
  "rosVersion": 2, // 1 or 2
  "input": [
    {
      "namespace": "std_msgs",
      "path": "/opt/ros/galactic/share/std_msgs"
    },
    {
      "namespace": "geometry_msgs",
      "path": "/opt/ros/galactic/share/geometry_msgs"
    },
    // Add any other messages including your own custom messages.
  ],
  "typePrefix": "IRosType"
}
  • Run npx ros-typescript-generator --config ros-ts-generator-config.json
  • Done!

Examples

Credit

Credit goes to foxglove for their foxglove/rosmsg library.

About

A CLI for generating typescript interfaces and enums from ros messages and services.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 97.3%
  • JavaScript 2.7%