JMotor
Loading...
Searching...
No Matches
JServoControllerStallProtected.h
Go to the documentation of this file.
1#ifndef J_SERVO_CONTROLLER_STALL_PROTECTED_H
2#define J_SERVO_CONTROLLER_STALL_PROTECTED_H
5#include <Arduino.h>
10protected:
11 bool stalled;
17 unsigned long stallActivateTimeout;
19
20public:
22 JServoControllerStallProtected(JServoControllerAdvanced advancedServo, JServoStallSensing& servoStallSensor, float _unStallThreshold, float _stallThreshold, unsigned long _stallActivateTimeout, unsigned long _stallDeactivateTimeout)
23 : JServoControllerAdvanced(advancedServo)
24 , stallSensor(servoStallSensor)
25 {
26 unStallThreshold = constrain(_unStallThreshold, 0, 1);
27 stallThreshold = constrain(_stallThreshold, 0, 1);
28 stalled = false;
29 stallProtected = true;
30 stallActivateTimeout = _stallActivateTimeout;
31 stallDeactivateTimeout = _stallDeactivateTimeout;
32 }
33 virtual void run()
34 {
35 float measurementTemp = stallSensor.getMeasurement(true);
36 if (measurementTemp > stallThreshold) {
37 if (!stalled) {
38 stalled = true;
39 stallStateChangeMillis = millis();
40 }
41 }
42 if (measurementTemp < unStallThreshold) {
43 if (stalled) {
44 stalled = false;
45 stallStateChangeMillis = millis();
46 }
47 }
50 }
51
53 if (stallProtected && !weakened) {
55 }
56 }
58 if (stallProtected && weakened) {
60 }
61 }
62
64 }
70 {
71 return millis() - stallStateChangeMillis;
72 }
73 bool isStalled()
74 {
75 return stalled;
76 }
78 {
79 return stallProtected;
80 }
81 void setStallProtectionEnable(bool enableStallProtection)
82 {
83 stallProtected = enableStallProtection;
84 if (stallProtected == false) {
85 if (stalled) {
87 }
88 }
89 }
90};
91#endif
class for controlling JMotorDriverServoAdvanced, with power reducing option along with standard JServ...
Definition JServoControllerAdvanced.h:10
void setStrengthNormal()
set servo to normal setting
Definition JServoControllerAdvanced.h:102
bool weakened
Definition JServoControllerAdvanced.h:21
virtual void run()
call this in your main loop
Definition JServoControllerAdvanced.h:63
void setStrengthWeak()
set servo to weaker setting
Definition JServoControllerAdvanced.h:94
this child class of JServoController uses JServoStallSensing to reduce servo power
Definition JServoControllerStallProtected.h:9
void setStallProtectionEnable(bool enableStallProtection)
Definition JServoControllerStallProtected.h:81
JServoControllerStallProtected(JServoControllerAdvanced advancedServo, JServoStallSensing &servoStallSensor, float _unStallThreshold, float _stallThreshold, unsigned long _stallActivateTimeout, unsigned long _stallDeactivateTimeout)
Definition JServoControllerStallProtected.h:22
bool stallProtected
Definition JServoControllerStallProtected.h:14
bool stallProtectionActivated
Definition JServoControllerStallProtected.h:16
unsigned long stallActivateTimeout
Definition JServoControllerStallProtected.h:17
unsigned long getTimeSinceStallStateChangeMillis()
Definition JServoControllerStallProtected.h:69
bool getStallProtectionEnable()
Definition JServoControllerStallProtected.h:77
bool stalled
Definition JServoControllerStallProtected.h:11
bool isStallProtectionActivated()
Definition JServoControllerStallProtected.h:65
virtual void run()
call this in your main loop
Definition JServoControllerStallProtected.h:33
unsigned long stallDeactivateTimeout
Definition JServoControllerStallProtected.h:18
float stallThreshold
Definition JServoControllerStallProtected.h:13
JServoStallSensing & stallSensor
Definition JServoControllerStallProtected.h:21
unsigned long stallStateChangeMillis
Definition JServoControllerStallProtected.h:15
bool isStalled()
Definition JServoControllerStallProtected.h:73
float unStallThreshold
Definition JServoControllerStallProtected.h:12
defines interface for classes that can measure how hard a servo is working
Definition JServoStallSensing.h:7
virtual float getMeasurement(bool _run=true)=0