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

Feat/add constants #997

Closed

Conversation

dnikitop
Copy link

@dnikitop dnikitop commented Oct 14, 2024

Public API Changes

Description

We use rclnodejs to provide type information on ros message types only. This is so we can run without having a ros installation. The current exported types to have constant values. This allows us to define type enums for constants.

Changes

  export interface MsgFwForkData {
    timestamp: builtin_interfaces.msg.Time;
    timestamp_us: number;
    position: number;
    status: number;
  }
  export interface MsgFwForkDataConstructor {
    readonly STATUS_NONE: number;
    readonly STATUS_STOPPED: number;
    new(other?: MsgFwForkData): MsgFwForkData;
  }

to

  export interface MsgFwForkData {
    timestamp: builtin_interfaces.msg.Time;
    timestamp_us: number;
    position: number;
    status: number;
  }
   export enum MsgFwForkDataConstants{
    STATUS_NONE = 1,
    STATUS_STOPPED = 2,
  }
  export interface MsgFwForkDataConstructor {
    readonly STATUS_NONE: MsgFwForkDataConstants.STATUS_NONE;
    readonly STATUS_STOPPED: MsgFwForkDataConstants.STATUS_STOPPED;
    new(other?: MsgFwForkData): MsgFwForkData;
  }

@@ -303,11 +303,21 @@ function saveMsgConstructorAsTSD(rosMsgInterface, fd) {
const type = rosMsgInterface.type();
const msgName = type.interfaceName;

fs.writeSync(fd, ` export interface ${msgName}Constants {\n`);
Copy link
Member

Choose a reason for hiding this comment

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

should be enum here?

fs.writeSync(fd, ` export interface ${msgName}Constructor {\n`);

for (const constant of rosMsgInterface.ROSMessageDef.constants) {
const constantType = primitiveType2JSName(constant.type);
fs.writeSync(fd, ` readonly ${constant.name}: ${constantType};\n`);
s.writeSync(fd, ` readonly ${constant.name}: ${msgName}Constants.${constant.name};\n`);
Copy link
Member

Choose a reason for hiding this comment

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

=>fs.writeSync

@dnikitop dnikitop closed this Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants