Skip to content

Commit 88bdca0

Browse files
authored
Merge pull request #75 from arduino-libraries/stop-sign
[Braccio_Record_and_Replay] Show stop sign when joint enters dead zone.
2 parents 8eef569 + 90df695 commit 88bdca0

File tree

2 files changed

+1034
-1
lines changed

2 files changed

+1034
-1
lines changed

examples/Braccio_Record_and_Replay/AppState.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ static float const HOME_POS[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0};
2727

2828
lv_obj_t * counter;
2929
lv_obj_t * btnm;
30+
lv_obj_t * menu_screen = nullptr;
31+
lv_obj_t * stop_screen = nullptr;
3032
const char * btnm_map[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" };
3133

3234
static float sample_buf[SAMPLE_BUF_SIZE];
@@ -90,6 +92,17 @@ void custom_main_menu()
9092
lv_obj_align(counter, LV_ALIGN_CENTER, 0, 80);
9193

9294
lv_obj_add_event_cb(btnm, event_handler_menu, LV_EVENT_ALL, NULL);
95+
96+
/* Store a pointer to the screen in the menu_screen variable. */
97+
menu_screen = lv_scr_act();
98+
99+
/* Create a separate screen for the stop sign image. */
100+
LV_IMG_DECLARE(stop_sign);
101+
stop_screen = lv_img_create(NULL);
102+
lv_img_set_src(stop_screen, &stop_sign);
103+
lv_obj_align(stop_screen, LV_ALIGN_CENTER, 0, 0);
104+
lv_obj_set_size(stop_screen, 240, 240);
105+
93106
Braccio.lvgl_unlock();
94107

95108
Braccio.connectJoystickTo(btnm);
@@ -166,7 +179,28 @@ State * RecordState::handle_OnTimerTick()
166179

167180
/* We still have space, let's sample some data. */
168181
Braccio.positions(sample_buf + sample_cnt);
169-
sample_cnt += 6;
182+
183+
/* Check if any of the servos reports a position of
184+
* 0.0 degrees. In this case we've entered the dead
185+
* zone and should display a warning on the screen.
186+
**/
187+
int const count = std::count_if(sample_buf + sample_cnt,
188+
sample_buf + sample_cnt + 6,
189+
[](float const v)
190+
{
191+
float const EPSILON = 0.01;
192+
return (fabs(v) < EPSILON);
193+
});
194+
if (count > 0) {
195+
if (lv_scr_act() != stop_screen)
196+
lv_scr_load(stop_screen);
197+
}
198+
else {
199+
sample_cnt += 6;
200+
/* Reload the menu screen if it has not been currently loaded. */
201+
if (lv_scr_act() != menu_screen)
202+
lv_scr_load(menu_screen);
203+
}
170204

171205
/* Update sample counter. */
172206
lv_label_set_text_fmt(counter, "Counter: %d" , (sample_cnt / 6));

0 commit comments

Comments
 (0)