Polargraph / Makelangelo kinematics (#22790)

This commit is contained in:
Dan Royer
2021-09-20 13:42:33 -07:00
committed by Scott Lahteine
parent 71b8a22d96
commit b3fd03198a
24 changed files with 304 additions and 104 deletions

View File

@ -26,22 +26,44 @@
#include "../gcode.h"
#include "../../module/servo.h"
#include "../../module/planner.h"
/**
* M280: Get or set servo position. P<index> [S<angle>]
* M280: Get or set servo position.
* P<index> - Servo index
* S<angle> - Angle to set, omit to read current angle, or use -1 to detach
*
* With POLARGRAPH:
* T<ms> - Duration of servo move
*/
void GcodeSuite::M280() {
if (!parser.seen('P')) return;
if (!parser.seenval('P')) return;
TERN_(POLARGRAPH, planner.synchronize());
const int servo_index = parser.value_int();
if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
if (parser.seen('S')) {
const int a = parser.value_int();
if (a == -1)
DETACH_SERVO(servo_index);
if (parser.seenval('S')) {
const int anew = parser.value_int();
if (anew >= 0) {
#if ENABLED(POLARGRAPH)
if (parser.seen('T')) { // (ms) Total duration of servo move
const int16_t t = constrain(parser.value_int(), 0, 10000);
const int aold = servo[servo_index].read();
millis_t now = millis();
const millis_t start = now, end = start + t;
while (PENDING(now, end)) {
safe_delay(50);
now = _MIN(millis(), end);
MOVE_SERVO(servo_index, LROUND(aold + (anew - aold) * (float(now - start) / t)));
}
}
#endif // POLARGRAPH
MOVE_SERVO(servo_index, anew);
}
else
MOVE_SERVO(servo_index, a);
DETACH_SERVO(servo_index);
}
else
SERIAL_ECHO_MSG(" Servo ", servo_index, ": ", servo[servo_index].read());

View File

@ -32,7 +32,7 @@
*/
void GcodeSuite::M282() {
if (!parser.seen('P')) return;
if (!parser.seenval('P')) return;
const int servo_index = parser.value_int();
if (WITHIN(servo_index, 0, NUM_SERVOS - 1))