Download
latest Releases : 2.0.0-RELESE
2.0.0-RELESE | Download page |
Number of Projects
RT-Component | 152 |
RT-Middleware | 33 |
Tools | 22 |
Documentation | 2 |
Choreonoid
Motion editor/Dynamics simulator
OpenHRP3
Dynamics simulator
OpenRTP
Integrated Development Platform
AIST RTC collection
RT-Components collection by AIST
TORK
Tokyo Opensource Robotics Association
DAQ-Middleware
Middleware for DAQ (Data Aquisition) by KEK
Components with Data Ports
In this sample, we will create two components with data ports, and try to send and receive data between two components. The specifications of the components that we will create are as follows.
Generating Source Codes Using rtc-template
To create the components with above specifications, you will prepare the following shell script named gen.sh.
The component1 is created by the first execution of rtc-template, and then the component2 is created by the next.
Implementaion of ConsoleIn
The ConsoleIn component will be implemented by editing the generated source code.
ConsoleIn.h
This component waits for input and outputs the inputted value to its OutPort, when activated. Therefore, you need to implement only its onExecute member function, which is executed periodically during the active state, so uncomment the commented-out onExecute function in ConsoleIn.h:
There is a declaration of the OutPort variables which is specified in rtc-template at the lower of ConsoleIn.h.
TimedLong m_out of declaration is the variable which is bound to OutPort.
OutPort<TimedLong> m_outOut of declaration is the instance of OutPort.
ConsoleIn.cpp
It is easy to implement ConsoleIn. Uncomment the commented-out onExecute function, and implement this way:
Implementation of ConsoleOut
It is a little complicated in ConsoleOut component. You must store the result value which the data from InPort is multiplied by the configuration parameter "multiply". It can be realized by the way you set a callback object to InPort.
Callback Object
Callback Object is an object in which operator() method is defined, which is invoked when an event is occurred at buffers of InPort or OutPort. Here, we use an OnWriteConvert as the callback object, which converts data when the data are written to a buffer of InPort.
Inherit RTC::OnWriteConvert and define the next class:
ConsoleOut.h
Insert this callback class just after the lines of include in ConsoleOut.h. Also, declare the instance of it as a member variable of ConsoleOut class. You may insert the declaration just after private:
When activated, this component reads data from InPort and prints the data to the standard output. Therefore, you need to implement only its onExecute member function, which is executed periodically during the active state, so uncomment the commented-out onExecute function in the generated ConsoleOut.h:
There are declarations of configuration variables and the InPort variables which is specified in rtc-template at the lower of ConsoleOut.h.
Since RingBuffer is used a buffer of InPort in ConsoleOut, you have to include RingBuffer.h. Around top of ConsoleIn.h, please include RingBuffer.h.
And, modify the part of InPort<TimedLong> m_inIn, which is the default declaration of InPort, to InPort<TimedLong, RTC::RingBuffer> m_inIn for the InPort to use a RingBuffer.
int m_multiply of declaration is the variable which is bound to the configuration "multiply".
TimedLong m_in of declaration is the variable which is bound to InPort.
InPort<TimedLong, RTC::RingBuffer> m_inIn of declaration is the instance of OutPort
ConsoleOut.cpp
Add an initialization of the instance of Multiply which you have defined before in the constructor of ConsoleOut class.
Also, describe the code to add the callback object to InPort in the constructor.
Uncomment the onExecute function, and implement this way:
Compile
Once you finished implementing, compile your sources as below:
In case of compile errors, check whether there are misspellings or other mistakes, and compile again.
Execute
Prepare an appropriate rtc.conf and run ConsoleInComp and ConsoleOutComp, using two terminals.
Start up RtcLink, connect the two components, and activate them.
#imgr(./figs/Manual/ConsoleInConsoleOut2.png,center,nolink)
In the terminal running ConsoleIn, a prompt Please input number: is shown, so enter an appropriate number:
In the other terminal, which is running ConsoleOut, results should be printed like this:
Next, on the configuration view of RtcLink, change the multiply value to 10. Then, values inputted in ConsoleIn should be multiplied by 10 and printed like this: