Skip to content

Commit

Permalink
add PolarXZ kinematics
Browse files Browse the repository at this point in the history
  • Loading branch information
bwnance committed Jan 7, 2024
1 parent 64fff4e commit 72a8ad7
Show file tree
Hide file tree
Showing 20 changed files with 2,591 additions and 43 deletions.
74 changes: 74 additions & 0 deletions config/example-polarxz.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This file is an example config file for polar style printers. One
# may copy and edit this file to configure a new polar printer.

# POLAR KINEMATICS ARE A WORK IN PROGRESS. Moves around the 0, 0
# position are known to not work properly.

# See docs/Config_Reference.md for a description of parameters.

[stepper_bed]
step_pin: PF0
dir_pin: PF1
enable_pin: !PD7
microsteps: 16
gear_ratio: 80:16

[stepper_x]
step_pin: PF6
dir_pin: PF7
enable_pin: !PF2
microsteps: 16
rotation_distance: 40
endstop_pin: ^PJ1
position_endstop: 300
position_max: 300
homing_speed: 50

[stepper_z]
step_pin: PL3
dir_pin: PL1
enable_pin: !PK0
microsteps: 16
rotation_distance: 8
endstop_pin: ^PD3
position_endstop: 0.5
position_max: 200

[extruder]
step_pin: PA4
dir_pin: PA6
enable_pin: !PA2
microsteps: 16
rotation_distance: 33.500
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PB4
sensor_type: ATC Semitec 104GT-2
sensor_pin: PK5
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 250

[heater_bed]
heater_pin: PH5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK6
control: watermark
min_temp: 0
max_temp: 130

[fan]
pin: PH6

[mcu]
serial: /dev/ttyACM0

[printer]
kinematics: polarxz
max_velocity: 300
max_accel: 3000
max_z_velocity: 25
max_z_accel: 30
14 changes: 14 additions & 0 deletions klippy/chelper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"kin_delta.c",
"kin_deltesian.c",
"kin_polar.c",
"kin_polarxz.c",
"kin_polarbed.c",
"kin_rotary_delta.c",
"kin_winch.c",
"kin_extruder.c",
Expand Down Expand Up @@ -149,6 +151,14 @@
struct stepper_kinematics *polar_stepper_alloc(char type);
"""

defs_kin_polarxz = """
struct stepper_kinematics *polarxz_stepper_alloc(char type);
"""

defs_kin_polarbed = """
struct stepper_kinematics *polarbed_stepper_alloc(char type);
"""

defs_kin_rotary_delta = """
struct stepper_kinematics *rotary_delta_stepper_alloc(
double shoulder_radius, double shoulder_height
Expand Down Expand Up @@ -251,13 +261,16 @@
defs_kin_delta,
defs_kin_deltesian,
defs_kin_polar,
defs_kin_polarxz,
defs_kin_polarbed,
defs_kin_rotary_delta,
defs_kin_winch,
defs_kin_extruder,
defs_kin_shaper,
defs_kin_idex,
]


# Update filenames to an absolute path
def get_abs_files(srcdir, filelist):
return [os.path.join(srcdir, fname) for fname in filelist]
Expand Down Expand Up @@ -305,6 +318,7 @@ def do_build_code(cmd):
FFI_lib = None
pyhelper_logging_callback = None


# Hepler invoked from C errorf() code to log errors
def logging_callback(msg):
logging.error(FFI_main.string(msg))
Expand Down
1 change: 1 addition & 0 deletions klippy/chelper/itersolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ itersolve_gen_steps_range(struct stepper_kinematics *sk, struct move *m
continue;
}
}

// Found next step - submit it
int ret = stepcompress_append(sk->sc, sdir, m->print_time, guess.time);
if (ret)
Expand Down
34 changes: 34 additions & 0 deletions klippy/chelper/kin_polarbed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <math.h> // sqrt
#include <stdlib.h> // malloc
#include <string.h> // memset
#include "compiler.h" // __visible
#include "itersolve.h" // struct stepper_kinematics
#include "trapq.h" // move_get_coord
#include "pyhelper.h" // errorf

static double
polarbed_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
if (c.x == 0 && c.y == 0)
errorf("polarbed_stepper_angle_calc_position: x==y==0");

double angle = atan2(c.y, c.x);

errorf("polarbed_stepper_angle_calc_position: x=%f y=%f angle=%f", c.x, c.y, angle * 180.0 / 3.14159);

return angle;
}

struct stepper_kinematics *__visible
polarbed_stepper_alloc(char type)
{
struct stepper_kinematics *sk = malloc(sizeof(*sk));
memset(sk, 0, sizeof(*sk));
sk->calc_position_cb = polarbed_stepper_angle_calc_position;
sk->active_flags = AF_X | AF_Y;

return sk;
}
76 changes: 76 additions & 0 deletions klippy/chelper/kin_polarxz.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <math.h> // sqrt
#include <stdlib.h> // malloc
#include <string.h> // memset
#include "compiler.h" // __visible
#include "itersolve.h" // struct stepper_kinematics
#include "trapq.h" // move_get_coord

static double
polarxz_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
if (c.x == 0 && c.y == 0)
return 0;
double angle = atan2(c.y, c.x);
if (angle - sk->commanded_pos > M_PI)
angle -= 2.f * M_PI;
else if (angle - sk->commanded_pos < -M_PI)
angle += 2.f * M_PI;
angle = round(angle * 1000000) / 1000000;

return angle;
}

static void
polarxz_stepper_angle_post_fixup(struct stepper_kinematics *sk)
{
// Normalize the stepper_bed angle
if (sk->commanded_pos < -M_PI)
sk->commanded_pos += 2 * M_PI;
else if (sk->commanded_pos > M_PI)
sk->commanded_pos -= 2 * M_PI;
}

static double
polarxz_stepper_plus_calc_position(struct stepper_kinematics *sk, struct move *m, double move_time)
{
struct coord c = move_get_coord(m, move_time);
float pos = (sqrt(c.x * c.x + c.y * c.y)) + c.z;
pos = round(pos * 1000000) / 1000000;
return pos;
}

static double
polarxz_stepper_minus_calc_position(struct stepper_kinematics *sk, struct move *m, double move_time)
{
struct coord c = move_get_coord(m, move_time);
float pos = (sqrt(c.x * c.x + c.y * c.y)) - c.z;
pos = round(pos * 1000000) / 1000000;
return pos;
}

struct stepper_kinematics *__visible
polarxz_stepper_alloc(char type)
{
struct stepper_kinematics *sk = malloc(sizeof(*sk));
memset(sk, 0, sizeof(*sk));
if (type == '+')
{
sk->calc_position_cb = polarxz_stepper_plus_calc_position;
sk->active_flags = AF_X | AF_Y | AF_Z;
}
else if (type == '-')
{
sk->calc_position_cb = polarxz_stepper_minus_calc_position;
sk->active_flags = AF_X | AF_Y | AF_Z;
}
else if (type == 'a')
{
sk->calc_position_cb = polarxz_stepper_angle_calc_position;
sk->post_cb = polarxz_stepper_angle_post_fixup;
sk->active_flags = AF_X | AF_Y;
}

return sk;
}
1 change: 1 addition & 0 deletions klippy/configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ def read_main_config(self):
def check_unused_options(self, config, error_on_unused):
fileconfig = config.fileconfig
objects = dict(self.printer.lookup_objects())
logging.info("objects: %s", objects)
# Determine all the fields that have been accessed
access_tracking = dict(config.access_tracking)
for section in self.autosave.fileconfig.sections():
Expand Down
Loading

0 comments on commit 72a8ad7

Please sign in to comment.