-
Notifications
You must be signed in to change notification settings - Fork 3
Rework 01_Braccio_learning_mode example #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
86b9db5
change home position to the "vertical" one
umbynos d1f6ece
make the buttons text labels uppercase for readability
umbynos 15aab33
make the focus outline orange and more visible
umbynos 2c37b26
add TODO comment
umbynos 2710953
make the "LEARN" menu entry the focused one at startup
umbynos 7e8ffe1
make the "REPLAY" menu option disabled at startup. It will be clickab…
umbynos ff364ef
remove unused var
umbynos cf2d42d
change the first button label from "LEARN" to "STOP" when "LEARN" is …
umbynos 007fd8a
new scaffolding for the library
clodpheasant f748dcd
fixed redundancy
clodpheasant 9348e57
fixed repo structure
clodpheasant 0f0d8cc
new naming for sketch
clodpheasant ac1cfb9
allow "STOP" during the "REPLAY"
umbynos 8ce8384
change and uniform button labels
umbynos ff78a9c
Ensure that both examples/Braccio_Learn_and_Repeat and examples/Platf…
aentinger c01de01
Rename button/state REPEAT to REPLAY.
aentinger db8e7f7
Rename button/state LEARN to RECORD.
aentinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
165 changes: 165 additions & 0 deletions
165
examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
#include <Braccio++.h> | ||
|
||
// Colors | ||
#define COLOR_TEAL 0x00878F | ||
#define COLOR_LIGHT_TEAL 0x62AEB2 | ||
#define COLOR_ORANGE 0xE47128 | ||
|
||
enum states { | ||
RECORD, | ||
REPLAY, | ||
ZERO_POSITION | ||
}; | ||
|
||
int state = ZERO_POSITION; | ||
|
||
float values[10000]; | ||
float* idx = values; | ||
float* final_idx = 0; | ||
float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; | ||
|
||
static lv_obj_t * counter; | ||
static lv_obj_t * btnm; | ||
|
||
static const char * btnm_map[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" }; | ||
|
||
|
||
static void eventHandlerMenu(lv_event_t * e) { | ||
lv_event_code_t code = lv_event_get_code(e); | ||
lv_obj_t * obj = lv_event_get_target(e); | ||
|
||
if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) { | ||
state = ZERO_POSITION; | ||
return; | ||
} | ||
|
||
if (code == LV_EVENT_CLICKED) { | ||
uint32_t id = lv_btnmatrix_get_selected_btn(obj); | ||
const char * txt = lv_btnmatrix_get_btn_text(obj, id); | ||
|
||
if (state == RECORD) { | ||
final_idx = idx; | ||
} | ||
|
||
idx = values; | ||
|
||
switch (id) { | ||
case 0: // if the button pressed is the first one | ||
if (txt == "RECORD") { | ||
state = RECORD; | ||
Braccio.disengage(); // allow the user to freely move the braccio | ||
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); | ||
Serial.println("RECORD"); | ||
lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button | ||
btnm_map[0] = "STOP"; // change the label of the first button to "STOP" | ||
} | ||
else if (txt == "STOP") { | ||
state = ZERO_POSITION; | ||
Braccio.engage(); // enable the steppers so that the braccio stands still | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" | ||
} | ||
break; | ||
case 1: | ||
btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" | ||
if (txt == "REPLAY"){ | ||
state = REPLAY; | ||
btnm_map[2] = "STOP"; // change the label of the second button to "STOP" | ||
Braccio.engage(); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); | ||
Serial.println("REPLAY"); | ||
} | ||
else if (txt=="STOP"){ | ||
state = ZERO_POSITION; | ||
Braccio.engage(); // enable the steppers so that the braccio stands still | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" | ||
} | ||
|
||
break; | ||
|
||
default: | ||
state = ZERO_POSITION; | ||
btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" | ||
btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" | ||
Braccio.engage(); | ||
delay(500); | ||
Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
Serial.println("ZERO_POSITION"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void mainMenu() { | ||
static lv_style_t style_focus; | ||
lv_style_init(&style_focus); | ||
lv_style_set_outline_color(&style_focus, lv_color_hex(COLOR_ORANGE)); | ||
lv_style_set_outline_width(&style_focus, 4); | ||
|
||
static lv_style_t style_btn; | ||
lv_style_init(&style_btn); | ||
lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL)); | ||
lv_style_set_text_color(&style_btn, lv_color_white()); | ||
|
||
btnm = lv_btnmatrix_create(lv_scr_act()); | ||
lv_obj_set_size(btnm, 240, 240); | ||
lv_btnmatrix_set_map(btnm, btnm_map); | ||
lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 0); | ||
|
||
lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); | ||
lv_obj_add_style(btnm, &style_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); | ||
|
||
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE); | ||
|
||
lv_btnmatrix_set_one_checked(btnm, true); | ||
lv_btnmatrix_set_selected_btn(btnm, 0); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
|
||
counter = lv_label_create(btnm); | ||
lv_label_set_text_fmt(counter, "Counter: %d" , 0); | ||
lv_obj_align(counter, LV_ALIGN_CENTER, 0, 80); | ||
|
||
lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_ALL, NULL); | ||
|
||
Braccio.connectJoystickTo(btnm); | ||
} | ||
|
||
void setup() { | ||
Braccio.begin(mainMenu); | ||
delay(500); | ||
|
||
Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); | ||
delay(500); | ||
|
||
Serial.begin(115200); | ||
Serial.println("Replicate a movement"); | ||
} | ||
|
||
void loop() { | ||
if (state == RECORD) { | ||
Braccio.positions(idx); | ||
idx += 6; | ||
} | ||
if (state == REPLAY) { | ||
Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); | ||
idx += 6; | ||
if (idx >= final_idx) { | ||
Serial.println("REPLAY done"); | ||
state = ZERO_POSITION; | ||
btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
} | ||
} | ||
if (idx - values >= sizeof(values)) { | ||
Serial.println("ZERO_POSITION"); | ||
state = ZERO_POSITION; | ||
} | ||
delay(100); | ||
if (state != ZERO_POSITION) { | ||
lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
165 changes: 165 additions & 0 deletions
165
...utorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
#include <Braccio++.h> | ||
|
||
// Colors | ||
#define COLOR_TEAL 0x00878F | ||
#define COLOR_LIGHT_TEAL 0x62AEB2 | ||
#define COLOR_ORANGE 0xE47128 | ||
|
||
enum states { | ||
RECORD, | ||
REPLAY, | ||
ZERO_POSITION | ||
}; | ||
|
||
int state = ZERO_POSITION; | ||
|
||
float values[10000]; | ||
float* idx = values; | ||
float* final_idx = 0; | ||
float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0}; | ||
|
||
static lv_obj_t * counter; | ||
static lv_obj_t * btnm; | ||
|
||
static const char * btnm_map[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n", "\0" }; | ||
|
||
|
||
static void eventHandlerMenu(lv_event_t * e) { | ||
lv_event_code_t code = lv_event_get_code(e); | ||
lv_obj_t * obj = lv_event_get_target(e); | ||
|
||
if (code == LV_EVENT_KEY && lv_indev_get_key(lv_indev_get_act()) == LV_KEY_HOME) { | ||
state = ZERO_POSITION; | ||
return; | ||
} | ||
|
||
if (code == LV_EVENT_CLICKED) { | ||
uint32_t id = lv_btnmatrix_get_selected_btn(obj); | ||
const char * txt = lv_btnmatrix_get_btn_text(obj, id); | ||
|
||
if (state == RECORD) { | ||
final_idx = idx; | ||
} | ||
|
||
idx = values; | ||
|
||
switch (id) { | ||
case 0: // if the button pressed is the first one | ||
if (txt == "RECORD") { | ||
state = RECORD; | ||
Braccio.disengage(); // allow the user to freely move the braccio | ||
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKED); | ||
Serial.println("RECORD"); | ||
lv_btnmatrix_clear_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); // remove disabled state of the replay button | ||
btnm_map[0] = "STOP"; // change the label of the first button to "STOP" | ||
} | ||
else if (txt == "STOP") { | ||
state = ZERO_POSITION; | ||
Braccio.engage(); // enable the steppers so that the braccio stands still | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" | ||
} | ||
break; | ||
case 1: | ||
btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" | ||
if (txt == "REPLAY"){ | ||
state = REPLAY; | ||
btnm_map[2] = "STOP"; // change the label of the second button to "STOP" | ||
Braccio.engage(); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); | ||
Serial.println("REPLAY"); | ||
} | ||
else if (txt=="STOP"){ | ||
state = ZERO_POSITION; | ||
Braccio.engage(); // enable the steppers so that the braccio stands still | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" | ||
} | ||
|
||
break; | ||
|
||
default: | ||
state = ZERO_POSITION; | ||
btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD" | ||
btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" | ||
Braccio.engage(); | ||
delay(500); | ||
Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
Serial.println("ZERO_POSITION"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void mainMenu() { | ||
static lv_style_t style_focus; | ||
lv_style_init(&style_focus); | ||
lv_style_set_outline_color(&style_focus, lv_color_hex(COLOR_ORANGE)); | ||
lv_style_set_outline_width(&style_focus, 4); | ||
|
||
static lv_style_t style_btn; | ||
lv_style_init(&style_btn); | ||
lv_style_set_bg_color(&style_btn, lv_color_hex(COLOR_LIGHT_TEAL)); | ||
lv_style_set_text_color(&style_btn, lv_color_white()); | ||
|
||
btnm = lv_btnmatrix_create(lv_scr_act()); | ||
lv_obj_set_size(btnm, 240, 240); | ||
lv_btnmatrix_set_map(btnm, btnm_map); | ||
lv_obj_align(btnm, LV_ALIGN_CENTER, 0, 0); | ||
|
||
lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); | ||
lv_obj_add_style(btnm, &style_focus, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); | ||
|
||
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_DISABLED); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKABLE); | ||
|
||
lv_btnmatrix_set_one_checked(btnm, true); | ||
lv_btnmatrix_set_selected_btn(btnm, 0); | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
|
||
counter = lv_label_create(btnm); | ||
lv_label_set_text_fmt(counter, "Counter: %d" , 0); | ||
lv_obj_align(counter, LV_ALIGN_CENTER, 0, 80); | ||
|
||
lv_obj_add_event_cb(btnm, eventHandlerMenu, LV_EVENT_ALL, NULL); | ||
|
||
Braccio.connectJoystickTo(btnm); | ||
} | ||
|
||
void setup() { | ||
Braccio.begin(mainMenu); | ||
delay(500); | ||
|
||
Braccio.moveTo(homePos[0], homePos[1], homePos[2], homePos[3], homePos[4], homePos[5]); | ||
delay(500); | ||
|
||
Serial.begin(115200); | ||
Serial.println("Replicate a movement"); | ||
} | ||
|
||
void loop() { | ||
if (state == RECORD) { | ||
Braccio.positions(idx); | ||
idx += 6; | ||
} | ||
if (state == REPLAY) { | ||
Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); | ||
idx += 6; | ||
if (idx >= final_idx) { | ||
Serial.println("REPLAY done"); | ||
state = ZERO_POSITION; | ||
btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY" | ||
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED); | ||
} | ||
} | ||
if (idx - values >= sizeof(values)) { | ||
Serial.println("ZERO_POSITION"); | ||
state = ZERO_POSITION; | ||
} | ||
delay(100); | ||
if (state != ZERO_POSITION) { | ||
lv_label_set_text_fmt(counter, "Counter: %d" , idx - values); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.