Skip to content

Commit 671909c

Browse files
committed
Fix: Do not perform a last capture when the sample cnt has been exceeded already.
1 parent f6931cf commit 671909c

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ void setup() {
146146
Serial.println("Replicate a movement");
147147
}
148148

149-
void loop() {
150-
if (state == RECORD) {
151-
149+
void loop()
150+
{
151+
if (state == RECORD)
152+
{
152153
/* Check if we still have space for samples. */
153154
if (sample_cnt >= MAX_SAMPLES) {
154155
state = ZERO_POSITION;
@@ -158,12 +159,17 @@ void loop() {
158159
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
159160
Braccio.lvgl_unlock();
160161
}
161-
/* Capture those samples. */
162-
Braccio.positions(idx);
163-
idx += 6;
164-
sample_cnt += 6;
162+
else
163+
{
164+
/* Capture those samples. */
165+
Braccio.positions(idx);
166+
idx += 6;
167+
sample_cnt += 6;
168+
}
165169
}
166-
if (state == REPLAY) {
170+
171+
if (state == REPLAY)
172+
{
167173
Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]);
168174
idx += 6;
169175
sample_cnt += 6;
@@ -176,8 +182,11 @@ void loop() {
176182
Braccio.lvgl_unlock();
177183
}
178184
}
185+
179186
delay(100);
180-
if (state != ZERO_POSITION) {
187+
188+
if (state != ZERO_POSITION)
189+
{
181190
Braccio.lvgl_lock();
182191
lv_label_set_text_fmt(counter, "Counter: %d" , (sample_cnt / 6));
183192
Braccio.lvgl_unlock();

0 commit comments

Comments
 (0)