JMotor
Loading...
Searching...
No Matches
JServoControllerAdvanced.h
Go to the documentation of this file.
1#ifndef J_SERVO_CONTROLLER_ADVANCED_H
2#define J_SERVO_CONTROLLER_ADVANCED_H
4#include "JServoController.h"
5#include <Arduino.h>
11protected:
18 unsigned long weakenTimeout;
20 float weakFreq;
22 unsigned long startWeakTimeout;
23 unsigned long enabledMillis;
24
25public:
51 JServoControllerAdvanced(JMotorDriverServoAdvanced& _servo, float _weakFreq = .5, unsigned long _weakenTimeout = 0, float _normalFreq = 1.0, unsigned long _startWeakTimeout = 0, bool _reverse = false, float velLimit = INFINITY, float accelLimit = INFINITY, float decelLimit = NAN, unsigned long _disableTimeout = 0, float _minAngleLimit = 0, float _maxAngleLimit = 180, float _pos = 90, float _minSetAngle = 0, float _maxSetAngle = 180, int minServoVal = 544, int maxServoVal = 2400, bool _preventGoingWrongWay = true, bool _preventGoingTooFast = true, float _stoppingDecelLimit = INFINITY)
52 : JServoController(_servo, _reverse, velLimit, accelLimit, decelLimit, _disableTimeout, _minAngleLimit, _maxAngleLimit, _pos, _minSetAngle, _maxSetAngle, minServoVal, maxServoVal, _preventGoingWrongWay, _preventGoingTooFast, _stoppingDecelLimit)
53 , adServo(_servo)
54 {
55 weakenTimeout = _weakenTimeout;
56 startWeakTimeout = _startWeakTimeout;
57 defaultFreq = _normalFreq;
58 weakFreq = _weakFreq;
59 adServo.adjustFrequency(_normalFreq);
60 weakened = false;
61 enabledMillis = millis();
62 }
63 virtual void run()
64 {
65 if (startWeakTimeout != 0 && millis() - enabledMillis < startWeakTimeout) {
66 if (!weakened) {
68 }
69 weakened = true;
70 } else if (weakenTimeout != 0) {
71 if (millis() - lastMovedMillis > weakenTimeout) {
72 if (weakened == false) {
74 }
75 weakened = true;
76 } else {
77 if (weakened == true) {
79 }
80 weakened = false;
81 }
82 }
84 }
85 // override JServoController
86 bool setEnable(bool _enable)
87 {
88 enabledMillis = millis();
89 return JServoController::setEnable(_enable);
90 }
95 {
96 weakened = true;
98 }
103 {
104 weakened = false;
106 }
113 void adjustServoFrequency(float freq = 1.0)
114 {
116 writeAngleToServo(dL.getPosition());
117 }
122 void setWeakFreq(float _weak)
123 {
124 weakFreq = _weak;
125 if (weakened) {
127 }
128 }
129 void setNormalFreq(float _norm)
130 {
131 defaultFreq = _norm;
132 if (!weakened) {
134 }
135 }
137 {
138 return weakened;
139 }
143 void setWeakTimeout(unsigned long _timeout)
144 {
145 weakenTimeout = _timeout;
146 }
147 unsigned long getWeakenTimeout()
148 {
149 return weakenTimeout;
150 }
151 void setStartWeakTimeout(unsigned long _timeout)
152 {
153 startWeakTimeout = _timeout;
154 }
155 unsigned long getStartWeakTimeout()
156 {
157 return startWeakTimeout;
158 }
160 {
161 return weakFreq;
162 }
164 {
165 return defaultFreq;
166 }
167};
168#endif
defines interface for servo driver with variable frequency, subclass of JMotorDriverServo and JMotorD...
Definition JMotorDriverServoAdvanced.h:8
virtual void adjustFrequency(float freq)=0
adjust frequency as a fraction of standard 50hz frequency lower frequencies (try ....
class for controlling JMotorDriverServoAdvanced, with power reducing option along with standard JServ...
Definition JServoControllerAdvanced.h:10
float getWeakFreq()
Definition JServoControllerAdvanced.h:159
unsigned long getStartWeakTimeout()
Definition JServoControllerAdvanced.h:155
bool getWeakened()
Definition JServoControllerAdvanced.h:136
float weakFreq
Definition JServoControllerAdvanced.h:20
void setStrengthNormal()
set servo to normal setting
Definition JServoControllerAdvanced.h:102
unsigned long getWeakenTimeout()
Definition JServoControllerAdvanced.h:147
void adjustServoFrequency(float freq=1.0)
adjust frequency as a fraction of standard 50hz frequency lower frequencies (try ....
Definition JServoControllerAdvanced.h:113
float defaultFreq
Definition JServoControllerAdvanced.h:19
unsigned long weakenTimeout
Definition JServoControllerAdvanced.h:18
void setStartWeakTimeout(unsigned long _timeout)
Definition JServoControllerAdvanced.h:151
void setNormalFreq(float _norm)
Definition JServoControllerAdvanced.h:129
void setWeakTimeout(unsigned long _timeout)
Definition JServoControllerAdvanced.h:143
unsigned long enabledMillis
Definition JServoControllerAdvanced.h:23
void setWeakFreq(float _weak)
change setting for what fraction of normal frequency the signal should go to in order to weaken the s...
Definition JServoControllerAdvanced.h:122
JServoControllerAdvanced(JMotorDriverServoAdvanced &_servo, float _weakFreq=.5, unsigned long _weakenTimeout=0, float _normalFreq=1.0, unsigned long _startWeakTimeout=0, bool _reverse=false, float velLimit=INFINITY, float accelLimit=INFINITY, float decelLimit=NAN, unsigned long _disableTimeout=0, float _minAngleLimit=0, float _maxAngleLimit=180, float _pos=90, float _minSetAngle=0, float _maxSetAngle=180, int minServoVal=544, int maxServoVal=2400, bool _preventGoingWrongWay=true, bool _preventGoingTooFast=true, float _stoppingDecelLimit=INFINITY)
Constructor for JServoControllerAdvanced, a class for controlling JMotorDriverServoAdvanced,...
Definition JServoControllerAdvanced.h:51
bool weakened
Definition JServoControllerAdvanced.h:21
bool setEnable(bool _enable)
enable or disable the servo (start or stop sending a signal to the servo)
Definition JServoControllerAdvanced.h:86
virtual void run()
call this in your main loop
Definition JServoControllerAdvanced.h:63
float getNormalFreq()
Definition JServoControllerAdvanced.h:163
void setStrengthWeak()
set servo to weaker setting
Definition JServoControllerAdvanced.h:94
JMotorDriverServoAdvanced & adServo
reference to the servo motor driver
Definition JServoControllerAdvanced.h:17
unsigned long startWeakTimeout
Definition JServoControllerAdvanced.h:22
class for controlling JMotorDriverServo, with angle calibration and accel and velocity limiting
Definition JServoController.h:12
virtual void run()
call this in your main loop
Definition JServoController.h:102
void writeAngleToServo(float ang)
Definition JServoController.h:602
unsigned long lastMovedMillis
variable used to keep track of how long the servo has been still for
Definition JServoController.h:47
virtual bool setEnable(bool _enable)
enable or disable the servo (start or stop sending a signal to the servo)
Definition JServoController.h:217
Derivs_Limiter dL
instance of Derivs_Limiter class used to smoothly move servo
Definition JServoController.h:63