From 86b9db512ce7fe4b971b236bc7d7ade508ed6dc7 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 14:57:39 +0200 Subject: [PATCH 01/17] change home position to the "vertical" one --- .../01_Braccio_learning_mode/01_Braccio_learning_mode.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index 16faee9..640dfa5 100644 --- a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -15,7 +15,7 @@ int state = IDLE; float values[10000]; float* idx = values; float* final_idx = 0; -float homePos[6] = {160.0, 150.0, 220.0, 220.0, 100.0, 180.0}; +float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; static lv_obj_t * counter; static lv_obj_t * btnm; From d1f6ece6222b9c9254464e9c4496a1f9794f825b Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 14:59:00 +0200 Subject: [PATCH 02/17] make the buttons text labels uppercase for readability --- .../01_Braccio_learning_mode/01_Braccio_learning_mode.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index 640dfa5..50b522d 100644 --- a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -20,7 +20,7 @@ float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; static lv_obj_t * counter; static lv_obj_t * btnm; -static const char * btnm_map[] = { "Learn", "\n", "Replay", "\n", "Idle", "\n", "\0" }; +static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "IDLE", "\n", "\0" }; static void eventHandlerMenu(lv_event_t * e) { From 15aab337bb15d389a7f3b0a92c9e871e72667d4b Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 14:59:53 +0200 Subject: [PATCH 03/17] make the focus outline orange and more visible --- .../01_Braccio_learning_mode/01_Braccio_learning_mode.ino | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index 50b522d..4b496a2 100644 --- a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -3,6 +3,7 @@ // Colors #define COLOR_TEAL 0x00878F #define COLOR_LIGHT_TEAL 0x62AEB2 +#define COLOR_ORANGE 0xE47128 enum states { LEARN, @@ -69,6 +70,11 @@ static void eventHandlerMenu(lv_event_t * e) { } void mainMenu() { + static lv_style_t style_focus; + lv_style_init(&style_focus); + lv_style_set_outline_color(&style_focus, lv_color_hex(COLOR_ORANGE)); + lv_style_set_outline_width(&style_focus, 4); + static lv_style_t style_btn; lv_style_init(&style_btn); lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL)); @@ -80,6 +86,7 @@ void mainMenu() { lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 0); lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); + lv_obj_add_style(btnm, &style_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKABLE); From 2c37b26aa489dfbbfa15840ae525def5be98cdcc Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 15:00:23 +0200 Subject: [PATCH 04/17] add TODO comment --- .../01_Braccio_learning_mode/01_Braccio_learning_mode.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index 4b496a2..f5bbf96 100644 --- a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -7,7 +7,7 @@ enum states { LEARN, - REPEAT, + REPEAT, // for consistency is better to name this REPLAY or rename the button label repeat TODO IDLE }; From 27109531305dde3617d7d16e33880a0d8d5437a9 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 16:33:16 +0200 Subject: [PATCH 05/17] make the "LEARN" menu entry the focused one at startup --- .../01_Braccio_learning_mode/01_Braccio_learning_mode.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index f5bbf96..d0479dc 100644 --- a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -93,7 +93,7 @@ void mainMenu() { lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE); lv_btnmatrix_set_one_checked(btnm, true); - lv_btnmatrix_set_selected_btn(btnm, 2); + lv_btnmatrix_set_selected_btn(btnm, 0); lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); counter = lv_label_create(btnm); From 7e8ffe18bcfc009330478dfca5bb7ee4593df912 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 16:36:17 +0200 Subject: [PATCH 06/17] make the "REPLAY" menu option disabled at startup. It will be clickable after learning --- .../01_Braccio_learning_mode/01_Braccio_learning_mode.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index d0479dc..45a60aa 100644 --- a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -50,6 +50,7 @@ static void eventHandlerMenu(lv_event_t * e) { Braccio.disengage(); lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); Serial.println("LEARN"); + lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button break; case 1: state = REPEAT; @@ -89,7 +90,7 @@ void mainMenu() { lv_obj_add_style(btnm, &style_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); - lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE); lv_btnmatrix_set_one_checked(btnm, true); From ff364ef5cac2f0a80f7b529feb13b8264125625b Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 16:53:50 +0200 Subject: [PATCH 07/17] remove unused var --- .../01_Braccio_learning_mode/01_Braccio_learning_mode.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index 45a60aa..91c2e84 100644 --- a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -43,7 +43,6 @@ static void eventHandlerMenu(lv_event_t * e) { idx = values; - FILE* f; switch (id) { case 0: state = LEARN; From cf2d42d5bdf53e0bbb694965f36a929adb8c4238 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 16:56:18 +0200 Subject: [PATCH 08/17] change the first button label from "LEARN" to "STOP" when "LEARN" is selected. "STOP" button actually does what it's supposed to do --- .../01_Braccio_learning_mode.ino | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index 91c2e84..43a137e 100644 --- a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -44,24 +44,35 @@ static void eventHandlerMenu(lv_event_t * e) { idx = values; switch (id) { - case 0: - state = LEARN; - Braccio.disengage(); - lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("LEARN"); - lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button + case 0: // if the button pressed is the first one + if (txt == "LEARN") { + state = LEARN; + Braccio.disengage(); // allow the user to freely move the braccio + lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("LEARN"); + lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button + btnm_map[0] = "STOP"; // change the label of the first button to "STOP" + } + else if (txt == "STOP") { + state = IDLE; + Braccio.engage(); // enable the steppers so that the braccio stands still + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + } break; case 1: state = REPEAT; + btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" Braccio.engage(); lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); Serial.println("REPEAT"); break; default: state = IDLE; + btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + Braccio.engage(); delay(500); Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); Serial.println("IDLE"); break; From 007fd8ad77513a77d35d38bc540c16401d902627 Mon Sep 17 00:00:00 2001 From: Claudio Scafesi Date: Fri, 22 Apr 2022 18:18:28 +0200 Subject: [PATCH 09/17] new scaffolding for the library --- ..._mode.ino => Braccio_Learn_and_Replay.ino} | 0 .../01_creating_a_button.ino | 0 .../01_creating_a_button/sketch.json | 0 .../02_designing_the_button.ino | 0 .../btn_style.ino.NANO_RP2040_CONNECT.bin | Bin .../02_designing_the_button/sketch.json | 0 .../03_creating_a_menu/03_creating_a_menu.ino | 0 .../04_testing_it_out/04_testing_it_out.ino | 0 .../05_display_challenge.ino | 0 .../01_playing_with_the_Joystick.ino | 0 .../02_handling_events_in_the_menu.ino | 0 .../03_navigate_challenge_I.ino | 0 .../04_navigate_challenge_II.ino | 0 .../01_playing_with_the_motors.ino | 0 ...ecting_the_motor_with_the_enter_button.ino | 0 ...03_moving_the_motors_with_the_joystick.ino | 0 .../04_servo_motors_challenge.ino | 0 .../01_playing_with_a_joint_angle_gauge.ino | 0 ...02_selecting_the_motor_in_the_LCD_menu.ino | 0 .../03_learnings_challenge_I.ino | 0 .../04_learnings_challenge_II.ino | 0 .../01_Braccio_learning_mode.ino | 152 ++++++++++++++++ .../02_learning_challenge.ino | 0 .../01_aligning_braccio.ino | 0 .../02_waving_with_Braccio.ino | 0 .../03_moving_challenge.ino | 0 .../01_controlling_manually_Braccio.ino | 0 .../02_manual_control_challenge.ino | 0 .../01_Braccio_learning_mode.ino | 152 ++++++++++++++++ .../02_learning_challenge.ino | 162 ++++++++++++++++++ .../Braccio_Basic/Braccio_Basic.ino | 0 .../Braccio_LearnByDoing.ino | 0 .../LCD_Custom_Menu/LCD_Custom_Menu.ino | 0 .../LCD_Menu_Joystick/LCD_Menu_Joystick.ino | 0 .../{ => Tools}/LCD_Motors/LCD_Motors.ino | 0 35 files changed, 466 insertions(+) rename examples/{tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino => Braccio_Learn_and_Replay.ino} (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/01-programming-the-braccio-display/01_creating_a_button/sketch.json (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/01-programming-the-braccio-display/02_designing_the_button/btn_style.ino.NANO_RP2040_CONNECT.bin (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/01-programming-the-braccio-display/02_designing_the_button/sketch.json (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/02-navigatting-the-display-menu/01_playing_with_the_Joystick/01_playing_with_the_Joystick.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/02-navigatting-the-display-menu/02_handling_events_in_the_menu/02_handling_events_in_the_menu.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/03-playing-with-the-motors/01_playing_with_the_motors/01_playing_with_the_motors.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/03-playing-with-the-motors/02_selecting_the_motor_with_the_enter_button/02_selecting_the_motor_with_the_enter_button.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/03-playing-with-the-motors/03_moving_the_motors_with_the_joystick/03_moving_the_motors_with_the_joystick.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/03-playing-with-the-motors/04_servo_motors_challenge/04_servo_motors_challenge.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/04-integration-of-previous-learnings/01_playing_with_a_joint_angle_gauge/01_playing_with_a_joint_angle_gauge.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/04-integration-of-previous-learnings/02_selecting_the_motor_in_the_LCD_menu/02_selecting_the_motor_in_the_LCD_menu.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino (100%) rename examples/{tutorials => Platform_Tutorials}/lessons/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino (100%) create mode 100644 examples/Platform_Tutorials/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino rename examples/{tutorials/projects => Platform_Tutorials}/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino (100%) rename examples/{tutorials => Platform_Tutorials}/projects/p01-moving-braccio/01_aligning_braccio/01_aligning_braccio.ino (100%) rename examples/{tutorials => Platform_Tutorials}/projects/p01-moving-braccio/02_waving_with_Braccio/02_waving_with_Braccio.ino (100%) rename examples/{tutorials => Platform_Tutorials}/projects/p01-moving-braccio/03_moving_challenge/03_moving_challenge.ino (100%) rename examples/{tutorials => Platform_Tutorials}/projects/p02-controlling-braccio-manually/01_controlling_manually_Braccio/01_controlling_manually_Braccio.ino (100%) rename examples/{tutorials => Platform_Tutorials}/projects/p02-controlling-braccio-manually/02_manual_control_challenge/02_manual_control_challenge.ino (100%) create mode 100644 examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino create mode 100644 examples/Platform_Tutorials/projects/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino rename examples/{ => Tools}/Braccio_Basic/Braccio_Basic.ino (100%) rename examples/{ => Tools}/Braccio_LearnByDoing/Braccio_LearnByDoing.ino (100%) rename examples/{ => Tools}/LCD_Custom_Menu/LCD_Custom_Menu.ino (100%) rename examples/{ => Tools}/LCD_Menu_Joystick/LCD_Menu_Joystick.ino (100%) rename examples/{ => Tools}/LCD_Motors/LCD_Motors.ino (100%) diff --git a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/Braccio_Learn_and_Replay.ino similarity index 100% rename from examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino rename to examples/Braccio_Learn_and_Replay.ino diff --git a/examples/tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino b/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino similarity index 100% rename from examples/tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino rename to examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino diff --git a/examples/tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/sketch.json b/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/sketch.json similarity index 100% rename from examples/tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/sketch.json rename to examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/sketch.json diff --git a/examples/tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino b/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino similarity index 100% rename from examples/tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino rename to examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino diff --git a/examples/tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/btn_style.ino.NANO_RP2040_CONNECT.bin b/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/btn_style.ino.NANO_RP2040_CONNECT.bin similarity index 100% rename from examples/tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/btn_style.ino.NANO_RP2040_CONNECT.bin rename to examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/btn_style.ino.NANO_RP2040_CONNECT.bin diff --git a/examples/tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/sketch.json b/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/sketch.json similarity index 100% rename from examples/tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/sketch.json rename to examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/sketch.json diff --git a/examples/tutorials/lessons/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino b/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino similarity index 100% rename from examples/tutorials/lessons/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino rename to examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino diff --git a/examples/tutorials/lessons/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino b/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino similarity index 100% rename from examples/tutorials/lessons/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino rename to examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino diff --git a/examples/tutorials/lessons/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino b/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino similarity index 100% rename from examples/tutorials/lessons/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino rename to examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino diff --git a/examples/tutorials/lessons/02-navigatting-the-display-menu/01_playing_with_the_Joystick/01_playing_with_the_Joystick.ino b/examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/01_playing_with_the_Joystick/01_playing_with_the_Joystick.ino similarity index 100% rename from examples/tutorials/lessons/02-navigatting-the-display-menu/01_playing_with_the_Joystick/01_playing_with_the_Joystick.ino rename to examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/01_playing_with_the_Joystick/01_playing_with_the_Joystick.ino diff --git a/examples/tutorials/lessons/02-navigatting-the-display-menu/02_handling_events_in_the_menu/02_handling_events_in_the_menu.ino b/examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/02_handling_events_in_the_menu/02_handling_events_in_the_menu.ino similarity index 100% rename from examples/tutorials/lessons/02-navigatting-the-display-menu/02_handling_events_in_the_menu/02_handling_events_in_the_menu.ino rename to examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/02_handling_events_in_the_menu/02_handling_events_in_the_menu.ino diff --git a/examples/tutorials/lessons/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino b/examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino similarity index 100% rename from examples/tutorials/lessons/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino rename to examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino diff --git a/examples/tutorials/lessons/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino b/examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino similarity index 100% rename from examples/tutorials/lessons/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino rename to examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino diff --git a/examples/tutorials/lessons/03-playing-with-the-motors/01_playing_with_the_motors/01_playing_with_the_motors.ino b/examples/Platform_Tutorials/lessons/03-playing-with-the-motors/01_playing_with_the_motors/01_playing_with_the_motors.ino similarity index 100% rename from examples/tutorials/lessons/03-playing-with-the-motors/01_playing_with_the_motors/01_playing_with_the_motors.ino rename to examples/Platform_Tutorials/lessons/03-playing-with-the-motors/01_playing_with_the_motors/01_playing_with_the_motors.ino diff --git a/examples/tutorials/lessons/03-playing-with-the-motors/02_selecting_the_motor_with_the_enter_button/02_selecting_the_motor_with_the_enter_button.ino b/examples/Platform_Tutorials/lessons/03-playing-with-the-motors/02_selecting_the_motor_with_the_enter_button/02_selecting_the_motor_with_the_enter_button.ino similarity index 100% rename from examples/tutorials/lessons/03-playing-with-the-motors/02_selecting_the_motor_with_the_enter_button/02_selecting_the_motor_with_the_enter_button.ino rename to examples/Platform_Tutorials/lessons/03-playing-with-the-motors/02_selecting_the_motor_with_the_enter_button/02_selecting_the_motor_with_the_enter_button.ino diff --git a/examples/tutorials/lessons/03-playing-with-the-motors/03_moving_the_motors_with_the_joystick/03_moving_the_motors_with_the_joystick.ino b/examples/Platform_Tutorials/lessons/03-playing-with-the-motors/03_moving_the_motors_with_the_joystick/03_moving_the_motors_with_the_joystick.ino similarity index 100% rename from examples/tutorials/lessons/03-playing-with-the-motors/03_moving_the_motors_with_the_joystick/03_moving_the_motors_with_the_joystick.ino rename to examples/Platform_Tutorials/lessons/03-playing-with-the-motors/03_moving_the_motors_with_the_joystick/03_moving_the_motors_with_the_joystick.ino diff --git a/examples/tutorials/lessons/03-playing-with-the-motors/04_servo_motors_challenge/04_servo_motors_challenge.ino b/examples/Platform_Tutorials/lessons/03-playing-with-the-motors/04_servo_motors_challenge/04_servo_motors_challenge.ino similarity index 100% rename from examples/tutorials/lessons/03-playing-with-the-motors/04_servo_motors_challenge/04_servo_motors_challenge.ino rename to examples/Platform_Tutorials/lessons/03-playing-with-the-motors/04_servo_motors_challenge/04_servo_motors_challenge.ino diff --git a/examples/tutorials/lessons/04-integration-of-previous-learnings/01_playing_with_a_joint_angle_gauge/01_playing_with_a_joint_angle_gauge.ino b/examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/01_playing_with_a_joint_angle_gauge/01_playing_with_a_joint_angle_gauge.ino similarity index 100% rename from examples/tutorials/lessons/04-integration-of-previous-learnings/01_playing_with_a_joint_angle_gauge/01_playing_with_a_joint_angle_gauge.ino rename to examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/01_playing_with_a_joint_angle_gauge/01_playing_with_a_joint_angle_gauge.ino diff --git a/examples/tutorials/lessons/04-integration-of-previous-learnings/02_selecting_the_motor_in_the_LCD_menu/02_selecting_the_motor_in_the_LCD_menu.ino b/examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/02_selecting_the_motor_in_the_LCD_menu/02_selecting_the_motor_in_the_LCD_menu.ino similarity index 100% rename from examples/tutorials/lessons/04-integration-of-previous-learnings/02_selecting_the_motor_in_the_LCD_menu/02_selecting_the_motor_in_the_LCD_menu.ino rename to examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/02_selecting_the_motor_in_the_LCD_menu/02_selecting_the_motor_in_the_LCD_menu.ino diff --git a/examples/tutorials/lessons/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino b/examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino similarity index 100% rename from examples/tutorials/lessons/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino rename to examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino diff --git a/examples/tutorials/lessons/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino b/examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino similarity index 100% rename from examples/tutorials/lessons/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino rename to examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino diff --git a/examples/Platform_Tutorials/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/Platform_Tutorials/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino new file mode 100644 index 0000000..43a137e --- /dev/null +++ b/examples/Platform_Tutorials/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -0,0 +1,152 @@ +#include + +// Colors +#define COLOR_TEAL 0x00878F +#define COLOR_LIGHT_TEAL 0x62AEB2 +#define COLOR_ORANGE 0xE47128 + +enum states { + LEARN, + REPEAT, // for consistency is better to name this REPLAY or rename the button label repeat TODO + IDLE +}; + +int state = IDLE; + +float values[10000]; +float* idx = values; +float* final_idx = 0; +float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; + +static lv_obj_t * counter; +static lv_obj_t * btnm; + +static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "IDLE", "\n", "\0" }; + + +static void eventHandlerMenu(lv_event_t * e) { + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * obj = lv_event_get_target(e); + + if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) { + state = IDLE; + return; + } + + if (code == LV_EVENT_CLICKED) { + uint32_t id = lv_btnmatrix_get_selected_btn(obj); + const char * txt = lv_btnmatrix_get_btn_text(obj, id); + + if (state == LEARN) { + final_idx = idx; + } + + idx = values; + + switch (id) { + case 0: // if the button pressed is the first one + if (txt == "LEARN") { + state = LEARN; + Braccio.disengage(); // allow the user to freely move the braccio + lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("LEARN"); + lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button + btnm_map[0] = "STOP"; // change the label of the first button to "STOP" + } + else if (txt == "STOP") { + state = IDLE; + Braccio.engage(); // enable the steppers so that the braccio stands still + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + } + break; + case 1: + state = REPEAT; + btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + Braccio.engage(); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("REPEAT"); + break; + default: + state = IDLE; + btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + Braccio.engage(); + delay(500); + Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("IDLE"); + break; + } + } +} + +void mainMenu() { + static lv_style_t style_focus; + lv_style_init(&style_focus); + lv_style_set_outline_color(&style_focus, lv_color_hex(COLOR_ORANGE)); + lv_style_set_outline_width(&style_focus, 4); + + static lv_style_t style_btn; + lv_style_init(&style_btn); + lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL)); + lv_style_set_text_color(&style_btn, lv_color_white()); + + btnm = lv_btnmatrix_create(lv_scr_act()); + lv_obj_set_size(btnm, 240, 240); + lv_btnmatrix_set_map(btnm, btnm_map); + lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 0); + + lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); + lv_obj_add_style(btnm, &style_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); + + lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE); + + lv_btnmatrix_set_one_checked(btnm, true); + lv_btnmatrix_set_selected_btn(btnm, 0); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + + counter = lv_label_create(btnm); + lv_label_set_text_fmt(counter, "Counter: %d" , 0); + lv_obj_align(counter, LV_ALIGN_CENTER, 0, 80); + + lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_ALL, NULL); + + Braccio.connectJoystickTo(btnm); +} + +void setup() { + Braccio.begin(mainMenu); + delay(500); + + Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); + delay(500); + + Serial.begin(115200); + Serial.println("Replicate a movement"); +} + +void loop() { + if (state == LEARN) { + Braccio.positions(idx); + idx += 6; + } + if (state == REPEAT) { + Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); + idx += 6; + if (idx >= final_idx) { + Serial.println("Repeat done"); + state = IDLE; + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + } + } + if (idx - values >= sizeof(values)) { + Serial.println("IDLE"); + state = IDLE; + } + delay(100); + if (state != IDLE) { + lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); + } +} diff --git a/examples/tutorials/projects/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino b/examples/Platform_Tutorials/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino similarity index 100% rename from examples/tutorials/projects/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino rename to examples/Platform_Tutorials/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino diff --git a/examples/tutorials/projects/p01-moving-braccio/01_aligning_braccio/01_aligning_braccio.ino b/examples/Platform_Tutorials/projects/p01-moving-braccio/01_aligning_braccio/01_aligning_braccio.ino similarity index 100% rename from examples/tutorials/projects/p01-moving-braccio/01_aligning_braccio/01_aligning_braccio.ino rename to examples/Platform_Tutorials/projects/p01-moving-braccio/01_aligning_braccio/01_aligning_braccio.ino diff --git a/examples/tutorials/projects/p01-moving-braccio/02_waving_with_Braccio/02_waving_with_Braccio.ino b/examples/Platform_Tutorials/projects/p01-moving-braccio/02_waving_with_Braccio/02_waving_with_Braccio.ino similarity index 100% rename from examples/tutorials/projects/p01-moving-braccio/02_waving_with_Braccio/02_waving_with_Braccio.ino rename to examples/Platform_Tutorials/projects/p01-moving-braccio/02_waving_with_Braccio/02_waving_with_Braccio.ino diff --git a/examples/tutorials/projects/p01-moving-braccio/03_moving_challenge/03_moving_challenge.ino b/examples/Platform_Tutorials/projects/p01-moving-braccio/03_moving_challenge/03_moving_challenge.ino similarity index 100% rename from examples/tutorials/projects/p01-moving-braccio/03_moving_challenge/03_moving_challenge.ino rename to examples/Platform_Tutorials/projects/p01-moving-braccio/03_moving_challenge/03_moving_challenge.ino diff --git a/examples/tutorials/projects/p02-controlling-braccio-manually/01_controlling_manually_Braccio/01_controlling_manually_Braccio.ino b/examples/Platform_Tutorials/projects/p02-controlling-braccio-manually/01_controlling_manually_Braccio/01_controlling_manually_Braccio.ino similarity index 100% rename from examples/tutorials/projects/p02-controlling-braccio-manually/01_controlling_manually_Braccio/01_controlling_manually_Braccio.ino rename to examples/Platform_Tutorials/projects/p02-controlling-braccio-manually/01_controlling_manually_Braccio/01_controlling_manually_Braccio.ino diff --git a/examples/tutorials/projects/p02-controlling-braccio-manually/02_manual_control_challenge/02_manual_control_challenge.ino b/examples/Platform_Tutorials/projects/p02-controlling-braccio-manually/02_manual_control_challenge/02_manual_control_challenge.ino similarity index 100% rename from examples/tutorials/projects/p02-controlling-braccio-manually/02_manual_control_challenge/02_manual_control_challenge.ino rename to examples/Platform_Tutorials/projects/p02-controlling-braccio-manually/02_manual_control_challenge/02_manual_control_challenge.ino diff --git a/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino new file mode 100644 index 0000000..43a137e --- /dev/null +++ b/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -0,0 +1,152 @@ +#include + +// Colors +#define COLOR_TEAL 0x00878F +#define COLOR_LIGHT_TEAL 0x62AEB2 +#define COLOR_ORANGE 0xE47128 + +enum states { + LEARN, + REPEAT, // for consistency is better to name this REPLAY or rename the button label repeat TODO + IDLE +}; + +int state = IDLE; + +float values[10000]; +float* idx = values; +float* final_idx = 0; +float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; + +static lv_obj_t * counter; +static lv_obj_t * btnm; + +static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "IDLE", "\n", "\0" }; + + +static void eventHandlerMenu(lv_event_t * e) { + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * obj = lv_event_get_target(e); + + if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) { + state = IDLE; + return; + } + + if (code == LV_EVENT_CLICKED) { + uint32_t id = lv_btnmatrix_get_selected_btn(obj); + const char * txt = lv_btnmatrix_get_btn_text(obj, id); + + if (state == LEARN) { + final_idx = idx; + } + + idx = values; + + switch (id) { + case 0: // if the button pressed is the first one + if (txt == "LEARN") { + state = LEARN; + Braccio.disengage(); // allow the user to freely move the braccio + lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("LEARN"); + lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button + btnm_map[0] = "STOP"; // change the label of the first button to "STOP" + } + else if (txt == "STOP") { + state = IDLE; + Braccio.engage(); // enable the steppers so that the braccio stands still + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + } + break; + case 1: + state = REPEAT; + btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + Braccio.engage(); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("REPEAT"); + break; + default: + state = IDLE; + btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + Braccio.engage(); + delay(500); + Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("IDLE"); + break; + } + } +} + +void mainMenu() { + static lv_style_t style_focus; + lv_style_init(&style_focus); + lv_style_set_outline_color(&style_focus, lv_color_hex(COLOR_ORANGE)); + lv_style_set_outline_width(&style_focus, 4); + + static lv_style_t style_btn; + lv_style_init(&style_btn); + lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL)); + lv_style_set_text_color(&style_btn, lv_color_white()); + + btnm = lv_btnmatrix_create(lv_scr_act()); + lv_obj_set_size(btnm, 240, 240); + lv_btnmatrix_set_map(btnm, btnm_map); + lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 0); + + lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); + lv_obj_add_style(btnm, &style_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); + + lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE); + + lv_btnmatrix_set_one_checked(btnm, true); + lv_btnmatrix_set_selected_btn(btnm, 0); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + + counter = lv_label_create(btnm); + lv_label_set_text_fmt(counter, "Counter: %d" , 0); + lv_obj_align(counter, LV_ALIGN_CENTER, 0, 80); + + lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_ALL, NULL); + + Braccio.connectJoystickTo(btnm); +} + +void setup() { + Braccio.begin(mainMenu); + delay(500); + + Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); + delay(500); + + Serial.begin(115200); + Serial.println("Replicate a movement"); +} + +void loop() { + if (state == LEARN) { + Braccio.positions(idx); + idx += 6; + } + if (state == REPEAT) { + Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); + idx += 6; + if (idx >= final_idx) { + Serial.println("Repeat done"); + state = IDLE; + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + } + } + if (idx - values >= sizeof(values)) { + Serial.println("IDLE"); + state = IDLE; + } + delay(100); + if (state != IDLE) { + lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); + } +} diff --git a/examples/Platform_Tutorials/projects/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino b/examples/Platform_Tutorials/projects/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino new file mode 100644 index 0000000..45686cb --- /dev/null +++ b/examples/Platform_Tutorials/projects/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino @@ -0,0 +1,162 @@ +#include + +// Colors +#define COLOR_TEAL 0x00878F +#define COLOR_LIGHT_TEAL 0x62AEB2 + +auto wristPitch = Braccio.get(3); + +enum states { + LEARN, + REPEAT, + IDLE, + DEMO +}; + +int state = IDLE; + +float values[1000]; +float* idx = values; +float* final_idx = 0; +float homePos[6] = {160.0, 150.0, 220.0, 220.0, 100.0, 180.0}; +float wavePos[6] = {180.0, 250.0, 145.0, 150.0, 150.0, 90.0}; + +static lv_obj_t * counter; +static lv_obj_t * btnm; + +static const char * btnm_map[] = { "Learn", "\n", "Replay", "\n", "Idle", "\n", "Demo", "\n", "\0" }; + + +void ciaoMovement() { + for (int i = 1; i <= 10; i++) { + wristPitch.move().to(100.0f); + delay(300); + wristPitch.move().to(190.0f); + delay(600); + wristPitch.move().to(145.0f); + delay(300); + } + + Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); +} + + +static void eventHandlerMenu(lv_event_t * e) { + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * obj = lv_event_get_target(e); + + if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) { + state = IDLE; + return; + } + + if (code == LV_EVENT_CLICKED) { + uint32_t id = lv_btnmatrix_get_selected_btn(obj); + const char * txt = lv_btnmatrix_get_btn_text(obj, id); + + if (state == LEARN) { + final_idx = idx; + } + + idx = values; + + FILE* f; + switch (id) { + case 0: + state = LEARN; + Braccio.disengage(); + lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("LEARN"); + break; + case 1: + state = REPEAT; + Braccio.engage(); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("REPEAT"); + break; + case 3: + state = DEMO; + Braccio.moveTo(wavePos[0], wavePos[1], wavePos[2], wavePos[3], wavePos[4], wavePos[5]); + lv_btnmatrix_set_btn_ctrl(btnm, 3, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("DEMO"); + break; + default: + state = IDLE; + Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + Serial.println("IDLE"); + break; + } + } +} + +void mainMenu() { + static lv_style_t style_btn; + lv_style_init(&style_btn); + lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL)); + lv_style_set_text_color(&style_btn, lv_color_white()); + + btnm = lv_btnmatrix_create(lv_scr_act()); + lv_obj_set_size(btnm, 240, 240); + lv_btnmatrix_set_map(btnm, btnm_map); + lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 0); + + lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); + + lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE); + + lv_btnmatrix_set_one_checked(btnm, true); + lv_btnmatrix_set_selected_btn(btnm, 2); + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + + counter = lv_label_create(btnm); + lv_label_set_text_fmt(counter, "Counter: %d" , 0); + lv_obj_align(counter, LV_ALIGN_CENTER, 0, 80); + + lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_ALL, NULL); + + Braccio.connectJoystickTo(btnm); +} + +void setup() { + Braccio.begin(mainMenu); + delay(500); + + Serial.begin(115200); + Serial.println("Replicate a movement"); + + Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); +} + +void loop() { + if (state == LEARN) { + Braccio.positions(idx); + idx += 6; + } + if (state == REPEAT) { + Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); + idx += 6; + if (idx >= final_idx) { + Serial.println("Repeat done"); + state = IDLE; + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + } + } + + if (state == DEMO) { + ciaoMovement(); + state = IDLE; + } + + if (idx - values >= sizeof(values)) { + Serial.println("IDLE"); + state = IDLE; + } + delay(100); + if (state != IDLE) { + lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); + } +} diff --git a/examples/Braccio_Basic/Braccio_Basic.ino b/examples/Tools/Braccio_Basic/Braccio_Basic.ino similarity index 100% rename from examples/Braccio_Basic/Braccio_Basic.ino rename to examples/Tools/Braccio_Basic/Braccio_Basic.ino diff --git a/examples/Braccio_LearnByDoing/Braccio_LearnByDoing.ino b/examples/Tools/Braccio_LearnByDoing/Braccio_LearnByDoing.ino similarity index 100% rename from examples/Braccio_LearnByDoing/Braccio_LearnByDoing.ino rename to examples/Tools/Braccio_LearnByDoing/Braccio_LearnByDoing.ino diff --git a/examples/LCD_Custom_Menu/LCD_Custom_Menu.ino b/examples/Tools/LCD_Custom_Menu/LCD_Custom_Menu.ino similarity index 100% rename from examples/LCD_Custom_Menu/LCD_Custom_Menu.ino rename to examples/Tools/LCD_Custom_Menu/LCD_Custom_Menu.ino diff --git a/examples/LCD_Menu_Joystick/LCD_Menu_Joystick.ino b/examples/Tools/LCD_Menu_Joystick/LCD_Menu_Joystick.ino similarity index 100% rename from examples/LCD_Menu_Joystick/LCD_Menu_Joystick.ino rename to examples/Tools/LCD_Menu_Joystick/LCD_Menu_Joystick.ino diff --git a/examples/LCD_Motors/LCD_Motors.ino b/examples/Tools/LCD_Motors/LCD_Motors.ino similarity index 100% rename from examples/LCD_Motors/LCD_Motors.ino rename to examples/Tools/LCD_Motors/LCD_Motors.ino From f748dcda076d31756a9e97d8997a07ee06a9cf2c Mon Sep 17 00:00:00 2001 From: Claudio Scafesi Date: Fri, 22 Apr 2022 18:25:10 +0200 Subject: [PATCH 10/17] fixed redundancy --- .../01_Braccio_learning_mode.ino | 152 ---------------- .../02_learning_challenge.ino | 162 ------------------ 2 files changed, 314 deletions(-) delete mode 100644 examples/Platform_Tutorials/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino delete mode 100644 examples/Platform_Tutorials/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino diff --git a/examples/Platform_Tutorials/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/Platform_Tutorials/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino deleted file mode 100644 index 43a137e..0000000 --- a/examples/Platform_Tutorials/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ /dev/null @@ -1,152 +0,0 @@ -#include - -// Colors -#define COLOR_TEAL 0x00878F -#define COLOR_LIGHT_TEAL 0x62AEB2 -#define COLOR_ORANGE 0xE47128 - -enum states { - LEARN, - REPEAT, // for consistency is better to name this REPLAY or rename the button label repeat TODO - IDLE -}; - -int state = IDLE; - -float values[10000]; -float* idx = values; -float* final_idx = 0; -float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; - -static lv_obj_t * counter; -static lv_obj_t * btnm; - -static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "IDLE", "\n", "\0" }; - - -static void eventHandlerMenu(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t * obj = lv_event_get_target(e); - - if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) { - state = IDLE; - return; - } - - if (code == LV_EVENT_CLICKED) { - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - const char * txt = lv_btnmatrix_get_btn_text(obj, id); - - if (state == LEARN) { - final_idx = idx; - } - - idx = values; - - switch (id) { - case 0: // if the button pressed is the first one - if (txt == "LEARN") { - state = LEARN; - Braccio.disengage(); // allow the user to freely move the braccio - lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("LEARN"); - lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button - btnm_map[0] = "STOP"; // change the label of the first button to "STOP" - } - else if (txt == "STOP") { - state = IDLE; - Braccio.engage(); // enable the steppers so that the braccio stands still - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" - } - break; - case 1: - state = REPEAT; - btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" - Braccio.engage(); - lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("REPEAT"); - break; - default: - state = IDLE; - btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" - Braccio.engage(); - delay(500); - Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("IDLE"); - break; - } - } -} - -void mainMenu() { - static lv_style_t style_focus; - lv_style_init(&style_focus); - lv_style_set_outline_color(&style_focus, lv_color_hex(COLOR_ORANGE)); - lv_style_set_outline_width(&style_focus, 4); - - static lv_style_t style_btn; - lv_style_init(&style_btn); - lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL)); - lv_style_set_text_color(&style_btn, lv_color_white()); - - btnm = lv_btnmatrix_create(lv_scr_act()); - lv_obj_set_size(btnm, 240, 240); - lv_btnmatrix_set_map(btnm, btnm_map); - lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 0); - - lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); - lv_obj_add_style(btnm, &style_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); - - lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); - lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE); - - lv_btnmatrix_set_one_checked(btnm, true); - lv_btnmatrix_set_selected_btn(btnm, 0); - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - - counter = lv_label_create(btnm); - lv_label_set_text_fmt(counter, "Counter: %d" , 0); - lv_obj_align(counter, LV_ALIGN_CENTER, 0, 80); - - lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_ALL, NULL); - - Braccio.connectJoystickTo(btnm); -} - -void setup() { - Braccio.begin(mainMenu); - delay(500); - - Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); - delay(500); - - Serial.begin(115200); - Serial.println("Replicate a movement"); -} - -void loop() { - if (state == LEARN) { - Braccio.positions(idx); - idx += 6; - } - if (state == REPEAT) { - Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); - idx += 6; - if (idx >= final_idx) { - Serial.println("Repeat done"); - state = IDLE; - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - } - } - if (idx - values >= sizeof(values)) { - Serial.println("IDLE"); - state = IDLE; - } - delay(100); - if (state != IDLE) { - lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); - } -} diff --git a/examples/Platform_Tutorials/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino b/examples/Platform_Tutorials/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino deleted file mode 100644 index 45686cb..0000000 --- a/examples/Platform_Tutorials/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino +++ /dev/null @@ -1,162 +0,0 @@ -#include - -// Colors -#define COLOR_TEAL 0x00878F -#define COLOR_LIGHT_TEAL 0x62AEB2 - -auto wristPitch = Braccio.get(3); - -enum states { - LEARN, - REPEAT, - IDLE, - DEMO -}; - -int state = IDLE; - -float values[1000]; -float* idx = values; -float* final_idx = 0; -float homePos[6] = {160.0, 150.0, 220.0, 220.0, 100.0, 180.0}; -float wavePos[6] = {180.0, 250.0, 145.0, 150.0, 150.0, 90.0}; - -static lv_obj_t * counter; -static lv_obj_t * btnm; - -static const char * btnm_map[] = { "Learn", "\n", "Replay", "\n", "Idle", "\n", "Demo", "\n", "\0" }; - - -void ciaoMovement() { - for (int i = 1; i <= 10; i++) { - wristPitch.move().to(100.0f); - delay(300); - wristPitch.move().to(190.0f); - delay(600); - wristPitch.move().to(145.0f); - delay(300); - } - - Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); -} - - -static void eventHandlerMenu(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); - lv_obj_t * obj = lv_event_get_target(e); - - if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) { - state = IDLE; - return; - } - - if (code == LV_EVENT_CLICKED) { - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - const char * txt = lv_btnmatrix_get_btn_text(obj, id); - - if (state == LEARN) { - final_idx = idx; - } - - idx = values; - - FILE* f; - switch (id) { - case 0: - state = LEARN; - Braccio.disengage(); - lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("LEARN"); - break; - case 1: - state = REPEAT; - Braccio.engage(); - lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("REPEAT"); - break; - case 3: - state = DEMO; - Braccio.moveTo(wavePos[0], wavePos[1], wavePos[2], wavePos[3], wavePos[4], wavePos[5]); - lv_btnmatrix_set_btn_ctrl(btnm, 3, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("DEMO"); - break; - default: - state = IDLE; - Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("IDLE"); - break; - } - } -} - -void mainMenu() { - static lv_style_t style_btn; - lv_style_init(&style_btn); - lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL)); - lv_style_set_text_color(&style_btn, lv_color_white()); - - btnm = lv_btnmatrix_create(lv_scr_act()); - lv_obj_set_size(btnm, 240, 240); - lv_btnmatrix_set_map(btnm, btnm_map); - lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 0); - - lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); - - lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); - lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKABLE); - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE); - - lv_btnmatrix_set_one_checked(btnm, true); - lv_btnmatrix_set_selected_btn(btnm, 2); - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - - counter = lv_label_create(btnm); - lv_label_set_text_fmt(counter, "Counter: %d" , 0); - lv_obj_align(counter, LV_ALIGN_CENTER, 0, 80); - - lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_ALL, NULL); - - Braccio.connectJoystickTo(btnm); -} - -void setup() { - Braccio.begin(mainMenu); - delay(500); - - Serial.begin(115200); - Serial.println("Replicate a movement"); - - Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); -} - -void loop() { - if (state == LEARN) { - Braccio.positions(idx); - idx += 6; - } - if (state == REPEAT) { - Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); - idx += 6; - if (idx >= final_idx) { - Serial.println("Repeat done"); - state = IDLE; - lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - } - } - - if (state == DEMO) { - ciaoMovement(); - state = IDLE; - } - - if (idx - values >= sizeof(values)) { - Serial.println("IDLE"); - state = IDLE; - } - delay(100); - if (state != IDLE) { - lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); - } -} From 9348e57242f98b9203cc9ca40e5f5a85128a6fc6 Mon Sep 17 00:00:00 2001 From: Claudio Scafesi Date: Fri, 22 Apr 2022 18:27:49 +0200 Subject: [PATCH 11/17] fixed repo structure --- .../{ => Braccio_Learn_and_Replay}/Braccio_Learn_and_Replay.ino | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{ => Braccio_Learn_and_Replay}/Braccio_Learn_and_Replay.ino (100%) diff --git a/examples/Braccio_Learn_and_Replay.ino b/examples/Braccio_Learn_and_Replay/Braccio_Learn_and_Replay.ino similarity index 100% rename from examples/Braccio_Learn_and_Replay.ino rename to examples/Braccio_Learn_and_Replay/Braccio_Learn_and_Replay.ino From 0f0d8ccb677d01edd4150b8e56831fde5d23f5bd Mon Sep 17 00:00:00 2001 From: Claudio Scafesi Date: Fri, 22 Apr 2022 18:36:07 +0200 Subject: [PATCH 12/17] new naming for sketch --- .../Braccio_Learn_and_Repeat.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{Braccio_Learn_and_Replay/Braccio_Learn_and_Replay.ino => Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino} (100%) diff --git a/examples/Braccio_Learn_and_Replay/Braccio_Learn_and_Replay.ino b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino similarity index 100% rename from examples/Braccio_Learn_and_Replay/Braccio_Learn_and_Replay.ino rename to examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino From ac1cfb9c79b6363a59406d61c9c758bb6c0bf487 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 18:41:46 +0200 Subject: [PATCH 13/17] allow "STOP" during the "REPLAY" --- .../Braccio_Learn_and_Repeat.ino | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino index 43a137e..d7831b6 100644 --- a/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino +++ b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino @@ -61,15 +61,27 @@ static void eventHandlerMenu(lv_event_t * e) { } break; case 1: - state = REPEAT; btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + if (txt == "REPLAY"){ + state = REPEAT; + btnm_map[2] = "STOP"; // change the label of the second button to "STOP" Braccio.engage(); lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); Serial.println("REPEAT"); + } + else if (txt=="STOP"){ + state = IDLE; + Braccio.engage(); // enable the steppers so that the braccio stands still + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" + } + break; + default: state = IDLE; btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" Braccio.engage(); delay(500); Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); @@ -138,6 +150,7 @@ void loop() { if (idx >= final_idx) { Serial.println("Repeat done"); state = IDLE; + btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); } } From 8ce83845b70b42500f37a986fb4cae01aaf5f96e Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 22 Apr 2022 18:55:34 +0200 Subject: [PATCH 14/17] change and uniform button labels --- .../Braccio_Learn_and_Repeat.ino | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino index d7831b6..1ecae98 100644 --- a/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino +++ b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino @@ -7,11 +7,11 @@ enum states { LEARN, - REPEAT, // for consistency is better to name this REPLAY or rename the button label repeat TODO - IDLE + REPEAT, // for consistency is better to name this REPEAT or rename the button label repeat TODO + ZERO_POSITION }; -int state = IDLE; +int state = ZERO_POSITION; float values[10000]; float* idx = values; @@ -21,7 +21,7 @@ float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; static lv_obj_t * counter; static lv_obj_t * btnm; -static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "IDLE", "\n", "\0" }; +static const char * btnm_map[] = { "LEARN", "\n", "REPEAT", "\n", "ZERO_POSITION", "\n", "\0" }; static void eventHandlerMenu(lv_event_t * e) { @@ -29,7 +29,7 @@ static void eventHandlerMenu(lv_event_t * e) { lv_obj_t * obj = lv_event_get_target(e); if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) { - state = IDLE; + state = ZERO_POSITION; return; } @@ -54,7 +54,7 @@ static void eventHandlerMenu(lv_event_t * e) { btnm_map[0] = "STOP"; // change the label of the first button to "STOP" } else if (txt == "STOP") { - state = IDLE; + state = ZERO_POSITION; Braccio.engage(); // enable the steppers so that the braccio stands still lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" @@ -62,7 +62,7 @@ static void eventHandlerMenu(lv_event_t * e) { break; case 1: btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" - if (txt == "REPLAY"){ + if (txt == "REPEAT"){ state = REPEAT; btnm_map[2] = "STOP"; // change the label of the second button to "STOP" Braccio.engage(); @@ -70,23 +70,23 @@ static void eventHandlerMenu(lv_event_t * e) { Serial.println("REPEAT"); } else if (txt=="STOP"){ - state = IDLE; + state = ZERO_POSITION; Braccio.engage(); // enable the steppers so that the braccio stands still lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" + btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" } break; default: - state = IDLE; + state = ZERO_POSITION; btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" - btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" + btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" Braccio.engage(); delay(500); Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("IDLE"); + Serial.println("ZERO_POSITION"); break; } } @@ -149,17 +149,17 @@ void loop() { idx += 6; if (idx >= final_idx) { Serial.println("Repeat done"); - state = IDLE; - btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" + state = ZERO_POSITION; + btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); } } if (idx - values >= sizeof(values)) { - Serial.println("IDLE"); - state = IDLE; + Serial.println("ZERO_POSITION"); + state = ZERO_POSITION; } delay(100); - if (state != IDLE) { + if (state != ZERO_POSITION) { lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); } } From ff78a9c417d09b91a07921a4e141a516212fcec1 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 27 Apr 2022 10:30:36 +0200 Subject: [PATCH 15/17] Ensure that both examples/Braccio_Learn_and_Repeat and examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode are identical. --- .../01_Braccio_learning_mode.ino | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index 43a137e..1ecae98 100644 --- a/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -7,11 +7,11 @@ enum states { LEARN, - REPEAT, // for consistency is better to name this REPLAY or rename the button label repeat TODO - IDLE + REPEAT, // for consistency is better to name this REPEAT or rename the button label repeat TODO + ZERO_POSITION }; -int state = IDLE; +int state = ZERO_POSITION; float values[10000]; float* idx = values; @@ -21,7 +21,7 @@ float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; static lv_obj_t * counter; static lv_obj_t * btnm; -static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "IDLE", "\n", "\0" }; +static const char * btnm_map[] = { "LEARN", "\n", "REPEAT", "\n", "ZERO_POSITION", "\n", "\0" }; static void eventHandlerMenu(lv_event_t * e) { @@ -29,7 +29,7 @@ static void eventHandlerMenu(lv_event_t * e) { lv_obj_t * obj = lv_event_get_target(e); if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) { - state = IDLE; + state = ZERO_POSITION; return; } @@ -54,27 +54,39 @@ static void eventHandlerMenu(lv_event_t * e) { btnm_map[0] = "STOP"; // change the label of the first button to "STOP" } else if (txt == "STOP") { - state = IDLE; + state = ZERO_POSITION; Braccio.engage(); // enable the steppers so that the braccio stands still lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" } break; case 1: - state = REPEAT; btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + if (txt == "REPEAT"){ + state = REPEAT; + btnm_map[2] = "STOP"; // change the label of the second button to "STOP" Braccio.engage(); lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); Serial.println("REPEAT"); + } + else if (txt=="STOP"){ + state = ZERO_POSITION; + Braccio.engage(); // enable the steppers so that the braccio stands still + lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); + btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" + } + break; + default: - state = IDLE; + state = ZERO_POSITION; btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" Braccio.engage(); delay(500); Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("IDLE"); + Serial.println("ZERO_POSITION"); break; } } @@ -137,16 +149,17 @@ void loop() { idx += 6; if (idx >= final_idx) { Serial.println("Repeat done"); - state = IDLE; + state = ZERO_POSITION; + btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); } } if (idx - values >= sizeof(values)) { - Serial.println("IDLE"); - state = IDLE; + Serial.println("ZERO_POSITION"); + state = ZERO_POSITION; } delay(100); - if (state != IDLE) { + if (state != ZERO_POSITION) { lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); } } From c01de013a9640ce111ffc7edd03d2d09c5c3acf2 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 27 Apr 2022 10:33:20 +0200 Subject: [PATCH 16/17] Rename button/state REPEAT to REPLAY. --- .../Braccio_Learn_and_Repeat.ino | 20 +++++++++---------- .../01_Braccio_learning_mode.ino | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino index 1ecae98..dfec06d 100644 --- a/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino +++ b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino @@ -7,7 +7,7 @@ enum states { LEARN, - REPEAT, // for consistency is better to name this REPEAT or rename the button label repeat TODO + REPLAY, ZERO_POSITION }; @@ -21,7 +21,7 @@ float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; static lv_obj_t * counter; static lv_obj_t * btnm; -static const char * btnm_map[] = { "LEARN", "\n", "REPEAT", "\n", "ZERO_POSITION", "\n", "\0" }; +static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" }; static void eventHandlerMenu(lv_event_t * e) { @@ -62,18 +62,18 @@ static void eventHandlerMenu(lv_event_t * e) { break; case 1: btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" - if (txt == "REPEAT"){ - state = REPEAT; + if (txt == "REPLAY"){ + state = REPLAY; btnm_map[2] = "STOP"; // change the label of the second button to "STOP" Braccio.engage(); lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("REPEAT"); + Serial.println("REPLAY"); } else if (txt=="STOP"){ state = ZERO_POSITION; Braccio.engage(); // enable the steppers so that the braccio stands still lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" + btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" } break; @@ -81,7 +81,7 @@ static void eventHandlerMenu(lv_event_t * e) { default: state = ZERO_POSITION; btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" - btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" + btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" Braccio.engage(); delay(500); Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); @@ -144,13 +144,13 @@ void loop() { Braccio.positions(idx); idx += 6; } - if (state == REPEAT) { + if (state == REPLAY) { Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); idx += 6; if (idx >= final_idx) { - Serial.println("Repeat done"); + Serial.println("REPLAY done"); state = ZERO_POSITION; - btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" + btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); } } diff --git a/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index 1ecae98..dfec06d 100644 --- a/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -7,7 +7,7 @@ enum states { LEARN, - REPEAT, // for consistency is better to name this REPEAT or rename the button label repeat TODO + REPLAY, ZERO_POSITION }; @@ -21,7 +21,7 @@ float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; static lv_obj_t * counter; static lv_obj_t * btnm; -static const char * btnm_map[] = { "LEARN", "\n", "REPEAT", "\n", "ZERO_POSITION", "\n", "\0" }; +static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" }; static void eventHandlerMenu(lv_event_t * e) { @@ -62,18 +62,18 @@ static void eventHandlerMenu(lv_event_t * e) { break; case 1: btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" - if (txt == "REPEAT"){ - state = REPEAT; + if (txt == "REPLAY"){ + state = REPLAY; btnm_map[2] = "STOP"; // change the label of the second button to "STOP" Braccio.engage(); lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("REPEAT"); + Serial.println("REPLAY"); } else if (txt=="STOP"){ state = ZERO_POSITION; Braccio.engage(); // enable the steppers so that the braccio stands still lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" + btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" } break; @@ -81,7 +81,7 @@ static void eventHandlerMenu(lv_event_t * e) { default: state = ZERO_POSITION; btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" - btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" + btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" Braccio.engage(); delay(500); Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); @@ -144,13 +144,13 @@ void loop() { Braccio.positions(idx); idx += 6; } - if (state == REPEAT) { + if (state == REPLAY) { Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); idx += 6; if (idx >= final_idx) { - Serial.println("Repeat done"); + Serial.println("REPLAY done"); state = ZERO_POSITION; - btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT" + btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); } } From db8e7f75c5a99191c55624a26e6c4f35e1e4a160 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 27 Apr 2022 10:35:40 +0200 Subject: [PATCH 17/17] Rename button/state LEARN to RECORD. --- .../Braccio_Learn_and_Repeat.ino | 20 +++++++++---------- .../01_Braccio_learning_mode.ino | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino index dfec06d..f9b5564 100644 --- a/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino +++ b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino @@ -6,7 +6,7 @@ #define COLOR_ORANGE 0xE47128 enum states { - LEARN, + RECORD, REPLAY, ZERO_POSITION }; @@ -21,7 +21,7 @@ float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; static lv_obj_t * counter; static lv_obj_t * btnm; -static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" }; +static const char * btnm_map[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" }; static void eventHandlerMenu(lv_event_t * e) { @@ -37,7 +37,7 @@ static void eventHandlerMenu(lv_event_t * e) { uint32_t id = lv_btnmatrix_get_selected_btn(obj); const char * txt = lv_btnmatrix_get_btn_text(obj, id); - if (state == LEARN) { + if (state == RECORD) { final_idx = idx; } @@ -45,11 +45,11 @@ static void eventHandlerMenu(lv_event_t * e) { switch (id) { case 0: // if the button pressed is the first one - if (txt == "LEARN") { - state = LEARN; + if (txt == "RECORD") { + state = RECORD; Braccio.disengage(); // allow the user to freely move the braccio lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("LEARN"); + Serial.println("RECORD"); lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button btnm_map[0] = "STOP"; // change the label of the first button to "STOP" } @@ -57,11 +57,11 @@ static void eventHandlerMenu(lv_event_t * e) { state = ZERO_POSITION; Braccio.engage(); // enable the steppers so that the braccio stands still lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" } break; case 1: - btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" if (txt == "REPLAY"){ state = REPLAY; btnm_map[2] = "STOP"; // change the label of the second button to "STOP" @@ -80,7 +80,7 @@ static void eventHandlerMenu(lv_event_t * e) { default: state = ZERO_POSITION; - btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" Braccio.engage(); delay(500); @@ -140,7 +140,7 @@ void setup() { } void loop() { - if (state == LEARN) { + if (state == RECORD) { Braccio.positions(idx); idx += 6; } diff --git a/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino b/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino index dfec06d..f9b5564 100644 --- a/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ b/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -6,7 +6,7 @@ #define COLOR_ORANGE 0xE47128 enum states { - LEARN, + RECORD, REPLAY, ZERO_POSITION }; @@ -21,7 +21,7 @@ float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; static lv_obj_t * counter; static lv_obj_t * btnm; -static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" }; +static const char * btnm_map[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" }; static void eventHandlerMenu(lv_event_t * e) { @@ -37,7 +37,7 @@ static void eventHandlerMenu(lv_event_t * e) { uint32_t id = lv_btnmatrix_get_selected_btn(obj); const char * txt = lv_btnmatrix_get_btn_text(obj, id); - if (state == LEARN) { + if (state == RECORD) { final_idx = idx; } @@ -45,11 +45,11 @@ static void eventHandlerMenu(lv_event_t * e) { switch (id) { case 0: // if the button pressed is the first one - if (txt == "LEARN") { - state = LEARN; + if (txt == "RECORD") { + state = RECORD; Braccio.disengage(); // allow the user to freely move the braccio lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); - Serial.println("LEARN"); + Serial.println("RECORD"); lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button btnm_map[0] = "STOP"; // change the label of the first button to "STOP" } @@ -57,11 +57,11 @@ static void eventHandlerMenu(lv_event_t * e) { state = ZERO_POSITION; Braccio.engage(); // enable the steppers so that the braccio stands still lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); - btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" } break; case 1: - btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" if (txt == "REPLAY"){ state = REPLAY; btnm_map[2] = "STOP"; // change the label of the second button to "STOP" @@ -80,7 +80,7 @@ static void eventHandlerMenu(lv_event_t * e) { default: state = ZERO_POSITION; - btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN" + btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" Braccio.engage(); delay(500); @@ -140,7 +140,7 @@ void setup() { } void loop() { - if (state == LEARN) { + if (state == RECORD) { Braccio.positions(idx); idx += 6; }