diff --git a/examples/Platform_Tutorials/lessons/03-important-programming-concepts/Braccio_moving_range_angles/Braccio_moving_range_angles.ino b/examples/Platform_Tutorials/lessons/03-important-programming-concepts/Braccio_moving_range_angles/Braccio_moving_range_angles.ino new file mode 100644 index 0000000..7206a1b --- /dev/null +++ b/examples/Platform_Tutorials/lessons/03-important-programming-concepts/Braccio_moving_range_angles/Braccio_moving_range_angles.ino @@ -0,0 +1,117 @@ +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * DEFINES + **************************************************************************************/ + +#define BUTTON_SELECT 3 +#define BUTTON_ENTER 6 +#define TIME_DELAY 2000 + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static float const HOME_POS[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +static auto gripper = Braccio.get(1); +static auto wristRoll = Braccio.get(2); +static auto wristPitch = Braccio.get(3); +static auto elbow = Braccio.get(4); +static auto shoulder = Braccio.get(5); +static auto base = Braccio.get(6); + +float angles[6]; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + if (Braccio.begin()) + { + /* Warning: keep a safe distance from the robot and watch out for the robot's + movement. It could be speedy and hit someone. */ + /* Move to home position. */ + Braccio.moveTo(HOME_POS[0], HOME_POS[1], HOME_POS[2], HOME_POS[3], HOME_POS[4], HOME_POS[5]); + delay(TIME_DELAY); + } +} + +void loop() { + int pressedKey = Braccio.getKey(); + + if (pressedKey == BUTTON_ENTER) + { + // Pinch movement + gripper.move().to(230.0f); delay(TIME_DELAY); + gripper.move().to(HOME_POS[0]); delay(TIME_DELAY); + + // // Wrist Roll movement + wristRoll.move().to(0.0f); delay(TIME_DELAY); + wristRoll.move().to(HOME_POS[1]); delay(TIME_DELAY); + wristRoll.move().to(315.0f); delay(TIME_DELAY); + wristRoll.move().to(HOME_POS[1]); delay(TIME_DELAY); + + // // Wrist Pitch movement + wristPitch.move().to(70.0f); delay(TIME_DELAY); + wristPitch.move().to(HOME_POS[2]); delay(TIME_DELAY); + wristPitch.move().to(260.0f); delay(TIME_DELAY); + wristPitch.move().to(HOME_POS[2]); delay(TIME_DELAY); + + // Elbow movement + for(float i=HOME_POS[3]; i >= 70.0; i-=5) + { elbow.move().to(i); delay(TIME_DELAY/2000); } + elbow.move().to(HOME_POS[3]); delay(TIME_DELAY); + for(float i=HOME_POS[3]; i <= 260.0; i+=5) + { elbow.move().to(i); delay(TIME_DELAY/2000); } + elbow.move().to(HOME_POS[3]); delay(TIME_DELAY); + + // Shoulder movement + shoulder.move().to(120.0f); delay(TIME_DELAY/2); + shoulder.move().to(90.0f); delay(TIME_DELAY/2); + shoulder.move().to(120.0f); delay(TIME_DELAY/2); + shoulder.move().to(HOME_POS[4]); delay(TIME_DELAY); + shoulder.move().to(200.0f); delay(TIME_DELAY/2); + shoulder.move().to(230.0f); delay(TIME_DELAY/2); + shoulder.move().to(200.0f); delay(TIME_DELAY/2); + shoulder.move().to(HOME_POS[4]); delay(TIME_DELAY); + + // Base movement + base.move().to(0.0f); delay(TIME_DELAY); + base.move().to(HOME_POS[5]); delay(TIME_DELAY); + base.move().to(315.0f); delay(TIME_DELAY); + base.move().to(HOME_POS[5]); delay(TIME_DELAY); + + while(pressedKey == BUTTON_ENTER) { pressedKey = Braccio.getKey(); } + } + + if (pressedKey == BUTTON_SELECT) + { + // Fetch the joints positions + Braccio.positions(angles); + + // Print the joint angles + Serial.println("************* Joints Angles *************"); + Serial.println("|\tMotor ID\t|\tAngle\t|"); + Serial.println("----------------------------------------"); + Serial.print("| 1 - Gripper\t\t|\t" + String(angles[0]) + "\t|\n" + + "| 2 - Wrist Rotation\t|\t" + String(angles[1]) + "\t|\n" + + "| 3 - Wrist Vertical\t|\t" + String(angles[2]) + "\t|\n" + + "| 4 - Elbow\t\t|\t" + String(angles[3]) + "\t|\n" + + "| 5 - Shoulder\t\t|\t" + String(angles[4]) + "\t|\n" + + "| 6 - Base\t\t|\t" + String(angles[5]) + "\t|\n" + + "*****************************************\n\n\n\n\n"); + + while(pressedKey == BUTTON_SELECT) { pressedKey = Braccio.getKey(); } + + } +} \ No newline at end of file diff --git a/examples/Platform_Tutorials/lessons/03-important-programming-concepts/Navigating_the_display_menu/Navigating_the_display_menu.ino b/examples/Platform_Tutorials/lessons/03-important-programming-concepts/Navigating_the_display_menu/Navigating_the_display_menu.ino new file mode 100644 index 0000000..a6b107b --- /dev/null +++ b/examples/Platform_Tutorials/lessons/03-important-programming-concepts/Navigating_the_display_menu/Navigating_the_display_menu.ino @@ -0,0 +1,81 @@ +#include + +#define MARGIN_LEFT 0 +#define MARGIN_TOP 0 + +// Arduino Colors +#define COLOR_TEAL 0x00878F +#define COLOR_LIGHT_TEAL 0x62AEB2 +#define COLOR_ORANGE 0xE47128 +#define COLOR_YELLOW 0xE5AD24 +#define COLOR_WHITE 0xFFFFFF + +static const char * btnm_map[] = {"Option 1", "Option 2", "\n", + "Option 3", "Option 4", "\n", + "Option 5", "Option 6", "\0" + }; + +void setup() { + if (!Braccio.begin(customMenu)) { + if (Serial) Serial.println("Braccio.begin() failed."); + for(;;) { } + } +} + +void loop() { + // Let here empty. +} + +void customMenu(){ + Braccio.lvgl_lock(); + + static lv_style_t style_bg; + lv_style_init(&style_bg); + lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE)); + + static lv_style_t style_btn; + lv_style_init(&style_btn); + lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_YELLOW)); + lv_style_set_border_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL)); + lv_style_set_border_width(&style_btn, 2); + lv_style_set_text_color(&style_btn, lv_color_hex(COLOR_TEAL)); + + + lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act()); + lv_btnmatrix_set_map(btnm, btnm_map); + lv_obj_align(btnm, LV_ALIGN_CENTER, MARGIN_LEFT, MARGIN_TOP); + + lv_obj_add_style(btnm, &style_bg, 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_btn_ctrl(btnm, 3, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_set_btn_ctrl(btnm, 4, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_set_btn_ctrl(btnm, 5, LV_BTNMATRIX_CTRL_CHECKABLE); + + lv_btnmatrix_set_one_checked(btnm, true); + + lv_obj_add_event_cb(btnm, eventHandler, LV_EVENT_ALL, NULL); + + Braccio.lvgl_unlock(); + + Braccio.connectJoystickTo(btnm); +} + +static void eventHandler(lv_event_t * e){ + Braccio.lvgl_lock(); + + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * obj = lv_event_get_target(e); + if (code == LV_EVENT_CLICKED) { + uint32_t id = lv_btnmatrix_get_selected_btn(obj); + const char * txt = lv_btnmatrix_get_btn_text(obj, id); + + LV_LOG_USER("%s was selected\n", txt); + Serial.println(String(txt) + " was selected."); + } + + Braccio.lvgl_unlock(); +} \ No newline at end of file diff --git a/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino b/examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino diff --git a/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/sketch.json b/examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/01_creating_a_button/sketch.json similarity index 100% rename from examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/sketch.json rename to examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/01_creating_a_button/sketch.json diff --git a/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino b/examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/02_designing_the_button/02_designing_the_button.ino diff --git a/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/btn_style.ino.NANO_RP2040_CONNECT.bin b/examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/02_designing_the_button/btn_style.ino.NANO_RP2040_CONNECT.bin similarity index 100% rename from examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/btn_style.ino.NANO_RP2040_CONNECT.bin rename to examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/02_designing_the_button/btn_style.ino.NANO_RP2040_CONNECT.bin diff --git a/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/sketch.json b/examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/02_designing_the_button/sketch.json similarity index 100% rename from examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/sketch.json rename to examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/02_designing_the_button/sketch.json diff --git a/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino b/examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/03_creating_a_menu/03_creating_a_menu.ino diff --git a/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino b/examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/04_testing_it_out/04_testing_it_out.ino diff --git a/examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino b/examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/01-programming-the-braccio-display/05_display_challenge/05_display_challenge.ino diff --git a/examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/01_playing_with_the_Joystick/01_playing_with_the_Joystick.ino b/examples/Platform_Tutorials/lessons/Basic_codes/02-navigatting-the-display-menu/01_playing_with_the_Joystick/01_playing_with_the_Joystick.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/01_playing_with_the_Joystick/01_playing_with_the_Joystick.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/02-navigatting-the-display-menu/01_playing_with_the_Joystick/01_playing_with_the_Joystick.ino diff --git a/examples/Platform_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/Basic_codes/02-navigatting-the-display-menu/02_handling_events_in_the_menu/02_handling_events_in_the_menu.ino similarity index 100% rename from examples/Platform_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/Basic_codes/02-navigatting-the-display-menu/02_handling_events_in_the_menu/02_handling_events_in_the_menu.ino diff --git a/examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino b/examples/Platform_Tutorials/lessons/Basic_codes/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/02-navigatting-the-display-menu/03_navigate_challenge_I/03_navigate_challenge_I.ino diff --git a/examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino b/examples/Platform_Tutorials/lessons/Basic_codes/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/02-navigatting-the-display-menu/04_navigate_challenge_II/04_navigate_challenge_II.ino diff --git a/examples/Platform_Tutorials/lessons/03-playing-with-the-motors/01_playing_with_the_motors/01_playing_with_the_motors.ino b/examples/Platform_Tutorials/lessons/Basic_codes/03-playing-with-the-motors/01_playing_with_the_motors/01_playing_with_the_motors.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/03-playing-with-the-motors/01_playing_with_the_motors/01_playing_with_the_motors.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/03-playing-with-the-motors/01_playing_with_the_motors/01_playing_with_the_motors.ino diff --git a/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 b/examples/Platform_Tutorials/lessons/Basic_codes/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/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 rename to examples/Platform_Tutorials/lessons/Basic_codes/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/Platform_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/Basic_codes/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/Platform_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/Basic_codes/03-playing-with-the-motors/03_moving_the_motors_with_the_joystick/03_moving_the_motors_with_the_joystick.ino diff --git a/examples/Platform_Tutorials/lessons/03-playing-with-the-motors/04_servo_motors_challenge/04_servo_motors_challenge.ino b/examples/Platform_Tutorials/lessons/Basic_codes/03-playing-with-the-motors/04_servo_motors_challenge/04_servo_motors_challenge.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/03-playing-with-the-motors/04_servo_motors_challenge/04_servo_motors_challenge.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/03-playing-with-the-motors/04_servo_motors_challenge/04_servo_motors_challenge.ino diff --git a/examples/Platform_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/Basic_codes/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/Platform_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/Basic_codes/04-integration-of-previous-learnings/01_playing_with_a_joint_angle_gauge/01_playing_with_a_joint_angle_gauge.ino diff --git a/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 b/examples/Platform_Tutorials/lessons/Basic_codes/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/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 rename to examples/Platform_Tutorials/lessons/Basic_codes/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/Platform_Tutorials/lessons/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino b/examples/Platform_Tutorials/lessons/Basic_codes/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/04-integration-of-previous-learnings/03_learnings_challenge_I/03_learnings_challenge_I.ino diff --git a/examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino b/examples/Platform_Tutorials/lessons/Basic_codes/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino similarity index 100% rename from examples/Platform_Tutorials/lessons/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino rename to examples/Platform_Tutorials/lessons/Basic_codes/04-integration-of-previous-learnings/04_learnings_challenge_II/04_learnings_challenge_II.ino diff --git a/examples/Platform_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 index b06b096..dee140c 100644 --- a/examples/Platform_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 @@ -1,6 +1,19 @@ +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + #include -// Variables +/************************************************************************************** + * DEFINES + **************************************************************************************/ + +#define TIME_DELAY 1000 + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + // Braccio ++ joints auto gripper = Braccio.get(1); auto wristRoll = Braccio.get(2); @@ -9,28 +22,28 @@ auto elbow = Braccio.get(4); auto shoulder = Braccio.get(5); auto base = Braccio.get(6); -float initialGripper = 160.0; float initialBase = 90.0; -float initialAngle = 150.0; +float initialAngle = 157.5; + float angles[6]; +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + void setup() { - Braccio.begin(); - delay(500); // Waits for the Braccio initialization - - // Send motors initial angle - gripper.move().to(initialGripper); - delay(100); - wristRoll.move().to(initialAngle); - delay(100); - wristPitch.move().to(initialAngle); - delay(100); - elbow.move().to(initialAngle); - delay(100); - shoulder.move().to(initialAngle); - delay(100); - base.move().to(initialBase); - delay(100); + if (Braccio.begin()){ + /* Warning: keep a safe distance from the robot and watch out for the robot's + movement. It could be speedy and hit someone. */ + + /* Move to home position. */ + gripper.move().to(initialAngle); delay(TIME_DELAY); + wristRoll.move().to(initialAngle); delay(TIME_DELAY); + wristPitch.move().to(initialAngle); delay(TIME_DELAY); + elbow.move().to(initialAngle); delay(TIME_DELAY); + shoulder.move().to(initialAngle); delay(TIME_DELAY); + base.move().to(initialBase); delay(TIME_DELAY); + } Serial.begin(115200); while(!Serial){} @@ -53,5 +66,5 @@ void loop() { Serial.println("*****************************************\n\n\n\n\n"); Serial.println("\n\n\n\n"); - delay(1000); + delay(TIME_DELAY); } diff --git a/examples/Platform_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 index f837495..f969acb 100644 --- a/examples/Platform_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 @@ -1,7 +1,27 @@ +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + #include +/************************************************************************************** + * DEFINES + **************************************************************************************/ + #define BUTTON_ENTER 6 +#define TIME_DELAY 1000 + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +float const HOME_POS[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; +float const WAVE_POS[6] = {180.0, 260.0, 157.5, 157.5, 157.5, 180.0}; +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + // Braccio ++ joints auto gripper = Braccio.get(1); auto wristRoll = Braccio.get(2); @@ -10,24 +30,27 @@ auto elbow = Braccio.get(4); auto shoulder = Braccio.get(5); auto base = Braccio.get(6); -/* Variables */ -// initialAngles[6] = {gripper, wristRoll, wristPitch, elbow, shoulder, base} -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}; - bool movement = false; // Flag to initialize joints' movements +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + void setup() { - Braccio.begin(); - delay(500); // Waits for the Braccio initialization + if (Braccio.begin()){ + /* Warning: + Keep a safe distance from the robot until you make sure the code is properly + working. Be mindful of the robot’s movement prior to that, as it could be + speedy and accidentally hit someone. + */ - // Set motors initial angle - // Should move all the motors at once - Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); - delay(500); + /* Move to home position. */ + Braccio.moveTo(HOME_POS[0], HOME_POS[1], HOME_POS[2], HOME_POS[3], HOME_POS[4], HOME_POS[5]); + delay(TIME_DELAY); + } } -// Waving whit Wrist pitch +// Waving with Wrist pitch void loop() { int pressedKey = Braccio.getKey(); @@ -35,16 +58,13 @@ void loop() { movement = true; // Trigger joints' movements if (movement) { - Braccio.moveTo(wavePos[0], wavePos[1], wavePos[2], wavePos[3], wavePos[4], wavePos[5]); - delay(1000); - - 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(WAVE_POS[0], WAVE_POS[1], WAVE_POS[2], WAVE_POS[3], WAVE_POS[4], WAVE_POS[5]); + delay(TIME_DELAY); + + for (int i = 1; i <= 5; i++) { + wristPitch.move().to(120.0f); delay(TIME_DELAY); + wristPitch.move().to(200.0f); delay(2*TIME_DELAY); + wristPitch.move().to(WAVE_POS[3]); } movement = false; // Stop joints' movements diff --git a/examples/Platform_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 index 138d7d7..cee77a0 100644 --- a/examples/Platform_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 @@ -1,6 +1,26 @@ +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + #include +/************************************************************************************** + * DEFINES + **************************************************************************************/ + #define BUTTON_ENTER 6 +#define TIME_DELAY 1000 + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static float const HOME_POS[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; +static float const AGREE_POS[6] = {160.0, 160.0, 210.0, 240.0, 100.0, 180.0}; + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ // Braccio ++ joints auto gripper = Braccio.get(1); @@ -10,20 +30,21 @@ auto elbow = Braccio.get(4); auto shoulder = Braccio.get(5); auto base = Braccio.get(6); -/* Variables */ -// initialAngles[6] = {gripper, wristRoll, wristPitch, elbow, shoulder, base} -float homePos[6] = {160.0, 150.0, 220.0, 220.0, 100.0, 180.0}; - bool movement = false; // Flag to initialize joints' movements +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + void setup() { - Braccio.begin(); - delay(500); // Waits for the Braccio initialization + if (Braccio.begin()){ + /* Warning: keep a safe distance from the robot and watch out for the robot's + movement. It could be speedy and hit someone. */ - // Set motors initial angle - // Should move all the motors at once - Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); - delay(500); + /* Move to home position. */ + Braccio.moveTo(HOME_POS[0], HOME_POS[1], HOME_POS[2], HOME_POS[3], HOME_POS[4], HOME_POS[5]); + delay(500); + } } void loop() { @@ -33,18 +54,15 @@ void loop() { movement = true; // Trigger joints' movements if (movement) { - Braccio.moveTo(160.0, 150.0, 220.0, 220.0, 100.0, 270.0); - delay(1000); + Braccio.moveTo(AGREE_POS[0], AGREE_POS[1], AGREE_POS[2], AGREE_POS[3], AGREE_POS[4], AGREE_POS[5]); + delay(TIME_DELAY/10); for (int i = 1; i <= 10; i++) { - wristPitch.move().to(190.0f); - delay(200); - wristPitch.move().to(250.0f); - delay(400); - wristPitch.move().to(220.0f); - delay(200); + wristPitch.move().to(190.0f); delay(TIME_DELAY/2); + wristPitch.move().to(240.0f); delay(TIME_DELAY); + wristPitch.move().to(AGREE_POS[3]); } - movement = false; // Stop joints' moviments + movement = false; // Stop joints' movements } }