Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum avoidance_enum {
- normal, check1, turn_clockwise, turn_anticlockwise_segment_one, turn_anticlockwise_segment_two, check2, turn_anticlockwise_segment_three
- };
- void carAvoidance(double function_RPM, double short_distance)
- {
- switch (avoidance_state)
- {
- case normal:
- target_RPM = function_RPM;
- driveStraight();
- avoidance_state = check;
- break;
- case check1: //Check from going forward
- //distance = ultra.current_distance();
- rotated = false;
- if (short_distance <= curent_distance)
- {
- avoidance_state = turn_clockwise;
- }
- else
- {
- avoidance_state = normal;
- }
- break;
- case turn_clockwise:
- turn(0);
- if (rotated)
- {
- avoidance_state = check1;
- }
- case turn_anticlockwise_segment_one:
- turn(1);
- if (rotated)
- {
- avoidance_state = turn_anticlockwise_segment_two;
- rotated = false;
- }
- case turn_anticlockwise_segment_two:
- turn(1);
- if (rotated)
- {
- avoidance_state = check2;
- }
- case check2: //check from going clockwise
- rotated = false;
- if (short_distance <= curent_distance)
- {
- avoidance_state = turn_anticlockwise_segment_three;
- }
- else
- {
- avoidance_state = normal;
- }
- break;
- case turn_anticlockwise_segment_three:
- turn(1);
- if (rotated)
- {
- avoidance_state = normal;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement