11 : distance(), controller(controller_), pidForSpeed(Kp_, Ki_, Kd_)
24 double goalDistance = specifiedDistance + distance.
getDistance(leftAngle, rightAngle);
30 if(specifiedDistance < 0) {
31 while(hasArrived(goalDistance,
false)) {
33 setPwmValue(-std::abs(pwm), -alpha);
37 while(hasArrived(goalDistance,
true)) {
39 setPwmValue(std::abs(pwm), -alpha);
51 double goalDistance = specifiedDistance + distance.
getDistance(leftAngle, rightAngle);
53 SpeedControl speedControl(controller, specifiedSpeed, pidForSpeed.
Kp, pidForSpeed.
Ki,
56 if(specifiedDistance < 0) {
57 while(hasArrived(goalDistance,
false)) {
58 double pwm = speedControl.
calculateSpeed(specifiedSpeed, pidForSpeed.
Kp, pidForSpeed.
Ki,
60 setPwmValue(static_cast<int>(-std::abs(pwm)));
64 while(hasArrived(goalDistance,
true)) {
65 double pwm = speedControl.
calculateSpeed(specifiedSpeed, pidForSpeed.
Kp, pidForSpeed.
Ki,
67 setPwmValue(static_cast<int>(std::abs(pwm)));
100 angle = std::abs(angle);
115 bool Navigator::hasArrived(
double goalDistance,
bool isForward)
121 int currentDistance = distance.
getDistance(leftAngle, rightAngle);
124 return currentDistance <= goalDistance;
126 return currentDistance >= goalDistance;
130 void Navigator::setPwmValue(
int pwm,
double alpha)
double calculateSpeed(int targetSpeed, double Kp, double Ki, double Kd)
void spin(double angle, bool clockwise=true, int pwm=10)
走行体を回頭させる(yawing)
double calculate(const int leftAngle, const int rightAngle)
自転したときの角度を求める
void setPidGain(double Kp_, double Ki_, double Kd_)
void setLeftMotorPwm(const int pwm)
Navigator(Controller &controller_, double Kp_=0.60, double Ki_=0.0, double Kd_=0.0)
Navigatorクラスのコンストラクタ
Color hsvToColor(const HsvStatus &status)
void moveToSpecifiedColor(Color specifiedColor, int pwm=30)
void convertHsv(int &r, int &g, int &b)
void setRightMotorPwm(const int pwm)
double control(double value, double delta=0.004)
static void tslpTsk(int time)
void moveAtSpecifiedSpeed(double specifiedDistance, int specifiedSpeed)
specifiedDistanceとSpeedControl.calculateSpeedから戻ってきたPWMをmoveに渡す
void move(double specifiedDistance, int pwm=30, const double pGain=0.0)
specifiedDistanceの値でbackwardかforwardを呼び出す。
double getDistance(int leftAngle, int rightAngle)
左右の平均走行距離を計算して戻り値として返す
void getRawColor(int &r, int &g, int &b)
void setPidGain(double Kp, double Ki, double Kd)
SpeedControl用のPidゲインのセッター