Robot team project
Dependencies: QEI Motordriver ros_lib_melodic
Diff: main.cpp
- Revision:
- 23:d1dc248b4e54
- Parent:
- 20:074a3638c702
- Child:
- 24:4d6ff25fb9cc
diff -r 074a3638c702 -r d1dc248b4e54 main.cpp --- a/main.cpp Tue Dec 10 10:23:54 2019 +0000 +++ b/main.cpp Mon Jan 06 14:55:03 2020 +0000 @@ -138,7 +138,9 @@ A.speed(-speed); B.speed(speed); - while(abs(current_pulse_reading) <= 8688) + wheel_B.reset(); + wheel_A.reset(); + while(abs(current_pulse_reading) <= 2782) { current_pulse_reading = wheel_A.getPulses(); } @@ -154,95 +156,22 @@ { wait(5);// required for audacity to play music - for (int i =0; i<5; i++) + for (int i =0; i<10; i++) { - int distance = (rand()%16000+2000); + int distance = (rand()%7000+2000); float A_speed = (rand()%2-1); float B_speed = (rand()%2-1); - if((A_speed < 0.4) and (A_speed > -0.4)){ +/* if((A_speed < 0.4) && (A_speed > -0.4)){ A_speed = 0.4; } - if((B_speed < 0.4) and (B_speed > -0.4)){ - B_speed = -0.4; - } + if((B_speed < 0.4) && (B_speed > -0.4)){ + B_speed = 0.4; + } */ move(A_speed,B_speed,distance); wheel_B.reset(); wheel_A.reset(); } -} - -/* float current_pulse_reading = 0; - while(abs(current_pulse_reading) <= 5388) - { - current_pulse_reading = wheel_A.getPulses(); - A.speed(-speed); - B.speed(0.0); - } - wait(0.05); - current_pulse_reading = 0; - wheel_B.reset(); - wheel_A.reset(); - while(abs(current_pulse_reading) <= 5388) - { - current_pulse_reading = wheel_A.getPulses(); - A.speed(speed); - B.speed(0); - } - wait(0.05); - wheel_B.reset(); - wheel_A.reset(); - current_pulse_reading = 0; - while(abs(current_pulse_reading) <= 5388) - { - current_pulse_reading = wheel_B.getPulses(); - A.speed(0); - B.speed(-speed); - } - wait(0.05); - wheel_B.reset(); - wheel_A.reset(); - current_pulse_reading = 0; - while(abs(current_pulse_reading) <=5388) - { - current_pulse_reading = wheel_B.getPulses(); - A.speed(0); - B.speed(speed); - } - wait(0.05); - wheel_B.reset(); - wheel_A.reset(); - current_pulse_reading = 0; - while(abs(current_pulse_reading) <21504) - { - current_pulse_reading = wheel_A.getPulses(); - A.speed(-speed); - B.speed(speed); - } - wait(0.05); - wheel_B.reset(); - wheel_A.reset(); - current_pulse_reading = 0; - while(abs(current_pulse_reading) <6000) - { - current_pulse_reading = wheel_A.getPulses(); - A.speed(-speed); - B.speed(-speed); - } - wait(0.05); - wheel_B.reset(); - wheel_A.reset(); - current_pulse_reading = 0; - while(abs(current_pulse_reading) <6000) - { - current_pulse_reading = wheel_A.getPulses(); - A.speed(speed); - B.speed(speed); - } - wait(0.05); - A.speed(0); - B.speed(0); - */ - +} // Function to set robot direction and distance according to data published on motor_control topic void control_motor(void) {