2018-06-06 22:49:44 +02:00
|
|
|
// Delta kinematics stepper pulse time generation
|
|
|
|
//
|
2018-06-09 03:30:38 +02:00
|
|
|
// Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
2018-06-06 22:49:44 +02:00
|
|
|
//
|
|
|
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
|
|
|
#include <math.h> // sqrt
|
2018-06-09 03:30:38 +02:00
|
|
|
#include <stddef.h> // offsetof
|
|
|
|
#include <stdlib.h> // malloc
|
|
|
|
#include <string.h> // memset
|
2018-06-06 22:49:44 +02:00
|
|
|
#include "compiler.h" // __visible
|
2018-06-09 03:30:38 +02:00
|
|
|
#include "itersolve.h" // struct stepper_kinematics
|
2018-06-06 22:49:44 +02:00
|
|
|
|
2018-06-09 03:30:38 +02:00
|
|
|
struct delta_stepper {
|
|
|
|
struct stepper_kinematics sk;
|
|
|
|
double arm2, tower_x, tower_y;
|
|
|
|
};
|
2018-06-06 22:49:44 +02:00
|
|
|
|
2018-06-09 03:30:38 +02:00
|
|
|
static double
|
|
|
|
delta_stepper_calc_position(struct stepper_kinematics *sk, struct move *m
|
|
|
|
, double move_time)
|
|
|
|
{
|
|
|
|
struct delta_stepper *ds = container_of(sk, struct delta_stepper, sk);
|
|
|
|
struct coord c = move_get_coord(m, move_time);
|
|
|
|
double dx = ds->tower_x - c.x, dy = ds->tower_y - c.y;
|
|
|
|
return sqrt(ds->arm2 - dx*dx - dy*dy) + c.z;
|
2018-06-06 22:49:44 +02:00
|
|
|
}
|
|
|
|
|
2018-06-09 03:30:38 +02:00
|
|
|
struct stepper_kinematics * __visible
|
|
|
|
delta_stepper_alloc(double arm2, double tower_x, double tower_y)
|
2018-06-06 22:49:44 +02:00
|
|
|
{
|
2018-06-09 03:30:38 +02:00
|
|
|
struct delta_stepper *ds = malloc(sizeof(*ds));
|
|
|
|
memset(ds, 0, sizeof(*ds));
|
|
|
|
ds->arm2 = arm2;
|
|
|
|
ds->tower_x = tower_x;
|
|
|
|
ds->tower_y = tower_y;
|
2019-10-27 16:06:46 +01:00
|
|
|
ds->sk.calc_position_cb = delta_stepper_calc_position;
|
2018-06-09 03:30:38 +02:00
|
|
|
return &ds->sk;
|
2018-06-06 22:49:44 +02:00
|
|
|
}
|