
Tutorial for first mbed project
Dependencies: mbed lib_workshop_2019
Revision 4:bf5caf4c0c88, committed 2019-10-23
- Comitter:
- gvaquette
- Date:
- Wed Oct 23 19:25:12 2019 +0000
- Parent:
- 3:a0e37b8918ac
- Child:
- 5:d99659a45cab
- Commit message:
- testing motors and add comments
Changed in this revision
--- a/includes/console_output.h Wed Oct 23 14:01:59 2019 +0000 +++ b/includes/console_output.h Wed Oct 23 19:25:12 2019 +0000 @@ -20,8 +20,10 @@ void ft_print_test_menu(Serial &pc); -void ft_print_to_be_imp(Serial &pc) +void ft_print_to_be_imp(Serial &pc); e_test ft_get_user_choice(Serial &pc); +int ft_get_user_int(Serial &pc); + #endif /* CONSOLEOUTPUT_H */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/includes/test_motor.h Wed Oct 23 19:25:12 2019 +0000 @@ -0,0 +1,29 @@ +/** + * @author geoffrey Vaquette + * + * @section DESCRIPTION + * + * Testing value from ultrasonic sensors on robot + * + */ + +#ifndef TEST_MOTOR_H +#define TEST_MOTOR_H + +#include "mbed.h" + +enum e_direction { + FORWARD, + BACKWARD + }; + +/// <summary>Sorts the list to by the given column</summary> +/// <param name="sel">Column to be sorted (index-1-based) and sort direction (pos. = ascending)</param> +/// <returns>Documentation of return type</returns> +void ft_run_motor(e_direction direction, double duty_cycle, PwmOut pwm_mot, DigitalOut dirA, DigitalOut dirB); + +void ft_test_motor(PwmOut pin_pwm_mot, DigitalOut pin_dirA, DigitalOut pin_dirB, Serial &pc); + + + +#endif \ No newline at end of file
--- a/main.cpp Wed Oct 23 14:01:59 2019 +0000 +++ b/main.cpp Wed Oct 23 19:25:12 2019 +0000 @@ -4,11 +4,11 @@ #include "test_us.h" #include "test_compass.h" #include "test_cny.h" +#include "test_motor.h" #include "pin_connexions.h" - Serial pc (PA_2, PA_3, 115200); int main() { @@ -16,8 +16,11 @@ ft_print_test_menu(pc); user_choice = ft_get_user_choice(pc); + + /* Main loop */ while(1) { + /* Which component to test ? */ switch (user_choice) { case ULTRASONIC : @@ -62,20 +65,12 @@ break; case LEFT_MOTOR : - do - { - ft_print_to_be_imp(pc); - } while (!pc.readable()); - pc.printf("\n"); + ft_test_motor(Pwm_MG,DIR_1G,DIR_2G,pc); user_choice = ft_get_user_choice(pc); break; case RIGHT_MOTOR: - do - { - ft_print_to_be_imp(pc); - } while (!pc.readable()); - pc.printf("\n"); + ft_test_motor(Pwm_MD,DIR_1D,DIR_2D,pc); user_choice = ft_get_user_choice(pc); break;
--- a/src/console_output.cpp Wed Oct 23 14:01:59 2019 +0000 +++ b/src/console_output.cpp Wed Oct 23 19:25:12 2019 +0000 @@ -19,7 +19,16 @@ return user_choice; } +int ft_get_user_int(Serial &pc) +{ + int user_int = (e_test) (pc.getc() -'0'); + if (user_int > 9 || user_int < 0) + return -1; + else + return user_int; +} + void ft_print_to_be_imp(Serial &pc) { - printf("\n\rTo be implemented\n"); + printf("\rTo be implemented"); } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test_motor/ft_run_motor.cpp Wed Oct 23 19:25:12 2019 +0000 @@ -0,0 +1,22 @@ +#include "mbed.h" +#include "test_motor.h" + +void ft_run_motor( e_direction direction, double duty_cycle, + PwmOut pwm_mot, DigitalOut dirA, DigitalOut dirB) +{ + + /* TO DO : define direction */ + + if (direction == FORWARD) + { + dirA = 1; + dirB = 0; + } + else // direction == BACKWARD + { + dirA = 0; + dirB = 1; + } + + pwm_mot = duty_cycle; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test_motor/test_motor.cpp Wed Oct 23 19:25:12 2019 +0000 @@ -0,0 +1,27 @@ +#include "mbed.h" +#include "test_motor.h" +#include "console_output.h" + + + + +void ft_test_motor(PwmOut pin_pwm_mot, DigitalOut pin_dirA, DigitalOut pin_dirB, + Serial &pc) +{ + e_direction direction = FORWARD; + + int user_int=1; + double duty_cycle =0.1; + + do{ + if (pc.readable() ) + { + user_int = ft_get_user_int(pc); + if (user_int < 10 && user_int >= 0) duty_cycle = user_int/10.0; + } + + ft_run_motor(direction, duty_cycle, pin_pwm_mot, pin_dirA, pin_dirB); + } while (user_int > 0); + + return; +} \ No newline at end of file