diff --git a/config.h b/config.h index e869cba..7c150b9 100644 --- a/config.h +++ b/config.h @@ -32,6 +32,10 @@ #define STEP_RATIO_X (6432 / M_PI) #define STEP_RATIO_Y (6432 / M_PI) +// Offset between home and zero [step] +#define ZERO_OFFSET_X (0) +#define ZERO_OFFSET_Y (2500) + // Offset between turret and lidar [cm] #define OFFSET_X (0) #define OFFSET_Y (21) diff --git a/turret.cpp b/turret.cpp index fc570ed..bf4c705 100644 --- a/turret.cpp +++ b/turret.cpp @@ -3,8 +3,8 @@ #include "maths.h" #include -Turret::Turret(StepRatio step_ratio, Offset offset, PinMap pin_map_x, - PinMap pin_map_y) +Turret::Turret(StepRatio step_ratio, Offset offset, ZeroOffset zero_offset, + PinMap pin_map_x, PinMap pin_map_y) : _stepper(kissStepper(static_cast(pin_map_x.direction), static_cast(pin_map_x.pulse), static_cast(pin_map_x.enable)), @@ -16,6 +16,7 @@ Turret::Turret(StepRatio step_ratio, Offset offset, PinMap pin_map_x, _pin.y = pin_map_y; _step_ratio = step_ratio; _offset = offset; + _zero_offset = zero_offset; } Turret::~Turret() { @@ -79,9 +80,8 @@ Turret &Turret::gotoHome() { } Turret &Turret::gotoZero() { - // TODO remove magic numbers - _stepper.x.prepareMove(_home.x + 0); - _stepper.y.prepareMove(_home.y + 2500); + _stepper.x.prepareMove(_home.x + _zero_offset.x); + _stepper.y.prepareMove(_home.y + _zero_offset.y); bool xStop = false; bool yStop = false; diff --git a/turret.h b/turret.h index e5cefb5..fed92cb 100644 --- a/turret.h +++ b/turret.h @@ -30,6 +30,8 @@ public: // y -> laser to stand // z -> unused + using ZeroOffset = vec2; + struct PinMap { int home; int direction; @@ -38,8 +40,8 @@ public: int laser; }; - Turret(StepRatio step_ratio, Offset offset, PinMap pin_map_x, - PinMap pin_map_y); + Turret(StepRatio step_ratio, Offset offset, ZeroOffset zero_offset, + PinMap pin_map_x, PinMap pin_map_y); ~Turret(); Turret &init(); @@ -74,6 +76,7 @@ private: vec2 _pin; StepRatio _step_ratio; Offset _offset; + ZeroOffset _zero_offset; }; #endif diff --git a/turret_debug.ino b/turret_debug.ino index 6806f71..2a3c56a 100644 --- a/turret_debug.ino +++ b/turret_debug.ino @@ -19,8 +19,9 @@ Turret::PinMap pinY = { Turret::StepRatio stepRatio(STEP_RATIO_X, STEP_RATIO_Y); Turret::Offset offset(OFFSET_X, OFFSET_Y, OFFSET_Z); +Turret::ZeroOffset zeroOffset(ZERO_OFFSET_X, ZERO_OFFSET_Y); -Turret turret(stepRatio, offset, pinX, pinY); +Turret turret(stepRatio, offset, zeroOffset, pinX, pinY); void setup() { turret.init();