Here, how to develop RT-Component(MRCConverter) with DataPort would be shown.
This RTC converts x-y value from input device (ex. joystick) to the wheel velocity of differential drive mobile robot.
The specification of the RTC is the following.
Here, how to create template codes by using RtcTemplate would be shown.
Create working directory in any place. In the following, the directory name is MRCConverter.
Create the following batch file (ex. gen.bat) on the working folder to run the rtc-template easily.
rtc-template.py -bcxx^ --module-name=MRCConvertor --module-desc="Convertor component for MobileRobot component"^ --module-version=1.0.0 --module-vendor=AIST --module-category=Category^ --module-comp-type=DataFlowComponent --module-act-type=PERIODIC^ --module-max-inst=1^ --inport=velFromInput:TimedFloatSeq^ --outport=velToWheel:TimedFloatSeq
Run the gen.bat, and the result will be the following.
>gen.bat rtc-template.py -bcxx --module-name=MRCConvertor --module-desc="Convertor component for MobileRobot component" --module-version=1.0.0 --module-vendor=AIST --module-category=Category --module-comp-type=DataFlowComponent --module-act-type=PERIODIC --module-max-inst=1 --inport=velFromInput:TimedFloatSeq --outport=velToWheel:TimedFloatSeq File "MRCConvertor.h" was generated. File "MRCConvertor.cpp" was generated. File "MRCConvertorComp.cpp" was generated. File "Makefile.MRCConvertor" was generated. File "MRCConvertorComp_vc8.vcproj" was generated. File "MRCConvertor_vc8.vcproj" was generated. File "MRCConvertorComp_vc9.vcproj" was generated. File "MRCConvertor_vc9.vcproj" was generated. File "MRCConvertor_vc8.sln" was generated. File "MRCConvertor_vc9.sln" was generated. File "copyprops.bat" was generated. File "user_config.vsprops" was generated. File "README.MRCConvertor" was generated. File "MRCConvertor.yaml" was generated.
Some source codes and other files would be generated in the woking diretory.
Input the following profiles in the RtcTempalte's editor window.
After input the component profile, push "Generate" button. Some source codes and other files would be generated in the working folder.
As the result of the above mentioned operation, copyprops.bat would be generated in the working folder. The copyprops.bat copies rtm_config.vsprops (Visual Studio Property Sheet) from installed OpenRTM-aist folder to current working folder. This file is necessary to build RTC on Visual C++.
Double-click te copyprops.bat.
Double-click MRCConvertorComp_vc?.sln and launch Visual Studio. XXX_vc8.sln is a solution file for VC2005, XXX_vc9.sln is a solution file for VC2008. Please select an appropriate solution file for your development environment.
Open the MRCConverter.h in "MRCConverterComp" -> "Header Files" from Solution Explorer.
#include <vector> // To use Math::M_PI in VC8 #define _USE_MATH_DEFINES #include <math.h>
private: float m_k; /*! * @brief This function converts input data from joystick to velocity of * differential drive mobile robot. * Only m_velFromInput.data[0 and 1] would be used. */ std::vector<float> convert(float x, float y) { float th = atan2(y,x); float v = m_k * hypot(x,y); std::vector<float> ret_val; ret_val.push_back(v * cos(th - (M_PI/4.0))); // left vel ret_val.push_back(v * sin(th - (M_PI/4.0))); // right vel return ret_val; }
Open the MRCConverter.cpp in "MRCConverterComp" -> "Source Files" from Solution Explorer.
/*! * @brief This function converts input data from joystick to velocity of * differential drive mobile robot. */ RTC::ReturnCode_t MRCConvertor::onExecute(RTC::UniqueId ec_id) { if (m_velFromInputIn.isNew()) { m_velFromInputIn.read(); if (m_velFromInput.data.length() > 2) { std::vector<float> con_val = this->convert(m_velFromInput.data[0],m_velFromInput.data[1]); for (int i = 0; i < 2; i++) m_velToWheel.data[i] = con_val[i]; m_velToWheelOut.write(); } } return RTC::RTC_OK; }
This function does the following.
Click "Build" menu button and build the project.
Create new file and input the following lines in it. Copy this file to Debug and Release folders.
corba.nameservers: localhost naming.formats: %n.rtc
Before running an RT-Component, launch CORBA name server. You can find the name server launching batch file from "Start"->"Program"->"OpenRTM-aist"->"C++"->"Example"->"NameService.bat"
Go to "Debug" or "Release" folder and run MRCConverter.exe.