Skip to content

Commit ff78a9c

Browse files
committed
Ensure that both examples/Braccio_Learn_and_Repeat and examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode are identical.
1 parent 8ce8384 commit ff78a9c

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
enum states {
99
LEARN,
10-
REPEAT, // for consistency is better to name this REPLAY or rename the button label repeat TODO
11-
IDLE
10+
REPEAT, // for consistency is better to name this REPEAT or rename the button label repeat TODO
11+
ZERO_POSITION
1212
};
1313

14-
int state = IDLE;
14+
int state = ZERO_POSITION;
1515

1616
float values[10000];
1717
float* idx = values;
@@ -21,15 +21,15 @@ float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0};
2121
static lv_obj_t * counter;
2222
static lv_obj_t * btnm;
2323

24-
static const char * btnm_map[] = { "LEARN", "\n", "REPLAY", "\n", "IDLE", "\n", "\0" };
24+
static const char * btnm_map[] = { "LEARN", "\n", "REPEAT", "\n", "ZERO_POSITION", "\n", "\0" };
2525

2626

2727
static void eventHandlerMenu(lv_event_t * e) {
2828
lv_event_code_t code = lv_event_get_code(e);
2929
lv_obj_t * obj = lv_event_get_target(e);
3030

3131
if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) {
32-
state = IDLE;
32+
state = ZERO_POSITION;
3333
return;
3434
}
3535

@@ -54,27 +54,39 @@ static void eventHandlerMenu(lv_event_t * e) {
5454
btnm_map[0] = "STOP"; // change the label of the first button to "STOP"
5555
}
5656
else if (txt == "STOP") {
57-
state = IDLE;
57+
state = ZERO_POSITION;
5858
Braccio.engage(); // enable the steppers so that the braccio stands still
5959
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED);
6060
btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN"
6161
}
6262
break;
6363
case 1:
64-
state = REPEAT;
6564
btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN"
65+
if (txt == "REPEAT"){
66+
state = REPEAT;
67+
btnm_map[2] = "STOP"; // change the label of the second button to "STOP"
6668
Braccio.engage();
6769
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED);
6870
Serial.println("REPEAT");
71+
}
72+
else if (txt=="STOP"){
73+
state = ZERO_POSITION;
74+
Braccio.engage(); // enable the steppers so that the braccio stands still
75+
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED);
76+
btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT"
77+
}
78+
6979
break;
80+
7081
default:
71-
state = IDLE;
82+
state = ZERO_POSITION;
7283
btnm_map[0] = "LEARN"; // reset the label of the first button back to "LEARN"
84+
btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT"
7385
Braccio.engage();
7486
delay(500);
7587
Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]);
7688
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED);
77-
Serial.println("IDLE");
89+
Serial.println("ZERO_POSITION");
7890
break;
7991
}
8092
}
@@ -137,16 +149,17 @@ void loop() {
137149
idx += 6;
138150
if (idx >= final_idx) {
139151
Serial.println("Repeat done");
140-
state = IDLE;
152+
state = ZERO_POSITION;
153+
btnm_map[2] = "REPEAT"; // reset the label of the first button back to "REPEAT"
141154
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED);
142155
}
143156
}
144157
if (idx - values >= sizeof(values)) {
145-
Serial.println("IDLE");
146-
state = IDLE;
158+
Serial.println("ZERO_POSITION");
159+
state = ZERO_POSITION;
147160
}
148161
delay(100);
149-
if (state != IDLE) {
162+
if (state != ZERO_POSITION) {
150163
lv_label_set_text_fmt(counter, "Counter: %d" , idx - values);
151164
}
152165
}

0 commit comments

Comments
 (0)