mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-30 15:26:18 +00:00
🩹 Clarify servo µs min/max
This commit is contained in:
parent
cb291e8d00
commit
85ded0b9bd
@ -60,8 +60,8 @@
|
|||||||
ServoInfo_t servo_info[MAX_SERVOS]; // static array of servo info structures
|
ServoInfo_t servo_info[MAX_SERVOS]; // static array of servo info structures
|
||||||
uint8_t ServoCount = 0; // the total number of attached servos
|
uint8_t ServoCount = 0; // the total number of attached servos
|
||||||
|
|
||||||
#define SERVO_MIN(v) (MIN_PULSE_WIDTH - (v) * 4) // minimum value in uS for this servo
|
#define SERVO_MIN_US(v) (MIN_PULSE_WIDTH - (v) * 4) // minimum value in uS for this servo
|
||||||
#define SERVO_MAX(v) (MAX_PULSE_WIDTH - (v) * 4) // maximum value in uS for this servo
|
#define SERVO_MAX_US(v) (MAX_PULSE_WIDTH - (v) * 4) // maximum value in uS for this servo
|
||||||
|
|
||||||
/************ static functions common to all instances ***********************/
|
/************ static functions common to all instances ***********************/
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ void Servo::detach() {
|
|||||||
|
|
||||||
void Servo::write(int value) {
|
void Servo::write(int value) {
|
||||||
if (value < MIN_PULSE_WIDTH) // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
|
if (value < MIN_PULSE_WIDTH) // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
|
||||||
value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN(min), SERVO_MAX(max));
|
value = map(constrain(value, 0, 180), 0, 180, SERVO_MIN_US(min), SERVO_MAX_US(max));
|
||||||
writeMicroseconds(value);
|
writeMicroseconds(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +126,8 @@ void Servo::writeMicroseconds(int value) {
|
|||||||
byte channel = servoIndex;
|
byte channel = servoIndex;
|
||||||
if (channel < MAX_SERVOS) { // ensure channel is valid
|
if (channel < MAX_SERVOS) { // ensure channel is valid
|
||||||
// ensure pulse width is valid
|
// ensure pulse width is valid
|
||||||
value = constrain(value, SERVO_MIN(min), SERVO_MAX(max)) - (TRIM_DURATION);
|
LIMIT(value, SERVO_MIN_US(min), SERVO_MAX_US(max));
|
||||||
value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
|
value = usToTicks(value - (TRIM_DURATION)); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009
|
||||||
|
|
||||||
CRITICAL_SECTION_START();
|
CRITICAL_SECTION_START();
|
||||||
servo_info[channel].ticks = value;
|
servo_info[channel].ticks = value;
|
||||||
@ -136,7 +136,7 @@ void Servo::writeMicroseconds(int value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return the value as degrees
|
// return the value as degrees
|
||||||
int Servo::read() { return map(readMicroseconds() + 1, SERVO_MIN(min), SERVO_MAX(max), 0, 180); }
|
int Servo::read() { return map(readMicroseconds() + 1, SERVO_MIN_US(min), SERVO_MAX_US(max), 0, 180); }
|
||||||
|
|
||||||
int Servo::readMicroseconds() {
|
int Servo::readMicroseconds() {
|
||||||
return (servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[servoIndex].ticks) + (TRIM_DURATION);
|
return (servoIndex == INVALID_SERVO) ? 0 : ticksToUs(servo_info[servoIndex].ticks) + (TRIM_DURATION);
|
||||||
|
Loading…
Reference in New Issue
Block a user