Skip to content

Commit e3a6f42

Browse files
committed
Cleaning up Servo class for better visibility in how it functions.
1 parent bd99719 commit e3a6f42

File tree

1 file changed

+21
-34
lines changed

1 file changed

+21
-34
lines changed

src/Braccio++.h

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -173,46 +173,33 @@ class BraccioClass
173173

174174
#define Braccio BraccioClass::get_default_instance()
175175

176-
class Servo {
176+
class Servo
177+
{
177178
public:
178-
Servo(SmartServoClass & servos, int idx) : _servos(servos), _idx(idx) {}
179-
Servo& to(float angle) {
180-
_servos.setPosition(_idx, angle, _speed);
181-
return *this;
182-
}
183-
Servo& in(std::chrono::milliseconds len) {
184-
_servos.setTime(_idx, len.count());
185-
return *this;
186-
}
187-
Servo& move() {
188-
return *this;
189-
}
190-
float position() {
191-
return _servos.getPosition(_idx);
192-
}
193179

194-
inline bool connected() { return Braccio.connected(_idx); }
180+
Servo(SmartServoClass & servos, int const idx) : _servos(servos), _idx(idx) { }
181+
182+
inline void disengage() { _servos.disengage(_idx); }
183+
inline void engage() { _servos.engage(_idx); }
184+
inline bool engaged() { return _servos.isEngaged(_idx); }
185+
186+
inline Servo & move() { return *this; }
187+
inline Servo & to (float const angle) { _servos.setPosition(_idx, angle, _speed); return *this; }
188+
inline Servo & in (std::chrono::milliseconds const len) { _servos.setTime(_idx, len.count()); return *this; }
189+
190+
inline float position() { return _servos.getPosition(_idx); }
191+
inline bool connected() { return Braccio.connected(_idx); }
192+
inline void info(Stream & stream) { _servos.getInfo(stream, _idx); }
193+
194+
operator bool() { return connected(); }
195195

196-
operator bool() {
197-
return connected();
198-
}
199-
void info(Stream& stream) {
200-
_servos.getInfo(stream, _idx);
201-
}
202-
void disengage() {
203-
_servos.disengage(_idx);
204-
}
205-
void engage() {
206-
_servos.engage(_idx);
207-
}
208-
bool engaged() {
209-
return _servos.isEngaged(_idx);
210-
}
211196

212197
private:
198+
213199
SmartServoClass & _servos;
214-
int _idx;
215-
int _speed = 100;
200+
int const _idx;
201+
int const _speed = 100;
202+
216203
};
217204

218205
struct __callback__container__ {

0 commit comments

Comments
 (0)