Skip to content

Commit 8434e1d

Browse files
committed
feat: new lessons codes
1 parent 26e270f commit 8434e1d

File tree

22 files changed

+501
-213
lines changed

22 files changed

+501
-213
lines changed

examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/sketch.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/Platform_Tutorials/lessons/01-programming-the-braccio-display/02_designing_the_button/sketch.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**************************************************************************************
2+
* INCLUDE
3+
**************************************************************************************/
4+
5+
#include <Braccio++.h>
6+
7+
/**************************************************************************************
8+
* DEFINES
9+
**************************************************************************************/
10+
11+
#define BUTTON_SELECT 3
12+
#define BUTTON_ENTER 6
13+
#define TIME_DELAY 2000
14+
15+
/**************************************************************************************
16+
* CONSTANTS
17+
**************************************************************************************/
18+
19+
static float const HOME_POS[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0};
20+
21+
/**************************************************************************************
22+
* GLOBAL VARIABLES
23+
**************************************************************************************/
24+
25+
static auto gripper = Braccio.get(1);
26+
static auto wristRoll = Braccio.get(2);
27+
static auto wristPitch = Braccio.get(3);
28+
static auto elbow = Braccio.get(4);
29+
static auto shoulder = Braccio.get(5);
30+
static auto base = Braccio.get(6);
31+
32+
float angles[6];
33+
34+
/**************************************************************************************
35+
* SETUP/LOOP
36+
**************************************************************************************/
37+
38+
void setup() {
39+
if (Braccio.begin())
40+
{
41+
/* Configure Braccio speed. */
42+
/* Warning: keep a safe distance from the robot and watch out for the robot's
43+
movement. It could be speedy and hit someone. */
44+
Braccio.speed(speed_grade_t(1000)/*SLOW*/);
45+
/* Move to home position. */
46+
Braccio.moveTo(HOME_POS[0], HOME_POS[1], HOME_POS[2], HOME_POS[3], HOME_POS[4], HOME_POS[5]);
47+
delay(TIME_DELAY);
48+
}
49+
}
50+
51+
void loop() {
52+
int pressedKey = Braccio.getKey();
53+
54+
if (pressedKey == BUTTON_ENTER)
55+
{
56+
// Pinch movement
57+
gripper.move().to(230.0f); delay(TIME_DELAY);
58+
gripper.move().to(HOME_POS[0]); delay(TIME_DELAY);
59+
60+
// // Wrist Roll movement
61+
wristRoll.move().to(0.0f); delay(TIME_DELAY);
62+
wristRoll.move().to(HOME_POS[1]); delay(TIME_DELAY);
63+
wristRoll.move().to(315.0f); delay(TIME_DELAY);
64+
wristRoll.move().to(HOME_POS[1]); delay(TIME_DELAY);
65+
66+
// // Wrist Pitch movement
67+
wristPitch.move().to(70.0f); delay(TIME_DELAY);
68+
wristPitch.move().to(HOME_POS[2]); delay(TIME_DELAY);
69+
wristPitch.move().to(260.0f); delay(TIME_DELAY);
70+
wristPitch.move().to(HOME_POS[2]); delay(TIME_DELAY);
71+
72+
// Elbow movement
73+
for(float i=HOME_POS[3]; i >= 70.0; i-=5)
74+
{ elbow.move().to(i); delay(TIME_DELAY/2000); }
75+
elbow.move().to(HOME_POS[3]); delay(TIME_DELAY);
76+
for(float i=HOME_POS[3]; i <= 260.0; i+=5)
77+
{ elbow.move().to(i); delay(TIME_DELAY/2000); }
78+
elbow.move().to(HOME_POS[3]); delay(TIME_DELAY);
79+
80+
// Shoulder movement
81+
shoulder.move().to(120.0f); delay(TIME_DELAY/2);
82+
shoulder.move().to(90.0f); delay(TIME_DELAY/2);
83+
shoulder.move().to(120.0f); delay(TIME_DELAY/2);
84+
shoulder.move().to(HOME_POS[4]); delay(TIME_DELAY);
85+
shoulder.move().to(200.0f); delay(TIME_DELAY/2);
86+
shoulder.move().to(230.0f); delay(TIME_DELAY/2);
87+
shoulder.move().to(200.0f); delay(TIME_DELAY/2);
88+
shoulder.move().to(HOME_POS[4]); delay(TIME_DELAY);
89+
90+
// Base movement
91+
base.move().to(0.0f); delay(TIME_DELAY);
92+
base.move().to(HOME_POS[5]); delay(TIME_DELAY);
93+
base.move().to(315.0f); delay(TIME_DELAY);
94+
base.move().to(HOME_POS[5]); delay(TIME_DELAY);
95+
96+
while(pressedKey == BUTTON_ENTER) { pressedKey = Braccio.getKey(); }
97+
}
98+
99+
if (pressedKey == BUTTON_SELECT)
100+
{
101+
// Fetch the joints positions
102+
Braccio.positions(angles);
103+
104+
// Print the joint angles
105+
Serial.println("************* Joints Angles *************");
106+
Serial.println("|\tMotor ID\t|\tAngle\t|");
107+
Serial.println("----------------------------------------");
108+
Serial.print("| 1 - Gripper\t\t|\t" + String(angles[0]) + "\t|\n" +
109+
"| 2 - Wrist Rotation\t|\t" + String(angles[1]) + "\t|\n" +
110+
"| 3 - Wrist Vertical\t|\t" + String(angles[2]) + "\t|\n" +
111+
"| 4 - Elbow\t\t|\t" + String(angles[3]) + "\t|\n" +
112+
"| 5 - Shoulder\t\t|\t" + String(angles[4]) + "\t|\n" +
113+
"| 6 - Base\t\t|\t" + String(angles[5]) + "\t|\n" +
114+
"*****************************************\n\n\n\n\n");
115+
116+
while(pressedKey == BUTTON_SELECT) { pressedKey = Braccio.getKey(); }
117+
118+
}
119+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <Braccio++.h>
2+
3+
#define MARGIN_LEFT 0
4+
#define MARGIN_TOP 0
5+
6+
// Arduino Colors
7+
#define COLOR_TEAL 0x00878F
8+
#define COLOR_LIGHT_TEAL 0x62AEB2
9+
#define COLOR_ORANGE 0xE47128
10+
#define COLOR_YELLOW 0xE5AD24
11+
#define COLOR_WHITE 0xFFFFFF
12+
13+
static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
14+
"Option 3", "Option 4", "\n",
15+
"Option 5", "Option 6", "\0"
16+
};
17+
18+
void setup() {
19+
if (!Braccio.begin(customMenu)) {
20+
if (Serial) Serial.println("Braccio.begin() failed.");
21+
for(;;) { }
22+
}
23+
}
24+
25+
void loop() {
26+
// Let here empty.
27+
}
28+
29+
void customMenu(){
30+
Braccio.lvgl_lock();
31+
32+
static lv_style_t style_bg;
33+
lv_style_init(&style_bg);
34+
lv_style_set_bg_color(&style_bg, lv_color_hex(COLOR_WHITE));
35+
36+
static lv_style_t style_btn;
37+
lv_style_init(&style_btn);
38+
lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_YELLOW));
39+
lv_style_set_border_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL));
40+
lv_style_set_border_width(&style_btn, 2);
41+
lv_style_set_text_color(&style_btn, lv_color_hex(COLOR_TEAL));
42+
43+
44+
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());
45+
lv_btnmatrix_set_map(btnm, btnm_map);
46+
lv_obj_align(btnm, LV_ALIGN_CENTER, MARGIN_LEFT, MARGIN_TOP);
47+
48+
lv_obj_add_style(btnm, &style_bg, 0);
49+
lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS);
50+
51+
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
52+
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKABLE);
53+
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE);
54+
lv_btnmatrix_set_btn_ctrl(btnm, 3, LV_BTNMATRIX_CTRL_CHECKABLE);
55+
lv_btnmatrix_set_btn_ctrl(btnm, 4, LV_BTNMATRIX_CTRL_CHECKABLE);
56+
lv_btnmatrix_set_btn_ctrl(btnm, 5, LV_BTNMATRIX_CTRL_CHECKABLE);
57+
58+
lv_btnmatrix_set_one_checked(btnm, true);
59+
60+
lv_obj_add_event_cb(btnm, eventHandler, LV_EVENT_ALL, NULL);
61+
62+
Braccio.lvgl_unlock();
63+
64+
Braccio.connectJoystickTo(btnm);
65+
}
66+
67+
static void eventHandler(lv_event_t * e){
68+
Braccio.lvgl_lock();
69+
70+
lv_event_code_t code = lv_event_get_code(e);
71+
lv_obj_t * obj = lv_event_get_target(e);
72+
if (code == LV_EVENT_CLICKED) {
73+
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
74+
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
75+
76+
LV_LOG_USER("%s was selected\n", txt);
77+
Serial.println(String(txt) + " was selected.");
78+
}
79+
80+
Braccio.lvgl_unlock();
81+
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
#include <Braccio++.h>
1+
#include <Braccio++.h>
22

33
void customMenu() {
44
Braccio.lvgl_lock();
5+
56
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
67
lv_obj_set_size(btn1, 120, 75);
78
lv_obj_t * label1 = lv_label_create(btn1);
89
lv_label_set_text(label1, "BTN 1");
910
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, 0);
1011
lv_obj_center(label1);
12+
1113
Braccio.lvgl_unlock();
1214
}
1315

1416
void setup() {
1517
// put your setup code here, to run once:
16-
Braccio.begin(customMenu);
18+
if (!Braccio.begin(customMenu)) {
19+
if (Serial) Serial.println("Braccio.begin() failed.");
20+
for(;;) { }
21+
}
1722
}
1823

1924
void loop() {
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
1-
#include <Braccio++.h>
2-
3-
// Arduino Colors
4-
#define COLOR_TEAL 0x00878F
5-
#define COLOR_LIGHT_TEAL 0x62AEB2
6-
#define COLOR_ORANGE 0xE47128
7-
#define COLOR_YELLOW 0xE5AD24
8-
#define COLOR_WHITE 0xFFFFFF
9-
10-
11-
void customMenu() {
12-
Braccio.lvgl_lock();
13-
static lv_style_t style;
14-
lv_style_init(&style);
15-
lv_style_set_bg_color(&style, lv_color_hex(COLOR_WHITE));
16-
lv_style_set_border_color(&style, lv_color_hex(COLOR_TEAL));
17-
lv_style_set_border_width(&style, 5);
18-
lv_style_set_text_color(&style, lv_color_hex(COLOR_ORANGE));
19-
20-
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
21-
lv_obj_set_size(btn1, 120, 75);
22-
23-
lv_obj_t * label1 = lv_label_create(btn1);
24-
lv_label_set_text(label1, "BTN 1");
25-
26-
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, 0);
27-
lv_obj_center(label1);
28-
29-
lv_obj_add_style(btn1, &style, 0);
30-
Braccio.lvgl_unlock();
31-
}
32-
33-
void setup() {
34-
// put your setup code here, to run once:
35-
Braccio.begin(customMenu);
36-
}
37-
38-
void loop() {
39-
// put your main code here, to run repeatedly:
40-
41-
}
1+
#include <Braccio++.h>
2+
3+
// Arduino Colors
4+
#define COLOR_TEAL 0x00878F
5+
#define COLOR_LIGHT_TEAL 0x62AEB2
6+
#define COLOR_ORANGE 0xE47128
7+
#define COLOR_YELLOW 0xE5AD24
8+
#define COLOR_WHITE 0xFFFFFF
9+
10+
11+
void customMenu() {
12+
Braccio.lvgl_lock();
13+
static lv_style_t style;
14+
lv_style_init(&style);
15+
lv_style_set_bg_color(&style, lv_color_hex(COLOR_WHITE));
16+
lv_style_set_border_color(&style, lv_color_hex(COLOR_TEAL));
17+
lv_style_set_border_width(&style, 5);
18+
lv_style_set_text_color(&style, lv_color_hex(COLOR_ORANGE));
19+
20+
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
21+
lv_obj_set_size(btn1, 120, 75);
22+
23+
lv_obj_t * label1 = lv_label_create(btn1);
24+
lv_label_set_text(label1, "BTN 1");
25+
26+
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, 0);
27+
lv_obj_center(label1);
28+
29+
lv_obj_add_style(btn1, &style, 0);
30+
Braccio.lvgl_unlock();
31+
}
32+
33+
void setup() {
34+
// put your setup code here, to run once:
35+
if (!Braccio.begin(customMenu)) {
36+
if (Serial) Serial.println("Braccio.begin() failed.");
37+
for(;;) { }
38+
}
39+
}
40+
41+
void loop() {
42+
// put your main code here, to run repeatedly:
43+
44+
}

0 commit comments

Comments
 (0)