JMotor
Loading...
Searching...
No Matches
JServoControllerGentle.h
Go to the documentation of this file.
1#ifndef J_SERVO_CONTROLLER_GENTLE_H
2#define J_SERVO_CONTROLLER_GENTLE_H
3#include "JServoController.h"
9protected:
12 float gripSpeed;
13
14public:
20
28 JServoControllerGentle(JServoControllerAdvanced servo, JServoStallSensing& servoStallSensor, float _targetForce = .05, float _gripSpeed = 30)
30 , stallSensor(servoStallSensor)
31 {
32 gripSpeed = max(_gripSpeed, (float)0);
33 grippingGently = false;
34 gripDirPos = true;
35 targetForce = max(_targetForce, (float)0);
36 }
37
38 virtual void run()
39 {
41 if (grippingGently) {
43 JServoController::setAngleImmediateInc((gripDirPos ? 1.0 : -1.0) * gripSpeed * dL.getTimeInterval(), false);
44 } else if (stallSensor.getMeasurement(false) > targetForce) {
45 JServoController::setAngleImmediateInc((!gripDirPos ? 1.0 : -1.0) * gripSpeed * dL.getTimeInterval(), false);
46 } else {
48 }
49 }
51 }
59 void gripGently(bool _dirPos, float _targetForce = NAN, float _gripSpeed = NAN, bool _run = false)
60 {
61 if (!isnan(_targetForce))
62 targetForce = _targetForce;
63 if (!isnan(_gripSpeed))
64 gripSpeed = _gripSpeed;
65 gripDirPos = _dirPos;
66 grippingGently = true;
67 if (_run)
68 run();
69 }
70
71 void setPosition(float pos, bool _run)
72 {
73 grippingGently = false;
75 }
76 void setAngleImmediate(float angle, bool _run = true)
77 {
78 grippingGently = false;
80 }
81 void setAngleImmediateInc(float angleDiff, bool _run = true)
82 {
83 grippingGently = false;
85 }
86 void setAngleSmoothed(float angle, bool _run = true)
87 {
88 grippingGently = false;
90 }
91};
92#endif
class for controlling JMotorDriverServoAdvanced, with power reducing option along with standard JServ...
Definition JServoControllerAdvanced.h:10
JServoControllerGentle is an extension of JServoController that uses JServoStallSensing to make a ser...
Definition JServoControllerGentle.h:8
void setAngleSmoothed(float angle, bool _run=true)
Definition JServoControllerGentle.h:86
JServoControllerGentle(JServoControllerAdvanced servo, JServoStallSensing &servoStallSensor, float _targetForce=.05, float _gripSpeed=30)
Constructor for JServoController Gentle (a child class of JServoController)
Definition JServoControllerGentle.h:28
float targetForce
Definition JServoControllerGentle.h:11
void setAngleImmediateInc(float angleDiff, bool _run=true)
Definition JServoControllerGentle.h:81
bool gripDirPos
Definition JServoControllerGentle.h:10
float gripSpeed
Definition JServoControllerGentle.h:12
bool grippingGently
true=gripping, false = other servo movmement set
Definition JServoControllerGentle.h:18
void gripGently(bool _dirPos, float _targetForce=NAN, float _gripSpeed=NAN, bool _run=false)
have the servo move until it is pushing with a set amount of force
Definition JServoControllerGentle.h:59
virtual void run()
call this in your main loop
Definition JServoControllerGentle.h:38
JServoStallSensing & stallSensor
Definition JServoControllerGentle.h:19
void setPosition(float pos, bool _run)
Definition JServoControllerGentle.h:71
void setAngleImmediate(float angle, bool _run=true)
Definition JServoControllerGentle.h:76
class for controlling JMotorDriverServo, with angle calibration and accel and velocity limiting
Definition JServoController.h:12
void setPosition(float pos, bool _run=true)
sets servo position, leaves target where it was
Definition JServoController.h:423
void setAngleSmoothed(float angle, bool _run=true)
set servo angle target, servo will move to target but at limited velocity and acceleration
Definition JServoController.h:164
void setAngleImmediate(float angle, bool _run=true)
set servo angle immediately, without velocity or acceleration limiting
Definition JServoController.h:132
virtual void run()
call this in your main loop
Definition JServoController.h:102
void setAngleImmediateInc(float angleDiff, bool _run=true)
increment servo angle and set immediately, without velocity or acceleration limiting
Definition JServoController.h:148
Derivs_Limiter dL
instance of Derivs_Limiter class used to smoothly move servo
Definition JServoController.h:63
JMotorDriverServo & servo
reference to driver that's a subclass of JMotorDriverServo
Definition JServoController.h:17
defines interface for classes that can measure how hard a servo is working
Definition JServoStallSensing.h:7
virtual float getMeasurement(bool _run=true)=0
virtual void run()=0