JMotor
Loading...
Searching...
No Matches
JMotorCompBasic.h
Go to the documentation of this file.
1#ifndef J_MOTOR_COMP_BASIC_H
2#define J_MOTOR_COMP_BASIC_H
3#include "JMotorCompensator.h"
5#include <Arduino.h>
10private:
11 JVoltageCompensator& voltComp;
12 float multiplier;
13 float minSpeed;
14
15public:
22 JMotorCompBasic(JVoltageCompensator& _voltComp, float _voltsPerSpeed, float _minSpeed)
23 : voltComp(_voltComp)
24 {
25 multiplier = _voltsPerSpeed;
26 minSpeed = abs(_minSpeed);
27 }
28 float compensate(float val)
29 {
30 if (val == 0 || abs(val) < minSpeed) {
31 return 0;
32 }
33 return constrain(voltComp.adjust(val * multiplier, driverRange), -maxDriverRange, maxDriverRange);
34 }
35 float getMaxVel()
36 {
37 return voltComp.getSupplyVoltage() / multiplier;
38 }
39 float getMinVel()
40 {
41 return minSpeed;
42 }
43
44 void setVoltsPerSpeed(float _voltsPerSpeed)
45 {
46 multiplier = _voltsPerSpeed;
47 }
49 {
50 return multiplier;
51 }
52 void setMinSpeed(float _speed)
53 {
54 minSpeed = abs(_speed);
55 }
56};
57#endif
Converts from speed to driver input compensating for variable supply voltage.
Definition JMotorCompBasic.h:9
JMotorCompBasic(JVoltageCompensator &_voltComp, float _voltsPerSpeed, float _minSpeed)
Converts from speed to driver input compensating for variable supply voltage.
Definition JMotorCompBasic.h:22
float getMaxVel()
How fast of a motor speed setting would get adjusted to full motor power.
Definition JMotorCompBasic.h:35
void setMinSpeed(float _speed)
Definition JMotorCompBasic.h:52
float getVoltsPerSpeed()
Definition JMotorCompBasic.h:48
float getMinVel()
Slowest speed motor can go.
Definition JMotorCompBasic.h:39
void setVoltsPerSpeed(float _voltsPerSpeed)
Definition JMotorCompBasic.h:44
float compensate(float val)
calculate
Definition JMotorCompBasic.h:28
This class defines a common interface for converting from speed to driver input. It should compensate...
Definition JMotorCompensator.h:9
float maxDriverRange
Definition JMotorCompensator.h:12
float driverRange
Definition JMotorCompensator.h:11
convert voltage to value needed to set driver at to get that voltage
Definition JVoltageCompensator.h:7
virtual float getSupplyVoltage()
virtual float adjust(float voltage, float driverRange)
do conversion