Skip to content

Commit

Permalink
refactor: 実機でコンパイルできない理由が名前ではなさそうなので元の名前に戻した.詳しくはNotion
Browse files Browse the repository at this point in the history
  • Loading branch information
CHIHAYATAKU committed Jun 9, 2024
1 parent 14c9ea6 commit d106c57
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file PwmFromSpeedCalculator.cpp
* @file SpeedCalculator.cpp
* @brief 目標速度に対応するPWM値を算出するクラス
* @author CHIHAYATAKU
*/
#include "PwmFromSpeedCalculator.h"
#include "SpeedCalculator.h"

PwmFromSpeedCalculator::PwmFromSpeedCalculator(double _targetSpeed)
SpeedCalculator::SpeedCalculator(double _targetSpeed)
: rightTargetSpeed(_targetSpeed),
leftTargetSpeed(_targetSpeed),
rightPid(K_P, K_I, K_D, _targetSpeed),
Expand All @@ -22,7 +22,7 @@ PwmFromSpeedCalculator::PwmFromSpeedCalculator(double _targetSpeed)
prevLeftTime = currentTime;
}

PwmFromSpeedCalculator::PwmFromSpeedCalculator(double _rightTargetSpeed, double _leftTargetSpeed)
SpeedCalculator::SpeedCalculator(double _rightTargetSpeed, double _leftTargetSpeed)
: rightTargetSpeed(_rightTargetSpeed),
leftTargetSpeed(_leftTargetSpeed),
rightPid(R_K_P, R_K_I, R_K_D, _rightTargetSpeed),
Expand All @@ -39,7 +39,7 @@ PwmFromSpeedCalculator::PwmFromSpeedCalculator(double _rightTargetSpeed, double
prevLeftTime = currentTime;
}

double PwmFromSpeedCalculator::calculateRightPwmFromTargetSpeed()
double SpeedCalculator::calculateRightPwmFromTargetSpeed()
{
// 右タイヤの回転角度を取得
int rightAngle = measurer.getRightCount();
Expand All @@ -60,7 +60,7 @@ double PwmFromSpeedCalculator::calculateRightPwmFromTargetSpeed()
return rightPwm;
}

double PwmFromSpeedCalculator::calculateLeftPwmFromTargetSpeed()
double SpeedCalculator::calculateLeftPwmFromTargetSpeed()
{
// 左タイヤの回転角度を取得
int leftAngle = measurer.getLeftCount();
Expand All @@ -81,7 +81,7 @@ double PwmFromSpeedCalculator::calculateLeftPwmFromTargetSpeed()
return leftPwm;
}

double PwmFromSpeedCalculator::calculateSpeed(double diffMileage, double diffTime)
double SpeedCalculator::calculateSpeed(double diffMileage, double diffTime)
{
// 走行時間が0のとき、0を返す
if(diffTime == 0.0) return 0.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/**
* @file PwmFromSpeedCalculator.h
* @file SpeedCalculator.h
* @brief 目標速度に対応するPWM値を算出するクラス
* @author CHIHAYATAKU
*/

#ifndef PWMFROMSPEEDCALCULATOR_H
#define PWMFROMSPEEDCALCULATOR_H
#ifndef SpeedCalculator_H
#define SpeedCalculator_H

#include "Mileage.h"
#include "Pid.h"
#include "Timer.h"
#include "Controller.h"
#include "Measurer.h"

class PwmFromSpeedCalculator {
class SpeedCalculator {
public:
/**
* @brief 引数1つの場合のコンストラクタ
* @param _targetSpeed 目標とする走行速度[mm/s]
*/
PwmFromSpeedCalculator(double _targetSpeed);
SpeedCalculator(double _targetSpeed);

/**
* @brief 引数2つの場合のコンストラクタ
* @param _rightTargetSpeed 目標とする右タイヤ走行速度[mm/s]
* @param _leftTargetSpeed 目標とする左タイヤ走行速度[mm/s]
*/
PwmFromSpeedCalculator(double _rightTargetSpeed, double _leftTargetSpeed);
SpeedCalculator(double _rightTargetSpeed, double _leftTargetSpeed);

/**
* @brief 目標とする走行速度に相当する右車輪のPWM値を算出する
Expand Down
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
/**
* @file PwmFromSpeedCalculatorTest.cpp
* @file SpeedCalculatorTest.cpp
* @brief SpeedCalculatorクラスをテストする
* @author CHIHAYATAKU
*/

#include "PwmFromSpeedCalculator.h"
#include "SpeedCalculator.h"
#include <gtest/gtest.h>

namespace etrobocon2024_test {

TEST(PwmFromSpeedCalculatorTest, calculateLeftPwmFromTargetSpeed)
TEST(SpeedCalculatorTest, calculateLeftPwmFromTargetSpeed)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(300.0);
SpeedCalculator speedCalc(300.0);
double actualPwm = speedCalc.calculateLeftPwmFromTargetSpeed();
EXPECT_LT(0, actualPwm);
}

TEST(PwmFromSpeedCalculatorTest, calculateRightPwmFromMinusSpeed)
TEST(SpeedCalculatorTest, calculateRightPwmFromMinusSpeed)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(-250.7);
SpeedCalculator speedCalc(-250.7);
double actualPwm = speedCalc.calculateRightPwmFromTargetSpeed();
EXPECT_GT(0, actualPwm);
}

TEST(PwmFromSpeedCalculatorTest, calculateRightPwmFromZeroSpeed)
TEST(SpeedCalculatorTest, calculateRightPwmFromZeroSpeed)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(0.0);
SpeedCalculator speedCalc(0.0);
double actualPwm = speedCalc.calculateRightPwmFromTargetSpeed();
EXPECT_EQ(0, actualPwm);
}

TEST(PwmFromSpeedCalculatorTest, calculateRightPwmFromTargetSpeed)
TEST(SpeedCalculatorTest, calculateRightPwmFromTargetSpeed)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(300.0);
SpeedCalculator speedCalc(300.0);
double actualPwm = speedCalc.calculateRightPwmFromTargetSpeed();
EXPECT_LT(0, actualPwm);
}

TEST(PwmFromSpeedCalculatorTest, calculateLeftPwmFromMinusSpeed)
TEST(SpeedCalculatorTest, calculateLeftPwmFromMinusSpeed)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(-250.7);
SpeedCalculator speedCalc(-250.7);
double actualPwm = speedCalc.calculateLeftPwmFromTargetSpeed();
EXPECT_GT(0, actualPwm);
}

TEST(PwmFromSpeedCalculatorTest, calculateLeftPwmFromZeroSpeed)
TEST(SpeedCalculatorTest, calculateLeftPwmFromZeroSpeed)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(0.0);
SpeedCalculator speedCalc(0.0);
double actualPwm = speedCalc.calculateLeftPwmFromTargetSpeed();
EXPECT_EQ(0, actualPwm);
}

TEST(PwmFromSpeedCalculatorTest, calculatePwmFromMinusLeftSpeedWithTwoArguments)
TEST(SpeedCalculatorTest, calculatePwmFromMinusLeftSpeedWithTwoArguments)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(300.0, -300.0);
SpeedCalculator speedCalc(300.0, -300.0);
double actualRightPwm = speedCalc.calculateRightPwmFromTargetSpeed();
double actualLeftPwm = speedCalc.calculateLeftPwmFromTargetSpeed();
EXPECT_LT(0, actualRightPwm);
EXPECT_GT(0, actualLeftPwm);
}

TEST(PwmFromSpeedCalculatorTest, calculatePwmFromMinusRightSpeedWithTwoArguments)
TEST(SpeedCalculatorTest, calculatePwmFromMinusRightSpeedWithTwoArguments)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(-250.7, 250.7);
SpeedCalculator speedCalc(-250.7, 250.7);
double actualRightPwm = speedCalc.calculateRightPwmFromTargetSpeed();
double actualLeftPwm = speedCalc.calculateLeftPwmFromTargetSpeed();
EXPECT_GT(0, actualRightPwm);
EXPECT_LT(0, actualLeftPwm);
}

TEST(PwmFromSpeedCalculatorTest, calculatePwmFromZeroRightSpeedWithTwoArguments)
TEST(SpeedCalculatorTest, calculatePwmFromZeroRightSpeedWithTwoArguments)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(0.0, 250.7);
SpeedCalculator speedCalc(0.0, 250.7);
double actualRightPwm = speedCalc.calculateRightPwmFromTargetSpeed();
double actualLeftPwm = speedCalc.calculateLeftPwmFromTargetSpeed();
EXPECT_EQ(0, actualRightPwm);
EXPECT_LT(0, actualLeftPwm);
}

TEST(PwmFromSpeedCalculatorTest, calculatePwmFromZeroLeftSpeedWithTwoArguments)
TEST(SpeedCalculatorTest, calculatePwmFromZeroLeftSpeedWithTwoArguments)
{
Controller controller;
// PWMの初期化
controller.setRightMotorPwm(0.0);
controller.setLeftMotorPwm(0.0);
PwmFromSpeedCalculator speedCalc(-300.0, 0.0);
SpeedCalculator speedCalc(-300.0, 0.0);
double actualRightPwm = speedCalc.calculateRightPwmFromTargetSpeed();
double actualLeftPwm = speedCalc.calculateLeftPwmFromTargetSpeed();
EXPECT_GT(0, actualRightPwm);
Expand Down

0 comments on commit d106c57

Please sign in to comment.