Skip to content

Remove redundant/not-implemented API calls #28

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 3 commits into from
Jan 19, 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
36 changes: 36 additions & 0 deletions src/Braccio++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,42 @@ bool BraccioClass::begin(voidFuncPtr customMenu) {
return true;
}

MotorsWrapper BraccioClass::move(int const id)
{
MotorsWrapper wrapper(servos, id);
return wrapper;
}

void BraccioClass::moveTo(float const a1, float const a2, float const a3, float const a4, float const a5, float const a6)
{
servos.setPositionMode(PositionMode::SYNC);
servos.setPosition(1, a1, runTime);
servos.setPosition(2, a2, runTime);
servos.setPosition(3, a3, runTime);
servos.setPosition(4, a4, runTime);
servos.setPosition(5, a5, runTime);
servos.setPosition(6, a6, runTime);
servos.synchronize();
servos.setPositionMode(PositionMode::IMMEDIATE);
}

void BraccioClass::positions(float * buffer)
{
for (int id = SmartServoClass::MIN_MOTOR_ID; id <= SmartServoClass::MAX_MOTOR_ID; id++)
*buffer++ = servos.getPosition(id);
}

void BraccioClass::positions(float & a1, float & a2, float & a3, float & a4, float & a5, float & a6)
{
// TODO: add check if motors are actually connected
a1 = servos.getPosition(1);
a2 = servos.getPosition(2);
a3 = servos.getPosition(3);
a4 = servos.getPosition(4);
a5 = servos.getPosition(5);
a6 = servos.getPosition(6);
}

void BraccioClass::connectJoystickTo(lv_obj_t* obj) {
lv_group_add_obj(p_objGroup, obj);
lv_indev_set_group(kb_indev, p_objGroup);
Expand Down
50 changes: 9 additions & 41 deletions src/Braccio++.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,47 +87,15 @@ class BraccioClass
inline bool begin() { return begin(nullptr); }
bool begin(voidFuncPtr customMenu);

// setters
MotorsWrapper move(int joint_index) {
MotorsWrapper wrapper(servos, joint_index);
return wrapper;
}
MotorsWrapper get(int joint_index) {
return move(joint_index);
}
void moveTo(int joint_index, int position) {
//servos.setPosition(joint_index, position, 100);
}
void moveTo(int joint_index, float angle) {
servos.setPosition(joint_index, angle, 100);
}
void moveTo(float a1, float a2, float a3, float a4, float a5, float a6) {
servos.setPositionMode(PositionMode::SYNC);
servos.setPosition(1, a1, runTime);
servos.setPosition(2, a2, runTime);
servos.setPosition(3, a3, runTime);
servos.setPosition(4, a4, runTime);
servos.setPosition(5, a5, runTime);
servos.setPosition(6, a6, runTime);
servos.synchronize();
servos.setPositionMode(PositionMode::IMMEDIATE);
}
// getters
void positions(float* buffer) {
for (int i = 1; i < 7; i++) {
*buffer++ = servos.getPosition(i);
}
}
void positions(float& a1, float& a2, float& a3, float& a4, float& a5, float& a6) {
// TODO: add check if motors are actually connected
a1 = servos.getPosition(1);
a2 = servos.getPosition(2);
a3 = servos.getPosition(3);
a4 = servos.getPosition(4);
a5 = servos.getPosition(5);
a6 = servos.getPosition(6);
}
float position(int joint_index);

MotorsWrapper move(int const id);
inline MotorsWrapper get(int const id) { return move(id); }

void moveTo(float const a1, float const a2, float const a3, float const a4, float const a5, float const a6);
void positions(float * buffer);
void positions(float & a1, float & a2, float & a3, float & a4, float & a5, float & a6);


bool connected(int joint_index) {
return _connected[joint_index];
}
Expand Down
7 changes: 3 additions & 4 deletions src/lib/motors/SmartServo.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ class SmartServoClass

inline int getErrors() const { return _errors; }

static const int BROADCAST = 0xFE;
static int constexpr BROADCAST = 0xFE;
static int constexpr MIN_MOTOR_ID = 1;
static int constexpr MAX_MOTOR_ID = 6;
static float constexpr MAX_ANGLE = 315.0f;

private:
Expand All @@ -81,9 +83,6 @@ class SmartServoClass
static int constexpr MAX_RX_PAYLOAD_LEN = 10;
static int constexpr MAX_POSITION = 4000;

static int constexpr MIN_MOTOR_ID = 1;
static int constexpr MAX_MOTOR_ID = 6;

inline bool isValidAngle(float const angle) { return ((angle >= 0.0f) && (angle <= MAX_ANGLE)); }
inline bool isValidId(int const id) const { return ((id >= MIN_MOTOR_ID) && (id <= MAX_MOTOR_ID)); }
inline int idToArrayIndex(int const id) const { return (id - 1); }
Expand Down