Go to the documentation of this file.00001
00010 package jp.go.aist.hrp.joystick.rtc;
00011
00012 import org.eclipse.swt.graphics.Point;
00013
00014 import jp.go.aist.hrp.joystick.views.joystickView;
00015 import jp.go.aist.rtm.RTC.DataFlowComponentBase;
00016 import jp.go.aist.rtm.RTC.Manager;
00017 import jp.go.aist.rtm.RTC.port.OutPort;
00018 import jp.go.aist.rtm.RTC.util.DataRef;
00019 import RTC.ReturnCode_t;
00020 import RTC.TimedFloatSeq;
00021 import RTC.Time;
00022
00023
00029 public class JoystickImpl extends DataFlowComponentBase {
00030
00035 public JoystickImpl(Manager manager) {
00036 super(manager);
00037 }
00038
00048 @Override
00049 protected ReturnCode_t onInitialize() {
00050
00051
00052 m_pos_val = new TimedFloatSeq(new Time(0,0), new float[2]);
00053 m_pos = new DataRef<TimedFloatSeq>(m_pos_val);
00054 m_posOut = new OutPort<TimedFloatSeq>("pos", m_pos);
00055 m_vel_val = new TimedFloatSeq(new Time(0,0), new float[2]);
00056 m_vel = new DataRef<TimedFloatSeq>(m_vel_val);
00057 m_velOut = new OutPort<TimedFloatSeq>("vel", m_vel);
00058
00059
00060
00061
00062
00063
00064
00065 try {
00066 registerOutPort(TimedFloatSeq.class, "pos", m_posOut);
00067 registerOutPort(TimedFloatSeq.class, "vel", m_velOut);
00068 } catch (Exception e) {
00069 e.printStackTrace();
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 return ReturnCode_t.RTC_OK;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 @Override
00093 protected ReturnCode_t onFinalize() {
00094 System.out.println("Joystick Finalized");
00095 return super.onFinalize();
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 @Override
00110 protected ReturnCode_t onStartup(int ec_id) {
00111 System.out.println("Joystick Started");
00112 return super.onStartup(ec_id);
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 @Override
00127 protected ReturnCode_t onShutdown(int ec_id) {
00128 System.out.println("Joystick Shutting down");
00129 return super.onShutdown(ec_id);
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 @Override
00144 protected ReturnCode_t onActivated(int ec_id) {
00145 System.out.println("Joystick Activated");
00146 return super.onActivated(ec_id);
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 @Override
00161 protected ReturnCode_t onDeactivated(int ec_id) {
00162 System.out.println("Joystick Deactivated");
00163 return super.onDeactivated(ec_id);
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 @Override
00178 protected ReturnCode_t onExecute(int ec_id) {
00179
00180 Point p = joystickView.getJoystickPosition();
00181 float[] pos = {p.x,p.y};
00182 float[] vel = this.convert(p);
00183 m_pos_val.data = pos;
00184 m_vel_val.data = vel;
00185 m_posOut.write();
00186 m_velOut.write();
00187
00188
00189
00190 return ReturnCode_t.RTC_OK;
00191 }
00192
00193
00200 protected float[] convert(Point p) {
00201 double k=1.0;
00202 double _th = Math.atan2(p.y,p.x);
00203 double _v = k * Math.hypot(p.x, p.y);
00204 double _vl = _v * Math.cos(_th - (Math.PI/4.0));
00205 double _vr = _v * Math.sin(_th - (Math.PI/4.0));
00206 if(_vr==-0.0) _vr*=-1;
00207 float[] v = {(float) _vl, (float) _vr};
00208 return v;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 @Override
00223 public ReturnCode_t onAborting(int ec_id) {
00224 System.out.println("Joystick Aborted");
00225 return super.onAborting(ec_id);
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 @Override
00240 public ReturnCode_t onError(int ec_id) {
00241 System.out.println("Joystick Error : "+ec_id);
00242 return super.onError(ec_id);
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 @Override
00257 protected ReturnCode_t onReset(int ec_id) {
00258 System.out.println("Joystick Reset");
00259 return super.onReset(ec_id);
00260 }
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 @Override
00274 protected ReturnCode_t onStateUpdate(int ec_id) {
00275 return super.onStateUpdate(ec_id);
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 @Override
00290 protected ReturnCode_t onRateChanged(int ec_id) {
00291 return super.onRateChanged(ec_id);
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 protected TimedFloatSeq m_pos_val;
00303 protected DataRef<TimedFloatSeq> m_pos;
00309 protected OutPort<TimedFloatSeq> m_posOut;
00310
00311 protected TimedFloatSeq m_vel_val;
00312 protected DataRef<TimedFloatSeq> m_vel;
00318 protected OutPort<TimedFloatSeq> m_velOut;
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 }