Skip to content

Commit 37a1918

Browse files
authored
Merge pull request #28 from bcmi-labs/remove-redundant-api
Remove redundant/not-implemented API calls
2 parents 61674d1 + f615bba commit 37a1918

File tree

3 files changed

+48
-45
lines changed

3 files changed

+48
-45
lines changed

src/Braccio++.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ bool BraccioClass::begin(voidFuncPtr customMenu) {
164164
return true;
165165
}
166166

167+
MotorsWrapper BraccioClass::move(int const id)
168+
{
169+
MotorsWrapper wrapper(servos, id);
170+
return wrapper;
171+
}
172+
173+
void BraccioClass::moveTo(float const a1, float const a2, float const a3, float const a4, float const a5, float const a6)
174+
{
175+
servos.setPositionMode(PositionMode::SYNC);
176+
servos.setPosition(1, a1, runTime);
177+
servos.setPosition(2, a2, runTime);
178+
servos.setPosition(3, a3, runTime);
179+
servos.setPosition(4, a4, runTime);
180+
servos.setPosition(5, a5, runTime);
181+
servos.setPosition(6, a6, runTime);
182+
servos.synchronize();
183+
servos.setPositionMode(PositionMode::IMMEDIATE);
184+
}
185+
186+
void BraccioClass::positions(float * buffer)
187+
{
188+
for (int id = SmartServoClass::MIN_MOTOR_ID; id <= SmartServoClass::MAX_MOTOR_ID; id++)
189+
*buffer++ = servos.getPosition(id);
190+
}
191+
192+
void BraccioClass::positions(float & a1, float & a2, float & a3, float & a4, float & a5, float & a6)
193+
{
194+
// TODO: add check if motors are actually connected
195+
a1 = servos.getPosition(1);
196+
a2 = servos.getPosition(2);
197+
a3 = servos.getPosition(3);
198+
a4 = servos.getPosition(4);
199+
a5 = servos.getPosition(5);
200+
a6 = servos.getPosition(6);
201+
}
202+
167203
void BraccioClass::connectJoystickTo(lv_obj_t* obj) {
168204
lv_group_add_obj(p_objGroup, obj);
169205
lv_indev_set_group(kb_indev, p_objGroup);

src/Braccio++.h

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -87,47 +87,15 @@ class BraccioClass
8787
inline bool begin() { return begin(nullptr); }
8888
bool begin(voidFuncPtr customMenu);
8989

90-
// setters
91-
MotorsWrapper move(int joint_index) {
92-
MotorsWrapper wrapper(servos, joint_index);
93-
return wrapper;
94-
}
95-
MotorsWrapper get(int joint_index) {
96-
return move(joint_index);
97-
}
98-
void moveTo(int joint_index, int position) {
99-
//servos.setPosition(joint_index, position, 100);
100-
}
101-
void moveTo(int joint_index, float angle) {
102-
servos.setPosition(joint_index, angle, 100);
103-
}
104-
void moveTo(float a1, float a2, float a3, float a4, float a5, float a6) {
105-
servos.setPositionMode(PositionMode::SYNC);
106-
servos.setPosition(1, a1, runTime);
107-
servos.setPosition(2, a2, runTime);
108-
servos.setPosition(3, a3, runTime);
109-
servos.setPosition(4, a4, runTime);
110-
servos.setPosition(5, a5, runTime);
111-
servos.setPosition(6, a6, runTime);
112-
servos.synchronize();
113-
servos.setPositionMode(PositionMode::IMMEDIATE);
114-
}
115-
// getters
116-
void positions(float* buffer) {
117-
for (int i = 1; i < 7; i++) {
118-
*buffer++ = servos.getPosition(i);
119-
}
120-
}
121-
void positions(float& a1, float& a2, float& a3, float& a4, float& a5, float& a6) {
122-
// TODO: add check if motors are actually connected
123-
a1 = servos.getPosition(1);
124-
a2 = servos.getPosition(2);
125-
a3 = servos.getPosition(3);
126-
a4 = servos.getPosition(4);
127-
a5 = servos.getPosition(5);
128-
a6 = servos.getPosition(6);
129-
}
130-
float position(int joint_index);
90+
91+
MotorsWrapper move(int const id);
92+
inline MotorsWrapper get(int const id) { return move(id); }
93+
94+
void moveTo(float const a1, float const a2, float const a3, float const a4, float const a5, float const a6);
95+
void positions(float * buffer);
96+
void positions(float & a1, float & a2, float & a3, float & a4, float & a5, float & a6);
97+
98+
13199
bool connected(int joint_index) {
132100
return _connected[joint_index];
133101
}

src/lib/motors/SmartServo.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class SmartServoClass
7171

7272
inline int getErrors() const { return _errors; }
7373

74-
static const int BROADCAST = 0xFE;
74+
static int constexpr BROADCAST = 0xFE;
75+
static int constexpr MIN_MOTOR_ID = 1;
76+
static int constexpr MAX_MOTOR_ID = 6;
7577
static float constexpr MAX_ANGLE = 315.0f;
7678

7779
private:
@@ -81,9 +83,6 @@ class SmartServoClass
8183
static int constexpr MAX_RX_PAYLOAD_LEN = 10;
8284
static int constexpr MAX_POSITION = 4000;
8385

84-
static int constexpr MIN_MOTOR_ID = 1;
85-
static int constexpr MAX_MOTOR_ID = 6;
86-
8786
inline bool isValidAngle(float const angle) { return ((angle >= 0.0f) && (angle <= MAX_ANGLE)); }
8887
inline bool isValidId(int const id) const { return ((id >= MIN_MOTOR_ID) && (id <= MAX_MOTOR_ID)); }
8988
inline int idToArrayIndex(int const id) const { return (id - 1); }

0 commit comments

Comments
 (0)