Skip to content

Commit c4df64c

Browse files
committed
added limiter in motor_control instead bypass ref
1 parent e46c4c6 commit c4df64c

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/motor_control/motor_control.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ MotorControl::MotorControl(DCmotor * _motor, Encoder * _encoder, const float _kp
4242
angle = 0.0;
4343
reference = 0.0;
4444

45+
return_flag = false;
46+
4547
trip = 0.0;
4648
iterations = 0.0;
4749
start_value = 0.0;
@@ -111,22 +113,28 @@ float MotorControl::getRPM(){
111113

112114

113115
bool MotorControl::setRPM(const float ref){
114-
if ((ref<=MOTOR_LIMIT)&&(ref>=-MOTOR_LIMIT)){
115-
reference = ref;
116-
if (control_mode==CONTROL_MODE_LINEAR){
117-
start_value=interpolation;
118-
end_value=reference;
119-
trip=0.0;
120-
iterations=abs(end_value-start_value)/step_size;
121-
step=1.0/iterations;
122-
step_index=0;
123-
}
124-
else if(control_mode==CONTROL_MODE_NORMAL){
125-
vel_pid->setReference(reference);
126-
}
127-
return true;
116+
reference = ref;
117+
return_flag = true;
118+
if (ref>MOTOR_LIMIT){
119+
reference=MOTOR_LIMIT;
120+
return_flag = false;
121+
}
122+
if (ref<-MOTOR_LIMIT){
123+
reference=-MOTOR_LIMIT;
124+
return_flag = false;
125+
}
126+
if (control_mode==CONTROL_MODE_LINEAR){
127+
start_value=interpolation;
128+
end_value=reference;
129+
trip=0.0;
130+
iterations=abs(end_value-start_value)/step_size;
131+
step=1.0/iterations;
132+
step_index=0;
133+
}
134+
else if(control_mode==CONTROL_MODE_NORMAL){
135+
vel_pid->setReference(reference);
128136
}
129-
return false;
137+
return return_flag;
130138
}
131139

132140
void MotorControl::update(){

src/motor_control/motor_control.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class MotorControl{
2929
private:
3030

3131
uint8_t control_mode;
32+
bool return_flag;
33+
3234

3335
float kp;
3436
float ki;

0 commit comments

Comments
 (0)