2018-07-13 05:28:58 +02:00
|
|
|
// Cable winch stepper kinematics
|
|
|
|
//
|
2019-10-29 04:35:22 +01:00
|
|
|
// Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net>
|
2018-07-13 05:28:58 +02:00
|
|
|
//
|
|
|
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
|
|
|
#include <math.h> // sqrt
|
|
|
|
#include <stddef.h> // offsetof
|
|
|
|
#include <stdlib.h> // malloc
|
|
|
|
#include <string.h> // memset
|
|
|
|
#include "compiler.h" // __visible
|
|
|
|
#include "itersolve.h" // struct stepper_kinematics
|
2019-10-27 18:23:03 +01:00
|
|
|
#include "trapq.h" // move_get_coord
|
2018-07-13 05:28:58 +02:00
|
|
|
|
|
|
|
struct winch_stepper {
|
|
|
|
struct stepper_kinematics sk;
|
|
|
|
struct coord anchor;
|
|
|
|
};
|
|
|
|
|
|
|
|
static double
|
|
|
|
winch_stepper_calc_position(struct stepper_kinematics *sk, struct move *m
|
|
|
|
, double move_time)
|
|
|
|
{
|
|
|
|
struct winch_stepper *hs = container_of(sk, struct winch_stepper, sk);
|
|
|
|
struct coord c = move_get_coord(m, move_time);
|
|
|
|
double dx = hs->anchor.x - c.x, dy = hs->anchor.y - c.y;
|
|
|
|
double dz = hs->anchor.z - c.z;
|
|
|
|
return sqrt(dx*dx + dy*dy + dz*dz);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stepper_kinematics * __visible
|
|
|
|
winch_stepper_alloc(double anchor_x, double anchor_y, double anchor_z)
|
|
|
|
{
|
|
|
|
struct winch_stepper *hs = malloc(sizeof(*hs));
|
|
|
|
memset(hs, 0, sizeof(*hs));
|
|
|
|
hs->anchor.x = anchor_x;
|
|
|
|
hs->anchor.y = anchor_y;
|
|
|
|
hs->anchor.z = anchor_z;
|
2019-10-27 16:06:46 +01:00
|
|
|
hs->sk.calc_position_cb = winch_stepper_calc_position;
|
2019-10-29 04:35:22 +01:00
|
|
|
hs->sk.active_flags = AF_X | AF_Y | AF_Z;
|
2018-07-13 05:28:58 +02:00
|
|
|
return &hs->sk;
|
|
|
|
}
|