M5Unified
IMU_Base.cpp
Go to the documentation of this file.
1 // Copyright (c) M5Stack. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 
4 #include "IMU_Base.hpp"
5 
6 namespace m5
7 {
9  IMU_Base::IMU_Base(std::uint8_t i2c_addr, std::uint32_t freq, I2C_Class* i2c)
10  : I2C_Device ( i2c_addr, freq, i2c )
11  {}
12 /*
13  int32_t IMU_Base::point3d_i32_t::calibration(const point3d_i16_t& dst)
14  {
15  { // 前回の座標情報との差が許容範囲よりも大きく移動しているか調べる
16  int32_t moving_distance = 0;
17  for (int i = 0; i < 3; ++i)
18  {
19  int32_t diff = dst.value[i] - prev_point.value[i];
20  moving_distance += diff * diff;
21  }
22  prev_point = dst;
23  uint32_t wait = wait_counter;
24  if (moving_distance > (tolerance * tolerance))
25  { // 移動変化量が大きい場合は補正を暫く停止する
26  wait = 16;
27  }
28  if (wait)
29  { // 座標移動が安定するまで待機
30  wait_counter = wait - 1;
31  return 0;
32  }
33  }
34 
35  float distance = 0;
36  float diffs[3];
37  for (int i = 0; i < 3; ++i)
38  {
39  float diff = (dst.value[i] << 16) - value[i];
40  diffs[i] = diff;
41  distance += diff * diff;
42  }
43  distance = sqrtf(distance * (1.0f / (65536.0f * 65536.0f)));
44 
45  // 誤差を求める (目的の半径と現在の距離の差)
46  float measure_error = distance - radius;
47 
48  int32_t tol = tolerance;
49  int32_t force = abs((int32_t)measure_error) - tol;
50  if (force <= 0) { return 1; }
51 
52  if (force > tol) { force = tol; }
53  if (signbit(measure_error)) { force = -force; }
54 
55  float fk = (force * strength) / (distance * 256.0f);
56  for (int i = 0; i < 3; ++i)
57  {
58  value[i] += diffs[i] * fk;
59  }
60  return 0;
61  }
62 //*/
63 }
IMU_Base(std::uint8_t i2c_addr, std::uint32_t freq=400000, I2C_Class *i2c=&In_I2C)
Definition: IMU_Base.cpp:9
virtual ~IMU_Base()
Definition: IMU_Base.cpp:8
Definition: M5Unified.cpp:48