farmbot-arduino-firmware/src/Movement.h

161 lines
4.2 KiB
C
Raw Permalink Normal View History

/*
2019-12-02 14:07:28 -07:00
* Movement.h
*
* Created on: 16 maj 2014
* Author: MattLech
*/
2019-12-02 14:07:28 -07:00
#ifndef MOVEMENT_H_
#define MOVEMENT_H_
#include "Arduino.h"
#include "CurrentState.h"
2014-08-17 14:15:05 -06:00
#include "ParameterList.h"
2019-12-02 14:07:28 -07:00
#include "MovementAxis.h"
#include "MovementEncoder.h"
#include "pins.h"
#include "Config.h"
#include <stdio.h>
#include <stdlib.h>
2016-10-02 15:43:39 -06:00
#include "Command.h"
2019-12-02 14:07:28 -07:00
class Movement
2017-04-19 08:12:12 -06:00
{
public:
2019-12-02 14:07:28 -07:00
Movement();
Movement(Movement const &);
void operator=(Movement const &);
2017-04-19 08:12:12 -06:00
2019-12-02 14:07:28 -07:00
static Movement *getInstance();
2017-04-19 08:12:12 -06:00
//int moveAbsolute( long xDest, long yDest,long zDest,
// unsigned int maxStepsPerSecond,
// unsigned int maxAccelerationStepsPerSecond);
2017-08-15 08:15:17 -06:00
int moveToCoords(double xDestScaled, double yDestScaled, double zDestScaled,
2017-04-19 08:12:12 -06:00
unsigned int xMaxSpd, unsigned int yMaxSpd, unsigned int zMaxSpd,
bool homeX, bool homeY, bool homeZ);
void handleMovementInterrupt();
2017-05-03 13:33:26 -06:00
void checkEncoders();
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
2019-04-01 12:55:59 -06:00
void initTMC2130();
void loadSettingsTMC2130();
2020-05-12 13:36:49 -06:00
void loadSettingsTMC2130_X();
void loadSettingsTMC2130_Y();
void loadSettingsTMC2130_Z();
#endif
2017-04-19 08:12:12 -06:00
int calibrateAxis(int axis);
//void initInterrupt();
2017-04-19 08:12:12 -06:00
void enableMotors();
void disableMotors();
void disableMotorsEmergency();
void primeMotors();
2017-04-19 08:12:12 -06:00
bool motorsEnabled();
void storePosition();
void loadSettings();
void setPositionX(long pos);
void setPositionY(long pos);
void setPositionZ(long pos);
void reportEncoders();
2018-08-17 18:41:40 -06:00
void getEncoderReport();
2017-04-19 08:12:12 -06:00
void test();
void test2();
unsigned long i1 = 0;
unsigned long i2 = 0;
2017-05-28 14:54:58 -06:00
unsigned long i3 = 0;
unsigned long i4 = 0;
private:
2019-03-20 12:39:28 -06:00
2019-12-02 14:07:28 -07:00
MovementAxis axisX;
MovementAxis axisY;
MovementAxis axisZ;
2017-04-19 08:12:12 -06:00
2019-12-02 14:07:28 -07:00
MovementEncoder encoderX;
MovementEncoder encoderY;
MovementEncoder encoderZ;
2017-04-19 08:12:12 -06:00
2017-06-29 14:00:48 -06:00
//char serialBuffer[100];
String serialBuffer;
int serialBufferLength = 0;
int serialBufferSending = 0;
int serialMessageNr = 0;
int serialMessageDelay = 0;
2020-05-15 13:16:53 -06:00
unsigned long calibrationTicks = 0;
2017-07-01 13:58:42 -06:00
void serialBufferSendNext();
void serialBufferEmpty();
2019-12-02 14:07:28 -07:00
void checkAxisVsEncoder(MovementAxis *axis, MovementEncoder *encoder, float *missedSteps, long *lastPosition, long *encoderLastPosition, int *encoderUseForPos, float *encoderStepDecay, bool *encoderEnabled);
void checkAxisSubStatus(MovementAxis *axis, int *axisSubStatus);
2017-04-19 08:12:12 -06:00
bool axisActive[3] = { false, false, false };
int axisSubStep[3] = { 0, 0, 0 };
2017-04-19 08:12:12 -06:00
void loadMotorSettings();
void loadEncoderSettings();
bool intToBool(int value);
void reportPosition();
2017-06-29 14:00:48 -06:00
String getReportPosition();
2017-04-19 08:12:12 -06:00
void storeEndStops();
void reportEndStops();
2019-12-02 14:07:28 -07:00
void reportStatus(MovementAxis *axis, int axisSubStatus);
void reportCalib(MovementAxis *axis, int calibStatus);
2017-04-19 08:12:12 -06:00
unsigned long getMaxLength(unsigned long lengths[3]);
bool endStopsReached();
bool homeIsUp[3] = {false, false, false};
long speedMax[3] = {0, 0, 0 };
2017-12-16 16:11:03 -07:00
long commandSpeed[3] = { 0, 0, 0 };
long speedMin[3] = { 0, 0, 0 };
long speedHome[3] = { 0, 0, 0 };
long stepsAcc[3] = { 0, 0, 0 };
bool motorInv[3] = { false, false, false };
2017-04-28 12:36:56 -06:00
long motorMaxSize[3] = { 0, 0, 0};
bool motorStopAtMax[3] = { false, false, false };
bool motorKeepActive[3] = { false, false, false };
bool motor2Inv[3] = { false, false, false };
bool motor2Enbl[3] = { false, false, false };
2017-04-27 14:32:41 -06:00
bool motorStopAtHome[3] = { false, false, false };
bool endStInv[3] = { false, false, false };
2018-01-04 14:14:30 -07:00
bool endStInv2[3] = { false, false, false };
bool endStEnbl[3] = { false, false, false };
long timeOut[3] = { 0, 0, 0 };
2017-08-15 08:15:17 -06:00
long stepsPerMm[3] = { 1.0, 1.0, 1.0 };
float motorConsMissedSteps[3] = { 0, 0, 0 };
int motorConsMissedStepsPrev[3] = { 0, 0, 0 };
long motorLastPosition[3] = { 0, 0, 0 };
long motorConsEncoderLastPosition[3] = { 0, 0, 0 };
int motorConsMissedStepsMax[3] = { 0, 0, 0 };
float motorConsMissedStepsDecay[3] = { 0, 0, 0 };
bool motorConsEncoderEnabled[3] = { false, false, false };
int motorConsEncoderType[3] = { 0, 0, 0 };
2019-02-07 18:43:28 -07:00
long motorConsEncoderScaling[3] = { 0, 0, 0 };
int motorConsEncoderUseForPos[3] = { 0, 0, 0 };
int motorConsEncoderInvert[3] = { 0, 0, 0 };
2017-06-29 14:00:48 -06:00
int axisServiced = 0;
int axisServicedNext = 0;
bool motorMotorsEnabled = false;
2020-02-06 13:53:12 -07:00
int testA = 0;
int testB = 0;
};
2019-12-02 14:07:28 -07:00
#endif /* MOVEMENT_H_ */