EM2019WSP06/Implementierungsdetails: Unterschied zwischen den Versionen

Aus Verteilte Systeme - Wiki
Zur Navigation springen Zur Suche springen
Zeile 64: Zeile 64:
 
</source>
 
</source>
   
Note that the values for determinate a color <code>(80, 35, 20)(40,40,20)</code>, are not fix. These values worked on a specific environment, and depending on the light or distance this values will be change and so should the values on the function too. Red Color can be added.
+
Note that the values for determinate a color <code>(80, 35, 20)(40,40,20)</code>, are not fix. These values worked on a specific environment, and depending on the light or distance this values will change and so should the values on the function too. Red Color can be added.

Version vom 5. März 2020, 18:05 Uhr

Source Code

Source Code can be found here

Implementations hints

PWM

In order to use the PWM Service from the Zephyr OS, some steps should be done:

-Enable PWM. This can be done in the .conf file project, or on the board .defconfig file. The first option is the best practice according to the Zephyr Documentation.

# Enable PWM
CONFIG_PWM=y 
# Enable PWM of Timer 2
CONFIG_PWM_STM32_2=y


- Enable the Hardware part of the Microcontroller. This can be done in the .overlay file of the project or in the .dts file of the board. Again the first option was choose.

&timers2 {
	status = "okay";
    pwm {
		status = "okay";
	};
};

This two steps are necessary for the use of the PWM Service of the Zephyr OS. And they worked fine in other boards like the nRf52, but for the ST Nucleo F446RE it did not. Other steps were needed:

-In the Zephyr Os: go to "/zephyr/boards/arm/nucleo_f446re/pinmux.c"

Here the connection between the Board Pin and the Board PWM Chanel need to be done:

#ifdef CONFIG_PWM_STM32_2
	{STM32_PIN_PA0, STM32F4_PINMUX_FUNC_PA0_PWM2_CH1},
#endif

"/zephyr/include/dt-bindings/pinctrl/stm32-pinctrl-common.h" // pinout of the board, STM32_PIN_PA0 can be found here.

"/zephyr/drivers/pinmux/stm32/pinmux_stm32f4.h" // pin multiplexing helper, STM32F4_PINMUX_FUNC_PA0_PWM2_CH1 can be found here.

Color Sensing

The function color_get(), returns the color detected.

color_t color_get()
{
	red = us_get(red_f);
	k_sleep(10);
	green = us_get(green_f);
	k_sleep(10);
	blue = us_get(blue_f);
	k_sleep(10);
	if (red > 80 && green < 35 && green > 20) {
		return RED;
	} else if (red < 40 && blue < 40 && green < 20) {
		return BLUE;
	} else {
		return CLEAR;
	}
}

Note that the values for determinate a color (80, 35, 20)(40,40,20), are not fix. These values worked on a specific environment, and depending on the light or distance this values will change and so should the values on the function too. Red Color can be added.