I have not visited the Servo service for a long time.  It gained functionality, but some of the implementations make it very difficult to extend in the future.  Additionally, there were some problems which made the code unecessarily complicated.

So, I've taken a stab at trying to refactor this service.  Its completely untested (I'll be beginning testing with JUnit next) - but I'm hoping to get some feedback on what's currently there.

A high level summary :

  • Service interfaces changed to use boxed primites (Integer, Double, Long) rather than primitives (int, double, log) - this has to do with the current invoking framework.  It's more proficient for the framework in addition to serialization.
  • ServoControl interface greatly refactored.  Methods removed that do not belong, some added for "kinde gentler" type conversions for the "users" of the interface
  • More "attach" methods supported
  • Created AbstractServo abstract class that potentially all Servo implementations can use. 
  • Created HobbyServo which extends AbstractServo,  DiyServo also extends AbstractServo which has reduced the necessary amount of DiyServo
  • Started GenericEncoder & TimeEncoder (neither are complete yet) - TimeEncoder will be used with future servos to generate "estimated" position events.  
  • Started thinking about Arduino's implementation of a Servo encoder which was used in the past to support ServoEvents
  • Removed IK knowledge from ServoControl
  • Removed sensor info from ServoControl - but should be supported the same way TimeEncoder & "real" encoders will be  e.g.  servo.attach(encoder)
  • Changed pin to String type ! - but also supports Integer.  PinArrayControl services need to provide the capability of addressing pins with strings.   e.g. controller.enablePin("A0") - updated PinArrayControl interface to also supply a conversion ->  arduino.getAddress("D0") returns 0
  • pos, rest changed to Double type
  • AbstractServo having a single method of max complexity supporting both blocking & non blocking
  • ServoControl & AbstractServo both support the capability of attaching to multiple controllers
  • Sync/Unsync implemented with control commands vs event commands - making it portable over controllers (not just Arduino)
  • Lots more javadocs

Code Links

Diff with develop branch - https://github.com/MyRobotLab/myrobotlab/pull/488/files 
The new ServoControl interface - https://github.com/MyRobotLab/myrobotlab/blob/new_servo_fixes/src/main/java/org/myrobotlab/service/interfaces/ServoControl.java

None of these changes have been tested - but that's next on my agenda
All futre testing for this will end up in junit - so auto-elves will keep things stable.