Skip to content

Cleanup/prettify examlples #49

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 9 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions examples/Braccio_Basic/Braccio_Basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* @brief Activating the "MOVE" button by pressing
* the joystick enables a waving motion of the arm.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <Braccio++.h>

/**************************************************************************************
* GLOBAL CONSTANTS
**************************************************************************************/

float const home_position[6] = {SmartServoClass::MAX_ANGLE / 2.0f,
SmartServoClass::MAX_ANGLE / 2.0f,
SmartServoClass::MAX_ANGLE / 2.0f,
SmartServoClass::MAX_ANGLE / 2.0f,
SmartServoClass::MAX_ANGLE / 2.0f,
90.0f};
static const char * btnm_map[] = {"Move", "\0"};

/**************************************************************************************
* GLOBAL VARIABLES
**************************************************************************************/

bool move_joint = false;

/**************************************************************************************
* FUNCTIONS
**************************************************************************************/

static void event_handler(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_CLICKED)
{
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
const char * txt = lv_btnmatrix_get_btn_text(obj, id);

LV_LOG_USER("%s was pressed\n", txt);
if (Serial) Serial.println(txt);

if (strcmp(txt, "Move") == 0)
move_joint = !move_joint;
}
}

void customMenu()
{
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_btnmatrix_set_btn_ctrl(btnm1, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
Braccio.connectJoystickTo(btnm1);
}

/**************************************************************************************
* SETUP/LOOP
**************************************************************************************/

void setup()
{
Serial.begin(115200);
for (auto const start = millis(); !Serial && ((millis() - start) < 5000); delay(10)) { }

if (!Braccio.begin(customMenu)) {
if (Serial) Serial.println("Braccio.begin() failed.");
for(;;) { }
}

Braccio.moveTo(home_position[0], home_position[1], home_position[2], home_position[3], home_position[4], home_position[5]);
delay(1000);
}

void loop()
{
if (move_joint)
{
Braccio.move(4).to((SmartServoClass::MAX_ANGLE / 2.0f) - 45.0f).in(1s);
delay(1000);
Braccio.move(4).to((SmartServoClass::MAX_ANGLE / 2.0f) + 45.0f).in(1s);
delay(1000);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#include "Braccio++.h"
/*
* @brief Learn the arm an movement and replay it.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <Braccio++.h>
#include "FlashIAPBlockDevice.h"
#include "FATFileSystem.h"

/**************************************************************************************
* VARIABLES
**************************************************************************************/

enum states {
LEARN,
REPEAT,
Expand All @@ -14,6 +26,10 @@ float values[10000];
float* idx = values;
float* final_idx = 0;

/**************************************************************************************
* FUNCTIONS
**************************************************************************************/

static void event_handler(lv_event_t * e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
Expand Down Expand Up @@ -95,9 +111,14 @@ void customMenu() {
static FlashIAPBlockDevice bd(XIP_BASE + 0x100000, 0x100000);
static mbed::FATFileSystem fs("fs");

void setup() {
/**************************************************************************************
* SETUP/LOOP
**************************************************************************************/

void setup()
{
Serial.begin(115200);
while (!Serial) { }

// Mount file system for load/store movements
int err = fs.mount(&bd);
Expand Down
54 changes: 0 additions & 54 deletions examples/Braccio__Template/Braccio__Template.ino

This file was deleted.

26 changes: 25 additions & 1 deletion examples/LCD_Custom_Menu/LCD_Custom_Menu.ino
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
#include "Braccio++.h"
/*
* @brief This sketch demonstrates how to build a very simple and basic custom menu.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <Braccio++.h>

/**************************************************************************************
* DEFINE
**************************************************************************************/

#define MARGIN_LEFT 0
#define MARGIN_TOP 0

/**************************************************************************************
* CONSTANTS
**************************************************************************************/

static const char * btnm_map[] = {"Option 1", "\n",
"Option 2", "\n",
"Option 3", "\n", "\0"
};

/**************************************************************************************
* FUNCTIONS
**************************************************************************************/

void customMenu(){
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_obj_align(btnm1, LV_ALIGN_CENTER, MARGIN_LEFT, MARGIN_TOP);
}

/**************************************************************************************
* SETUP/LOOP
**************************************************************************************/

void setup() {
Braccio.begin(customMenu);
}
Expand Down
38 changes: 32 additions & 6 deletions examples/LCD_Menu_Joystick/LCD_Menu_Joystick.ino
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
#include "Braccio++.h"
/*
* @brief This sketch demonstrates how to build a very simple
* and basic custom menu interacting with the Braccio++ carriers
* joystick.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <Braccio++.h>

/**************************************************************************************
* DEFINE
**************************************************************************************/

#define MARGIN_LEFT 0
#define MARGIN_TOP 0

/**************************************************************************************
* CONSTANT
**************************************************************************************/

static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
"Option 3", "Option 4", "\n",
"Option 5", "Option 6", "\n", "\0"
};

/**************************************************************************************
* FUNCTIONS
**************************************************************************************/

static void event_handler(lv_event_t * e){
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
Expand All @@ -15,11 +42,6 @@ static void event_handler(lv_event_t * e){
}
}

static const char * btnm_map[] = {"Option 1", "Option 2", "\n",
"Option 3", "Option 4", "\n",
"Option 5", "Option 6", "\n", "\0"
};

void customMenu(){
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
Expand All @@ -34,6 +56,10 @@ void customMenu(){
Braccio.connectJoystickTo(btnm1);
}

/**************************************************************************************
* SETUP/LOOP
**************************************************************************************/

void setup() {
Braccio.begin(customMenu);
}
Expand Down
41 changes: 33 additions & 8 deletions examples/LCD_Motors/LCD_Motors.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
#include "Braccio++.h"
/*
* @brief This sketch demonstrates how to build a very simple
* and basic custom menu interacting with the Braccio++ carriers
* joystick, allowing to control a specific motor by selecting
* it from the menu.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <Braccio++.h>

/**************************************************************************************
* VARIABLES
**************************************************************************************/

int selected_motor = 0;

/**************************************************************************************
* CONSTANTS
**************************************************************************************/

static const char * btnm_map[] = {"Motor 1", "Motor 2", "\n",
"Motor 3", "Motor 4", "\n",
"Motor 5", "Motor 6", "\n", "\0"
};

/**************************************************************************************
* FUNCTIONS
**************************************************************************************/

static void event_handler(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
Expand Down Expand Up @@ -37,12 +65,6 @@ static void event_handler(lv_event_t * e)
}
}


static const char * btnm_map[] = {"Motor 1", "Motor 2", "\n",
"Motor 3", "Motor 4", "\n",
"Motor 5", "Motor 6", "\n", "\0"
};

void customMenu() {
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
Expand All @@ -57,8 +79,11 @@ void customMenu() {
Braccio.connectJoystickTo(btnm1);
}

/**************************************************************************************
* SETUP/LOOP
**************************************************************************************/

void setup() {
// Call Braccio.begin() for default menu or pass a function for custom menu
Braccio.begin(customMenu);
Serial.begin(115200);
}
Expand Down
33 changes: 0 additions & 33 deletions examples/New_APIs/New_APIs.ino

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Braccio++.h"
#include <Braccio++.h>

void customMenu() {
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
Expand Down
Loading