ETrobocon2017 - 片山研究所モデルベース開発推進事業部
example_SpeedControl.cpp
[詳解]
1 
10 #include <iostream>
11 #include <random>
12 #include <unistd.h>
14 #include "SpeedControl.h"
15 
16 // グローバル変数
19 
20 // プロトタイプ宣言
21 void calcVirtualWheels();
22 
23 int main(){
25 
27  SpeedControl sp;
28 
36  sp.setPid(2.0, 2.0, 0.024, 70.0);
37 
38  // 注)4msごとに実行されると仮定して2500回(10秒)回してます
39  for(int i=0; i<2500; i++){
44  // 結果を画面に出力
45  std::cout << "スピード(100ms) " << speed100ms << ", PID値 " << value << ", 前進値" << (right_motor + left_motor) / 2 << std::endl;
46  usleep(4000);
47  }
48  return 0;
49 }
50 
51 // 仮想的なモータエンコーダです。
53  // モータの前進にランダム性を持たせる
54  std::random_device rnd;
55  std::mt19937 mt(rnd());
56  std::uniform_int_distribution<int> rand50(0,50); // 1~10の一様乱数
57  double r_value = rand50(mt) * 0.1;
58 
59  // 実際に進んだ距離とする
60  left_motor = right_motor += (speed100ms/25 + value + r_value) * 0.1;
61 }
int speed100ms
int right_motor
void calcVirtualWheels()
std::int32_t calculateSpeedForPid(std::int32_t curAngleL, std::int32_t curAngleR)
void setPid(double _p_gain, double _i_gain, double _d_gain, double _target)
Definition: Pid.cpp:40
PID制御による速度制御クラス
Definition: SpeedControl.h:18
int left_motor
int main()
std::int16_t getSpeed100ms()
PID制御による速度制御クラス