etrobocon2018 feat.KatLab  770af34cce41ae9c30c41303275e1add2daae0c3 (with uncommitted changes)
 全て クラス 名前空間 ファイル 関数 変数 列挙型 列挙値 フレンド マクロ定義 ページ
WheelOdometry.cpp
[詳解]
1 #include "WheelOdometry.h"
2 
9 void Coordinate::update(float distance, float angle)
10 {
11  // 移動角度
12  float theta = angle / 2.0f;
13 
14  // 直交座標の更新
15  x += distance * std::cos(arg + theta);
16  y += distance * std::sin(arg + theta);
17 
19  radius += distance;
21  arg += theta;
22 }
23 
29 {
30  radius = 0.0f;
31  arg = 0.0f;
32  x = 0.0f;
33  y = 0.0f;
34 }
35 
43 float WheelOdometry::velocity(std::int32_t left_motor, std::int32_t right_motor)
44 {
45  // 回転速度から走行体の速度へ変換するときに必要な係数
46  float transform = 3.14f * property.radius_wheel / 180.0f;
47  // 走行体の回転角の差を求める(LPF処理つき)
48  float angle = motor_angle.relativeAngleMean(left_motor, right_motor);
49 
50  return transform * angle / property.dt;
51 }
52 
60 float WheelOdometry::angularVelocity(std::int32_t left_motor, std::int32_t right_motor)
61 {
62  // 回転速度から角速度へ変換するときに必要な係数
63  float transform = property.radius_wheel / property.between_wheels;
64 
65  // 走行体の回転角の差を求める(右モータ - 左モータ), LPF処理つき
66  float angle = motor_angle.angularDifference(left_motor, right_motor);
67 
68  return transform * angle / property.dt;
69 }
70 
76 {
77  coordinate.reset();
78  motor_angle.reset();
79  return coordinate;
80 }
81 
89 const Coordinate& WheelOdometry::update(std::int32_t left_motor, std::int32_t right_motor)
90 {
91  // 走行体の移動距離を計算する
92  float distance = velocity(left_motor, right_motor) * property.dt;
93  // 走行体の旋回角度を計算する
94  float angle = angularVelocity(left_motor, right_motor) * property.dt;
95  // 走行体の位置情報を更新する
96  coordinate.update(distance, angle);
97  return coordinate;
98 }
99 
107 float WheelOdometry::getRotationAngle(std::int32_t left_motor, std::int32_t right_motor)
108 {
109  // モータの角度から回転角度へ変換するときに必要な係数
110  float transform = 2.0f * property.radius_wheel / property.between_wheels;
111 
112  // モータの角度を絶対値で取得する
113  left_motor = motor_angle.absoluteValueOfAngle(left_motor);
114  right_motor = motor_angle.absoluteValueOfAngle(right_motor);
115 
116  // モータの角度の平均値を求める
117  float mean = motor_angle.absoluteAngleMean(left_motor, right_motor);
118 
119  return transform * mean;
120 }
121 
127 {
128  return coordinate;
129 }
130 
136 {
137  return coordinate.x;
138 }
139 
145 {
146  return coordinate.y;
147 }
float relativeAngleMean(std::int32_t current_left_motor, std::int32_t current_right_motor)
左右モータの相対角度の平均値を計算する
Definition: MotorAngle.cpp:51
float getPointX()
走行体の位置x座標を返す
float angularVelocity(std::int32_t left_motor, std::int32_t right_motor)
走行体の旋回角速度を求める
void reset()
左右モータ角度の過去値を0にリセットする
Definition: MotorAngle.cpp:26
const Coordinate & getCoordinate()
走行体の位置情報を返す
float getRotationAngle(std::int32_t left_motor, std::int32_t right_motor)
走行体の回転角度を返す
float angularDifference(std::int32_t left_motor, std::int32_t right_motor)
左右モータ角度の差を計算する(右手系/反時計回りが正)
Definition: MotorAngle.cpp:72
std::int32_t absoluteValueOfAngle(std::int32_t motor)
モータ角度の絶対値を計算する
Definition: MotorAngle.cpp:83
float radius
Definition: WheelOdometry.h:17
void reset()
走行体の位置情報を初期化する
const Coordinate & update(std::int32_t left_motor, std::int32_t right_motor)
走行体の位置情報を更新する
float absoluteAngleMean(std::int32_t left_motor, std::int32_t right_motor)
左右モータの絶対角度の平均値を計算する
Definition: MotorAngle.cpp:39
float velocity(std::int32_t left_motor, std::int32_t right_motor)
走行体の旋回速度を求める
const Coordinate & reset()
走行体の位置情報を初期化する
void update(float distance, float angle)
走行体の位置情報を更新する
float getPointY()
走行体の位置y座標を返す
オドメトリ(Wheel odometry)手法を用いた速度/角度/自己位置推定
走行体の位置情報をまとめた構造体
Definition: WheelOdometry.h:16