2018-06-06 23:49:44 +03:00
|
|
|
// Cartesian kinematics stepper pulse time generation
|
|
|
|
//
|
2019-10-29 05:45:02 +03:00
|
|
|
// Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net>
|
2018-06-06 23:49:44 +03:00
|
|
|
//
|
|
|
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
2018-06-09 21:30:22 +03:00
|
|
|
#include <stdlib.h> // malloc
|
|
|
|
#include <string.h> // memset
|
2018-06-14 21:01:33 +03:00
|
|
|
#include "compiler.h" // __visible
|
2019-10-27 20:23:03 +03:00
|
|
|
#include "itersolve.h" // struct stepper_kinematics
|
2018-06-06 23:49:44 +03:00
|
|
|
#include "pyhelper.h" // errorf
|
2019-10-27 20:23:03 +03:00
|
|
|
#include "trapq.h" // move_get_coord
|
2018-06-09 21:30:22 +03:00
|
|
|
|
|
|
|
static double
|
|
|
|
cart_stepper_x_calc_position(struct stepper_kinematics *sk, struct move *m
|
|
|
|
, double move_time)
|
|
|
|
{
|
|
|
|
return move_get_coord(m, move_time).x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
|
|
|
cart_stepper_y_calc_position(struct stepper_kinematics *sk, struct move *m
|
|
|
|
, double move_time)
|
|
|
|
{
|
|
|
|
return move_get_coord(m, move_time).y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
|
|
|
cart_stepper_z_calc_position(struct stepper_kinematics *sk, struct move *m
|
|
|
|
, double move_time)
|
|
|
|
{
|
|
|
|
return move_get_coord(m, move_time).z;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stepper_kinematics * __visible
|
|
|
|
cartesian_stepper_alloc(char axis)
|
|
|
|
{
|
|
|
|
struct stepper_kinematics *sk = malloc(sizeof(*sk));
|
|
|
|
memset(sk, 0, sizeof(*sk));
|
2019-10-29 05:45:02 +03:00
|
|
|
if (axis == 'x') {
|
2019-10-27 18:06:46 +03:00
|
|
|
sk->calc_position_cb = cart_stepper_x_calc_position;
|
2019-10-29 05:45:02 +03:00
|
|
|
sk->active_flags = AF_X;
|
|
|
|
} else if (axis == 'y') {
|
2019-10-27 18:06:46 +03:00
|
|
|
sk->calc_position_cb = cart_stepper_y_calc_position;
|
2019-10-29 05:45:02 +03:00
|
|
|
sk->active_flags = AF_Y;
|
|
|
|
} else if (axis == 'z') {
|
2019-10-27 18:06:46 +03:00
|
|
|
sk->calc_position_cb = cart_stepper_z_calc_position;
|
2019-10-29 05:45:02 +03:00
|
|
|
sk->active_flags = AF_Z;
|
|
|
|
}
|
2018-06-09 21:30:22 +03:00
|
|
|
return sk;
|
|
|
|
}
|