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

Enum generation is not supported correctly #76

Open
VishalDevnale opened this issue Feb 27, 2024 · 3 comments
Open

Enum generation is not supported correctly #76

VishalDevnale opened this issue Feb 27, 2024 · 3 comments

Comments

@VishalDevnale
Copy link

VishalDevnale commented Feb 27, 2024

Hi,
I have enum defined inside module and same enum is used inside a struct.

My IDL file looks like this:

module std_msgs { module msg { 

enum Number{
  ONE,
  TWO,
  THREE, 
  FOURTH,   
  FIFTH 
};
 
struct Header {
    std_msgs::msg::Number VariableSpeedSign_element;
    std_msgs::msg::Time stamp; 
    string frame_id; 
}; 
 
}; };  // module msg::std_msgs

Generated code looks like:

typedef enum Number
{
    ONE,
    TWO,
    THREE,
    FOURTH,
    FIFTH
} Number;

typedef uint32_t Number_cdr;
typedef struct std_msgs_msg_Header
{
    std_msgs::msg::Number_cdr VariableSpeedSign_element;
    std_msgs_msg_Time stamp;
    char frame_id[255];

} std_msgs_msg_Header;

struct ucdrBuffer;

bool std_msgs_msg_Header_serialize_topic(struct ucdrBuffer* writer, const std_msgs_msg_Header* topic);
bool std_msgs_msg_Header_deserialize_topic(struct ucdrBuffer* reader, std_msgs_msg_Header* topic);
uint32_t std_msgs_msg_Header_size_of_topic(const std_msgs_msg_Header* topic, uint32_t size);

In the above code struct element VariableSpeedSign_element type is generated wrongly. Could you please take a look at it?
Let me know if I am doing anything wrong.

@pablogs9
Copy link
Member

I have added a commit fixing this here: #74

Could you test and confirm that it fixes your issue?

@Ryanf55
Copy link
Contributor

Ryanf55 commented May 25, 2024

Does this also fix the issue that defaults aren't used? The generated goemetry_msgs/msg/Quaternion is therefore not normalized and breaks other tooling. You have to manually set the fields to the defaults already specified in the IDL because it's unititialized.

See /opt/ros/humble/include/geometry_msgs/geometry_msgs/msg/detail/quaternion__struct.hpp in ros:humble docker image:
docker run -it ros:humble cat cat /opt/ros/humble/include/geometry_msgs/geometry_msgs/msg/detail/quaternion__struct.hpp

And, compare it to the generated type from MicroXRCEDDSGen:

// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file Quaternion.h
 * This header file contains the declaration of the described types in the IDL file.
 *
 * This file was generated by the tool microxrceddsgen.
 */

#ifndef _Quaternion_H_
#define _Quaternion_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdint.h>
#include <stdbool.h>

typedef struct geometry_msgs_msg_Quaternion
{
    double x;

    double y;

    double z;

    double w;

} geometry_msgs_msg_Quaternion;

struct ucdrBuffer;
bool geometry_msgs_msg_Quaternion_serialize_topic(struct ucdrBuffer* writer, const geometry_msgs_msg_Quaternion* topic);
bool geometry_msgs_msg_Quaternion_deserialize_topic(struct ucdrBuffer* reader, geometry_msgs_msg_Quaternion* topic);
uint32_t geometry_msgs_msg_Quaternion_size_of_topic(const geometry_msgs_msg_Quaternion* topic, uint32_t size);

#ifdef __cplusplus
}
#endif

#endif // _Quaternion_H_

@pablogs9
Copy link
Member

You have to manually set the fields to the defaults already specified in the IDL because it's unititialized.

Since this generator targets C99 code generation, at most we can create a utility that fills the struct members with defaults values. As far as I see it is not possible to have something like inherent initialization in a C struct.

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

No branches or pull requests

3 participants