Skip to content

Commit 69f6d4d

Browse files
committed
changed sleep_for to safer value to decrease chance of motor/sensor disconect
1 parent 36d8542 commit 69f6d4d

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/diferential_drive.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ void Diferential_drive::track_position(){
4848

4949
int16_t left_motor_pos_dif = (left_motor_pos - left_motor_last_pos) * (left_motor_inverted ? -1 : 1);
5050
int16_t right_motor_pos_dif = (right_motor_pos - right_motor_last_pos) * (right_motor_inverted ? -1 : 1);
51-
if(right_motor_pos_dif == 0 && left_motor_pos_dif == 0) {
52-
std::this_thread::sleep_for(std::chrono::microseconds(500));
53-
continue;
54-
}
5551
float left_wheel_dist = wheel_circumference * left_motor_pos_dif / 360;
5652
float right_wheel_dist = wheel_circumference * right_motor_pos_dif / 360;
5753
float average_distance = (left_wheel_dist + right_wheel_dist) / 2;
@@ -66,8 +62,8 @@ void Diferential_drive::track_position(){
6662
position = p_position;
6763
left_motor_last_pos = left_motor_pos;
6864
right_motor_last_pos = right_motor_pos;
69-
angle_last = angle_gyro;
70-
std::this_thread::sleep_for(std::chrono::microseconds(1000));
65+
//angle_last = angle_gyro;
66+
std::this_thread::sleep_for(std::chrono::microseconds(1500));
7167
}
7268
}
7369

@@ -211,7 +207,7 @@ void Diferential_drive::rotate_to_abs_angle(float angle, float precision, int ma
211207
int speed = std::fmin(1, std::fmax(-1, angle_dif * P_const));
212208
left_motor->run_direct(fmax(abs(speed) * max_speed, min_speed), left_motor_inverted ? !(speed < 0) : speed < 0);
213209
right_motor->run_direct(fmax(abs(speed) * max_speed, min_speed), !right_motor_inverted ? !(speed < 0) : speed < 0);
214-
std::this_thread::sleep_for(std::chrono::microseconds(1000)); // same as in position tracking
210+
std::this_thread::sleep_for(std::chrono::microseconds(2000));
215211
angle_dif = normalize_angle(position.angle - angle);
216212
}
217213

@@ -232,7 +228,7 @@ void Diferential_drive::go_until_reflection(int reflection, bool darker, int spe
232228
bool left_motor_stopped = false, right_motor_stopped = false;
233229

234230
while(true){
235-
// handle full sensor disconect is_connected doesnt register disconects
231+
// handle full sensor disconect, is_connected() doesnt register disconects
236232
if(__builtin_expect(!color_left->is_connected() && !color_right->is_connected(), 0)){
237233
std::cout << "error in go_until_reflection no color sensor is connected" << std::endl;
238234
std::cerr << "error in go_until_reflection no color sensor is connected" << std::endl;
@@ -269,7 +265,7 @@ void Diferential_drive::go_until_reflection(int reflection, bool darker, int spe
269265
right_motor_stopped = true;
270266
}
271267

272-
std::this_thread::sleep_for(std::chrono::microseconds(1000));
268+
std::this_thread::sleep_for(std::chrono::microseconds(1500));
273269
if(left_motor_stopped && right_motor_stopped) break;
274270
}
275271
}

0 commit comments

Comments
 (0)