JMotor
Loading...
Searching...
No Matches
JMotorDriverAvrServo.h
Go to the documentation of this file.
1#ifndef J_MOTOR_DRIVER_AVR_SERVO_H
2#define J_MOTOR_DRIVER_AVR_SERVO_H
3#include "JMotorDriverServo.h"
4#include <Arduino.h>
5#include <Servo.h>
11private:
12 bool enabled = false;
13 byte servoPin;
14 Servo motorServo;
15
16public:
24 JMotorDriverAvrServo(byte _servoPin, int _minServoValue = 544, int _maxServoValue = 2400, bool _constrainRange = true)
25 {
26 minServoValue = _minServoValue;
27 maxServoValue = _maxServoValue;
28 enabled = false;
29 servoPin = _servoPin;
30 constrainRange = _constrainRange;
31 }
32 bool set(float _val)
33 {
34 float val;
36 val = constrain(_val, -1.0, 1.0);
37 else
38 val = _val;
39 if (enabled) {
40 if (!motorServo.attached()) {
41 motorServo.attach(servoPin);
42 }
44 motorServo.writeMicroseconds(setMicroseconds);
45 }
46 return abs(_val) < 1.0;
47 }
48 bool setEnable(bool _enable)
49 {
50 if (_enable) {
51 if (!enabled) {
52 // actually enable
53 enabled = true;
54 return true;
55 }
56 } else { // disable
57 if (enabled) {
58 // actually disable
59 motorServo.detach();
60 enabled = false;
61 return true;
62 }
63 }
64 return false;
65 }
66 bool getEnable()
67 {
68 return enabled;
69 }
71 {
72 return 1.0;
73 }
75 {
76 return -1.0;
77 }
78};
79#endif
wraps standard servo library. For servos and motor controllers that use servo signals (ESCs)
Definition JMotorDriverAvrServo.h:10
bool setEnable(bool _enable)
use to enable or disable a motor, and sets up pin states
Definition JMotorDriverAvrServo.h:48
JMotorDriverAvrServo(byte _servoPin, int _minServoValue=544, int _maxServoValue=2400, bool _constrainRange=true)
constructor, sets pins
Definition JMotorDriverAvrServo.h:24
bool getEnable()
get the enable state of the driver
Definition JMotorDriverAvrServo.h:66
bool set(float _val)
set motor power
Definition JMotorDriverAvrServo.h:32
float getMaxRange()
high end of the range
Definition JMotorDriverAvrServo.h:70
float getMinRange()
low end of the range
Definition JMotorDriverAvrServo.h:74
class that can be used to specify a driver that controls specifically a servo
Definition JMotorDriverServo.h:8
int maxServoValue
Definition JMotorDriverServo.h:11
bool constrainRange
Definition JMotorDriverServo.h:16
int setMicroseconds
Definition JMotorDriverServo.h:15
int minServoValue
Definition JMotorDriverServo.h:10