aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/chelper/kin_polar.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-08-23 14:21:58 -0400
committerKevinOConnor <kevin@koconnor.net>2018-12-24 11:38:59 -0500
commitec9cb3a1b302bddf10bde84fc87ae2a8ad6230b3 (patch)
treeef403d6f16b3a869e25473ba60202e7e85f3bb27 /klippy/chelper/kin_polar.c
parent7e3e02a17ab33b89e633aafce2b0216ec7b35c49 (diff)
downloadkutter-ec9cb3a1b302bddf10bde84fc87ae2a8ad6230b3.tar.gz
kutter-ec9cb3a1b302bddf10bde84fc87ae2a8ad6230b3.tar.xz
kutter-ec9cb3a1b302bddf10bde84fc87ae2a8ad6230b3.zip
polar: Experimental support for polar kinematics
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/chelper/kin_polar.c')
-rw-r--r--klippy/chelper/kin_polar.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/klippy/chelper/kin_polar.c b/klippy/chelper/kin_polar.c
new file mode 100644
index 00000000..cc1f2eab
--- /dev/null
+++ b/klippy/chelper/kin_polar.c
@@ -0,0 +1,41 @@
+// Polar kinematics stepper pulse time generation
+//
+// Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include <math.h> // sqrt
+#include <stdlib.h> // malloc
+#include <string.h> // memset
+#include "compiler.h" // __visible
+#include "itersolve.h" // struct stepper_kinematics
+
+static double
+polar_stepper_radius_calc_position(struct stepper_kinematics *sk, struct move *m
+ , double move_time)
+{
+ struct coord c = move_get_coord(m, move_time);
+ return sqrt(c.x*c.x + c.y*c.y);
+}
+
+static double
+polar_stepper_angle_calc_position(struct stepper_kinematics *sk, struct move *m
+ , double move_time)
+{
+ struct coord c = move_get_coord(m, move_time);
+ // XXX - handle x==y==0
+ // XXX - handle angle wrapping
+ return atan2(c.y, c.x);
+}
+
+struct stepper_kinematics * __visible
+polar_stepper_alloc(char type)
+{
+ struct stepper_kinematics *sk = malloc(sizeof(*sk));
+ memset(sk, 0, sizeof(*sk));
+ if (type == 'r')
+ sk->calc_position = polar_stepper_radius_calc_position;
+ else if (type == 'a')
+ sk->calc_position = polar_stepper_angle_calc_position;
+ return sk;
+}