Go to the documentation of this file.00001
00007 #include "SwitchInputRTC.h"
00008
00009
00010
00011 static const char* switchinputrtc_spec[] =
00012 {
00013 "implementation_id", "SwitchInputRTC",
00014 "type_name", "SwitchInputRTC",
00015 "description", "Swtich input component",
00016 "version", "1.0",
00017 "vendor", "AIST",
00018 "category", "example",
00019 "activity_type", "SPORADIC",
00020 "kind", "DataFlowComponent",
00021 "max_instance", "10",
00022 "language", "C++",
00023 "lang_type", "compile",
00024
00025 ""
00026 };
00027
00028
00029 SwitchInputRTC::SwitchInputRTC(RTC::Manager* manager)
00030
00031 : RTC::DataFlowComponentBase(manager),
00032 m_outVelOut("outVel", m_outVel),
00033 m_inVelJoyIn("inVelJoy", m_inVelJoy),
00034 m_inVelAutoIn("inVelAuto", m_inVelAuto)
00035
00036
00037 {
00038 }
00039
00040 SwitchInputRTC::~SwitchInputRTC()
00041 {
00042 }
00043
00044
00045 RTC::ReturnCode_t SwitchInputRTC::onInitialize()
00046 {
00047
00048
00049
00050 addInPort("inVelJoy", m_inVelJoyIn);
00051 addInPort("inVelAuto", m_inVelAutoIn);
00052
00053
00054 addOutPort("outVel", m_outVelOut);
00055
00056 tv0.tv_sec = 0;
00057 tv1.tv_sec = 0;
00058 tv0.tv_usec = 0;
00059 tv1.tv_usec = 0;
00060
00061 return RTC::RTC_OK;
00062 }
00063
00064
00065 RTC::ReturnCode_t SwitchInputRTC::onExecute(RTC::UniqueId ec_id)
00066 {
00067 if (m_inVelJoyIn.isNew())
00068 {
00069 m_inVelJoyIn.read();
00070 gettimeofday(&tv0,0);
00071 std::cout << "JoyStick vx:" << m_inVelJoy.data.vx << "vy:" << m_inVelJoy.data.vy << "TimeStamp: " << tv0.tv_sec << "[s] " << tv0.tv_usec << "[usec]" << std::endl;
00072 m_outVel.data.vx = m_inVelJoy.data.vx;
00073 m_outVel.data.vy = m_inVelJoy.data.vy;
00074 m_outVel.data.va = m_inVelJoy.data.va;
00075 m_outVelOut.write();
00076 }
00077 else if (m_inVelAutoIn.isNew())
00078 {
00079 m_inVelAutoIn.read();
00080 gettimeofday(&tv1,0);
00081
00082 dsec = tv1.tv_sec - tv0.tv_sec;
00083 dusec = tv1.tv_usec - tv0.tv_usec;
00084 dusec = dsec*1000*1000+dusec;
00085
00086
00087 if(dusec>500000){
00088 std::cout << "AUTO vx:" << m_inVelAuto.data.vx << "vy:" << m_inVelAuto.data.vy << "TimeStamp: " << tv1.tv_sec << "[s] " << tv1.tv_usec << "[usec]" << std::endl;
00089 m_outVel.data.vx = m_inVelAuto.data.vx;
00090 m_outVel.data.vy = m_inVelAuto.data.vy;
00091 m_outVel.data.va = m_inVelAuto.data.va;
00092 m_outVelOut.write();
00093 }
00094 }
00095 usleep(50000);
00096
00097 return RTC::RTC_OK;
00098 }
00099
00100
00101 extern "C"
00102 {
00103
00104 void SwitchInputRTCInit(RTC::Manager* manager)
00105 {
00106 coil::Properties profile(switchinputrtc_spec);
00107 manager->registerFactory(profile,
00108 RTC::Create<SwitchInputRTC>,
00109 RTC::Delete<SwitchInputRTC>);
00110 }
00111
00112 };
00113