Skip to content

Open Bot Brain primitives for motors + color sensor #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c6a002c
Add open bot brain Zephyr primitives
MaartenS11 Oct 31, 2024
10a8e7f
Move some motor code into a separate file
MaartenS11 Nov 4, 2024
70f5c07
Refactor motor code a bit more by creating a Motor class that does mo…
MaartenS11 Nov 5, 2024
c514f7b
Only use one interrupt for the motor encoders instead of two, this al…
MaartenS11 Dec 2, 2024
3693904
Enable CONFIG_STM32_ENABLE_DEBUG_SLEEP_STOP to allow flashing the boa…
MaartenS11 Apr 28, 2025
4077a60
Clean up color sensor code a bit
MaartenS11 Dec 4, 2024
b5e89a6
Rename colour_sensor to color_sensor + add abort primitive + set hear…
MaartenS11 Dec 4, 2024
2e2a56e
Minor cleanup
MaartenS11 Dec 4, 2024
767ac22
Move sensor setup into separate function
MaartenS11 Dec 4, 2024
551378e
Move most of the color sensor code into the uart_sensor files
MaartenS11 Dec 4, 2024
3c43e4c
Fix case where invalid data was read from the sensor
MaartenS11 Dec 4, 2024
a33a871
Move uart sensor data into a struct
MaartenS11 Dec 5, 2024
e1bceec
Misc type conversions
MaartenS11 Dec 5, 2024
698a08c
Invert motor direction to match the forward direction used by Lego th…
MaartenS11 Apr 28, 2025
3ad2875
Update motor primitives to all have the port and speed first and othe…
MaartenS11 Apr 28, 2025
5a0a2e3
Put open bot brain primitives in an ifdef for the board
MaartenS11 Apr 28, 2025
bd9f3a5
Use DT_FOREACH_PROP_ELEM_SEP to get all pwm specs
MaartenS11 Apr 28, 2025
222b395
Don't hardcode the number of motors
MaartenS11 Apr 28, 2025
49865f3
Run clang-tidy
MaartenS11 Apr 28, 2025
12ed1d0
Place mindstorms file under ifndef ARDUINO
MaartenS11 Apr 28, 2025
b9af362
Read debug messages in debug thread again instead of timer interrupt …
MaartenS11 Apr 29, 2025
e6bc64f
clang-format
MaartenS11 Apr 29, 2025
e36a862
Make print_int print signed integers
MaartenS11 Apr 30, 2025
f7bb69f
Make color_sensor push signed integers
MaartenS11 Apr 30, 2025
08fc336
Support data messages consisting of two bytes
MaartenS11 Apr 30, 2025
19cf7df
Fix color sensors no longer working because they send 2^0 bytes inste…
MaartenS11 May 7, 2025
5eb0623
Configure uart controllers 2, 4 and 3 for input sensors
MaartenS11 May 7, 2025
2bdd0b9
Support using multiple sensors at the same time
MaartenS11 May 7, 2025
63e6c38
Rename color_sensor to read_uart_sensor
MaartenS11 May 7, 2025
8050e34
clang-format
MaartenS11 May 7, 2025
d2b0376
Use zephyr LISTIFY macro to create a list of devices
MaartenS11 May 8, 2025
15a5fdc
Cleanup + clang-format
MaartenS11 May 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions platforms/Zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ target_sources(app PRIVATE
../../src/Interpreter/instructions.cpp
../../src/Interpreter/interpreter.cpp
../../src/Primitives/zephyr.cpp
../../src/Primitives/Mindstorms/Motor.cpp
../../src/Primitives/Mindstorms/uart_sensor.cpp
../../src/Memory/mem.cpp
../../src/Utils/util.cpp
../../src/Utils/util_arduino.cpp
Expand Down
280 changes: 159 additions & 121 deletions platforms/Zephyr/boards/stm32l496g_disco.overlay
Original file line number Diff line number Diff line change
@@ -1,132 +1,170 @@
#include "../app.overlay"

/ {
zephyr,user {
warduino-gpios =
<&gpioa 0 0>,
<&gpioa 1 0>,
<&gpioa 2 0>,
<&gpioa 3 0>,
<&gpioa 4 0>,
<&gpioa 5 0>,
<&gpioa 6 0>,
<&gpioa 7 0>,
<&gpioa 8 0>,
<&gpioa 9 0>,
<&gpioa 10 0>,
<&gpioa 11 0>,
<&gpioa 12 0>,
<&gpioa 15 0>,
<&gpiob 0 0>,
<&gpiob 1 0>,
<&gpiob 2 0>,
<&gpiob 3 0>,
<&gpiob 4 0>,
<&gpiob 5 0>,
<&gpiob 6 0>,
<&gpiob 7 0>,
<&gpiob 8 0>,
<&gpiob 9 0>,
<&gpiob 12 0>,
<&gpiob 13 0>,
<&gpiob 14 0>,
<&gpiob 15 0>,
<&gpioc 0 0>,
<&gpioc 1 0>,
<&gpioc 2 0>,
<&gpioc 3 0>,
<&gpioc 4 0>,
<&gpioc 5 0>,
<&gpioc 6 0>,
<&gpioc 7 0>,
<&gpioc 8 0>,
<&gpioc 9 0>,
<&gpioc 12 0>,
<&gpioc 15 0>,
<&gpiod 0 0>,
<&gpiod 1 0>,
<&gpiod 2 0>,
<&gpiod 3 0>,
<&gpiod 4 0>,
<&gpiod 7 0>,
<&gpiod 8 0>,
<&gpiod 9 0>,
<&gpiod 10 0>,
<&gpiod 11 0>,
<&gpiod 12 0>,
<&gpiod 13 0>,
<&gpiod 14 0>,
<&gpiod 15 0>,
<&gpioe 0 0>,
<&gpioe 1 0>,
<&gpioe 2 0>,
<&gpioe 3 0>,
<&gpioe 4 0>,
<&gpioe 7 0>,
<&gpioe 8 0>,
<&gpioe 10 0>,
<&gpioe 11 0>,
<&gpioe 12 0>,
<&gpioe 13 0>,
<&gpioe 14 0>,
<&gpioe 15 0>,
<&gpiof 3 0>,
<&gpiof 4 0>,
<&gpiof 5 0>,
<&gpiof 6 0>,
<&gpiof 7 0>,
<&gpiof 8 0>,
<&gpiof 9 0>,
<&gpiof 10 0>,
<&gpiof 11 0>,
<&gpiof 12 0>,
<&gpiof 13 0>,
<&gpiof 14 0>,
<&gpiog 2 0>,
<&gpiog 3 0>,
<&gpiog 4 0>,
<&gpiog 5 0>,
<&gpiog 6 0>,
<&gpiog 7 0>,
<&gpiog 8 0>,
<&gpiog 11 0>,
<&gpiog 12 0>,
<&gpiog 15 0>,
<&gpiob 10 0>,
<&gpiob 11 0>,
<&gpioc 10 0>,
<&gpioc 11 0>,
<&gpiog 13 0>,
<&gpiog 14 0>,
<&gpiod 5 0>,
<&gpiod 6 0>,
<&gpiof 0 0>,
<&gpiof 1 0>,
<&gpiog 9 0>,
<&gpiog 10 0>;
zephyr,user {
warduino-gpios =
<&gpioa 0 0>,
<&gpioa 1 0>,
<&gpioa 2 0>,
<&gpioa 3 0>,
<&gpioa 4 0>,
<&gpioa 5 0>,
<&gpioa 6 0>,
<&gpioa 7 0>,
<&gpioa 8 0>,
<&gpioa 9 0>,
<&gpioa 10 0>,
<&gpioa 11 0>,
<&gpioa 12 0>,
<&gpioa 15 0>,
<&gpiob 0 0>,
<&gpiob 1 0>,
<&gpiob 2 0>,
<&gpiob 3 0>,
<&gpiob 4 0>,
<&gpiob 5 0>,
<&gpiob 6 0>,
<&gpiob 7 0>,
<&gpiob 8 0>,
<&gpiob 9 0>,
<&gpiob 12 0>,
<&gpiob 13 0>,
<&gpiob 14 0>,
<&gpiob 15 0>,
<&gpioc 0 0>,
<&gpioc 1 0>,
<&gpioc 2 0>,
<&gpioc 3 0>,
<&gpioc 4 0>,
<&gpioc 5 0>,
<&gpioc 6 0>,
<&gpioc 7 0>,
<&gpioc 8 0>,
<&gpioc 9 0>,
<&gpioc 12 0>,
<&gpioc 15 0>,
<&gpiod 0 0>,
<&gpiod 1 0>,
<&gpiod 2 0>,
<&gpiod 3 0>,
<&gpiod 4 0>,
<&gpiod 7 0>,
<&gpiod 8 0>,
<&gpiod 9 0>,
<&gpiod 10 0>,
<&gpiod 11 0>,
<&gpiod 12 0>,
<&gpiod 13 0>,
<&gpiod 14 0>,
<&gpiod 15 0>,
<&gpioe 0 0>,
<&gpioe 1 0>,
<&gpioe 2 0>,
<&gpioe 3 0>,
<&gpioe 4 0>,
<&gpioe 7 0>,
<&gpioe 8 0>,
<&gpioe 10 0>,
<&gpioe 11 0>,
<&gpioe 12 0>,
<&gpioe 13 0>,
<&gpioe 14 0>,
<&gpioe 15 0>,
<&gpiof 3 0>,
<&gpiof 4 0>,
<&gpiof 5 0>,
<&gpiof 6 0>,
<&gpiof 7 0>,
<&gpiof 8 0>,
<&gpiof 9 0>,
<&gpiof 10 0>,
<&gpiof 11 0>,
<&gpiof 12 0>,
<&gpiof 13 0>,
<&gpiof 14 0>,
<&gpiog 2 0>,
<&gpiog 3 0>,
<&gpiog 4 0>,
<&gpiog 5 0>,
<&gpiog 6 0>,
<&gpiog 7 0>,
<&gpiog 8 0>,
<&gpiog 11 0>,
<&gpiog 12 0>,
<&gpiog 15 0>,
<&gpiob 10 0>,
<&gpiob 11 0>,
<&gpioc 10 0>,
<&gpioc 11 0>,
<&gpiog 13 0>,
<&gpiog 14 0>,
<&gpiod 5 0>,
<&gpiod 6 0>,
<&gpiof 0 0>,
<&gpiof 1 0>,
<&gpiog 9 0>,
<&gpiog 10 0>;

pwms =
<&pwm8 3 10000 PWM_POLARITY_NORMAL>,
<&pwm8 4 10000 PWM_POLARITY_NORMAL>,
<&pwm8 1 10000 PWM_POLARITY_NORMAL>,
<&pwm8 2 10000 PWM_POLARITY_NORMAL>;

warduino-uarts =
<&usart1>;
};
pwms =
<&pwm8 3 10000 PWM_POLARITY_NORMAL>,
<&pwm8 4 10000 PWM_POLARITY_NORMAL>,
<&pwm8 1 10000 PWM_POLARITY_NORMAL>,
<&pwm8 2 10000 PWM_POLARITY_NORMAL>,
<&pwm1 3 10000 PWM_POLARITY_NORMAL>,
<&pwm1 4 10000 PWM_POLARITY_NORMAL>,
<&pwm1 1 10000 PWM_POLARITY_NORMAL>,
<&pwm1 2 10000 PWM_POLARITY_NORMAL>;

warduino-uarts =
<&usart3>,
<&uart4>,
<&usart2>,
<&usart1>;
};
};

&timers8 {
status = "okay";
pwm8: pwm {
status = "okay";
pinctrl-0 = <&tim8_ch3_pc8 &tim8_ch4_pc9 &tim8_ch1_pc6 &tim8_ch2_pc7>;
pinctrl-names =
"default";
};
status = "okay";

pwm8: pwm {
status = "okay";
pinctrl-0 = <&tim8_ch3_pc8 &tim8_ch4_pc9 &tim8_ch1_pc6 &tim8_ch2_pc7>;
pinctrl-names =
"default";
};
};

&timers1 {
status = "okay";

pwm1: pwm {
status = "okay";
pinctrl-0 = <&tim1_ch3_pe13 &tim1_ch4_pe14 &tim1_ch1_pa8 &tim1_ch2_pa9>;
pinctrl-names =
"default";
};
};

&usart1 {
pinctrl-0 = <&usart1_tx_pg9 &usart1_rx_pg10>;
current-speed = <2400>;
pinctrl-0 = <&usart1_tx_pg9 &usart1_rx_pg10>;
current-speed = <2400>;
};

&usart2 {
pinctrl-0 = <&usart2_tx_pd5 &usart2_rx_pd6>;
current-speed = <2400>;
};

&uart4 {
pinctrl-0 = <&uart4_tx_pc10 &uart4_rx_pc11>;
current-speed = <2400>;
status = "okay";
pinctrl-names = "default";
};

&usart3 {
pinctrl-0 = <&usart3_tx_pb10 &usart3_rx_pb11>;
current-speed = <2400>;
status = "okay";
pinctrl-names = "default";
};
2 changes: 1 addition & 1 deletion platforms/Zephyr/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void startDebuggerStd() {
int valread;
uint8_t buffer[1024] = {0};
while (true) {
k_msleep(1000);
k_msleep(500);

while ((valread = war_console_read(NULL, buffer, 1024)) > 0) {
wac->handleInterrupt(valread, buffer);
Expand Down
4 changes: 4 additions & 0 deletions platforms/Zephyr/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ CONFIG_CONSOLE_PUTCHAR_BUFSIZE=4096

CONFIG_POSIX_API=y
CONFIG_MAIN_STACK_SIZE=8192

# Allow flashing the board without reset (increases power consumption so should only be used for development)
CONFIG_STM32_ENABLE_DEBUG_SLEEP_STOP=y

Loading