diff --git a/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino new file mode 100644 index 0000000..f9b5564 --- /dev/null +++ b/examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino @@ -0,0 +1,165 @@ +#include + +// Colors +#define COLOR_TEAL 0x00878F +#define COLOR_LIGHT_TEAL 0x62AEB2 +#define COLOR_ORANGE 0xE47128 + +enum states { + RECORD, + REPLAY, + ZERO_POSITION +}; + +int state = ZERO_POSITION; + +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[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITION", "\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 = ZERO_POSITION; + 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 == RECORD) { + final_idx = idx; + } + + idx = values; + + switch (id) { + case 0: // if the button pressed is the first one + 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("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" + } + 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[0] = "RECORD"; // reset the label of the first button back to "RECORD" + } + break; + case 1: + 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" + Braccio.engage(); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); + 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] = "REPLAY"; // reset the label of the first button back to "REPLAY" + } + + break; + + default: + state = ZERO_POSITION; + 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); + 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("ZERO_POSITION"); + 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 == RECORD) { + Braccio.positions(idx); + idx += 6; + } + 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("REPLAY done"); + state = ZERO_POSITION; + 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); + } + } + if (idx - values >= sizeof(values)) { + Serial.println("ZERO_POSITION"); + state = ZERO_POSITION; + } + delay(100); + if (state != ZERO_POSITION) { + lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); + } +} 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/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..f9b5564 --- /dev/null +++ b/examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino @@ -0,0 +1,165 @@ +#include + +// Colors +#define COLOR_TEAL 0x00878F +#define COLOR_LIGHT_TEAL 0x62AEB2 +#define COLOR_ORANGE 0xE47128 + +enum states { + RECORD, + REPLAY, + ZERO_POSITION +}; + +int state = ZERO_POSITION; + +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[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITION", "\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 = ZERO_POSITION; + 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 == RECORD) { + final_idx = idx; + } + + idx = values; + + switch (id) { + case 0: // if the button pressed is the first one + 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("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" + } + 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[0] = "RECORD"; // reset the label of the first button back to "RECORD" + } + break; + case 1: + 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" + Braccio.engage(); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); + 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] = "REPLAY"; // reset the label of the first button back to "REPLAY" + } + + break; + + default: + state = ZERO_POSITION; + 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); + 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("ZERO_POSITION"); + 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 == RECORD) { + Braccio.positions(idx); + idx += 6; + } + 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("REPLAY done"); + state = ZERO_POSITION; + 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); + } + } + if (idx - values >= sizeof(values)) { + Serial.println("ZERO_POSITION"); + state = ZERO_POSITION; + } + delay(100); + if (state != ZERO_POSITION) { + 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/projects/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/projects/p03-learning-mode/02_learning_challenge/02_learning_challenge.ino 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 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 deleted file mode 100644 index 16faee9..0000000 --- a/examples/tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino +++ /dev/null @@ -1,134 +0,0 @@ -#include - -// Colors -#define COLOR_TEAL 0x00878F -#define COLOR_LIGHT_TEAL 0x62AEB2 - -enum states { - LEARN, - REPEAT, - IDLE -}; - -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}; - -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; - - 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; - default: - state = IDLE; - 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_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); - - 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); - } -}