Giter Site home page Giter Site logo

greenroom-robotics / ros-typescript-generator Goto Github PK

View Code? Open in Web Editor NEW
23.0 1.0 9.0 830 KB

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

Home Page: https://greenroom-robotics.github.io/ros-typescript-generator/

License: MIT License

TypeScript 98.73% JavaScript 1.27%
ros2 typescript ros rcl robotics

ros-typescript-generator's Introduction

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 (config: {"typePrefix": "IRosType"})
  • TypeScript namespaces for ROS packages (config: {"useNamespaces": true})
  • Works with custom .msg, .srv and .action files
  • No runtime dependencies
  • Smart enum support (config: {"smartEnums": true})
# 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

Becomes

export interface ExampleMsgsExample {
  status: ExampleMsgsExampleStatus;
  other: ExampleMsgsExampleOther;
  more: number;
}

export enum ExampleMsgsExampleStatus {
  DISABLED = 0,
  ENABLED = 1,
}

export enum ExampleMsgsExampleOther {
  THING_1 = 1,
  THING_2 = 2,
}

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
  "typePrefix": "IRosType",
  "useNamespaces": false, // Should we use namespaces for ROS packages?
  "smartEnums": true, // Should we use smart enums (as described above)
  "input": [
    {
      "namespace": "std_msgs",
      "path": "/opt/ros/iron/share/std_msgs"
    },
    {
      "namespace": "geometry_msgs",
      "path": "/opt/ros/iron/share/geometry_msgs"
    },
    // Add any other messages including your own custom messages.
  ],
}
  • Run npx ros-typescript-generator --config ros-ts-generator-config.json
  • Done!

Examples

Credit

Credit goes to foxglove for their foxglove/rosmsg library.

ros-typescript-generator's People

Contributors

emresiimseek avatar ezrabrooks avatar hunk86 avatar jobafr avatar kabilan235 avatar mrblenny avatar philippemorier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ros-typescript-generator's Issues

How to use this on a device that doesn't have ROS

  • I'm submitting a ...
    question about how to use this project

  • Summary
    I am developing a web interface to control my ROS1 robot. My machine doesn't have ROS, it connects using rosbridge. Is it still possible to use this generator, what should the path be?

  • Other information
    No

Function changes need for Bazel

Hi, I tried to use this library in Bazel. But in build process, Some files couldn't find. In my opinion, It's related to build process in bazel.
We can replace "readDir" function with "readdirSync". I forked the project and replace the function. "readdirSync" function can be more effective for asyncron process. I made some tests and I saw no error.
I can use forked version. But I think, if we replace the function, It will be more useful.
What do you think about this?

for (const entry of await readdir(dir, { withFileTypes: true })) {

Make parsing ROS version configurable

First, thanks for your work ๐Ÿ’!

I'm submitting a ...

  • feature request
  • PR #3

Summary

Currently, the parsing of ROS2 is hard-coded:

const messageDefinitions = parse(rosDefinition, { ros2: true });

See: https://github.com/Greenroom-Robotics/ros-typescript-generator/blob/master/src/lib/generateFromRosMsg.ts#L11

It would be awesome if it would be possible to change this in the ros-ts-generator-config.json?

Background

http://docs.ros.org/en/noetic/api/sensor_msgs/html/msg/CameraInfo.html can't be parsed because of e.g. float64[9] K # 3x3 row-major matrix.

BUG: wrong attributes are being generated for Time and Duration in ROS1

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    You can see here and in the following line that sec and nanosec are being generated. This is correct for ROS2 but not for ROS1 where it is named secs and nsecs. Can you provide a fix for this please?

Tested with latest version. Thank you!

Do you have plan to support *.srv?

  • I'm submitting a ...

    • bug report
    • feature request
    • question about the decisions made in the repository
    • question about how to use this project
  • Summary
    Hi, thank you for your hard work! I have a question after using your project!

    • Are you going to support generating types for *.srv files in the future?
  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

`bool` const is converted to an `enum` with its value being set to `true` or `false`

I'm submitting a

  • bug report

Summary

A bool const which is initialized with 0 or 1 is converted to an enum with its value trying to be set to true or false which leads to

TS18033: Only numeric enums can have computed members, but this expression has type 'true'. If you do not need exhaustiveness checks, consider using an object literal instead.

MSG: test_msgs/State
  bool OFF = 0
  bool ON = 1

gets converted to

export enum StateConst {
  OFF = false,
  ON = true,
}

BUG: Constants as pure message type

  • I'm submitting a bug report when having nothing but constants in a message type
    [ X ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    It is regarded as best practice to have constants and nothing but constants in their own custom message type and then referred to from main custom message type.
    But generated typescript appends Const keyword to enums but does not add Const keyword in the files referring to them, so generating invalid typescript code.

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Example:
RobotMode.msg file:
`
std_msgs/Header header

RobotModeConstants robot_mode_constant

int8 value
`

RobotModeConstants.msg file:
`

int8 DISCONNECTED=0
int8 BOOTING=1
int8 POWER_OFF=2
int8 POWER_ON=3
int8 IDLE=4
int8 RUNNING=5

`

Generated typescript file:
`
export enum IRosTypeRobotModeConstantsConst {
DISCONNECTED = 0,
BOOTING = 1,
POWER_OFF = 2,
POWER_ON = 3,
IDLE = 4,
RUNNING = 5,
}

export interface IRosTypeRobotMode {
header: IRosTypeStdMsgsHeader;
robot_mode_constant: IRosTypeRobotModeConstants;
value: number;
}
`

Error trying to convert a string

  • I'm submitting a ...
    [ x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Hi, thank you for your great work!

I'm having some problems trying to convert a message from Universal_Robots_ROS_Driver, not sure if they should change their syntax or there is new use case you may need to consider.

ProgramState.msg

string STOPPED=STOPPED
string PLAYING=PLAYING
string PAUSED=PAUSED

string state

https://github.com/UniversalRobots/Universal_Robots_ROS_Driver/blob/master/ur_dashboard_msgs/msg/ProgramState.msg

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
Error: Syntax error at line 1 col 16:

  string STOPPED=STOPPED
                 ^
Unexpected fieldOrType token: "STOPPED". Instead, I was expecting to see one of the following:

A space token based on:
    _$subexpression$1 โ†’  โ— %space
    _ โ†’  โ— _$subexpression$1
    main โ†’ _ stringType __ constantField _ assignment โ— _ stringConstantValue _ main$ebnf$11
A doubleQuotedString token based on:
    doubleQuotedString โ†’  โ— %doubleQuotedString
    stringConstantValue$subexpression$1 โ†’  โ— doubleQuotedString
    stringConstantValue โ†’  โ— stringConstantValue$subexpression$1
    main โ†’ _ stringType __ constantField _ assignment _ โ— stringConstantValue _ main$ebnf$11
A singleQuotedString token based on:
    singleQuotedString โ†’  โ— %singleQuotedString
    stringConstantValue$subexpression$1 โ†’  โ— singleQuotedString
    stringConstantValue โ†’  โ— stringConstantValue$subexpression$1
    main โ†’ _ stringType __ constantField _ assignment _ โ— stringConstantValue _ main$ebnf$11

ERROR: 1

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.