Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00016 #ifndef OPENHRP_CONTROLLER_BRIDGE_VIRTUAL_ROBOT_RTC_H_INCLUDED
00017 #define OPENHRP_CONTROLLER_BRIDGE_VIRTUAL_ROBOT_RTC_H_INCLUDED
00018
00019 #include <set>
00020 #include <string>
00021 #include <rtm/Manager.h>
00022 #include <rtm/DataFlowComponentBase.h>
00023
00024 #include "VirtualRobotPortHandler.h"
00025
00026 class Controller_impl;
00027
00028 class VirtualRobotRTC : public RTC::DataFlowComponentBase
00029 {
00030 public:
00031
00032 static void registerFactory(RTC::Manager* manager, const char* componentTypeName);
00033
00034 VirtualRobotRTC(RTC::Manager* manager);
00035 ~VirtualRobotRTC();
00036
00037 RTC::ReturnCode_t onInitialize();
00038
00039 PortHandlerPtr getPortHandler(const std::string& name);
00040
00041 RTC::RTCList* getConnectedRtcs();
00042
00043 void inputDataFromSimulator(Controller_impl* controller);
00044 void outputDataToSimulator(Controller_impl* controller);
00045
00046 void writeDataToOutPorts(Controller_impl* controller);
00047 void readDataFromInPorts(Controller_impl* controller);
00048 void stop();
00049 bool checkOutPortStepTime(double controlTimeStep);
00050 bool isOwnedByController;
00051
00052 private:
00053
00054 typedef std::map<std::string, OutPortHandlerPtr> OutPortHandlerMap;
00055 OutPortHandlerMap outPortHandlers;
00056
00057 typedef std::map<std::string, InPortHandlerPtr> InPortHandlerMap;
00058 InPortHandlerMap inPortHandlers;
00059
00060
00061 #ifdef OPENRTM_VERSION_042
00062 void createOutPortHandler(PortInfo& portInfo);
00063 void createInPortHandler(PortInfo& portInfo);
00064 template <class TOutPortHandler>
00065 void registerOutPortHandler(TOutPortHandler* handler) {
00066 const std::string& name = handler->portName;
00067 if(!getPortHandler(name)){
00068 registerOutPort(name.c_str(), handler->outPort);
00069 outPortHandlers.insert(std::make_pair(name, OutPortHandlerPtr(handler)));
00070 }
00071 }
00072 template <class TInPortHandler>
00073 void registerInPortHandler(TInPortHandler* handler) {
00074 const std::string& name = handler->portName;
00075 if(!getPortHandler(name)){
00076 registerInPort(name.c_str(), handler->inPort);
00077 inPortHandlers.insert(std::make_pair(name, InPortHandlerPtr(handler)));
00078 }
00079 }
00080 #else
00081 bool createOutPortHandler(PortInfo& portInfo);
00082 bool createInPortHandler(PortInfo& portInfo);
00083 template <class TOutPortHandler>
00084 bool registerOutPortHandler(TOutPortHandler* handler) {
00085 const std::string& name = handler->portName;
00086 if(!getPortHandler(name)){
00087 if (!addOutPort(name.c_str(), handler->outPort)) return false;
00088 outPortHandlers.insert(std::make_pair(name, OutPortHandlerPtr(handler)));
00089 }
00090 return true;
00091 }
00092
00093 template <class TInPortHandler>
00094 bool registerInPortHandler(TInPortHandler* handler) {
00095 const std::string& name = handler->portName;
00096 if(!getPortHandler(name)){
00097 if (!addInPort(name.c_str(), handler->inPort)) return false;
00098 inPortHandlers.insert(std::make_pair(name, InPortHandlerPtr(handler)));
00099 }
00100 return true;
00101 }
00102 #endif
00103 void updatePortObjectRefs();
00104
00105 void addConnectedRtcs(Port_Service_Ptr_Type portRef, RTC::RTCList& rtcList, std::set<std::string>& foundRtcNames);
00106 };
00107
00108
00109 #endif