IROS-based message tools, systems, methods, devices and media
By providing the message-class tool IROSMsg in IROS, using dynamic libraries and virtual function interfaces, the complexity of message publishing, subscription and query in IROS is solved, efficient message transmission and listening is achieved, and development and testing efficiency is improved.
Patent Information
- Application Number
- CN202210057948.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-19
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2042-01-19
AI Technical Summary
In IROS, users need to manually write code for publishing, subscribing and real-time query of messages, resulting in increased workload for developers and testers, and the need to compile and modify IROSMsg code, which increases complexity.
Provides IROS-based message class tool IROSMsg. By loading a dynamic library containing user message classes and deserialization and type query virtual function interfaces, it realizes message transmission, listening and query without compiling and modifying IROSMsg code.
It enables the transmission and monitoring of specified message types without compiling and modifying IROSMsg code, and improves the work efficiency of IROS developers and testers.
Smart Images

Figure CN114564256B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of message management, and in particular to IROS-based message tools, systems, methods, devices and media. Background Art
[0002] In IROS, user-defined data types are defined in a text file with the suffix msg, which contains the data type, name, and remarks. For C++ users, the data file needs to be converted into a data structure that can be used directly, such as a class, structure, etc. IROS provides a message conversion tool msg_generate, which can easily generate C++ type header files.
[0003] However, if users want to use this type of header file to publish, subscribe, and query messages in real time, they need to manually write relevant code, including header files of related classes, which is relatively time-consuming. In addition, different programs need to be written for different messages, which increases the workload of IROS developers and testers to varying degrees.
[0004] How to conveniently transmit and monitor specified message types without compiling and modifying the IROSMsg code is a technical problem that needs to be solved. Summary of the invention
[0005] The technical task of the present invention is to address the above shortcomings and provide IROS-based message tools, systems, methods, devices and media to solve the technical problem of how to conveniently transmit and monitor specified message types without compiling and modifying the IROSMsg code.
[0006] In the first aspect, the IROS-based message class tool of the present invention is IROSMsg, in which three virtual function interfaces of IROSMsgBaseClass are defined, and a dynamic library containing a user message class is loaded, and the three virtual function interfaces are encapsulated in the dynamic library, and the three virtual functions are:
[0007] Serialization interface, which is used to serialize the data of its own members age and name in the form of strings into the pointer message_c of type char*, and specifies the length messageLen after serialization;
[0008] Deserialization interface, which is used to deserialize message_c into IDCard, that is, to fill in age and name data;
[0009] Type query interface, which is used to return the data structure of IDCard in the form of a string;
[0010] Based on the three virtual function interfaces, the IROSMsg is used to provide four functions, namely list, show, echo and pub. When the IROSMsg is executed, the function type, function parameters and message type need to be specified. The message type is a user-defined message name.
[0011] Preferably, the three virtual function interfaces are generated and implemented by the message conversion tool msg_generate in IROS, and the dynamic library contains an IDCard object, which is generated by the message conversion tool msg_generate in IROS and is used for dynamic loading by IROSMsg.
[0012] Preferably, the IROSMsg is used to implement message publishing, subscription and query, including:
[0013] Based on the specified message name, IROSMsg is used to search for message files under all IROS packages through rospack, and check whether there is a dynamic library corresponding to the specified message name. If it cannot be found, a prompt message is returned. If the corresponding dynamic library is found, the dynamic library is loaded;
[0014] After loading the dynamic library, IROSMsg is used to load the specific message entity from the dynamic library into the memory, and create an interface class pointer IROSMsgBaseClass* to point to the object to implement the loading of the user-defined message object;
[0015] For the list function, the IROSMsg is used to query the current valid message type through rospack;
[0016] For the show function, after loading the message object, the IROSMsg calls the messagetype interface to display the message type;
[0017] For the echo function, the IROSMsg is used to create a subscriber object for a specified topic. After subscribing to the corresponding topic, the data is deserialized into the object by calling the deserialization interface, and finally printed out to the terminal;
[0018] For the pub function, the IROSMsg is used to create a publisher of a specified topic, assign the data input by the user to the message object, call the serialization interface serialize, and finally publish the data through the topic publisher.
[0019] Preferably, the IROSMsg is used to perform a standardization check on the input user message to check whether the input parameters corresponding to the user message meet the specifications, and the input parameters include function type, function parameters and message type;
[0020] If the input user message meets the specification, the IROSMsg is used to obtain the message name based on the user message, and query the dynamic library corresponding to the message type through rospack;
[0021] If the input user information does not meet the specifications, a prompt message is returned.
[0022] In a second aspect, the message transmission system of the present invention comprises:
[0023] IROSMsg, wherein the IROSMsg is a message tool as described in any one of the first aspects;
[0024] msg_generate, msg_generate is a message conversion tool in IROS, which is used to generate a C++ header file that can be called by IROS according to a user-defined message file. The header file contains a class implementation with the message file name as the class name, and inherits from IROSMsgBaseClass, and is used to generate three virtual function interfaces of IROSMsgBaseClass, which are used to generate a dynamic library for the IROSMsg to call. The three virtual function interfaces are encapsulated in the dynamic library;
[0025] rospack, which is a package tool of IROS and is called by IROSMsg to query the absolute path of each package of IROS.
[0026] In a third aspect, a message transmission method of the present invention performs message transmission through the message transmission system as described in the second aspect, comprising:
[0027] According to the message name specified by the user, IROSMsg calls rospack to query the corresponding dynamic library and loads the dynamic library;
[0028] Point to the specific message object through the IROSMsgBaseClass pointer, and use the polymorphism of C++ to call the virtual function interface through the base class pointer;
[0029] By calling the virtual function interface, the message type query, message subscription and publishing under the specified topic can be realized.
[0030] Preferably, by calling a virtual function interface, the type query of the message, the subscription and publishing of the message under the specified topic are realized, including:
[0031] Based on the list function, query the current valid message type through rospack;
[0032] Based on the show function, after loading the message object through IROSMsg, the messagetype interface is called to display the message type;
[0033] Based on the echo function, create a subscriber object of a specified topic through IROSMsg. After subscribing to the corresponding topic, deserialize the data into the object by calling the deserialization interface, and finally print it out to the terminal;
[0034] Based on the pub function, a publisher of a specified topic is created through IROSMsg. After the data entered by the user is assigned to the message object, the serialization interface serialize is called, and finally the data is published through the topic publisher.
[0035] Even better, it also includes:
[0036] Perform a standardization check on the input user message through IROSMsg to check whether the input parameters corresponding to the user message meet the specifications, and the input parameters include function type, function parameters and message type;
[0037] If the input user message meets the specification, the message name is obtained through IROSMsg based on the user message, and the dynamic library corresponding to the message type is queried through rospack;
[0038] If the input user information does not meet the specifications, a prompt message is returned.
[0039] In a fourth aspect, a device of the present invention includes: at least one memory and at least one processor;
[0040] The at least one memory is used to store a machine-readable program;
[0041] The at least one processor is used to call the machine-readable program to execute any method described in the third aspect.
[0042] In a fourth aspect, the medium of the present invention is a computer-readable medium, characterized in that computer instructions are stored on the computer-readable medium, and when the computer instructions are executed by a processor, the processor executes any method described in the third aspect.
[0043] The IROS-based message tools, systems, methods, devices and media of the present invention have the following advantages: the IROSMsg tool can realize topic publishing, subscription and real-time monitoring of messages under user-defined message types through three virtual function interfaces without the need for additional compilation, effectively improving the work efficiency of IROS developers and testers. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0045] The present invention is further described below in conjunction with the accompanying drawings.
[0046] Figure 1 This is a working principle block diagram of the IROS-based message tool interface class IROSMsgBaseClass in Example 1;
[0047] Figure 2 This is a flowchart of the workflow of the message tool based on IROS in Example 1. DETAILED DESCRIPTION
[0048] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.
[0049] The embodiments of the present invention provide message tools, systems, methods, devices and media based on IROS, which are used to solve the technical problem of how to conveniently transmit and monitor specified message types without compiling and modifying IROSMsg codes.
[0050] Embodiment 1:
[0051] The present invention is based on the IROS message class tool, which is IROSMsg. The IROSMsg defines three virtual function interfaces of IROSMsgBaseClass and loads a dynamic library containing a user message class. The three virtual function interfaces are encapsulated in the dynamic library. The three virtual functions are a serialization interface, a deserialization interface, and a type query interface.
[0052] In this embodiment, a message interface class IROSMsgBaseClass is defined, and its class diagram and example message class IDCard are shown in FIG. Figure 1As shown, the interface class IROSMsgBaseClass provides three virtual function interfaces: serialization, deserialization, and type query (messagetype). All IROS message classes need to inherit from it and implement the above interface functions.
[0053] IROS's message processing tool msg_generate can generate a C++ header file that can be called by IROS based on a user-defined message file. The header file contains a class implementation with the message file name as the class name, and inherits from IROSMsgBaseClass, and implements various interfaces according to its own structure; at the same time, msg_generate will also generate a dynamic library containing specific message objects for IROSMsg to dynamically load. In this embodiment, the example message class IDCard generated by msg_generate implements these three interfaces, where the serialization interface serializes its own member age and name data in the form of a string into the pointer message_c of the char* type, and specifies the length messageLen after serialization; the deserialization interface deserializes message_c into IDCard, that is, fills in age and name data; the type query returns the data structure of IDCard in the form of a string. In addition, msg_generate will also generate a dynamic library containing IDCard objects. After IROSMsg loads the dynamic library, it can load the object into memory.
[0054] Based on the above three virtual function interfaces, IROSMsg provides four functions, namely list, show, echo and pub. When executing IROSMsg, you need to specify the function type, function parameters and message type. Each function type corresponds to a different type of function parameter, as shown in Table 1. The message type is a user-defined message name.
[0055] Table 1 IROSMsg supported functions and parameter list:
[0056] Function Type parameter list none show [message name] echo [topic name][message name] pub [topic name][message name][data]
[0057] The basis of IROSMsg is the message base class IROSMsgBaseClass. All user message classes generated by msg_generate in IROS inherit from it and implement serialization, deserialization and type query interfaces based on their own data structure. msg_generate also generates a dynamic library containing the user message class to ensure that IROSMsg can load specific message objects into memory. IROSMsg will query the corresponding dynamic library through rospack according to the message name specified by the user, point to the specific message object through the IROSMsgBaseClass pointer, and then use the polymorphism of C++ to call the virtual function interface through the base class pointer to implement the various functions of the specific message class, and finally realize the message type query, message subscription and publishing under the specified topic and other functions.
[0058] In this embodiment, IROSMsg can perform the following operations:
[0059] Operation 1: After specifying the message name, IROSMsg will use rospack to search for message files under all packages and check whether there is a corresponding dynamic library. If it cannot be found, it will directly give a prompt message and return;
[0060] Operation 2: After the dynamic library is correctly loaded, IROSMsg will load the specific message class entity from the dynamic library into the memory, and create an interface class pointer IROSMsgBaseClass* to point to the object. At this point, the loading of the user-defined message object is completed;
[0061] Operation three, for the list function of IROSMsg, IROSMsg can directly query the current valid message type through rospack; for the show function, after loading the message object, IROSMsg calls the messagetype interface to display the message type; for the echo function, IROSMsg will create a subscriber object for a specified topic, and after subscribing to the corresponding topic, it will call the deserialization interface deserialize to deserialize the data into the object, and finally print it to the terminal; for the pub function, IROSMsg will create a publisher for a specified topic, assign the data entered by the user to the message object, call the serialization interface serialize, and finally publish the data through the topic publisher.
[0062] Based on the above operations, the IROSMsg tool can realize the publishing and subscription of user-defined messages. The specific process is as follows:
[0063] When transmitting messages, IROSMsg will first check whether the input parameters meet the specifications. The specific functions are shown in Table 1. If they do not meet the input specifications, it will output usage instructions to the user and exit directly;
[0064] On the basis that the instructions comply with the specifications, the specific function code is entered according to the user's function input. Because the list function does not involve data transmission, IROSMsg will query the message files under all packages through rospack and output the message name and specific message path; under the show function, IROSMsg will find the specific message file through rospack and load the corresponding dynamic library, then load the message class into the memory, call the type function interface through the IROSMsgBaseClass pointer, and output the type information; similarly, the echo function will also load the dynamic library of the specified message and create a topic subscriber. When subscribing to the topic, the data is deserialized into a specific message object by calling the deserialization interface and output to the user; similar to the echo function, the pub function will create a topic publisher, serialize the user input data into a string through the serialization interface, and then publish it on the specified topic through the publisher.
[0065] Embodiment 2:
[0066] The message transmission system of the present invention includes IROSMsg, msg_generate and rospack, IROSMsg is the message class tool disclosed in Example 1, msg_generate is the message conversion class tool in IROS, which is used to generate a C++ header file that can be called by IROS according to a user-defined message file, the header file includes a class implementation with the message file name as the class name, and inherits from IROSMsgBaseClass, and is used to generate three virtual function interfaces of IROSMsgBaseClass, which are used to generate a dynamic library for IROSMsg to call, and the three virtual function interfaces are encapsulated in the dynamic library; rospack is a package tool of IROS, which is called by IROSMsg and is used to query the absolute path of each package of IROS.
[0067] Embodiment 3:
[0068] The message transmission method of the present invention performs message transmission through the message transmission system disclosed in Example 2, including:
[0069] S100. According to the message name specified by the user, IROSMsg calls rospack to query the corresponding dynamic library and loads the dynamic library;
[0070] S200, point to the specific message object through the IROSMsgBaseClass pointer, and use the polymorphism of C++ to call the virtual function interface through the base class pointer;
[0071] S300, by calling the virtual function interface, the message type query, message subscription and publishing under the specified topic are realized.
[0072] Among them, by calling the virtual function interface, the message type query, message subscription and publishing under the specified topic are realized, including:
[0073] Based on the list function, query the current valid message type through rospack;
[0074] Based on the show function, after loading the message object through IROSMsg, the messagetype interface is called to display the message type;
[0075] Based on the echo function, create a subscriber object of a specified topic through IROSMsg. After subscribing to the corresponding topic, deserialize the data into the object by calling the deserialization interface, and finally print it out to the terminal;
[0076] Based on the pub function, a publisher of a specified topic is created through IROSMsg. After the data entered by the user is assigned to the message object, the serialization interface serialize is called, and finally the data is published through the topic publisher.
[0077] As an improvement, given that the function type, function parameters and message name need to be specified when IROSMsg is executed, and the requirements for function types and function parameters are different, it is necessary to perform a standardization check on the input user message through IROSMsg to check whether the input parameters corresponding to the user message meet the specifications. The input parameters include function type, function parameters and message type; if the input user message meets the specifications, the message name is obtained based on the user message through IROSMsg, and the dynamic library corresponding to the message type is queried through rospack; if the input user information does not meet the specifications, a prompt message is returned.
[0078] In specific application, the process of this method is:
[0079] When transmitting messages, IROSMsg will first check whether the input parameters meet the specifications. The specific functions are shown in Table 1. If they do not meet the input specifications, it will output usage instructions to the user and exit directly;
[0080] On the basis that the instructions comply with the specifications, the specific function code is entered according to the user's function input. Because the list function does not involve data transmission, IROSMsg will query the message files under all packages through rospack and output the message name and specific message path; under the show function, IROSMsg will find the specific message file through rospack and load the corresponding dynamic library, then load the message class into memory, call the type function interface through the IROSMsgBaseClass pointer, and output the type information; similarly, the echo function will also load the dynamic library of the specified message and create a topic subscriber. When subscribing to the topic, the data is deserialized into a specific message object by calling the deserialization interface and output to the user; similar to the echo function, the pub function will create a topic publisher, serialize the user input data into a string through the serialization interface, and then publish it on the specified topic through the publisher.
[0081] Embodiment 4:
[0082] The device of the present invention comprises: at least one memory and at least one processor; the at least one memory is used to store a machine-readable program; the at least one processor is used to call the machine-readable program to execute the method disclosed in Example 3.
[0083] Embodiment 5:
[0084] The medium of the present invention is a computer-readable medium, on which computer instructions are stored, and when the computer instructions are executed by a processor, the processor executes the method disclosed in Embodiment 3. Specifically, a system or device equipped with a storage medium can be provided, on which a software program code for implementing the functions of any of the above embodiments is stored, and a computer (or CPU or MPU) of the system or device reads and executes the program code stored in the storage medium.
[0085] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.
[0086] The storage medium embodiments for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer by a communication network.
[0087] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.
[0088] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or written to a memory provided in an expansion unit connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or the expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned embodiments.
[0089] The present invention has been shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the means in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.
Claims
1. IROS-based message tools, characterized by The message class tool is IROSMsg, in which three virtual function interfaces of IROSMsgBaseClass are defined, and a dynamic library containing a user message class is loaded. The three virtual function interfaces are encapsulated in the dynamic library, and the three virtual functions are: Serialization interface, which is used to serialize the data of its own members age and name in the form of strings into the pointer message_c of type char*, and specifies the length messageLen after serialization; Deserialization interface, which is used to deserialize message_c into IDCard, that is, to fill in age and name data; Type query interface, which is used to return the data structure of IDCard in the form of a string; Based on the three virtual function interfaces, the IROSMsg is used to provide four functions, namely list, show, echo and pub. When the IROSMsg is executed, the function type, function parameters and message type need to be specified. The message type is a user-defined message name. The IROSMsg is used to implement message publishing, subscription and query, including: Based on the specified message name, IROSMsg is used to search for message files under all IROS packages through rospack, and check whether there is a dynamic library corresponding to the specified message name. If it cannot be found, a prompt message is returned. If the corresponding dynamic library is found, the dynamic library is loaded; After loading the dynamic library, IROSMsg is used to load the specific message entity from the dynamic library into the memory, and create an interface class pointer IROSMsgBaseClass* to point to the message object to implement the loading of the user-defined message object; For the list function, the IROSMsg is used to query the current valid message type through rospack; For the show function, after loading the message object, the IROSMsg calls the messagetype interface to display the message type; For the echo function, the IROSMsg is used to create a subscriber object for a specified topic. After subscribing to the corresponding topic, the data is deserialized into the object by calling the deserialization interface, and finally printed out to the terminal; For the pub function, the IROSMsg is used to create a publisher of a specified topic, assign the data input by the user to the message object, call the serialization interface serialize, and finally publish the data through the topic publisher.
2. The IROS-based message tool according to claim 1, characterized in that The three virtual function interfaces are generated and implemented by the message conversion tool msg_generate in IROS. The dynamic library contains the IDCard object, which is generated by the message conversion tool msg_generate in IROS and is used for dynamic loading by IROSMsg.
3. The IROS-based message tool according to claim 1, characterized in that The IROSMsg is used to perform a standardization check on the input user message to check whether the input parameters corresponding to the user message meet the specifications, and the input parameters include function type, function parameters and message type; If the input user message meets the specification, the IROSMsg is used to obtain the message name based on the user message, and query the dynamic library corresponding to the message type through rospack; If the input user information does not meet the specifications, a prompt message is returned.
4. A message transmission system, characterized in that include: IROSMsg, wherein the IROSMsg is a message tool according to any one of claims 1 to 3; msg_generate, msg_generate is a message conversion tool in IROS, which is used to generate a C++ header file that can be called by IROS according to a user-defined message file. The header file contains a class implementation with the message file name as the class name, and inherits from IROSMsgBaseClass, and is used to generate three virtual function interfaces of IROSMsgBaseClass, which are used to generate a dynamic library for the IROSMsg to call. The three virtual function interfaces are encapsulated in the dynamic library; rospack, which is a package tool of IROS and is called by IROSMsg to query the absolute path of each package of IROS.
5. A message transmission method, characterized in that The message transmission is performed by the message transmission system as claimed in claim 4, comprising: According to the message name specified by the user, IROSMsg calls rospack to query the corresponding dynamic library and loads the dynamic library; Point to the specific message object through the IROSMsgBaseClass pointer, and use the polymorphism of C++ to call the virtual function interface through the base class pointer; By calling the virtual function interface, the message type query, message subscription and publishing under the specified topic can be realized.
6. The message transmission method according to claim 5, characterized in that By calling the virtual function interface, you can query the message type, subscribe to the message under the specified topic, and publish it, including: Based on the list function, query the current valid message type through rospack; Based on the show function, after loading the message object through IROSMsg, the messagetype interface is called to display the message type; Based on the echo function, create a subscriber object of a specified topic through IROSMsg. After subscribing to the corresponding topic, deserialize the data into the object by calling the deserialization interface, and finally print it out to the terminal; Based on the pub function, a publisher of a specified topic is created through IROSMsg. After the data entered by the user is assigned to the message object, the serialization interface serialize is called, and finally the data is published through the topic publisher.
7. The message transmission method according to claim 6, characterized in that Also includes: Perform a standardization check on the input user message through IROSMsg to check whether the input parameters corresponding to the user message meet the specifications, and the input parameters include function type, function parameters and message type; If the input user message meets the specification, the message name is obtained through IROSMsg based on the user message, and the dynamic library corresponding to the message type is queried through rospack; If the input user information does not meet the specifications, a prompt message is returned.
8. The device, characterized in that include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 5 to 7.
9. A medium, which is a computer-readable medium, characterized in that: The computer readable medium stores computer instructions, and when the computer instructions are executed by a processor, the processor executes the method according to any one of claims 5 to 7.
Citation Information
Patent Citations
Message format analyzer and analysis method
CN113687817A