polar: Implement bed angle wrapping adjustments in chelper code

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-10-27 11:14:40 -04:00
parent 92993c062b
commit 374eb98765
4 changed files with 19 additions and 10 deletions

View File

@ -206,6 +206,8 @@ itersolve_gen_steps(struct stepper_kinematics *sk, struct move *m)
} }
queue_append_finish(qa); queue_append_finish(qa);
sk->commanded_pos = last.position; sk->commanded_pos = last.position;
if (sk->post_cb)
sk->post_cb(sk);
return 0; return 0;
} }

View File

@ -32,10 +32,12 @@ struct coord move_get_coord(struct move *m, double move_time);
struct stepper_kinematics; struct stepper_kinematics;
typedef double (*sk_calc_callback)(struct stepper_kinematics *sk, struct move *m typedef double (*sk_calc_callback)(struct stepper_kinematics *sk, struct move *m
, double move_time); , double move_time);
typedef void (*sk_post_callback)(struct stepper_kinematics *sk);
struct stepper_kinematics { struct stepper_kinematics {
double step_dist, commanded_pos; double step_dist, commanded_pos;
struct stepcompress *sc; struct stepcompress *sc;
sk_calc_callback calc_position_cb; sk_calc_callback calc_position_cb;
sk_post_callback post_cb;
}; };
int32_t itersolve_gen_steps(struct stepper_kinematics *sk, struct move *m); int32_t itersolve_gen_steps(struct stepper_kinematics *sk, struct move *m);

View File

@ -32,14 +32,26 @@ polar_stepper_angle_calc_position(struct stepper_kinematics *sk, struct move *m
return angle; return angle;
} }
static void
polar_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;
}
struct stepper_kinematics * __visible struct stepper_kinematics * __visible
polar_stepper_alloc(char type) polar_stepper_alloc(char type)
{ {
struct stepper_kinematics *sk = malloc(sizeof(*sk)); struct stepper_kinematics *sk = malloc(sizeof(*sk));
memset(sk, 0, sizeof(*sk)); memset(sk, 0, sizeof(*sk));
if (type == 'r') if (type == 'r') {
sk->calc_position_cb = polar_stepper_radius_calc_position; sk->calc_position_cb = polar_stepper_radius_calc_position;
else if (type == 'a') } else if (type == 'a') {
sk->calc_position_cb = polar_stepper_angle_calc_position; sk->calc_position_cb = polar_stepper_angle_calc_position;
sk->post_cb = polar_stepper_angle_post_fixup;
}
return sk; return sk;
} }

View File

@ -120,14 +120,7 @@ class PolarKinematics:
cmove = move.cmove cmove = move.cmove
if axes_d[0] or axes_d[1]: if axes_d[0] or axes_d[1]:
self.rails[0].step_itersolve(cmove) self.rails[0].step_itersolve(cmove)
stepper_bed = self.steppers[0] self.steppers[0].step_itersolve(cmove)
stepper_bed.step_itersolve(cmove)
# Normalize the stepper_bed angle
angle = stepper_bed.get_commanded_position()
if angle < -math.pi:
stepper_bed.set_commanded_position(angle + 2. * math.pi)
elif angle > math.pi:
stepper_bed.set_commanded_position(angle - 2. * math.pi)
if axes_d[2]: if axes_d[2]:
self.rails[1].step_itersolve(cmove) self.rails[1].step_itersolve(cmove)
def get_status(self): def get_status(self):