style: apply fmt with clang-format
This commit is contained in:
parent
3ef45566d5
commit
5575f0cb3c
12
maths.cpp
12
maths.cpp
|
|
@ -3,13 +3,9 @@
|
||||||
// rollH atan((22.5 - 18.5) / 236) ~0.97°
|
// rollH atan((22.5 - 18.5) / 236) ~0.97°
|
||||||
// rollV ~1°
|
// rollV ~1°
|
||||||
|
|
||||||
double degToRad(double deg) {
|
double degToRad(double deg) { return deg * M_PI / 180.0; }
|
||||||
return deg * M_PI / 180.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double radToDeg(double rad) {
|
double radToDeg(double rad) { return rad * 180.0 / M_PI; }
|
||||||
return rad * 180.0 / M_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
void angleToStep(long &stepX, long &stepY, double angleX, double angleY) {
|
void angleToStep(long &stepX, long &stepY, double angleX, double angleY) {
|
||||||
// TODO remove magic numbers
|
// TODO remove magic numbers
|
||||||
|
|
@ -25,7 +21,8 @@ double rollCorrection(double x, double max, double width) {
|
||||||
return x - correction;
|
return x - correction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cartesianToPolar(long &stepX, long &stepY, double zeroX, double zeroY, double x, double y, double z) {
|
void cartesianToPolar(long &stepX, long &stepY, double zeroX, double zeroY,
|
||||||
|
double x, double y, double z) {
|
||||||
// TODO remove magic numbers
|
// TODO remove magic numbers
|
||||||
double distance = 166.0; // turret to screen
|
double distance = 166.0; // turret to screen
|
||||||
double offsetY = 21.0; // laser to stand
|
double offsetY = 21.0; // laser to stand
|
||||||
|
|
@ -36,7 +33,6 @@ void cartesianToPolar(long &stepX, long &stepY, double zeroX, double zeroY, doub
|
||||||
double dY = rollCorrection(y + offsetY, 0.2, 400.0);
|
double dY = rollCorrection(y + offsetY, 0.2, 400.0);
|
||||||
double dZ = z + distance;
|
double dZ = z + distance;
|
||||||
|
|
||||||
|
|
||||||
double roll = atan2(4.0, 236.0);
|
double roll = atan2(4.0, 236.0);
|
||||||
double rollY = dX * tan(roll);
|
double rollY = dX * tan(roll);
|
||||||
double rollX = dY * tan(roll);
|
double rollX = dY * tan(roll);
|
||||||
|
|
|
||||||
3
maths.h
3
maths.h
|
|
@ -1,4 +1,5 @@
|
||||||
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(long &stepX, long &stepY, double angleX, double angleY);
|
||||||
void cartesianToPolar(long &stepX, long &stepY, double zeroX, double zeroY, double x, double y, double z);
|
void cartesianToPolar(long &stepX, long &stepY, double zeroX, double zeroY,
|
||||||
|
double x, double y, double z);
|
||||||
|
|
|
||||||
49
turret.cpp
49
turret.cpp
|
|
@ -1,12 +1,13 @@
|
||||||
#include <kissStepper.h>
|
|
||||||
#include "config.h"
|
|
||||||
#include "turret.h"
|
#include "turret.h"
|
||||||
|
#include "config.h"
|
||||||
#include "maths.h"
|
#include "maths.h"
|
||||||
|
#include <kissStepper.h>
|
||||||
|
|
||||||
Turret::Turret(
|
Turret::Turret(int pin_x_direction, int pin_x_pulse, int pin_x_enable,
|
||||||
int pin_x_direction, int pin_x_pulse, int pin_x_enable, int pin_x_home,
|
int pin_x_home, int pin_y_direction, int pin_y_pulse,
|
||||||
int pin_y_direction, int pin_y_pulse, int pin_y_enable, int pin_y_home,
|
int pin_y_enable, int pin_y_home, int pin_laser)
|
||||||
int pin_laser) : _stepperX(pin_x_direction, pin_x_pulse, pin_x_enable), _stepperY(pin_y_direction, pin_y_pulse, pin_y_enable) {
|
: _stepperX(pin_x_direction, pin_x_pulse, pin_x_enable),
|
||||||
|
_stepperY(pin_y_direction, pin_y_pulse, pin_y_enable) {
|
||||||
|
|
||||||
_pin_x_direction = pin_x_direction;
|
_pin_x_direction = pin_x_direction;
|
||||||
_pin_x_pulse = pin_x_pulse;
|
_pin_x_pulse = pin_x_pulse;
|
||||||
|
|
@ -80,9 +81,12 @@ Turret& Turret::gotoZero() {
|
||||||
bool yStop = false;
|
bool yStop = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (xStop && yStop) break;
|
if (xStop && yStop)
|
||||||
if (!xStop) xStop = _stepperY.move() == STATE_STOPPED;
|
break;
|
||||||
if (!yStop) yStop = _stepperX.move() == STATE_STOPPED;
|
if (!xStop)
|
||||||
|
xStop = _stepperY.move() == STATE_STOPPED;
|
||||||
|
if (!yStop)
|
||||||
|
yStop = _stepperX.move() == STATE_STOPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
_zeroX = _stepperX.getPos();
|
_zeroX = _stepperX.getPos();
|
||||||
|
|
@ -102,7 +106,8 @@ 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, z / 10.0);
|
cartesianToPolar(stepX, stepY, _zeroX, _zeroY, x / 10.0, y / 10.0,
|
||||||
|
z / 10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit == Unit::CM) {
|
if (unit == Unit::CM) {
|
||||||
|
|
@ -110,7 +115,8 @@ Turret& Turret::moveTo(double x, double y, double z, Unit unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit == Unit::M) {
|
if (unit == Unit::M) {
|
||||||
cartesianToPolar(stepX, stepY, _zeroX, _zeroY, x * 100.0, y * 100.0, z * 100.0);
|
cartesianToPolar(stepX, stepY, _zeroX, _zeroY, x * 100.0, y * 100.0,
|
||||||
|
z * 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit == Unit::STEP) {
|
if (unit == Unit::STEP) {
|
||||||
|
|
@ -134,9 +140,12 @@ Turret& Turret::moveTo(double x, double y, double z, Unit unit) {
|
||||||
bool yStop = false;
|
bool yStop = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (xStop && yStop) break;
|
if (xStop && yStop)
|
||||||
if (!xStop) xStop = _stepperX.move() == STATE_STOPPED;
|
break;
|
||||||
if (!yStop) yStop = _stepperY.move() == STATE_STOPPED;
|
if (!xStop)
|
||||||
|
xStop = _stepperX.move() == STATE_STOPPED;
|
||||||
|
if (!yStop)
|
||||||
|
yStop = _stepperY.move() == STATE_STOPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentX = x;
|
_currentX = x;
|
||||||
|
|
@ -177,17 +186,11 @@ Turret& Turret::moveToZ(double z, Unit unit) {
|
||||||
return moveTo(_currentX, _currentY, z, unit);
|
return moveTo(_currentX, _currentY, z, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
Turret& Turret::moveByX(double x, Unit unit) {
|
Turret &Turret::moveByX(double x, Unit unit) { return moveBy(x, 0, 0, unit); }
|
||||||
return moveBy(x, 0, 0, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
Turret& Turret::moveByY(double y, Unit unit) {
|
Turret &Turret::moveByY(double y, Unit unit) { return moveTo(0, y, 0, unit); }
|
||||||
return moveTo(0, y, 0, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
Turret& Turret::moveByZ(double z, Unit unit) {
|
Turret &Turret::moveByZ(double z, Unit unit) { return moveTo(0, 0, z, unit); }
|
||||||
return moveTo(0, 0, z, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
Turret &Turret::getPosition(double &x, double &y, double &z, Unit unit) {
|
Turret &Turret::getPosition(double &x, double &y, double &z, Unit unit) {
|
||||||
// TODO implement
|
// TODO implement
|
||||||
|
|
|
||||||
17
turret.h
17
turret.h
|
|
@ -5,21 +5,11 @@
|
||||||
|
|
||||||
class Turret {
|
class Turret {
|
||||||
public:
|
public:
|
||||||
|
enum Unit { MM, CM, M, RAD, DEG, STEP };
|
||||||
|
|
||||||
enum Unit {
|
Turret(int pin_x_direction, int pin_x_pulse, int pin_x_enable, int pin_x_home,
|
||||||
MM,
|
|
||||||
CM,
|
|
||||||
M,
|
|
||||||
RAD,
|
|
||||||
DEG,
|
|
||||||
STEP
|
|
||||||
};
|
|
||||||
|
|
||||||
Turret(
|
|
||||||
int pin_x_direction, 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_y_direction, int pin_y_pulse, int pin_y_enable, int pin_y_home,
|
||||||
int pin_laser
|
int pin_laser);
|
||||||
);
|
|
||||||
|
|
||||||
Turret &init();
|
Turret &init();
|
||||||
Turret &gotoHome();
|
Turret &gotoHome();
|
||||||
|
|
@ -46,7 +36,6 @@ class Turret {
|
||||||
Turret &laserOff();
|
Turret &laserOff();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
kissStepper _stepperX;
|
kissStepper _stepperX;
|
||||||
kissStepper _stepperY;
|
kissStepper _stepperY;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "turret.h"
|
#include "turret.h"
|
||||||
|
|
||||||
Turret turret(
|
Turret turret(PIN_X_DIRECTION, PIN_X_PULSE, PIN_X_ENABLE, PIN_X_HOME,
|
||||||
PIN_X_DIRECTION, PIN_X_PULSE, PIN_X_ENABLE, PIN_X_HOME,
|
|
||||||
PIN_Y_DIRECTION, PIN_Y_PULSE, PIN_Y_ENABLE, PIN_Y_HOME,
|
PIN_Y_DIRECTION, PIN_Y_PULSE, PIN_Y_ENABLE, PIN_Y_HOME,
|
||||||
PIN_LASER
|
PIN_LASER);
|
||||||
);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
turret.init();
|
turret.init();
|
||||||
|
|
@ -95,6 +93,4 @@ void setup() {
|
||||||
turret.gotoZero();
|
turret.gotoZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue