klipper/klippy/chelper/kin_idex.c
Dmitry Butyugin cc6736c3e3
kinematics: Generic Cartesian kinematics implementation (#6815)
* tests: Added a regression test for generic_cartesian kinematics

* kinematics: An intial implementation of generic_cartesian kinematics

* generic_cartesian: Refactored kinematics configuration API

* generic_cartesian: Use stepper instead of kinematic_stepper in configs

* generic_cartesian: Added SET_STEPPER_KINEMATICS command

* generic_cartesian: Fixed parsing of section names

* docs: Generic Caretsian kinematics documentation and config samples

* generic_cartesian: Implemented multi-mcu homing validation

* generic_cartesian: Fixed typos in docs, minor fixes

* generic_cartesian: Renamed `kinematics` option to `carriages`

* generic_cartesian: Moved kinematic_stepper.py file

* idex_modes: Internal refactoring of handling dual carriages

* stepper: Refactored the code to not store a reference to config object

* config: Updated example-generic-cartesian config

* generic_cartesian: Restricted SET_STEPPER_CARRIAGES and exported status

* idex_modes: Fixed handling stepper kinematics with input shaper enabled

* config: Updated configs and tests for SET_DUAL_CARRIAGE new params

* generic_cartesian: Avoid inheritance in the added classes

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
2025-05-06 18:06:36 -04:00

83 lines
2.5 KiB
C

// Idex dual carriage kinematics
//
// Copyright (C) 2023 Dmitry Butyugin <dmbutyugin@google.com>
//
// This file may be distributed under the terms of the GNU GPLv3 license.
#include <stddef.h> // offsetof
#include <stdlib.h> // malloc
#include <string.h> // memset
#include "compiler.h" // __visible
#include "itersolve.h" // struct stepper_kinematics
#include "trapq.h" // struct move
#define DUMMY_T 500.0
struct dual_carriage_stepper {
struct stepper_kinematics sk;
struct stepper_kinematics *orig_sk;
struct move m;
double x_scale, x_offs, y_scale, y_offs;
};
double
dual_carriage_calc_position(struct stepper_kinematics *sk, struct move *m
, double move_time)
{
struct dual_carriage_stepper *dc = container_of(
sk, struct dual_carriage_stepper, sk);
struct coord pos = move_get_coord(m, move_time);
dc->m.start_pos.x = pos.x * dc->x_scale + dc->x_offs;
dc->m.start_pos.y = pos.y * dc->y_scale + dc->y_offs;
dc->m.start_pos.z = pos.z;
return dc->orig_sk->calc_position_cb(dc->orig_sk, &dc->m, DUMMY_T);
}
void __visible
dual_carriage_set_sk(struct stepper_kinematics *sk
, struct stepper_kinematics *orig_sk)
{
struct dual_carriage_stepper *dc = container_of(
sk, struct dual_carriage_stepper, sk);
dc->sk.calc_position_cb = dual_carriage_calc_position;
dc->sk.active_flags = orig_sk->active_flags;
dc->orig_sk = orig_sk;
}
int __visible
dual_carriage_set_transform(struct stepper_kinematics *sk, char axis
, double scale, double offs)
{
struct dual_carriage_stepper *dc = container_of(
sk, struct dual_carriage_stepper, sk);
if (axis == 'x') {
dc->x_scale = scale;
dc->x_offs = offs;
if (!scale)
dc->sk.active_flags &= ~AF_X;
else if (scale && dc->orig_sk->active_flags & AF_X)
dc->sk.active_flags |= AF_X;
return 0;
}
if (axis == 'y') {
dc->y_scale = scale;
dc->y_offs = offs;
if (!scale)
dc->sk.active_flags &= ~AF_Y;
else if (scale && dc->orig_sk->active_flags & AF_Y)
dc->sk.active_flags |= AF_Y;
return 0;
}
return -1;
}
struct stepper_kinematics * __visible
dual_carriage_alloc(void)
{
struct dual_carriage_stepper *dc = malloc(sizeof(*dc));
memset(dc, 0, sizeof(*dc));
dc->m.move_t = 2. * DUMMY_T;
dc->x_scale = dc->y_scale = 1.0;
return &dc->sk;
}