Compare commits
10 commits
1c7cdc2f1f
...
e307e96344
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e307e96344 | ||
|
|
5575f0cb3c | ||
|
|
3ef45566d5 | ||
|
|
f605172270 | ||
|
|
b093b54598 | ||
|
|
222fc2b172 | ||
|
|
5f6091a671 | ||
|
|
d759521530 | ||
|
|
6832f350da | ||
|
|
e59fb66c80 |
288
.clang-format
Normal file
288
.clang-format
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
---
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: true
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCaseArrows: false
|
||||
AlignCaseColons: false
|
||||
AlignConsecutiveTableGenBreakingDAGArgColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveTableGenCondOperatorColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveTableGenDefinitionColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
OverEmptyLines: 0
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowBreakBeforeNoexceptSpecifier: Never
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseExpressionOnASingleLine: true
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortNamespacesOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: true
|
||||
BinPackParameters: BinPack
|
||||
BitFieldColonSpacing: Both
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterExternBlock: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakAdjacentStringLiterals: true
|
||||
BreakAfterAttributes: Leave
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakAfterReturnType: None
|
||||
BreakArrays: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInlineASMColon: OnlyMultiline
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakBinaryOperations: Never
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakFunctionDefinitionParameters: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakStringLiterals: true
|
||||
BreakTemplateDeclarations: MultiLine
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IfMacros:
|
||||
- KJ_IF_MAYBE
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: false
|
||||
IndentExportBlock: true
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentRequiresClause: true
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertBraces: false
|
||||
InsertNewlineAtEOF: false
|
||||
InsertTrailingCommas: None
|
||||
IntegerLiteralSeparator:
|
||||
Binary: 0
|
||||
BinaryMinDigits: 0
|
||||
Decimal: 0
|
||||
DecimalMinDigits: 0
|
||||
Hex: 0
|
||||
HexMinDigits: 0
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLines:
|
||||
AtEndOfFile: false
|
||||
AtStartOfBlock: true
|
||||
AtStartOfFile: true
|
||||
KeepFormFeed: false
|
||||
LambdaBodyIndentation: Signature
|
||||
LineEnding: DeriveLF
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MainIncludeChar: Quote
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PackConstructorInitializers: BinPack
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakBeforeMemberAccess: 150
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakScopeResolution: 500
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
PPIndentWidth: -1
|
||||
QualifierAlignment: Leave
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: Always
|
||||
RemoveBracesLLVM: false
|
||||
RemoveEmptyLinesInUnwrappedLines: false
|
||||
RemoveParentheses: Leave
|
||||
RemoveSemicolon: false
|
||||
RequiresClausePosition: OwnLine
|
||||
RequiresExpressionIndentation: OuterScope
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SkipMacroDefinitionBody: false
|
||||
SortIncludes: CaseSensitive
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: LexicographicNumeric
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeJsonColon: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterIfMacros: true
|
||||
AfterOverloadedOperator: false
|
||||
AfterPlacementOperator: true
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Never
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParens: Never
|
||||
SpacesInParensOptions:
|
||||
ExceptDoubleParentheses: false
|
||||
InCStyleCasts: false
|
||||
InConditionalStatements: false
|
||||
InEmptyParentheses: false
|
||||
Other: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TableGenBreakInsideDAGArg: DontBreak
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
VerilogBreakBetweenInstancePorts: true
|
||||
WhitespaceSensitiveMacros:
|
||||
- BOOST_PP_STRINGIZE
|
||||
- CF_SWIFT_NAME
|
||||
- NS_SWIFT_NAME
|
||||
- PP_STRINGIZE
|
||||
- STRINGIZE
|
||||
WrapNamespaceBodyWithEmptyLines: Leave
|
||||
...
|
||||
|
||||
17
README.md
17
README.md
|
|
@ -1 +1,18 @@
|
|||
# Laser turret Debug
|
||||
|
||||
Code de la tourelle de pointage laser du projet bouchons EDF.
|
||||
|
||||
> [!WARNING]
|
||||
> Code de debuggage uniquement.
|
||||
|
||||
# Usage
|
||||
|
||||
Compile through Arduino IDE or equivalent.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Add [kissStepper](https://github.com/risitt/kissStepper) to your project
|
||||
> librairies.
|
||||
|
||||
## Contributing
|
||||
|
||||
Before `git commit`, run `git clang-format` to format stagged files.
|
||||
|
|
|
|||
48
maths.cpp
Normal file
48
maths.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include "math.h"
|
||||
|
||||
// rollH atan((22.5 - 18.5) / 236) ~0.97°
|
||||
// rollV ~1°
|
||||
|
||||
double degToRad(double deg) { return deg * M_PI / 180.0; }
|
||||
|
||||
double radToDeg(double rad) { return rad * 180.0 / M_PI; }
|
||||
|
||||
void angleToStep(long &stepX, long &stepY, double angleX, double angleY) {
|
||||
// TODO remove magic numbers
|
||||
double stepRatioX = M_PI / ((51.2 / 15.0) * (100.0 * 64.0));
|
||||
double stepRatioY = M_PI / ((48.0 / 15.0) * (100.0 * 64.0));
|
||||
|
||||
stepX = angleX / stepRatioX;
|
||||
stepY = angleY / stepRatioY;
|
||||
}
|
||||
|
||||
double rollCorrection(double x, double max, double width) {
|
||||
double correction = max * (1.0 - cos((10.0 * x) / (width * M_PI))) / 2.0;
|
||||
return x - correction;
|
||||
}
|
||||
|
||||
void cartesianToPolar(long &stepX, long &stepY, double zeroX, double zeroY,
|
||||
double x, double y, double z) {
|
||||
// TODO remove magic numbers
|
||||
double distance = 166.0; // turret to screen
|
||||
double offsetY = 21.0; // laser to stand
|
||||
double offsetX = 0.0; // unused
|
||||
|
||||
x = -x; // natural axis direction
|
||||
double dX = x + offsetX;
|
||||
double dY = rollCorrection(y + offsetY, 0.2, 400.0);
|
||||
double dZ = z + distance;
|
||||
|
||||
double roll = atan2(4.0, 236.0);
|
||||
double rollY = dX * tan(roll);
|
||||
double rollX = dY * tan(roll);
|
||||
|
||||
double dXr = dX + rollX;
|
||||
double dYr = dY + rollY;
|
||||
|
||||
double rho = sqrt(pow(dXr, 2.0) + pow(dYr, 2.0) + pow(dZ, 2.0));
|
||||
double angleY = M_PI / 2.0 - acos(dYr / rho);
|
||||
double angleX = atan2(dXr, dZ);
|
||||
|
||||
angleToStep(stepX, stepY, angleX, angleY);
|
||||
}
|
||||
5
maths.h
Normal file
5
maths.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
double degToRad(double deg);
|
||||
double radToDeg(double rad);
|
||||
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);
|
||||
218
turret.cpp
Normal file
218
turret.cpp
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
#include "turret.h"
|
||||
#include "config.h"
|
||||
#include "maths.h"
|
||||
#include <kissStepper.h>
|
||||
|
||||
Turret::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_laser)
|
||||
: _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_pulse = pin_x_pulse;
|
||||
_pin_x_enable = pin_x_enable;
|
||||
|
||||
_pin_y_direction = pin_y_direction;
|
||||
_pin_y_pulse = pin_y_pulse;
|
||||
_pin_y_enable = pin_y_enable;
|
||||
|
||||
_pin_x_home = pin_x_home;
|
||||
_pin_y_home = pin_y_home;
|
||||
_pin_laser = pin_laser;
|
||||
}
|
||||
|
||||
Turret &Turret::init() {
|
||||
pinMode(_pin_laser, OUTPUT);
|
||||
|
||||
pinMode(_pin_x_direction, OUTPUT);
|
||||
pinMode(_pin_x_pulse, OUTPUT);
|
||||
pinMode(_pin_x_enable, OUTPUT);
|
||||
pinMode(_pin_x_home, INPUT_PULLUP);
|
||||
|
||||
pinMode(_pin_y_direction, OUTPUT);
|
||||
pinMode(_pin_y_pulse, OUTPUT);
|
||||
pinMode(_pin_y_enable, OUTPUT);
|
||||
pinMode(_pin_y_home, INPUT_PULLUP);
|
||||
|
||||
_stepperX.begin();
|
||||
_stepperY.begin();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::gotoHome() {
|
||||
long xStop = 0;
|
||||
long yStop = 0;
|
||||
|
||||
_stepperX.prepareMove(-1000000l);
|
||||
_stepperY.prepareMove(-1000000l);
|
||||
|
||||
while (true) {
|
||||
_stepperX.move();
|
||||
_stepperY.move();
|
||||
|
||||
if (xStop == 2 && yStop == 2) {
|
||||
_homeX = _stepperX.getPos();
|
||||
_homeY = _stepperY.getPos();
|
||||
break;
|
||||
}
|
||||
|
||||
if (xStop < 2 && digitalRead(_pin_x_home)) {
|
||||
xStop++;
|
||||
_stepperX.stop();
|
||||
}
|
||||
|
||||
if (yStop < 2 && digitalRead(_pin_y_home)) {
|
||||
yStop++;
|
||||
_stepperY.stop();
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::gotoZero() {
|
||||
// TODO remove magic numbers
|
||||
_stepperX.prepareMove(_homeX + 9300);
|
||||
_stepperY.prepareMove(_homeY + 3500);
|
||||
|
||||
bool xStop = false;
|
||||
bool yStop = false;
|
||||
|
||||
while (true) {
|
||||
if (xStop && yStop)
|
||||
break;
|
||||
if (!xStop)
|
||||
xStop = _stepperY.move() == STATE_STOPPED;
|
||||
if (!yStop)
|
||||
yStop = _stepperX.move() == STATE_STOPPED;
|
||||
}
|
||||
|
||||
_zeroX = _stepperX.getPos();
|
||||
_zeroY = _stepperY.getPos();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::calibrate() {
|
||||
gotoHome();
|
||||
gotoZero();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::moveTo(double x, double y, double z, Unit unit) {
|
||||
long stepX;
|
||||
long stepY;
|
||||
|
||||
if (unit == Unit::MM) {
|
||||
cartesianToPolar(stepX, stepY, _zeroX, _zeroY, x / 10.0, y / 10.0,
|
||||
z / 10.0);
|
||||
}
|
||||
|
||||
if (unit == Unit::CM) {
|
||||
cartesianToPolar(stepX, stepY, _zeroX, _zeroY, x, y, z);
|
||||
}
|
||||
|
||||
if (unit == Unit::M) {
|
||||
cartesianToPolar(stepX, stepY, _zeroX, _zeroY, x * 100.0, y * 100.0,
|
||||
z * 100.0);
|
||||
}
|
||||
|
||||
if (unit == Unit::STEP) {
|
||||
stepX = x;
|
||||
stepY = y;
|
||||
}
|
||||
|
||||
if (unit == Unit::RAD) {
|
||||
angleToStep(stepX, stepY, x, y);
|
||||
}
|
||||
|
||||
if (unit == Unit::DEG) {
|
||||
angleToStep(stepX, stepY, degToRad(x), degToRad(y));
|
||||
}
|
||||
|
||||
// TODO min(valueI, -_homeI);
|
||||
_stepperX.prepareMove(_zeroX + stepX);
|
||||
_stepperY.prepareMove(_zeroY + stepY);
|
||||
|
||||
bool xStop = false;
|
||||
bool yStop = false;
|
||||
|
||||
while (true) {
|
||||
if (xStop && yStop)
|
||||
break;
|
||||
if (!xStop)
|
||||
xStop = _stepperX.move() == STATE_STOPPED;
|
||||
if (!yStop)
|
||||
yStop = _stepperY.move() == STATE_STOPPED;
|
||||
}
|
||||
|
||||
_currentX = x;
|
||||
_currentY = y;
|
||||
_currentZ = z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::moveBy(double x, double y, double z, Unit unit) {
|
||||
long zeroXStored = _zeroX;
|
||||
long zeroYStored = _zeroY;
|
||||
|
||||
_zeroX += _stepperX.getPos();
|
||||
_zeroY += _stepperY.getPos();
|
||||
|
||||
moveTo(x, y, z, unit);
|
||||
|
||||
_zeroX = zeroXStored;
|
||||
_zeroY = zeroYStored;
|
||||
|
||||
_currentX = x;
|
||||
_currentY = y;
|
||||
_currentZ = z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::moveToX(double x, Unit unit) {
|
||||
return moveTo(x, _currentY, _currentZ, unit);
|
||||
}
|
||||
|
||||
Turret &Turret::moveToY(double y, Unit unit) {
|
||||
return moveTo(_currentX, y, _currentZ, unit);
|
||||
}
|
||||
|
||||
Turret &Turret::moveToZ(double z, Unit unit) {
|
||||
return moveTo(_currentX, _currentY, z, unit);
|
||||
}
|
||||
|
||||
Turret &Turret::moveByX(double x, Unit unit) { return moveBy(x, 0, 0, unit); }
|
||||
|
||||
Turret &Turret::moveByY(double y, Unit unit) { return moveTo(0, y, 0, unit); }
|
||||
|
||||
Turret &Turret::moveByZ(double z, Unit unit) { return moveTo(0, 0, z, unit); }
|
||||
|
||||
Turret &Turret::getPosition(double &x, double &y, double &z, Unit unit) {
|
||||
// TODO implement
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::getHome(double &x, double &y, double &z, Unit unit) {
|
||||
// TODO implement
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::getZero(double &x, double &y, double &z, Unit unit) {
|
||||
// TODO implement
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::laserOn() {
|
||||
digitalWrite(_pin_laser, HIGH);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Turret &Turret::laserOff() {
|
||||
digitalWrite(_pin_laser, LOW);
|
||||
return *this;
|
||||
}
|
||||
65
turret.h
Normal file
65
turret.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#ifndef TURRET_H
|
||||
#define TURRET_H
|
||||
|
||||
#include <kissStepper.h>
|
||||
|
||||
class Turret {
|
||||
public:
|
||||
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,
|
||||
int pin_y_direction, int pin_y_pulse, int pin_y_enable, int pin_y_home,
|
||||
int pin_laser);
|
||||
|
||||
Turret &init();
|
||||
Turret &gotoHome();
|
||||
Turret &gotoZero();
|
||||
|
||||
Turret &moveTo(double x, double y, double z, Unit unit = Turret::Unit::CM);
|
||||
Turret &moveBy(double x, double y, double z, Unit unit = Turret::Unit::CM);
|
||||
|
||||
Turret &moveToX(double x, Unit unit = Turret::Unit::CM);
|
||||
Turret &moveToY(double y, Unit unit = Turret::Unit::CM);
|
||||
Turret &moveToZ(double z, Unit unit = Turret::Unit::CM);
|
||||
|
||||
Turret &moveByX(double x, Unit unit = Turret::Unit::CM);
|
||||
Turret &moveByY(double y, Unit unit = Turret::Unit::CM);
|
||||
Turret &moveByZ(double z, Unit unit = Turret::Unit::CM);
|
||||
|
||||
Turret &getPosition(double &x, double &y, double &z, Unit unit);
|
||||
Turret &getHome(double &x, double &y, double &z, Unit unit);
|
||||
Turret &getZero(double &x, double &y, double &z, Unit unit);
|
||||
|
||||
Turret &calibrate();
|
||||
|
||||
Turret &laserOn();
|
||||
Turret &laserOff();
|
||||
|
||||
private:
|
||||
kissStepper _stepperX;
|
||||
kissStepper _stepperY;
|
||||
|
||||
int _homeX;
|
||||
int _homeY;
|
||||
|
||||
int _zeroX;
|
||||
int _zeroY;
|
||||
|
||||
int _currentX;
|
||||
int _currentY;
|
||||
int _currentZ;
|
||||
|
||||
int _pin_x_direction;
|
||||
int _pin_x_pulse;
|
||||
int _pin_x_enable;
|
||||
|
||||
int _pin_y_direction;
|
||||
int _pin_y_pulse;
|
||||
int _pin_y_enable;
|
||||
|
||||
int _pin_x_home;
|
||||
int _pin_y_home;
|
||||
int _pin_laser;
|
||||
};
|
||||
|
||||
#endif
|
||||
96
turret_debug.ino
Normal file
96
turret_debug.ino
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#include "config.h"
|
||||
#include "turret.h"
|
||||
|
||||
Turret turret(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_LASER);
|
||||
|
||||
void setup() {
|
||||
turret.init();
|
||||
|
||||
Serial.begin(BAUDRATE);
|
||||
|
||||
turret.laserOn().calibrate();
|
||||
turret.moveTo(0, 0, 0);
|
||||
delay(5000);
|
||||
|
||||
// test pointage
|
||||
double panelWidth = 124.7;
|
||||
double panelHeight = 145.0;
|
||||
int panelHCount = 3;
|
||||
int panelVCount = 2;
|
||||
|
||||
// double zeroOffsetV = -31.5;
|
||||
double zeroOffsetV = -20.8;
|
||||
// double zeroOffsetH = -184.5;
|
||||
double zeroOffsetH = -195.5;
|
||||
|
||||
// Test constant step h,v
|
||||
Serial.println("Start demo_0");
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Serial.print("> ");
|
||||
Serial.println(i);
|
||||
for (double step = -198.5; step < 176.0; step += 10) {
|
||||
Serial.print("[step]: ");
|
||||
Serial.println(step);
|
||||
turret.moveTo(step, 87, 0);
|
||||
// turret.moveBy(20.0, 0.0, 0.0);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
for (double step = 0; step < 200.0; step += 10) {
|
||||
Serial.print("[step]: ");
|
||||
Serial.println(step);
|
||||
turret.moveTo(0, step, 0);
|
||||
// turret.moveBy(20.0, 0.0, 0.0);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
delay(5000);
|
||||
turret.moveTo(0, 0, 0);
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
// Test rollX
|
||||
turret.moveTo(0 * panelWidth + zeroOffsetH, 0, 0);
|
||||
delay(5000);
|
||||
turret.moveTo((panelHCount * panelWidth) / 2 + zeroOffsetH, 0, 0);
|
||||
delay(5000);
|
||||
turret.moveTo(panelHCount * panelWidth + zeroOffsetH, 0, 0);
|
||||
delay(5000);
|
||||
turret.gotoZero();
|
||||
|
||||
// Test rollY
|
||||
turret.moveTo(0, 0 * panelHeight + zeroOffsetV, 0);
|
||||
delay(5000);
|
||||
turret.moveTo(0, (panelVCount * panelHeight) / 2 + zeroOffsetV, 0);
|
||||
delay(5000);
|
||||
turret.moveTo(0, panelVCount * panelHeight + zeroOffsetV, 0);
|
||||
delay(5000);
|
||||
turret.gotoZero();
|
||||
|
||||
// Test align to panels
|
||||
for (double panelH = 0; panelH < panelHCount + 1; panelH += 0.5) {
|
||||
for (double panelV = 0; panelV < panelVCount + 1; panelV += 0.5) {
|
||||
double x = panelH * panelWidth + zeroOffsetH;
|
||||
double y = panelV * panelHeight + zeroOffsetV;
|
||||
double z = 0;
|
||||
|
||||
Serial.print("Goto (x, y, z) => (");
|
||||
Serial.print(x);
|
||||
Serial.print(", ");
|
||||
Serial.print(y);
|
||||
Serial.print(", ");
|
||||
Serial.print(z);
|
||||
Serial.println(")");
|
||||
|
||||
turret.moveTo(x, y, z);
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
turret.gotoZero();
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
Loading…
Reference in a new issue