
TUK Workshop
Dependencies: mbed lib_workshop_2019
Revision 1:7a8764e627b5, committed 2019-10-23
- Comitter:
- gvaquette
- Date:
- Wed Oct 23 13:01:35 2019 +0000
- Parent:
- 0:0a75a79d6b77
- Child:
- 2:8153195b1672
- Commit message:
- test ULTRASONIC and COMPASS
Changed in this revision
--- a/includes/console_output.h Wed Oct 23 12:16:18 2019 +0000 +++ b/includes/console_output.h Wed Oct 23 13:01:35 2019 +0000 @@ -20,6 +20,6 @@ void ft_print_test_menu(Serial &pc); - +e_test ft_get_user_choice(Serial &pc); #endif /* CONSOLEOUTPUT_H */ \ No newline at end of file
--- a/includes/pin_connexions.h Wed Oct 23 12:16:18 2019 +0000 +++ b/includes/pin_connexions.h Wed Oct 23 13:01:35 2019 +0000 @@ -1,4 +1,10 @@ -#define BOUSSOLE_adress 0xC0 +#ifndef PINCONNEXIONS_H +#define PINCONNEXIONS_H + +#include "VMA306.h" +#include "CMPS03.h" + +#define COMPASS_adress 0xC0 #define PIXY_adress 0x54 #define CC_BLOCSIZE 14 @@ -30,15 +36,21 @@ /** Motor by PWM declarations **/ /* To be completed */ -DigitalOut DIR_1G (PC_9); -DigitalOut DIR_2G (PC_8); -DigitalOut DIR_1D (PC_6); -DigitalOut DIR_2D (PC_5); +DigitalOut DIR_1G (PC_9); +DigitalOut DIR_2G (PC_8); +DigitalOut DIR_1D (PC_6); +DigitalOut DIR_2D (PC_5); -PwmOut Pwm_MG (PA_9); -PwmOut Pwm_MD (PA_8); +PwmOut Pwm_MG (PA_9); +PwmOut Pwm_MD (PA_8); /** End of Motor by PWM declarations **/ /****************************************/ +/* Proximity sensors */ +VMA306 ultra_sonic (PB_13, PB_2, PB_14, PC_7, PB_15, PA_6); +/* Compass sensor */ +CMPS03 compass (PC_4); + +#endif /* PINCONNEXIONS_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/includes/test_compass.h Wed Oct 23 13:01:35 2019 +0000 @@ -0,0 +1,18 @@ +/** + * @author geoffrey Vaquette + * + * @section DESCRIPTION + * + * Testing value from ultrasonic sensors on robot + * + */ + +#ifndef COMPASS_H +#define COMPASS_H + +#include "mbed.h" +#include "CMPS03.h" + +void ft_print_compass_values(CMPS03 &compass , Serial &pc); + +#endif /*COMPASS_H*/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/includes/test_us.h Wed Oct 23 13:01:35 2019 +0000 @@ -0,0 +1,22 @@ +/** + * @author geoffrey Vaquette + * + * @section DESCRIPTION + * + * Testing value from ultrasonic sensors on robot + * + */ + +#ifndef test_us_H +#define test_us_H + +#include "mbed.h" +#include "VMA306.h" + + +void ft_print_value_US_front_to_pc(VMA306 &ultra_sonic, Serial &pc); +void ft_print_value_US_left_to_pc(VMA306 &ultra_sonic, Serial &pc); +void ft_print_value_US_right_to_pc(VMA306 &ultra_sonic, Serial &pc); +void ft_print_all_values_US(VMA306 &ultra_sonic, Serial &pc); + +#endif \ No newline at end of file
--- a/main.cpp Wed Oct 23 12:16:18 2019 +0000 +++ b/main.cpp Wed Oct 23 13:01:35 2019 +0000 @@ -1,8 +1,46 @@ #include "mbed.h" + #include "console_output.h" +#include "test_us.h" +#include "test_compass.h" + +#include "pin_connexions.h" + + Serial pc (PA_2, PA_3, 115200); int main() { + e_test user_choice ; ft_print_test_menu(pc); + user_choice = ft_get_user_choice(pc); + + while(1) + { + switch (user_choice) + { + case ULTRASONIC : + do + { + ft_print_all_values_US(ultra_sonic, pc); + } while (!pc.readable()); + user_choice = ft_get_user_choice(pc); + pc.printf("\n"); + break; + + case COMPASS : + do + { + ft_print_compass_values(compass, pc); + } while (!pc.readable()); + pc.printf("\n"); + user_choice = ft_get_user_choice(pc); + break; + default : + ft_print_test_menu(pc); + user_choice = ft_get_user_choice(pc); + break; + } + } + } \ No newline at end of file
--- a/src/console_output.cpp Wed Oct 23 12:16:18 2019 +0000 +++ b/src/console_output.cpp Wed Oct 23 13:01:35 2019 +0000 @@ -11,4 +11,10 @@ Pc.printf ("\r%d- Left motor\n", LEFT_MOTOR); Pc.printf ("\r%d- MRight motor \n", RIGHT_MOTOR); Pc.printf ("\r%d- PIXY (CMUCAM5)\n", PIXY); +} + +e_test ft_get_user_choice(Serial &pc) +{ + e_test user_choice = (e_test) (pc.getc() -'0'); + return user_choice; } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test_compass/test_compass.cpp Wed Oct 23 13:01:35 2019 +0000 @@ -0,0 +1,10 @@ +#include "mbed.h" +#include "CMPS03.h" + +#include "test_compass.h" + + +void ft_print_compass_values(CMPS03 &compass , Serial &pc) +{ + pc.printf("\r Bearing from library (PWM) : %lf", compass.getBearing()); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test_us/ft_print_value_us.cpp Wed Oct 23 13:01:35 2019 +0000 @@ -0,0 +1,27 @@ +#include "mbed.h" +#include "VMA306.h" + +#include "test_us.h" + + +void ft_print_value_US_front_to_pc(VMA306& ultra_sonic, Serial &pc) +{ + if (ultra_sonic.isUSBReady()) pc.printf ("\r us_front = %5.2lf -", ultra_sonic.readUSB()); +} + +void ft_print_value_US_left_to_pc(VMA306& ultra_sonic, Serial &pc) +{ + if (ultra_sonic.isUSGReady()) pc.printf (" us_left = %5.2lf -", ultra_sonic.readUSG()); +} + +void ft_print_value_US_right_to_pc(VMA306& ultra_sonic, Serial &pc) +{ + if (ultra_sonic.isUSDReady()) pc.printf (" us_right = %5.2lf -", ultra_sonic.readUSD()); +} + +void ft_print_all_values_US(VMA306 &ultra_sonic, Serial &pc) +{ + ft_print_value_US_left_to_pc(ultra_sonic, pc); + ft_print_value_US_front_to_pc(ultra_sonic, pc); + ft_print_value_US_right_to_pc(ultra_sonic, pc); +} \ No newline at end of file