Skip to content

Commit da73227

Browse files
authored
Merge pull request #49 from bcmi-labs/clean-examples
Cleanup/prettify `examlples`
2 parents 7f47aa8 + c2d4933 commit da73227

File tree

32 files changed

+226
-129
lines changed

32 files changed

+226
-129
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* @brief Activating the "MOVE" button by pressing
3+
* the joystick enables a waving motion of the arm.
4+
*/
5+
6+
/**************************************************************************************
7+
* INCLUDE
8+
**************************************************************************************/
9+
10+
#include <Braccio++.h>
11+
12+
/**************************************************************************************
13+
* GLOBAL CONSTANTS
14+
**************************************************************************************/
15+
16+
float const home_position[6] = {SmartServoClass::MAX_ANGLE / 2.0f,
17+
SmartServoClass::MAX_ANGLE / 2.0f,
18+
SmartServoClass::MAX_ANGLE / 2.0f,
19+
SmartServoClass::MAX_ANGLE / 2.0f,
20+
SmartServoClass::MAX_ANGLE / 2.0f,
21+
90.0f};
22+
static const char * btnm_map[] = {"Move", "\0"};
23+
24+
/**************************************************************************************
25+
* GLOBAL VARIABLES
26+
**************************************************************************************/
27+
28+
bool move_joint = false;
29+
30+
/**************************************************************************************
31+
* FUNCTIONS
32+
**************************************************************************************/
33+
34+
static void event_handler(lv_event_t * e)
35+
{
36+
lv_event_code_t code = lv_event_get_code(e);
37+
lv_obj_t * obj = lv_event_get_target(e);
38+
if (code == LV_EVENT_CLICKED)
39+
{
40+
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
41+
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
42+
43+
LV_LOG_USER("%s was pressed\n", txt);
44+
if (Serial) Serial.println(txt);
45+
46+
if (strcmp(txt, "Move") == 0)
47+
move_joint = !move_joint;
48+
}
49+
}
50+
51+
void customMenu()
52+
{
53+
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
54+
lv_btnmatrix_set_map(btnm1, btnm_map);
55+
lv_btnmatrix_set_btn_ctrl(btnm1, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
56+
lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
57+
lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
58+
Braccio.connectJoystickTo(btnm1);
59+
}
60+
61+
/**************************************************************************************
62+
* SETUP/LOOP
63+
**************************************************************************************/
64+
65+
void setup()
66+
{
67+
Serial.begin(115200);
68+
for (auto const start = millis(); !Serial && ((millis() - start) < 5000); delay(10)) { }
69+
70+
if (!Braccio.begin(customMenu)) {
71+
if (Serial) Serial.println("Braccio.begin() failed.");
72+
for(;;) { }
73+
}
74+
75+
Braccio.moveTo(home_position[0], home_position[1], home_position[2], home_position[3], home_position[4], home_position[5]);
76+
delay(1000);
77+
}
78+
79+
void loop()
80+
{
81+
if (move_joint)
82+
{
83+
Braccio.move(4).to((SmartServoClass::MAX_ANGLE / 2.0f) - 45.0f).in(1s);
84+
delay(1000);
85+
Braccio.move(4).to((SmartServoClass::MAX_ANGLE / 2.0f) + 45.0f).in(1s);
86+
delay(1000);
87+
}
88+
}

examples/LearnByDoing/LearnByDoing.ino renamed to examples/Braccio_LearnByDoing/Braccio_LearnByDoing.ino

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
#include "Braccio++.h"
1+
/*
2+
* @brief Learn the arm an movement and replay it.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <Braccio++.h>
210
#include "FlashIAPBlockDevice.h"
311
#include "FATFileSystem.h"
412

13+
/**************************************************************************************
14+
* VARIABLES
15+
**************************************************************************************/
16+
517
enum states {
618
LEARN,
719
REPEAT,
@@ -14,6 +26,10 @@ float values[10000];
1426
float* idx = values;
1527
float* final_idx = 0;
1628

29+
/**************************************************************************************
30+
* FUNCTIONS
31+
**************************************************************************************/
32+
1733
static void event_handler(lv_event_t * e) {
1834
lv_event_code_t code = lv_event_get_code(e);
1935
lv_obj_t * obj = lv_event_get_target(e);
@@ -95,9 +111,14 @@ void customMenu() {
95111
static FlashIAPBlockDevice bd(XIP_BASE + 0x100000, 0x100000);
96112
static mbed::FATFileSystem fs("fs");
97113

98-
void setup() {
114+
/**************************************************************************************
115+
* SETUP/LOOP
116+
**************************************************************************************/
99117

118+
void setup()
119+
{
100120
Serial.begin(115200);
121+
while (!Serial) { }
101122

102123
// Mount file system for load/store movements
103124
int err = fs.mount(&bd);

examples/Braccio__Template/Braccio__Template.ino

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

examples/LCD_Custom_Menu/LCD_Custom_Menu.ino

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
1-
#include "Braccio++.h"
1+
/*
2+
* @brief This sketch demonstrates how to build a very simple and basic custom menu.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <Braccio++.h>
10+
11+
/**************************************************************************************
12+
* DEFINE
13+
**************************************************************************************/
214

315
#define MARGIN_LEFT 0
416
#define MARGIN_TOP 0
517

18+
/**************************************************************************************
19+
* CONSTANTS
20+
**************************************************************************************/
21+
622
static const char * btnm_map[] = {"Option 1", "\n",
723
"Option 2", "\n",
824
"Option 3", "\n", "\0"
925
};
1026

27+
/**************************************************************************************
28+
* FUNCTIONS
29+
**************************************************************************************/
30+
1131
void customMenu(){
1232
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
1333
lv_btnmatrix_set_map(btnm1, btnm_map);
1434
lv_obj_align(btnm1, LV_ALIGN_CENTER, MARGIN_LEFT, MARGIN_TOP);
1535
}
1636

37+
/**************************************************************************************
38+
* SETUP/LOOP
39+
**************************************************************************************/
40+
1741
void setup() {
1842
Braccio.begin(customMenu);
1943
}

examples/LCD_Menu_Joystick/LCD_Menu_Joystick.ino

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1-
#include "Braccio++.h"
1+
/*
2+
* @brief This sketch demonstrates how to build a very simple
3+
* and basic custom menu interacting with the Braccio++ carriers
4+
* joystick.
5+
*/
6+
7+
/**************************************************************************************
8+
* INCLUDE
9+
**************************************************************************************/
10+
11+
#include <Braccio++.h>
12+
13+
/**************************************************************************************
14+
* DEFINE
15+
**************************************************************************************/
216

317
#define MARGIN_LEFT 0
418
#define MARGIN_TOP 0
519

20+
/**************************************************************************************
21+
* CONSTANT
22+
**************************************************************************************/
23+
24+
static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
25+
"Option 3", "Option 4", "\n",
26+
"Option 5", "Option 6", "\n", "\0"
27+
};
28+
29+
/**************************************************************************************
30+
* FUNCTIONS
31+
**************************************************************************************/
32+
633
static void event_handler(lv_event_t * e){
734
lv_event_code_t code = lv_event_get_code(e);
835
lv_obj_t * obj = lv_event_get_target(e);
@@ -15,11 +42,6 @@ static void event_handler(lv_event_t * e){
1542
}
1643
}
1744

18-
static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
19-
"Option 3", "Option 4", "\n",
20-
"Option 5", "Option 6", "\n", "\0"
21-
};
22-
2345
void customMenu(){
2446
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
2547
lv_btnmatrix_set_map(btnm1, btnm_map);
@@ -34,6 +56,10 @@ void customMenu(){
3456
Braccio.connectJoystickTo(btnm1);
3557
}
3658

59+
/**************************************************************************************
60+
* SETUP/LOOP
61+
**************************************************************************************/
62+
3763
void setup() {
3864
Braccio.begin(customMenu);
3965
}

examples/LCD_Motors/LCD_Motors.ino

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1-
#include "Braccio++.h"
1+
/*
2+
* @brief This sketch demonstrates how to build a very simple
3+
* and basic custom menu interacting with the Braccio++ carriers
4+
* joystick, allowing to control a specific motor by selecting
5+
* it from the menu.
6+
*/
7+
8+
/**************************************************************************************
9+
* INCLUDE
10+
**************************************************************************************/
11+
12+
#include <Braccio++.h>
13+
14+
/**************************************************************************************
15+
* VARIABLES
16+
**************************************************************************************/
217

318
int selected_motor = 0;
419

20+
/**************************************************************************************
21+
* CONSTANTS
22+
**************************************************************************************/
23+
24+
static const char * btnm_map[] = {"Motor 1", "Motor 2", "\n",
25+
"Motor 3", "Motor 4", "\n",
26+
"Motor 5", "Motor 6", "\n", "\0"
27+
};
28+
29+
/**************************************************************************************
30+
* FUNCTIONS
31+
**************************************************************************************/
32+
533
static void event_handler(lv_event_t * e)
634
{
735
lv_event_code_t code = lv_event_get_code(e);
@@ -37,12 +65,6 @@ static void event_handler(lv_event_t * e)
3765
}
3866
}
3967

40-
41-
static const char * btnm_map[] = {"Motor 1", "Motor 2", "\n",
42-
"Motor 3", "Motor 4", "\n",
43-
"Motor 5", "Motor 6", "\n", "\0"
44-
};
45-
4668
void customMenu() {
4769
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
4870
lv_btnmatrix_set_map(btnm1, btnm_map);
@@ -57,8 +79,11 @@ void customMenu() {
5779
Braccio.connectJoystickTo(btnm1);
5880
}
5981

82+
/**************************************************************************************
83+
* SETUP/LOOP
84+
**************************************************************************************/
85+
6086
void setup() {
61-
// Call Braccio.begin() for default menu or pass a function for custom menu
6287
Braccio.begin(customMenu);
6388
Serial.begin(115200);
6489
}

examples/New_APIs/New_APIs.ino

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

examples/tutorials/lessons/01-programming-the-braccio-display/01_creating_a_button/01_creating_a_button.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "Braccio++.h"
1+
#include <Braccio++.h>
22

33
void customMenu() {
44
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());

0 commit comments

Comments
 (0)