HerkuleXLib  1.2
Arduino library to drive HerkuleX DRS-0101 and DRS-0201
/home/benoit/sketchbook/libraries/HerkuleXLib/HkxSetup.h
Go to the documentation of this file.
1 #ifndef _HKXSETUP_H
2 #define _HKXSETUP_H
3 
13 #include "Arduino.h"
14 #include "HkxCommunication.h"
15 
21 class HkxSetup{
22 private:
29  const String _className;
30 
36  void errorPrint(const String& message){if(_print._errorMessages){_print.errorPrint(_className + message);}};
37 
43  void warningPrint(const String& message){if(_print._errorMessages){_print.warningPrint(_className + message);}};
44 
50  void infoPrint(const String& message){if(_print._errorMessages){_print.infoPrint(_className + message);}};
51 
70  uint8_t setPolicies(uint8_t ID, uint8_t newAlarmLEDPolicy, uint8_t newTorquePolicy);
71 
84  uint8_t setTemperatureVoltage(uint8_t ID, int16_t newMaxTemp, uint16_t newMinVoltage, uint16_t newMaxVoltage);
85 
110  uint8_t setAcceleration(uint8_t ID, uint8_t newAccelerationRatio, uint16_t newMaxAccelerationTime);
111 
142  uint8_t setLoadControl(uint8_t ID, uint16_t newDeadZone, uint8_t newSaturatorOffset, const uint32_t& newSaturatorSlope, int8_t newPWMOffset, uint8_t newMinPWM, uint16_t newMaxPWM);
143 
155  uint8_t setPWMPositionLimits(uint8_t ID, uint16_t newOverlaodPWMThreshold, int16_t newMinPosition, int16_t newMaxPosition);
156 
170  uint8_t setControlSystem(uint8_t ID, uint16_t kProportionnal, uint16_t kDerivative, uint16_t kInteger, uint16_t feedforwardGain1, uint16_t feedforwardGain2);
171 
185  uint8_t setErrorsCheckPeriod(uint8_t ID, uint16_t LEDBlink, uint16_t ADCFault, uint16_t packetGarbage, uint16_t stopDetection, uint16_t overloadDetection);
186 
197  uint8_t setInPositionCriteria(uint8_t ID, uint16_t stopThreshold, uint16_t inPositionMargin);
198 
220  uint8_t setTorqueLEDControl(uint8_t ID, hkxTorqueControl newTorqueControl,hkxLEDControl newLEDControl);
221 
230  uint8_t clearStatus(uint8_t ID);
231 
242  uint8_t factoryReset(uint8_t ID, boolean IDskip, boolean baudrateSkip);
243 
252  uint8_t reboot(uint8_t ID){
253  if(ID > HKX_ID_ALL){
254  errorPrint(F("reboot > Input not correct"));
255  return 1;
256  }
257  return _herkXCom.rebootRequest(ID);
258  };
260 public:
267  HkxSetup(HkxCommunication& herkXCom, HkxPrint& print) : _herkXCom(herkXCom), _print(print), _className(F("HkxSetup::")){};
268 
281  uint8_t getServoInfo(uint8_t ID, HkxMaybe<uint16_t> model, HkxMaybe<uint16_t> version);
282 
294  uint8_t getBaudRate(uint8_t ID, hkxBaudrate* baudRate);
295 
312  uint8_t setAllBaudRate(const hkxBaudrate& baudrate);
313 
324  uint8_t setID(uint8_t ID, uint8_t newID);
325 
338  uint8_t getPolicies(uint8_t ID, HkxMaybe<uint8_t> newAlarmLEDPolicy, HkxMaybe<uint8_t> newTorquePolicy);
339 
358  uint8_t setOnePolicies(uint8_t ID, uint8_t newAlarmLEDPolicy, uint8_t newTorquePolicy){
359  if(ID > HKX_MAX_ID){
360  errorPrint(F("setOnePolicies > Input not correct"));
361  return 1;
362  }
363  return setPolicies(ID, newAlarmLEDPolicy, newTorquePolicy);
364  };
365 
383  uint8_t setAllPolicies(uint8_t newAlarmLEDPolicy, uint8_t newTorquePolicy){return setPolicies(HKX_ID_ALL, newAlarmLEDPolicy, newTorquePolicy);};
384 
398  uint8_t getTemperatureVoltage(uint8_t ID, HkxMaybe<int16_t> maxTemp, HkxMaybe<uint16_t> minVoltage, HkxMaybe<uint16_t> maxVoltage);
399 
411  uint8_t setOneTemperatureVoltage(uint8_t ID, int16_t newMaxTemp, uint16_t newMinVoltage, uint16_t newMaxVoltage){
412  if(ID > HKX_MAX_ID){
413  errorPrint(F("setOneMaxTemperature > Input value not correct"));
414  return 1;
415  }
416  return setTemperatureVoltage(ID, newMaxTemp, newMinVoltage, newMaxVoltage);
417  };
418 
429  uint8_t setAllTemperatureVoltage(int16_t newMaxTemp, int16_t newMinVoltage, int16_t newMaxVoltage){return setTemperatureVoltage(HKX_ID_ALL, newMaxTemp, newMinVoltage, newMaxVoltage);};
430 
457  uint8_t getAcceleration(uint8_t ID, HkxMaybe<uint8_t> accelerationRatio, HkxMaybe<uint16_t> maxAccelerationTime);
458 
485  uint8_t setOneAcceleration(uint8_t ID, uint8_t newAccelerationRatio, uint16_t newMaxAccelerationTime){
486  if(ID > HKX_MAX_ID){
487  errorPrint(F("setOneAcceleration > acceleration ratio value or max acceleration time not correct"));
488  return 1;
489  }
490  return setAcceleration(ID, newAccelerationRatio, newMaxAccelerationTime);
491  };
492 
516  uint8_t setAllAcceleration(uint8_t newAccelerationRatio, uint16_t newMaxAccelerationTime){return setAcceleration(HKX_ID_ALL, newAccelerationRatio, newMaxAccelerationTime);};
517 
550  uint8_t getLoadControl(uint8_t ID, HkxMaybe<uint16_t> deadZone, HkxMaybe<uint8_t> saturatorOffSet, HkxMaybe<uint32_t> saturatorSlope, HkxMaybe<int8_t> PWMoffset, HkxMaybe<uint8_t> minPWM, HkxMaybe<uint16_t> maxPWM);
551 
582  uint8_t setOneLoadControl(uint8_t ID, uint16_t newDeadZone, uint8_t newSaturatorOffset, const uint32_t& newSaturatorSlope, int8_t newPWMOffset, uint8_t newMinPWM, uint16_t newMaxPWM){
583  if(ID > HKX_MAX_ID){
584  errorPrint(F("setOneLoadControl > Input not correct"));
585  return 1;
586  }
587  return setLoadControl(ID, newDeadZone, newSaturatorOffset, newSaturatorSlope, newPWMOffset, newMinPWM, newMaxPWM);
588  };
589 
619  uint8_t setAllLoadControl(uint16_t newDeadZone, uint8_t newSaturatorOffset, const uint32_t& newSaturatorSlope, int8_t newPWMOffset, uint8_t newMinPWM, uint16_t newMaxPWM){return setLoadControl(HKX_ID_ALL, newDeadZone, newSaturatorOffset, newSaturatorSlope, newPWMOffset, newMinPWM, newMaxPWM);};
620 
634  uint8_t getPWMPositionLimits(uint8_t ID, HkxMaybe<uint16_t> overlaodPWMThreshold, HkxMaybe<int16_t> minPosition, HkxMaybe<int16_t> maxPosition);
635 
647  uint8_t setOnePWMPositionLimits(uint8_t ID, uint16_t newOverlaodPWMThreshold, int16_t newMinPosition, int16_t newMaxPosition){
648  if(ID > HKX_MAX_ID){
649  errorPrint(F("setOnePWMPositionLimits > Input not correct"));
650  return 1;
651  }
652  return setPWMPositionLimits(ID, newOverlaodPWMThreshold, newMinPosition, newMaxPosition);
653  };
654 
665  uint8_t setAllPWMPositionLimits(uint16_t newOverlaodPWMThreshold, int16_t newMinPosition, int16_t newMaxPosition){return setPWMPositionLimits(HKX_ID_ALL, newOverlaodPWMThreshold, newMinPosition, newMaxPosition);};
666 
682  uint8_t getControlSystem(uint8_t ID, HkxMaybe<uint16_t> kProportionnal, HkxMaybe<uint16_t> kDerivative, HkxMaybe<uint16_t> kInteger, HkxMaybe<uint16_t> feedforwardGain1, HkxMaybe<uint16_t> feedforwardGain2);
683 
697  uint8_t setOneControlSystem(uint8_t ID, uint16_t kProportionnal, uint16_t kDerivative, uint16_t kInteger, uint16_t feedforwardGain1, uint16_t feedforwardGain2){
698  if(ID > HKX_MAX_ID){
699  errorPrint(F("setOneControlSystem > Input not correct"));
700  return 1;
701  }
702  return setControlSystem(ID, kProportionnal, kDerivative, kInteger, feedforwardGain1, feedforwardGain2);
703  };
704 
717  uint8_t setAllControlSystem(uint16_t kProportionnal, uint16_t kDerivative, uint16_t kInteger, uint16_t feedforwardGain1, uint16_t feedforwardGain2){return setControlSystem(HKX_ID_ALL, kProportionnal, kDerivative, kInteger, feedforwardGain1, feedforwardGain2);};
718 
734  uint8_t getErrorsCheckPeriod(uint8_t ID, HkxMaybe<uint16_t> LEDBlink, HkxMaybe<uint16_t> ADCFault, HkxMaybe<uint16_t> packetGarbage, HkxMaybe<uint16_t> stopDetection, HkxMaybe<uint16_t> overloadDetection);
735 
749  uint8_t setOneErrorsCheckPeriod(uint8_t ID, uint16_t LEDBlink, uint16_t ADCFault, uint16_t packetGarbage, uint16_t stopDetection, uint16_t overloadDetection){
750  if(ID > HKX_MAX_ID){
751  errorPrint(F("setOneErrorsCheckPeriod > Input not correct"));
752  return 1;
753  }
754  return setErrorsCheckPeriod(ID, LEDBlink, ADCFault, packetGarbage, stopDetection, overloadDetection);
755  };
756 
769  uint8_t setAllErrorsCheckPeriod(uint16_t LEDBlink, uint16_t ADCFault, uint16_t packetGarbage, uint16_t stopDetection, uint16_t overloadDetection){return setErrorsCheckPeriod(HKX_ID_ALL, LEDBlink, ADCFault, packetGarbage, stopDetection, overloadDetection);};
770 
783  uint8_t getInPositionCriteria(uint8_t ID, HkxMaybe<uint16_t> stopThreshold, HkxMaybe<uint16_t> inPositionMargin);
784 
795  uint8_t setOneInPositionCriteria(uint8_t ID, uint16_t stopThreshold, uint16_t inPositionMargin){
796  if(ID > HKX_MAX_ID){
797  errorPrint(F("setOneInPositionCriteria > Input not correct"));
798  return 1;
799  }
800  return setInPositionCriteria(ID, stopThreshold, inPositionMargin);
801  };
802 
812  uint8_t setAllInPositionCriteria(uint16_t stopThreshold, uint16_t inPositionMargin){return setInPositionCriteria(HKX_ID_ALL, stopThreshold, inPositionMargin);};
813 
826  uint8_t getTorqueLEDControl(uint8_t ID, HkxMaybe<hkxTorqueControl> torqueControl, HkxMaybe<hkxLEDControl> LEDControl);
827 
849  uint8_t setOneTorqueLEDControl(uint8_t ID, hkxTorqueControl newTorqueControl, hkxLEDControl newLEDControl){
850  if(ID > HKX_MAX_ID){
851  errorPrint(F("setOneTorqueLEDControl > Input not correct"));
852  return 1;
853  }
854  return setTorqueLEDControl(ID, newTorqueControl, newLEDControl);
855  };
856 
877  uint8_t setAllTorqueLEDControl(hkxTorqueControl newTorqueControl,hkxLEDControl newLEDControl){return setTorqueLEDControl(HKX_ID_ALL, newTorqueControl, newLEDControl);};
878 
899  uint8_t getBehaviour(uint8_t ID, HkxMaybe<uint16_t> voltage, HkxMaybe<uint16_t> temperature, HkxMaybe<hkxControlMode> controlMode, HkxMaybe<uint16_t> tick, HkxMaybe<int16_t> absolutePosition, HkxMaybe<int16_t> velocity, HkxMaybe<int16_t> PWM, HkxMaybe<int16_t> absoluteGoalPosition, HkxMaybe<int16_t> absoluteDesiredTrajectoryPosition, HkxMaybe<int16_t> desiredVelocity);
900 
912  uint8_t getStatus(uint8_t ID, HkxStatus& statusED);
913 
922  uint8_t clearOneStatus(uint8_t ID){
923  if(ID > HKX_MAX_ID){
924  errorPrint(F("clearOneStatus > Input not correct"));
925  return 1;
926  }
927  return clearStatus(ID);
928  };
929 
937  uint8_t clearAllStatus(){return clearStatus(HKX_ID_ALL);};
938 
949  void scanIDs(boolean IDs[]);
950 
961  uint8_t factoryResetOne(uint8_t ID, boolean IDskip, boolean baudrateSkip){
962  if(ID > HKX_MAX_ID){
963  errorPrint(F("factoryResetOne > Input not correct"));
964  return 1;
965  }
966  return factoryReset(ID, IDskip, baudrateSkip);
967  };
968 
978  uint8_t factoryResetAll(boolean IDskip, boolean baudrateSkip){return factoryReset(HKX_ID_ALL, IDskip, baudrateSkip);};
979 
988  uint8_t rebootOne(uint8_t ID){
989  if(ID > HKX_MAX_ID){
990  errorPrint(F("rebootOne > Input not correct"));
991  return 1;
992  }
993  return reboot(ID);
994  };
995 
1000  void rebootAll(){reboot(HKX_ID_ALL);};
1001 
1002 };
1003 
1004 #endif // _HKXSETUP_H
1005 
uint8_t getTorqueLEDControl(uint8_t ID, HkxMaybe< hkxTorqueControl > torqueControl, HkxMaybe< hkxLEDControl > LEDControl)
Get torque actuation and LED colour.
Definition: HkxSetup.cpp:417
uint8_t getLoadControl(uint8_t ID, HkxMaybe< uint16_t > deadZone, HkxMaybe< uint8_t > saturatorOffSet, HkxMaybe< uint32_t > saturatorSlope, HkxMaybe< int8_t > PWMoffset, HkxMaybe< uint8_t > minPWM, HkxMaybe< uint16_t > maxPWM)
Get load control.
Definition: HkxSetup.cpp:202
uint8_t setOneTorqueLEDControl(uint8_t ID, hkxTorqueControl newTorqueControl, hkxLEDControl newLEDControl)
Set torque actuation and LED colour.
Definition: HkxSetup.h:849
uint8_t setAllLoadControl(uint16_t newDeadZone, uint8_t newSaturatorOffset, const uint32_t &newSaturatorSlope, int8_t newPWMOffset, uint8_t newMinPWM, uint16_t newMaxPWM)
Set load control parameters for all.
Definition: HkxSetup.h:619
void warningPrint(const String &message) const
Print warning.
Definition: HkxCommunication.h:394
uint8_t setOnePWMPositionLimits(uint8_t ID, uint16_t newOverlaodPWMThreshold, int16_t newMinPosition, int16_t newMaxPosition)
Set PWM and position limits.
Definition: HkxSetup.h:647
HkxCommunication & _herkXCom
Definition: HkxSetup.h:24
uint8_t setOneLoadControl(uint8_t ID, uint16_t newDeadZone, uint8_t newSaturatorOffset, const uint32_t &newSaturatorSlope, int8_t newPWMOffset, uint8_t newMinPWM, uint16_t newMaxPWM)
Set load control parameters.
Definition: HkxSetup.h:582
void scanIDs(boolean IDs[])
Scan IDs.
Definition: HkxSetup.cpp:524
uint8_t setOnePolicies(uint8_t ID, uint8_t newAlarmLEDPolicy, uint8_t newTorquePolicy)
Set policies.
Definition: HkxSetup.h:358
uint8_t setOneTemperatureVoltage(uint8_t ID, int16_t newMaxTemp, uint16_t newMinVoltage, uint16_t newMaxVoltage)
Set temperature and voltage.
Definition: HkxSetup.h:411
void errorPrint(const String &message) const
Print error.
Definition: HkxCommunication.h:381
uint8_t setID(uint8_t ID, uint8_t newID)
Set ID.
Definition: HkxSetup.cpp:75
uint8_t setAllInPositionCriteria(uint16_t stopThreshold, uint16_t inPositionMargin)
Set in position criteria for all.
Definition: HkxSetup.h:812
uint8_t getStatus(uint8_t ID, HkxStatus &statusED)
Get status.
Definition: HkxSetup.cpp:490
uint8_t clearAllStatus()
Clear status for all.
Definition: HkxSetup.h:937
uint8_t factoryResetAll(boolean IDskip, boolean baudrateSkip)
Factory reset for all.
Definition: HkxSetup.h:978
hkxBaudrate
Baud rate.
Definition: HkxCommunication.h:109
hkxTorqueControl
Torque control.
Definition: HkxCommunication.h:127
uint8_t clearOneStatus(uint8_t ID)
Clear status.
Definition: HkxSetup.h:922
Class to manage the communication.
Definition: HkxCommunication.h:636
Class to manage the status of the servos.
Definition: HkxStatus.h:55
uint8_t setOneAcceleration(uint8_t ID, uint8_t newAccelerationRatio, uint16_t newMaxAccelerationTime)
Set Acceleration.
Definition: HkxSetup.h:485
uint8_t getPolicies(uint8_t ID, HkxMaybe< uint8_t > newAlarmLEDPolicy, HkxMaybe< uint8_t > newTorquePolicy)
Get Policies.
Definition: HkxSetup.cpp:94
uint8_t setAllErrorsCheckPeriod(uint16_t LEDBlink, uint16_t ADCFault, uint16_t packetGarbage, uint16_t stopDetection, uint16_t overloadDetection)
Set check periods for all.
Definition: HkxSetup.h:769
uint8_t setAllAcceleration(uint8_t newAccelerationRatio, uint16_t newMaxAccelerationTime)
Set Acceleration for all.
Definition: HkxSetup.h:516
uint8_t getAcceleration(uint8_t ID, HkxMaybe< uint8_t > accelerationRatio, HkxMaybe< uint16_t > maxAccelerationTime)
Get Acceleration.
Definition: HkxSetup.cpp:164
uint8_t setAllTemperatureVoltage(int16_t newMaxTemp, int16_t newMinVoltage, int16_t newMaxVoltage)
Set temperature and voltage for all.
Definition: HkxSetup.h:429
uint8_t getPWMPositionLimits(uint8_t ID, HkxMaybe< uint16_t > overlaodPWMThreshold, HkxMaybe< int16_t > minPosition, HkxMaybe< int16_t > maxPosition)
Get PWM and position limits.
Definition: HkxSetup.cpp:251
uint8_t getBehaviour(uint8_t ID, HkxMaybe< uint16_t > voltage, HkxMaybe< uint16_t > temperature, HkxMaybe< hkxControlMode > controlMode, HkxMaybe< uint16_t > tick, HkxMaybe< int16_t > absolutePosition, HkxMaybe< int16_t > velocity, HkxMaybe< int16_t > PWM, HkxMaybe< int16_t > absoluteGoalPosition, HkxMaybe< int16_t > absoluteDesiredTrajectoryPosition, HkxMaybe< int16_t > desiredVelocity)
Get behaviour.
Definition: HkxSetup.cpp:451
uint8_t getBaudRate(uint8_t ID, hkxBaudrate *baudRate)
Get the baud rate.
Definition: HkxSetup.cpp:38
hkxLEDControl
LED control.
Definition: HkxCommunication.h:146
uint8_t getErrorsCheckPeriod(uint8_t ID, HkxMaybe< uint16_t > LEDBlink, HkxMaybe< uint16_t > ADCFault, HkxMaybe< uint16_t > packetGarbage, HkxMaybe< uint16_t > stopDetection, HkxMaybe< uint16_t > overloadDetection)
Get check periods.
Definition: HkxSetup.cpp:334
uint8_t setOneControlSystem(uint8_t ID, uint16_t kProportionnal, uint16_t kDerivative, uint16_t kInteger, uint16_t feedforwardGain1, uint16_t feedforwardGain2)
Set Control System.
Definition: HkxSetup.h:697
uint8_t rebootOne(uint8_t ID)
Reboot.
Definition: HkxSetup.h:988
uint8_t getControlSystem(uint8_t ID, HkxMaybe< uint16_t > kProportionnal, HkxMaybe< uint16_t > kDerivative, HkxMaybe< uint16_t > kInteger, HkxMaybe< uint16_t > feedforwardGain1, HkxMaybe< uint16_t > feedforwardGain2)
Get Control System.
Definition: HkxSetup.cpp:291
Class to manage the print of the messages.
Definition: HkxCommunication.h:278
uint8_t setOneErrorsCheckPeriod(uint8_t ID, uint16_t LEDBlink, uint16_t ADCFault, uint16_t packetGarbage, uint16_t stopDetection, uint16_t overloadDetection)
Set check periods.
Definition: HkxSetup.h:749
uint8_t setAllPWMPositionLimits(uint16_t newOverlaodPWMThreshold, int16_t newMinPosition, int16_t newMaxPosition)
Set PWM and position limits for all.
Definition: HkxSetup.h:665
void rebootAll()
Reboot.
Definition: HkxSetup.h:1000
HkxPrint & _print
Definition: HkxSetup.h:26
void infoPrint(const String &message) const
Print info.
Definition: HkxCommunication.h:407
uint8_t setAllPolicies(uint8_t newAlarmLEDPolicy, uint8_t newTorquePolicy)
Set policies for all.
Definition: HkxSetup.h:383
uint8_t setAllBaudRate(const hkxBaudrate &baudrate)
Set the baud rate for all.
Definition: HkxSetup.cpp:60
HkxSetup(HkxCommunication &herkXCom, HkxPrint &print)
Constructor.
Definition: HkxSetup.h:267
uint8_t getServoInfo(uint8_t ID, HkxMaybe< uint16_t > model, HkxMaybe< uint16_t > version)
Get model and firmware.
Definition: HkxSetup.cpp:13
uint8_t setOneInPositionCriteria(uint8_t ID, uint16_t stopThreshold, uint16_t inPositionMargin)
Set in position criteria.
Definition: HkxSetup.h:795
uint8_t getInPositionCriteria(uint8_t ID, HkxMaybe< uint16_t > stopThreshold, HkxMaybe< uint16_t > inPositionMargin)
Get in position criteria.
Definition: HkxSetup.cpp:380
uint8_t setAllControlSystem(uint16_t kProportionnal, uint16_t kDerivative, uint16_t kInteger, uint16_t feedforwardGain1, uint16_t feedforwardGain2)
Set Control System for all.
Definition: HkxSetup.h:717
Communication management of the Arduino library for HerkuleX servo (DRS-0101 and DRS-0201 models) ...
Class to setup the servos.
Definition: HkxSetup.h:21
uint8_t factoryResetOne(uint8_t ID, boolean IDskip, boolean baudrateSkip)
Factory reset.
Definition: HkxSetup.h:961
uint8_t getTemperatureVoltage(uint8_t ID, HkxMaybe< int16_t > maxTemp, HkxMaybe< uint16_t > minVoltage, HkxMaybe< uint16_t > maxVoltage)
Get temperature and voltage.
Definition: HkxSetup.cpp:128
uint8_t setAllTorqueLEDControl(hkxTorqueControl newTorqueControl, hkxLEDControl newLEDControl)
Set torque actuation and LED colour for all.
Definition: HkxSetup.h:877