CN115756899A - Method for realizing irosBridge supporting IROS self-defined message type - Google Patents

Method for realizing irosBridge supporting IROS self-defined message type Download PDF

Info

Publication number
CN115756899A
CN115756899A CN202211516163.6A CN202211516163A CN115756899A CN 115756899 A CN115756899 A CN 115756899A CN 202211516163 A CN202211516163 A CN 202211516163A CN 115756899 A CN115756899 A CN 115756899A
Authority
CN
China
Prior art keywords
class
message
iros
function
library
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211516163.6A
Other languages
Chinese (zh)
Inventor
赵洪宇
李朝铭
马辰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shandong New Generation Information Industry Technology Research Institute Co Ltd
Original Assignee
Shandong New Generation Information Industry Technology Research Institute Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shandong New Generation Information Industry Technology Research Institute Co Ltd filed Critical Shandong New Generation Information Industry Technology Research Institute Co Ltd
Priority to CN202211516163.6A priority Critical patent/CN115756899A/en
Publication of CN115756899A publication Critical patent/CN115756899A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention provides an irosBridge implementation method supporting an IROS self-defined message type, which belongs to the field of robot communication, and the invention uses a C + + base class and polymorphic characteristics to implement a class reflection mechanism and provides interfaces for registering classes and creating class instances to the outside; modifying the generation tool for generating the IROS message type header file, adding the reflection mechanism of the classes into the generated header file, and registering the class of the message type by using the interface of the registration class. Any non-IROS device is enabled to communicate with the IROS robot by means of the irosBridge, and meanwhile the irosBridge is enabled to complete communication of newly-added custom message types in a running state.

Description

Method for realizing irosBridge supporting IROS self-defined message type
Technical Field
The invention relates to the field of robot communication, in particular to an irosBridge implementation method supporting an IROS self-defined message type.
Background
IROS is a robot operating system, and communication between robots is realized in a distributed node mode, but in actual needs, communication is not only needed between robots, and sometimes communication with IROS on terminal equipment such as mobile phones and web pages is more desirable, so that behaviors of robots are controlled. For this reason, an IROS bridge tool needs to be developed based on the IROS to fulfill the requirement that various devices communicate with the IROS.
The irosBridge is used as an intermediate message proxy node in communication, is a Server end of a C/S communication model, and needs to be kept running for a long time. In an IROS robot in an actual working scene, a user often creates some customized message types, and a compiled language such as C + + causes the customized message types to be unknown to running IROS bridge, and conventionally, header files of the customized message types are included in the IROS bridge and then compiled and run again, which obviously does not meet the characteristics of a Server end, and the user is also required to care about and complete the compiling and running of the IROS bridge, which not only exposes the source code of the IROS bridge, but also increases the workload of the user.
Therefore, it is necessary to implement an irossbridge tool supporting custom message types based on the IROS to meet the requirement of various devices to communicate with the IROS, and at the same time, enable the irossbridge to complete the communication of newly added custom message types in a running state.
Disclosure of Invention
In order to solve the technical problem, the invention provides an irosBridge implementation method supporting the IROS self-defined message type.
The technical scheme of the invention is as follows:
an IROS bridge implementation method supporting IROS self-defined message types is characterized in that a C + + base class and a polymorphic characteristic are used for writing a reflection library of classes to implement a reflection mechanism of the classes, the reflection library defines a virtual function in the base class to implement the polymorphic, and provides interfaces for registering the classes and creating class instances to the outside. Modifying a generate tool for generating an IROS message type header file, adding a reflection mechanism of the classes into the generated header file, wherein the class of the message type is derived from a base class of a reflection library, rewriting a virtual function of the base class, and completing the registration of the message type by using an interface of a registration class in the reflection library. The irosBridge is a tool for realizing communication between the non-IROS device and the IROS robot, and in order to enable the irosBridge to identify and complete communication of a newly added custom message type of the IROS in a running state, the method adopts a dynamic library loading mode to register and create a class instance of the message type.
Further, in the above-mentioned case,
the method comprises the steps of modifying a general tool, compiling a header file of a message type into a dynamic library after the header file is generated, wherein a one-to-one mapping relation exists between the file name of the dynamic library and the message type, obtaining a library directory of the IROS by the general tool in a mode of reading an environment variable, and moving the compiled message type dynamic library into the library directory of the IROS. Based on the idea, the compiling and running of the irosBridge only depend on the reflection library, the head file of the message type is not required to depend on, for the newly added self-defined message type, the corresponding dynamic library is only put into the IROS library directory, the irosBridge can dynamically load the library file of the self-defined message type, the registration of the class and the creation of the instance are completed, and further the conversion of the message format is completed through the virtual function access of the base class and the member variable of the operation derivative class (the class of the message type), so that the communication is realized.
In a further aspect of the present invention,
the irosBridge is used as a server end of the websocket, a class example of the message type is established by adopting a dynamic library loading mode, a rossbridge protocol is followed, JSON character strings are used as a format of message transmission by the protocol, the protocol is the prior art, and the description is omitted here. For an operation that a non-IROS device such as publish requests to send a message to an IROS, when receiving a JSON message sent by the non-IROS device, an IROSBridge dynamically loads a library file of a message type to create a class instance and returns the class instance to a base class pointer, calls a JSON2obj () function rewritten by a derived class to fill the message with data in a JSON format to a member variable of the class instance, calls a serialize () function rewritten by the derived class before sending the message to the IROS, executes a message serialization function of the derived class in a function body, stores the serialized data and data length in msg and msg _ len of the base class respectively, then calls a publish interface sending the message to the IROS, calls a serialization function of the message type based on a template in the interface, and the base class pointer causes the actually called serialization function of the base class, and assigns values to outgoing parameters of the base class in the function body and then sends the outgoing parameters to the IROS.
Further, in the above-mentioned case,
for an operation that a non-IROS device such as a script requests to receive an IROS message, an irosBridge registers a function with a parameter type of a base class pointer as a callback function for processing the IROS message, the IROS calls an deserialization function of the message type based on a template before transmitting the message to the callback function, the base class pointer causes the deserialization function of the base class to be actually called, the function body respectively assigns the incoming message and the message length to msg and msg _ len of the base class, the msg does not really serialize, in the callback function, the irosBri firstly creates a class instance of the message type by using a dynamic library loading mode and returns the class instance of the message type to the base class pointer, calls a deserialize () function rewritten by a derivative class, executes the message deserialization function of the class based on the base class msg and msg _ len in the function body, fills deserialized data into the class instance, calls an ob j2JSON function rewritten by the derivative class instance to convert the message into a non-derivative class variable () format, and then transmits the JSON message to the JSON device.
The invention has the advantages that
Enabling any non-IROS device to communicate with the IROS robot by means of the irosBridge, and enabling the irosBridge to complete communication of the newly added custom message types in the running state.
Drawings
FIG. 1 is a schematic workflow diagram of the present invention;
FIG. 2 is a schematic diagram of the workflow of the generate tool of the present invention;
fig. 3 is a schematic diagram of an implementation concept of irosBridge in the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer and more complete, the technical solutions in the embodiments of the present invention will be described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention, and based on the embodiments of the present invention, all other embodiments obtained by a person of ordinary skill in the art without creative efforts belong to the scope of the present invention.
The invention provides an IROS bridge implementation method supporting IROS self-defined message types, as shown in figure 1, a reflection library of classes is written by using the characteristics of C + + base classes and virtual function polymorphism to implement a reflection mechanism of the classes, the reflection library defines virtual functions such as conversion between a JSON format and a class instance format in the base classes to implement the polymorphism, and provides interfaces for registering the classes and creating class instances externally. Adding a reflection mechanism of the above classes into a header file of an IROS message type, deriving the class of the message type from a base class of a reflection library, re-establishing a virtual function of the base class, and registering the class of the message type in the reflection library by using a registration interface. The core of the C + + reflection technology is base class and polymorphism, and the specific implementation scheme is not discussed in detail herein. The IROS uses the generic tool to automatically generate the header file of the message type, so the generic program needs to be modified to complete the modification of the header file of the message type.
As shown in fig. 2, the irobridge is a tool for realizing communication between a non-IROS device and an IROS robot, which is to be kept running for a long time as an intermediate message proxy node, in order to enable the irobridge to register and create a new custom message type in a running state, dependence of the irobridge on a message type header file must be avoided, and the method is realized by using dlopen dynamic loading library, this requires the generation tool to compile the header file into a dynamic library after generating it for the message type, and compile the interface for creating class instance into the dynamic library in the register interface of the reflection library in the specification of C language, in order to avoid the problem of redefining the homonym function, the _ COUNT _ macro is used as the suffix for creating the function name of the class instance interface, and the function name of the class instance interface and the message type are in one-to-one mapping relationship. The dynamic library file name and the message type are also in one-to-one mapping relation, the generate tool finds the library directory of the IROS in a mode of reading the environment variable, and the compiled message type dynamic library is moved to the library directory of the IROS.
Based on the thought, the compiling and running of the irosBridge only depend on the reflection library, the head file of the message type is not needed, and for the newly-added self-defined message type, the irosBridge can obtain the file name of the dynamic library and the function name of the created class instance interface based on the message type mapping only by putting the corresponding dynamic library into the IROS library directory. The message types are registered when library files of the message types are dynamically loaded, an interface for creating class instances in a library is called to obtain instances of the message types and the instances are returned to a base class pointer, and due to the characteristic of C + + polymorphism, the irosBridge can access and operate member variables of the class instances by calling virtual functions of the base class.
The irosBridge is used as a server end of the websocket, a rossbridge protocol is followed, JSON character strings are used as a format for message transmission by the protocol, a corresponding specification is established, the protocol is the prior art, and details are not repeated herein. As shown at 0.
For the operation that a non-IROS device such as publish requests to send a message to an IROS, when receiving a JSON message sent by the non-IROS device, the iroSCridge firstly creates a class instance of a message type in a dynamic library loading mode and returns the class instance to a base class pointer, and calls a JSON2obj () function rewritten by a derived class (a class of the message type) to fill the message with data in a JSON format to a member variable of the class instance; secondly, before sending the message to the IROS, calling a servralize () function rewritten by a derived class, executing a message serialization function of the derived class in a function body, and respectively storing the serialized data and data length in msg and msg _ len of a base class; and then calling a serialization function of a message type based on the template when calling a publish interface of the IROS to send the message to the IROS, wherein the actually called serialization function of the base class is caused by the base class pointer, and msg _ len of the base class are assigned to outgoing parameters in the function body to complete the serialization of the message, so that the message is sent to the IROS.
For the operation that a non-IROS device such as a script requests to accept an IROS message, the IROSBridge registers a function with a parameter type of a base class pointer as a callback function for processing the IROS message, the IROS calls an deserialization function of the message type based on a template before transmitting the message to the callback function, the base class pointer causes the deserialization function of the base class to be actually called, the function assigns the length of the incoming message and the length of the message to msg and msg _ len of the base class respectively, and the msg is not really serialized; in a callback function, an irosBridge firstly creates a class instance of a message type by using a dynamic library loading mode and returns the class instance to a base class pointer, calls a deserialize () function rewritten by a derived class, executes a message deserialization function of the derived class in a function body according to msg and msg _ len of the base class, and fills deserialized data into the class instance; and calling an obj2JSON () function rewritten by the derived class to convert the message into a JSON format from the member variable of the class instance, and then sending the message to the non-IROS equipment.
Based on the above embodiment of the invention, the communication between any non-IROS device and the IROS robot can be realized by means of the irobridge, and the dependence of the irobridge on the message type header file is removed on the premise, so that the irobridge can realize the communication for the newly added custom message type of the IROS robot in the state of keeping running.
The above description is only a preferred embodiment of the present invention, and is only used to illustrate the technical solutions of the present invention, and not to limit the protection scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (8)

1. An irosBridge implementation method supporting IROS self-defined message types is characterized in that,
writing a reflection library of the class by using the characteristics of the C + + base class and the polymorphism to realize a reflection mechanism of the class, defining a virtual function in the base class by the reflection library to realize the polymorphism, and externally providing interfaces for registering the class and creating a class instance;
modifying a generation tool for generating an IROS message type header file, adding a reflection mechanism of the classes into the generated header file, wherein the classes of the message types are derived from a base class of a reflection library, rewriting a virtual function of the base class, and completing the registration of the message types by using an interface of a registration class in the reflection library;
and registering and creating class instances of the message types in a dynamic library loading mode.
2. The method of claim 1,
the method comprises the steps of registering classes and creating instances by adopting a dynamic library loading mode, compiling a header file of a message type into a dynamic library after the header file is generated by modifying a general tool, wherein a one-to-one mapping relation exists between the file name of the dynamic library and the message type, the general tool obtains an IROS library directory by reading an environment variable, and the compiled message type dynamic library is moved into the IROS library directory.
3. The method of claim 2,
for the newly added self-defined message type, only the corresponding dynamic library is put into the IROS library directory, the IROS bridge can dynamically load the library file of the self-defined message type to complete the registration of the class and the creation of the instance, and further the conversion of the message format is completed through the virtual function access and operation of the base class and the member variable of the derived class, namely the class of the message type, so as to realize the communication.
4. The method of claim 3,
for the operation that the non-IROS device of publish requests to send a message to the IROS, when the JSON message sent by the non-IROS device is received by the IROSBridge, firstly, a library file is dynamically loaded, a class instance of a message type is created and returned to a base class pointer, and a JSON2obj () function rewritten by a derived class is called to fill the message with data in a JSON format to a member variable of the class instance.
5. The method of claim 4,
before sending a message to the IROS, calling a servize () function rewritten by a derived class, executing a message serialization function of the derived class in a function body, respectively storing serialized data and data length in msg and msg _ len of a base class, and then calling a publish interface for sending the message to the IROS.
6. The method of claim 5,
and calling a serialized function of the message type based on the template in the publish interface, wherein the actually called serialized function of the base class is caused by the base class pointer, and msg _ len of the base class are assigned to outgoing parameters in the function body and then sent to the IROS.
7. The method of claim 6,
for the operation that a non-IROS device such as a subscribe requests to receive an IROS message, the IROSBridge registers a function with a parameter type of a base class pointer as a callback function for processing the IROS message, the IROS calls an deserialization function of the message type based on a template before transmitting the message to the callback function, the base class pointer causes the actually called deserialization function of the base class, the function body respectively assigns the length of the transmitted message and the length of the message to msg and msg _ len of the base class, and the msg is not deserialized.
8. The method of claim 7,
in a callback function, an irosBridge firstly adopts a dynamic library loading mode to create a class instance of a message type and return the class instance to a base class pointer, then calls a desuriaize () function rewritten by a derived class, executes a message deserialization function of the derived class based on msg and msg _ len of the base class in the function body, fills deserialized data to the class instance, and finally calls an obj2JSON () function rewritten by the derived class to convert a message from a member variable of the class instance into a JSON format, and then sends the message to a non-IROS device.
CN202211516163.6A 2022-11-30 2022-11-30 Method for realizing irosBridge supporting IROS self-defined message type Pending CN115756899A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211516163.6A CN115756899A (en) 2022-11-30 2022-11-30 Method for realizing irosBridge supporting IROS self-defined message type

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211516163.6A CN115756899A (en) 2022-11-30 2022-11-30 Method for realizing irosBridge supporting IROS self-defined message type

Publications (1)

Publication Number Publication Date
CN115756899A true CN115756899A (en) 2023-03-07

Family

ID=85341168

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211516163.6A Pending CN115756899A (en) 2022-11-30 2022-11-30 Method for realizing irosBridge supporting IROS self-defined message type

Country Status (1)

Country Link
CN (1) CN115756899A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116700834A (en) * 2023-08-07 2023-09-05 天津华来科技股份有限公司 App modularized loading method and system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116700834A (en) * 2023-08-07 2023-09-05 天津华来科技股份有限公司 App modularized loading method and system
CN116700834B (en) * 2023-08-07 2023-10-24 天津华来科技股份有限公司 App modularized loading method and system

Similar Documents

Publication Publication Date Title
CN110365751B (en) Service processing method, device and equipment of gateway system
US6609158B1 (en) Component architecture in a computer system
US6484214B1 (en) Method for distributed object communications based on dynamically acquired and assembled software components
CN111176626B (en) Cross-programming-language code calling method and device, medium and equipment
CN102810069A (en) JAVA object requesting and responding methods, devices and systems and terminal
CN115756899A (en) Method for realizing irosBridge supporting IROS self-defined message type
CN114398191A (en) Remote service calling method, system, computer equipment and storage medium
CN113076144A (en) Power amplifier adaptation method, terminal device, storage medium and computer program product
US7003773B2 (en) Dynamic interface aggregation on demand
CN111198770B (en) Communication method, device and system, conversion method and device of ROS1 message
CN110457013B (en) Program component configuration device and method
WO2023083071A1 (en) View interaction method and apparatus, electronic device, and computer readable medium
CN114827297B (en) Protocol adaptation method, device, equipment and storage medium
CN111124924A (en) API (application program interface) deployment method and device, electronic equipment and storage medium
CN115061678A (en) Code compiling method and client based on browser proxy service
CN113835904A (en) Remote procedure call control method, device, equipment and storage medium
CN112398870A (en) Cross-platform protocol generation method, device, system, equipment and storage medium
JP3647827B2 (en) Wireless printing interface kit and method
KR100494827B1 (en) Distributed object model based radio server with hardware-independent communication interface and communication control method using the same
CN111142860B (en) Method and device for realizing interface call
CN113434147B (en) Method and device for analyzing message based on ProtoBuf protocol
CN115640144A (en) Method for realizing communication between IROS (Internet radio operating System) equipment and IROS equipment based on C + +
EP4155844A1 (en) Remote function customization method and apparatus, device, and storage medium
CN111885194B (en) Communication method and device for communication application and electronic equipment
CN111338820B (en) Operation method, client and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination