Skip to content

Commit 03e81ff

Browse files
committed
add: 回転速度、ブレーキ、アームホールド関係の関数の追加
1 parent af265c1 commit 03e81ff

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

modules/API/Controller.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ int Controller::powerOfRightWheel = 0.0;
1717
int Controller::powerOfLeftWheel = 0.0;
1818
int Controller::powerOfArm = 0.0;
1919

20-
// モータに設定するPWM値の制限
20+
// // speed値の初期化
21+
// int Controller::speedOfRightWheel = 0;
22+
// int Controller::speedOfLeftWheel = 0;
23+
24+
// モータに設定するpower値の制限
2125
int Controller::limitPowerValue(const int inputPower)
2226
{
2327
if(inputPower > MOTOR_POWER_MAX) {
@@ -65,6 +69,18 @@ void Controller::resetWheelsMotorPower()
6569
leftWheel.setPower(powerOfLeftWheel);
6670
}
6771

72+
// 右タイヤのモータに回転速度をセット
73+
void Controller::setRightMotorSpeed(int speed)
74+
{
75+
rightWheel.setSpeed(speed);
76+
}
77+
78+
// 右タイヤのモータに回転速度をセット
79+
void Controller::setLeftMotorSpeed(int speed)
80+
{
81+
leftWheel.setSpeed(speed);
82+
}
83+
6884
// タイヤのモータを停止する
6985
void Controller::stopWheelsMotor()
7086
{
@@ -74,6 +90,15 @@ void Controller::stopWheelsMotor()
7490
leftWheel.stop();
7591
}
7692

93+
// ブレーキをかけてタイヤのモータを停止する
94+
void Controller::brakeWheelsMotor()
95+
{
96+
powerOfRightWheel = 0;
97+
powerOfLeftWheel = 0;
98+
rightWheel.brake();
99+
leftWheel.brake();
100+
}
101+
77102
// アームのモータにpower値をセット
78103
void Controller::setArmMotorPower(const int power)
79104
{
@@ -95,6 +120,12 @@ void Controller::stopArmMotor()
95120
armMotor.stop();
96121
}
97122

123+
//  アームモータを止めて角度を維持する
124+
void Controller::holdArmMotor()
125+
{
126+
armMotor.hold();
127+
}
128+
98129
// 右タイヤのpower値を取得する
99130
int Controller::getRightMotorPower()
100131
{
@@ -105,4 +136,16 @@ int Controller::getRightMotorPower()
105136
int Controller::getLeftMotorPower()
106137
{
107138
return leftWheel.getPower();
108-
}
139+
}
140+
141+
// 右タイヤモータの回転速度を取得する
142+
int Controller::getRightMotorSpeed()
143+
{
144+
return rightWheel.getSpeed();
145+
}
146+
147+
// 左タイヤモータの回転速度を取得する
148+
int Controller::getLeftMotorSpeed()
149+
{
150+
return leftWheel.getSpeed();
151+
}

modules/API/Controller.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,22 @@ class Controller {
3535
void resetLeftMotorPower();
3636
void resetWheelsMotorPower();
3737

38+
/**
39+
* @brief タイヤのモータに回転速度をセット
40+
* @param speed 回転速度
41+
*/
42+
void setRightMotorSpeed(const int speed);
43+
void setLeftMotorSpeed(const int speed);
3844
/**
3945
* @brief タイヤのモータを停止する
4046
*/
4147
void stopWheelsMotor();
4248

49+
/**
50+
* @brief ブレーキをかけてタイヤのモータを停止する
51+
*/
52+
void brakeWheelsMotor();
53+
4354
/**
4455
* @brief アームのモータにpower値をセット
4556
* @param power power値
@@ -56,6 +67,12 @@ class Controller {
5667
*/
5768
void stopArmMotor();
5869

70+
/**
71+
* アームモータを止めて角度を維持する
72+
* @return -
73+
*/
74+
void holdArmMotor();
75+
5976
/**
6077
* @brief 右タイヤのpower値を取得する
6178
* @return 右タイヤのpower値
@@ -68,13 +85,27 @@ class Controller {
6885
*/
6986
int getLeftMotorPower();
7087

88+
/**
89+
* @brief 右タイヤの回転速度を取得する
90+
* @return 右タイヤの回転速度
91+
*/
92+
int getRightMotorSpeed();
93+
94+
/**
95+
* @brief 左タイヤの回転速度を取得する
96+
* @return 左タイヤの回転速度
97+
*/
98+
int getLeftMotorSpeed();
99+
71100
private:
72101
Motor rightWheel;
73102
Motor leftWheel;
74103
Motor armMotor;
75104
static int powerOfRightWheel; // 右タイヤpower
76105
static int powerOfLeftWheel; // 左タイヤpower
77106
static int powerOfArm; // アームpower
107+
static int speedOfRightWheel; // 右タイヤ回転速度
108+
static int speedOfLeftWheel; // 左タイヤ回転速度
78109

79110
/**
80111
* @brief モータに設定するpower値の制限

0 commit comments

Comments
 (0)