• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン17 (tree)
日時2008-05-18 09:47:45
作者satofumi

ログメッセージ

add IR function

変更サマリ

差分

--- trunk/libs/controller/samples/wiiJoystickSample.cpp (revision 16)
+++ trunk/libs/controller/samples/wiiJoystickSample.cpp (revision 17)
@@ -22,12 +22,12 @@
2222 }
2323 printf("O.K.\n");
2424
25- // バッテリー情報の出力
26- printf("battery: %d [%%]\n", joystick.getBatteryPercent());
27-
2825 size_t buttons_num = joystick.getButtonsNum();
2926 while (1) {
3027
28+ // バッテリー情報
29+ printf("%d[%%], ", joystick.getBatteryPercent());
30+
3131 // 軸情報
3232 int x_axis = joystick.getAxisValue(WiiJoystick::AxisX);
3333 int y_axis = joystick.getAxisValue(WiiJoystick::AxisY);
@@ -42,8 +42,20 @@
4242 // 加速度情報
4343 Grid3D<double> acceleration;
4444 joystick.getAcceleration(acceleration);
45- printf("%.2f, %.2f, %.2f", acceleration.x, acceleration.y, acceleration.z);
45+ printf("%.2f, %.2f, %.2f, ",
46+ acceleration.x, acceleration.y, acceleration.z);
4647
48+ // IR 情報
49+ std::vector<WiiJoystick::ir_position> ir_positions;
50+ joystick.getIrPosition(ir_positions);
51+ if (! ir_positions.empty()) {
52+ printf("\n");
53+ }
54+ for (std::vector<WiiJoystick::ir_position>::iterator it =
55+ ir_positions.begin(); it != ir_positions.end(); ++it) {
56+ printf("(%.2f, %.2f, %d), ", it->position.x, it->position.y, it->size);
57+ }
58+
4759 printf("\n");
4860
4961 delay(100);
--- trunk/libs/controller/WiiJoystick.cpp (revision 16)
+++ trunk/libs/controller/WiiJoystick.cpp (revision 17)
@@ -41,6 +41,8 @@
4141 Grid3D<double> acceleration_;
4242 size_t acceleration_timestamp_;
4343
44+ std::vector<ir_position> ir_positions_;
45+
4446 WiiInformation(void)
4547 : quit_(false), battery_percent_(0),
4648 buttons_timestamp_(0), acceleration_timestamp_(0) {
@@ -54,7 +56,7 @@
5456 pressed_times_[i] = 0;
5557 }
5658
57- // !!! calibration_ は未初期化...
59+ // !!! calibration_ は未初期化
5860 }
5961 };
6062 typedef std::map<const cwiid_wiimote_t*, WiiInformation*> WiiHash;
@@ -117,7 +119,7 @@
117119 // !!!
118120 }
119121
120- static void recordAcceleration(struct cwiid_acc_mesg *mesg,
122+ static void recordAcceleration(struct cwiid_acc_mesg* mesg,
121123 WiiInformation* state) {
122124
123125 uint8_t* acc = mesg->acc;
@@ -134,6 +136,29 @@
134136 (calibration.one[CWIID_Z] - calibration.zero[CWIID_Z]);
135137 }
136138
139+ static void recordIrPosition(struct cwiid_ir_mesg* ir_data,
140+ WiiInformation* state) {
141+
142+ state->ir_positions_.clear();
143+ for (int i = 0; i < CWIID_IR_SRC_COUNT; ++i) {
144+ ir_position each_position;
145+
146+ if (ir_data->src[i].valid) {
147+ if (ir_data->src[i].size == -1) {
148+ each_position.size = 3;
149+ } else {
150+ each_position.size = ir_data->src[i].size + 1;
151+ }
152+
153+ // 位置情報の格納
154+ each_position.position =
155+ Grid<double>(1.0 * ir_data->src[i].pos[CWIID_X] / CWIID_IR_X_MAX,
156+ 1.0 * ir_data->src[i].pos[CWIID_Y] / CWIID_IR_Y_MAX);
157+ state->ir_positions_.push_back(each_position);
158+ }
159+ }
160+ }
161+
137162 static void callback(cwiid_wiimote_t *wii, int mesg_count,
138163 union cwiid_mesg mesg_array[],
139164 struct timespec *timestamp) {
@@ -161,8 +186,8 @@
161186 break;
162187
163188 case CWIID_MESG_IR:
164- //cwiid_ir(&mesg_array[i].ir_mesg);
165- // !!! とりあえず省略
189+ // IR 情報の取得
190+ recordIrPosition(&mesg_array[i].ir_mesg, state);
166191 break;
167192
168193 case CWIID_MESG_ERROR:
@@ -349,3 +374,13 @@
349374
350375 return pimpl->callback_->getBatteryPercent(pimpl->wii_);
351376 }
377+
378+
379+bool WiiJoystick::getIrPosition(std::vector<ir_position>& positions) {
380+
381+ // !!! 排他制御
382+
383+ positions = pimpl->callback_->wii_hash_[pimpl->wii_]->ir_positions_;
384+
385+ return true;
386+}
--- trunk/libs/controller/WiiJoystick.h (revision 16)
+++ trunk/libs/controller/WiiJoystick.h (revision 17)
@@ -5,6 +5,8 @@
55 \file
66 \brief Wii コントローラ
77
8+ \attention 接続後、最初のデータが返されるまでの各メソッドの戻り値は不定となる
9+
810 \author Satofumi KAMIMURA
911
1012 $Id$
@@ -13,6 +15,7 @@
1315 */
1416
1517 #include <memory>
18+#include <vector>
1619 #include "GridTypes.h"
1720
1821
@@ -40,6 +43,11 @@
4043 BUTTON_2,
4144 };
4245
46+ typedef struct {
47+ Grid<double> position;
48+ size_t size;
49+ } ir_position;
50+
4351 WiiJoystick(void);
4452 ~WiiJoystick(void);
4553
@@ -134,11 +142,17 @@
134142 \brief バッテリー充電率の取得
135143
136144 \return バッテリーの充電率
137-
138- \bug 現状、必ずゼロが返される
139145 */
140146 size_t getBatteryPercent(void);
141147
148+ /*!
149+ \brief IR 情報の取得
150+
151+ \param positions [i] IR 検出位置
152+
153+ */
154+ bool getIrPosition(std::vector<ir_position>& positions);
155+
142156 // Wii コントローラの制御
143157 // !!! 振動
144158 // !!! LED
旧リポジトリブラウザで表示