質問編集履歴

1

追記

2019/05/03 10:06

投稿

tannu
tannu

スコア13

test CHANGED
File without changes
test CHANGED
@@ -223,3 +223,125 @@
223
223
 
224
224
 
225
225
  知識不足な部分が多いかと思いますがよろしくお願いします.
226
+
227
+
228
+
229
+ ### 追記
230
+
231
+ DMPを利用した角度を算出するプログラムを見つけることができたのですが,絶対角度で算出することができません.
232
+
233
+ こちらのコードから絶対角度を算出する方法があれば教えていただきたいです.
234
+
235
+ (加速度,ジャイロ,地磁気の値を取り出せれば回転行列によって求められるのですが,,,)
236
+
237
+ 以下にそのコードを添付いたします.(必要ないものはコメントアウトしています)
238
+
239
+ [参照サイト](http://kousukeno.seesaa.net/article/445610208.html)
240
+
241
+ ```Arduino
242
+
243
+ #include "freeram.h"
244
+
245
+
246
+
247
+ #include "mpu.h"
248
+
249
+ #include "I2Cdev.h"
250
+
251
+
252
+
253
+ int ret;
254
+
255
+ void setup() {
256
+
257
+ Fastwire::setup(400,0);
258
+
259
+ Serial.begin(9600);
260
+
261
+ ret = mympu_open(200);
262
+
263
+ //Serial.print("MPU init: "); Serial.println(ret);
264
+
265
+ //Serial.print("Free mem: "); Serial.println(freeRam());
266
+
267
+
268
+
269
+ }
270
+
271
+
272
+
273
+ unsigned int c = 0; //cumulative number of successful MPU/DMP reads
274
+
275
+ unsigned int np = 0; //cumulative number of MPU/DMP reads that brought no packet back
276
+
277
+ unsigned int err_c = 0; //cumulative number of MPU/DMP reads that brought corrupted packet
278
+
279
+ unsigned int err_o = 0; //cumulative number of MPU/DMP reads that had overflow bit set
280
+
281
+
282
+
283
+ void loop() {
284
+
285
+ ret = mympu_update();
286
+
287
+
288
+
289
+ switch (ret) {
290
+
291
+ case 0: c++; break;
292
+
293
+ case 1: np++; return;
294
+
295
+ case 2: err_o++; return;
296
+
297
+ case 3: err_c++; return;
298
+
299
+ default:
300
+
301
+ Serial.print("READ ERROR! ");
302
+
303
+ Serial.println(ret);
304
+
305
+ return;
306
+
307
+ }
308
+
309
+
310
+
311
+ if (!(c%25)) {
312
+
313
+ // Serial.print(np); Serial.print(" "); Serial.print(err_c); Serial.print(" "); Serial.print(err_o);
314
+
315
+ //Serial.print(" Yaw: ");
316
+
317
+ Serial.print(mympu.ypr[0]);
318
+
319
+   Serial.print(',');
320
+
321
+ //Serial.print(" Pitch: ");
322
+
323
+ Serial.print(mympu.ypr[1]);
324
+
325
+   Serial.print(',');
326
+
327
+ //Serial.print(" Roll: ");
328
+
329
+ Serial.println(mympu.ypr[2]);
330
+
331
+
332
+
333
+
334
+
335
+ //Serial.print("\tgy: "); Serial.print(mympu.gyro[0]);
336
+
337
+ //Serial.print(" gp: "); Serial.print(mympu.gyro[1]);
338
+
339
+ //Serial.print(" gr: "); Serial.println(mympu.gyro[2]);
340
+
341
+ }
342
+
343
+ }
344
+
345
+
346
+
347
+ ```