Skip to content

Enhance controlling manually braccio #73

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 23 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5005624
copy sketch to the root `example/` folder
umbynos Apr 29, 2022
155e6f9
change home position
umbynos Apr 29, 2022
eef357b
use joystick directional keys to directly move the braccio
umbynos Apr 29, 2022
0a24af5
add switch between states (SHOULDER, ELBOW, WRIST) using enter button
umbynos Apr 29, 2022
0debf06
remove `eventHandlerMenu` callback & optimizations
umbynos Apr 29, 2022
2651550
fix braccio being slow responding to commands
umbynos Apr 29, 2022
cb0fe0b
add pinch movement
umbynos Apr 29, 2022
6fcd8c0
change buttons according to active state
umbynos Apr 29, 2022
3816c47
code cleanup
May 2, 2022
724e1b8
added checked state of buttons when pressed
May 3, 2022
83ac180
added removal of checked state on press released
May 3, 2022
60562f2
added joystick click as input to switch joints - same as enter button
May 3, 2022
5ff8dde
Update Controlling_Manually_Braccio.ino
Esquirio May 3, 2022
7ceb29c
temp save.
aentinger May 9, 2022
149c046
One SW event per button event.
aentinger May 9, 2022
3725c9c
Hide buttons not used in a given state, execute enter action on press…
aentinger May 11, 2022
2cb30d9
Same functionality for SELECT as for ENTER.
aentinger May 11, 2022
ffd4e8d
Only enable buttons after init sequence is complete.
aentinger May 11, 2022
e3a8069
Check buttons every 100 ms.
aentinger May 11, 2022
87fdd59
Only check for button pressed/released events every 10 ms (debouncing).
aentinger May 11, 2022
33437a5
Cleanup.
aentinger May 11, 2022
4a8e9ce
Finalising application.
aentinger May 11, 2022
fa97865
Fine tuning ...
aentinger May 11, 2022
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
192 changes: 192 additions & 0 deletions examples/Controlling_Manually_Braccio/AppState.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include "AppState.h"

#include <Braccio++.h>

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

enum BUTTONS {
BTN_UP = 1,
BTN_DOWN = 7,
BTN_LEFT = 3,
BTN_RIGHT = 5,
};

/**************************************************************************************
* EXTERN
**************************************************************************************/

extern lv_obj_t * label;
extern lv_obj_t * direction_btnm;

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

static auto gripper = Braccio.get(1);
static auto wristRoll = Braccio.get(2);
static auto wristPitch = Braccio.get(3);
static auto elbow = Braccio.get(4);
static auto shoulder = Braccio.get(5);
static auto base = Braccio.get(6);

/**************************************************************************************
* ShoulderState
**************************************************************************************/

ShoulderState::ShoulderState()
{
Braccio.lvgl_lock();
lv_label_set_text(label, "Shoulder");
Braccio.lvgl_unlock();
}

State * ShoulderState::handle_OnEnter()
{
return new ElbowState();
}

State * ShoulderState::handle_OnUp()
{
shoulder.move().to(shoulder.position() + 5.0f);
return this;
}

State * ShoulderState::handle_OnDown()
{
shoulder.move().to(shoulder.position() - 5.0f);
return this;
}

State * ShoulderState::handle_OnLeft()
{
base.move().to(base.position() + 5.0f);
return this;
}

State * ShoulderState::handle_OnRight()
{
base.move().to(base.position() - 5.0f);
return this;
}

/**************************************************************************************
* ElbowState
**************************************************************************************/

ElbowState::ElbowState()
{
Braccio.lvgl_lock();
lv_label_set_text(label, "Elbow");
lv_btnmatrix_set_btn_ctrl(direction_btnm, BTN_LEFT, LV_BTNMATRIX_CTRL_HIDDEN);
lv_btnmatrix_set_btn_ctrl(direction_btnm, BTN_RIGHT, LV_BTNMATRIX_CTRL_HIDDEN);
Braccio.lvgl_unlock();
}

ElbowState::~ElbowState()
{
Braccio.lvgl_lock();
lv_btnmatrix_clear_btn_ctrl(direction_btnm, BTN_LEFT, LV_BTNMATRIX_CTRL_HIDDEN);
lv_btnmatrix_clear_btn_ctrl(direction_btnm, BTN_RIGHT, LV_BTNMATRIX_CTRL_HIDDEN);
Braccio.lvgl_unlock();
}

State * ElbowState::handle_OnEnter()
{
return new WristState();
}

State * ElbowState::handle_OnUp()
{
elbow.move().to(elbow.position() + 5.0f);
return this;
}

State * ElbowState::handle_OnDown()
{
elbow.move().to(elbow.position() - 5.0f);
return this;
}

/**************************************************************************************
* WristState
**************************************************************************************/

WristState::WristState()
{
Braccio.lvgl_lock();
lv_label_set_text(label, "Wrist");
Braccio.lvgl_unlock();
}

State * WristState::handle_OnEnter()
{
return new PinchState();
}

State * WristState::handle_OnUp()
{
wristPitch.move().to(wristPitch.position() + 5.0f);
return this;
}

State * WristState::handle_OnDown()
{
wristPitch.move().to(wristPitch.position() - 5.0f);
return this;
}

State * WristState::handle_OnLeft()
{
wristRoll.move().to(wristRoll.position() + 10.0f);
return this;
}

State * WristState::handle_OnRight()
{
wristRoll.move().to(wristRoll.position() - 10.0f);
return this;
}

/**************************************************************************************
* PinchState
**************************************************************************************/

PinchState::PinchState()
{
Braccio.lvgl_lock();
lv_label_set_text(label, "Pinch");
lv_btnmatrix_set_btn_ctrl(direction_btnm, BTN_UP, LV_BTNMATRIX_CTRL_HIDDEN);
lv_btnmatrix_set_btn_ctrl(direction_btnm, BTN_DOWN, LV_BTNMATRIX_CTRL_HIDDEN);
Braccio.lvgl_unlock();
}

PinchState::~PinchState()
{
Braccio.lvgl_lock();
lv_btnmatrix_clear_btn_ctrl(direction_btnm, BTN_UP, LV_BTNMATRIX_CTRL_HIDDEN);
lv_btnmatrix_clear_btn_ctrl(direction_btnm, BTN_DOWN, LV_BTNMATRIX_CTRL_HIDDEN);
Braccio.lvgl_unlock();
}

State * PinchState::handle_OnEnter()
{
return new ShoulderState();
}

State * PinchState::handle_OnLeft()
{
gripper.move().to(gripper.position() + 5.0f);
return this;
}

State * PinchState::handle_OnRight()
{
gripper.move().to(gripper.position() - 5.0f);
return this;
}
132 changes: 132 additions & 0 deletions examples/Controlling_Manually_Braccio/AppState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#ifndef APP_STATE_H_
#define APP_STATE_H_

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

#include <mbed.h>

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

enum class Button
{
None, Enter, Home, Up, Down, Left, Right
};

/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/

class State
{
public:
virtual ~State() { }
State * update(Button const button)
{
State * next_state = this;
switch (button)
{
case Button::Home:
case Button::Enter: next_state = handle_OnEnter(); break;
case Button::Up: next_state = handle_OnUp(); break;
case Button::Down: next_state = handle_OnDown(); break;
case Button::Left: next_state = handle_OnLeft(); break;
case Button::Right: next_state = handle_OnRight(); break;
default: break;
}
return next_state;
}

protected:
virtual State * handle_OnEnter() = 0;
virtual State * handle_OnUp () { return this; }
virtual State * handle_OnDown () { return this; }
virtual State * handle_OnLeft () { return this; }
virtual State * handle_OnRight() { return this; }
};

class ShoulderState : public State
{
public:
ShoulderState();
virtual ~ShoulderState() { }
protected:
virtual State * handle_OnEnter() override;
virtual State * handle_OnUp () override;
virtual State * handle_OnDown () override;
virtual State * handle_OnLeft () override;
virtual State * handle_OnRight() override;
};


class ElbowState : public State
{
public:
ElbowState();
virtual ~ElbowState();
protected:
virtual State * handle_OnEnter() override;
virtual State * handle_OnUp () override;
virtual State * handle_OnDown () override;
};

class WristState : public State
{
public:
WristState();
virtual ~WristState() { }
protected:
virtual State * handle_OnEnter() override;
virtual State * handle_OnUp () override;
virtual State * handle_OnDown () override;
virtual State * handle_OnLeft () override;
virtual State * handle_OnRight() override;
};


class PinchState : public State
{
public:
PinchState();
virtual ~PinchState();
protected:
virtual State * handle_OnEnter() override;
virtual State * handle_OnLeft () override;
virtual State * handle_OnRight() override;
};

class ManualControlApp
{
public:
ManualControlApp()
: _state{nullptr}
, _mtx{}
{ }

void update(Button const button)
{
mbed::ScopedLock<rtos::Mutex> lock(_mtx);

if (!_state)
{
_state = new ShoulderState();
return;
}

State * next_state = _state->update(button);

if (next_state != _state) {
delete _state;
_state = next_state;
}
}

private:
State * _state;
rtos::Mutex _mtx;
};

#endif /* APP_STATE_H_ */
Loading