00001
00010 #include "hrpsys/util/VectorConvert.h"
00011 #include "Joystick2PanTiltAngles.h"
00012
00013
00014
00015 static const char* joystick2velocity_spec[] =
00016 {
00017 "implementation_id", "Joystick2PanTiltAngles",
00018 "type_name", "Joystick2PanTiltAngles",
00019 "description", "joystick output to velocity converter",
00020 "version", HRPSYS_PACKAGE_VERSION,
00021 "vendor", "AIST",
00022 "category", "example",
00023 "activity_type", "DataFlowComponent",
00024 "max_instance", "10",
00025 "language", "C++",
00026 "lang_type", "compile",
00027
00028 "conf.default.debugLevel", "0",
00029 "conf.default.axesIds", "0,1,2",
00030 "conf.default.scales", "1.0,1.0,1.0",
00031 "conf.default.neutrals", "0.0,0.0,0.0",
00032 ""
00033 };
00034
00035
00036 Joystick2PanTiltAngles::Joystick2PanTiltAngles(RTC::Manager* manager)
00037 : RTC::DataFlowComponentBase(manager),
00038
00039 m_axesIn("axes", m_axes),
00040 m_anglesOut("angles", m_angles),
00041
00042 dummy(0),
00043 m_debugLevel(0)
00044 {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 }
00059
00060 Joystick2PanTiltAngles::~Joystick2PanTiltAngles()
00061 {
00062 }
00063
00064
00065
00066 RTC::ReturnCode_t Joystick2PanTiltAngles::onInitialize()
00067 {
00068
00069
00070
00071 bindParameter("debugLevel", m_debugLevel, "0");
00072 bindParameter("axesIds", m_axesIds, "0,1,2");
00073 bindParameter("scales", m_scales, "1.0,1.0,1.0");
00074 bindParameter("neutrals", m_neutrals, "0.0,0.0,0.0");
00075
00076
00077 addInPort("axes", m_axesIn);
00078 addOutPort("vel", m_anglesOut);
00079
00080 m_axes.data.length(4);
00081 for (unsigned int i=0; i<m_axes.data.length(); i++){
00082 m_axes.data[i] = 0.0;
00083 }
00084
00085 return RTC::RTC_OK;
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 RTC::ReturnCode_t Joystick2PanTiltAngles::onActivated(RTC::UniqueId ec_id)
00112 {
00113 return RTC::RTC_OK;
00114 }
00115
00116 RTC::ReturnCode_t Joystick2PanTiltAngles::onDeactivated(RTC::UniqueId ec_id)
00117 {
00118 return RTC::RTC_OK;
00119 }
00120
00121 RTC::ReturnCode_t Joystick2PanTiltAngles::onExecute(RTC::UniqueId ec_id)
00122 {
00123 if (m_debugLevel > 0){
00124 std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")"
00125 << std::endl;
00126 }
00127
00128 if (m_axesIn.isNew()) m_axesIn.read();
00129
00130 m_angles.pan = m_neutrals[0] + m_scales[0]*m_axes.data[m_axesIds[0]];
00131 m_angles.tilt = m_neutrals[1] + m_scales[1]*m_axes.data[m_axesIds[1]];
00132 if (m_debugLevel > 0) {
00133 printf("pan/tilt command: %5.2f %5.2f",
00134 m_angles.pan, m_angles.tilt);
00135 }
00136 m_anglesOut.write();
00137
00138 return RTC::RTC_OK;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 extern "C"
00179 {
00180
00181 void Joystick2PanTiltAnglesInit(RTC::Manager* manager)
00182 {
00183 RTC::Properties profile(joystick2velocity_spec);
00184 manager->registerFactory(profile,
00185 RTC::Create<Joystick2PanTiltAngles>,
00186 RTC::Delete<Joystick2PanTiltAngles>);
00187 }
00188
00189 };
00190
00191