feat!: remove magic numbers for step ratios and offsets
This commit is contained in:
parent
4f79010aa2
commit
82ea36bda2
22
maths.cpp
22
maths.cpp
|
|
@ -4,30 +4,24 @@ double degToRad(double deg) { return deg * M_PI / 180.0; }
|
||||||
|
|
||||||
double radToDeg(double rad) { return rad * 180.0 / M_PI; }
|
double radToDeg(double rad) { return rad * 180.0 / M_PI; }
|
||||||
|
|
||||||
void angleToStep(long &stepX, long &stepY, double angleX, double angleY) {
|
void angleToStep(double stepRatioX, double stepRatioY, long &stepX, long &stepY,
|
||||||
// TODO remove magic numbers
|
double angleX, double angleY) {
|
||||||
double stepRatioX = 6000 / M_PI;
|
|
||||||
double stepRatioY = 6500 / M_PI;
|
|
||||||
|
|
||||||
stepX = angleX * stepRatioX;
|
stepX = angleX * stepRatioX;
|
||||||
stepY = angleY * stepRatioY;
|
stepY = angleY * stepRatioY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cartesianToPolar(long &stepX, long &stepY, double zeroX, double zeroY,
|
void cartesianToPolar(double stepRatioX, double stepRatioY, double offsetX,
|
||||||
double x, double y, double z) {
|
double offsetY, double offsetZ, long &stepX, long &stepY,
|
||||||
// TODO remove magic numbers
|
double zeroX, double zeroY, double x, double y,
|
||||||
double distance = 166.0; // turret to screen
|
double z) {
|
||||||
double offsetY = 21.0; // laser to stand
|
|
||||||
double offsetX = 0.0; // unused
|
|
||||||
|
|
||||||
// x = -x; // natural axis direction
|
// x = -x; // natural axis direction
|
||||||
y = -y; // natural axis direction
|
y = -y; // natural axis direction
|
||||||
double dX = x + offsetX;
|
double dX = x + offsetX;
|
||||||
double dY = y + offsetY;
|
double dY = y + offsetY;
|
||||||
double dZ = z + distance;
|
double dZ = z + offsetZ;
|
||||||
|
|
||||||
double angleY = atan2(dZ, dY) - M_PI / 2;
|
double angleY = atan2(dZ, dY) - M_PI / 2;
|
||||||
double angleX = atan2(dZ, dX) - M_PI / 2;
|
double angleX = atan2(dZ, dX) - M_PI / 2;
|
||||||
|
|
||||||
angleToStep(stepX, stepY, angleX, angleY);
|
angleToStep(stepRatioX, stepRatioY, stepX, stepY, angleX, angleY);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
maths.h
8
maths.h
|
|
@ -1,5 +1,7 @@
|
||||||
double degToRad(double deg);
|
double degToRad(double deg);
|
||||||
double radToDeg(double rad);
|
double radToDeg(double rad);
|
||||||
void angleToStep(long &stepX, long &stepY, double angleX, double angleY);
|
void angleToStep(double stepRatioX, double stepRatioY, long &stepX, long &stepY,
|
||||||
void cartesianToPolar(long &stepX, long &stepY, double zeroX, double zeroY,
|
double angleX, double angleY);
|
||||||
double x, double y, double z);
|
void cartesianToPolar(double stepRatioX, double stepRatioY, double offsetX,
|
||||||
|
double offsetY, double offsetZ, long &stepX, long &stepY,
|
||||||
|
double zeroX, double zeroY, double x, double y, double z);
|
||||||
|
|
|
||||||
33
turret.cpp
33
turret.cpp
|
|
@ -3,9 +3,11 @@
|
||||||
#include "maths.h"
|
#include "maths.h"
|
||||||
#include <kissStepper.h>
|
#include <kissStepper.h>
|
||||||
|
|
||||||
Turret::Turret(int pin_x_direction, int pin_x_pulse, int pin_x_enable,
|
Turret::Turret(double stepRatioX, double stepRatioY, double offsetX,
|
||||||
int pin_x_home, int pin_y_direction, int pin_y_pulse,
|
double offsetY, double offsetZ, int pin_x_direction,
|
||||||
int pin_y_enable, int pin_y_home, int pin_laser)
|
int pin_x_pulse, int pin_x_enable, int pin_x_home,
|
||||||
|
int pin_y_direction, int pin_y_pulse, int pin_y_enable,
|
||||||
|
int pin_y_home, int pin_laser)
|
||||||
: _stepperX(pin_x_direction, pin_x_pulse, pin_x_enable),
|
: _stepperX(pin_x_direction, pin_x_pulse, pin_x_enable),
|
||||||
_stepperY(pin_y_direction, pin_y_pulse, pin_y_enable) {
|
_stepperY(pin_y_direction, pin_y_pulse, pin_y_enable) {
|
||||||
|
|
||||||
|
|
@ -20,6 +22,13 @@ Turret::Turret(int pin_x_direction, int pin_x_pulse, int pin_x_enable,
|
||||||
_pin_x_home = pin_x_home;
|
_pin_x_home = pin_x_home;
|
||||||
_pin_y_home = pin_y_home;
|
_pin_y_home = pin_y_home;
|
||||||
_pin_laser = pin_laser;
|
_pin_laser = pin_laser;
|
||||||
|
|
||||||
|
_step_ratio_x = stepRatioX;
|
||||||
|
_step_ratio_y = stepRatioY;
|
||||||
|
|
||||||
|
_offset_x = offsetX;
|
||||||
|
_offset_y = offsetY;
|
||||||
|
_offset_z = offsetZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Turret &Turret::init() {
|
Turret &Turret::init() {
|
||||||
|
|
@ -106,17 +115,20 @@ Turret &Turret::moveTo(double x, double y, double z, Unit unit) {
|
||||||
long stepY;
|
long stepY;
|
||||||
|
|
||||||
if (unit == Unit::MM) {
|
if (unit == Unit::MM) {
|
||||||
cartesianToPolar(stepX, stepY, _zeroX, _zeroY, x / 10.0, y / 10.0,
|
cartesianToPolar(_step_ratio_x, _step_ratio_y, _offset_x, _offset_y,
|
||||||
z / 10.0);
|
_offset_z, stepX, stepY, _zeroX, _zeroY, x / 10.0,
|
||||||
|
y / 10.0, z / 10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit == Unit::CM) {
|
if (unit == Unit::CM) {
|
||||||
cartesianToPolar(stepX, stepY, _zeroX, _zeroY, x, y, z);
|
cartesianToPolar(_step_ratio_x, _step_ratio_y, _offset_x, _offset_y,
|
||||||
|
_offset_z, stepX, stepY, _zeroX, _zeroY, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit == Unit::M) {
|
if (unit == Unit::M) {
|
||||||
cartesianToPolar(stepX, stepY, _zeroX, _zeroY, x * 100.0, y * 100.0,
|
cartesianToPolar(_step_ratio_x, _step_ratio_y, _offset_x, _offset_y,
|
||||||
z * 100.0);
|
_offset_z, stepX, stepY, _zeroX, _zeroY, x * 100.0,
|
||||||
|
y * 100.0, z * 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit == Unit::STEP) {
|
if (unit == Unit::STEP) {
|
||||||
|
|
@ -125,11 +137,12 @@ Turret &Turret::moveTo(double x, double y, double z, Unit unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit == Unit::RAD) {
|
if (unit == Unit::RAD) {
|
||||||
angleToStep(stepX, stepY, x, y);
|
angleToStep(_step_ratio_x, _step_ratio_y, stepX, stepY, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit == Unit::DEG) {
|
if (unit == Unit::DEG) {
|
||||||
angleToStep(stepX, stepY, degToRad(x), degToRad(y));
|
angleToStep(_step_ratio_x, _step_ratio_y, stepX, stepY, degToRad(x),
|
||||||
|
degToRad(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO min(valueI, -_homeI);
|
// TODO min(valueI, -_homeI);
|
||||||
|
|
|
||||||
14
turret.h
14
turret.h
|
|
@ -7,9 +7,10 @@ class Turret {
|
||||||
public:
|
public:
|
||||||
enum Unit { MM, CM, M, RAD, DEG, STEP };
|
enum Unit { MM, CM, M, RAD, DEG, STEP };
|
||||||
|
|
||||||
Turret(int pin_x_direction, int pin_x_pulse, int pin_x_enable, int pin_x_home,
|
Turret(double stepRatioX, double stepRatioY, double offsetX, double offsetY,
|
||||||
int pin_y_direction, int pin_y_pulse, int pin_y_enable, int pin_y_home,
|
double offsetZ, int pin_x_direction, int pin_x_pulse, int pin_x_enable,
|
||||||
int pin_laser);
|
int pin_x_home, int pin_y_direction, int pin_y_pulse, int pin_y_enable,
|
||||||
|
int pin_y_home, int pin_laser);
|
||||||
|
|
||||||
Turret &init();
|
Turret &init();
|
||||||
Turret &gotoHome();
|
Turret &gotoHome();
|
||||||
|
|
@ -60,6 +61,13 @@ private:
|
||||||
int _pin_x_home;
|
int _pin_x_home;
|
||||||
int _pin_y_home;
|
int _pin_y_home;
|
||||||
int _pin_laser;
|
int _pin_laser;
|
||||||
|
|
||||||
|
double _step_ratio_x;
|
||||||
|
double _step_ratio_y;
|
||||||
|
|
||||||
|
double _offset_x; // turret to screen
|
||||||
|
double _offset_y; // laser to stand
|
||||||
|
double _offset_z; // unused
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue