Skip to content

Commit

Permalink
Merge pull request #132 from TimEvWw/master
Browse files Browse the repository at this point in the history
Genesis 1.5 board support and Express reporting encoder position
  • Loading branch information
TimEvWw authored Feb 11, 2020
2 parents f452af7 + 37bc380 commit ffe3573
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 77 deletions.
6 changes: 6 additions & 0 deletions src/Board.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#ifndef FARMBOT_BOARD_ID

// Farmbot using RAMPS board
//#define RAMPS_V14

//#define FARMDUINO_V10
//#define FARMDUINO_V14

// Farmbot Genesis 1.5
//#define FARMDUINO_V30

// Farmbot Express
#define FARMDUINO_EXP_V20

#else
Expand Down
70 changes: 17 additions & 53 deletions src/Movement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void Movement::loadSettings()

}

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
void Movement::initTMC2130()
{
axisX.initTMC2130();
Expand Down Expand Up @@ -289,7 +289,7 @@ void Movement::loadSettings()

void Movement::test()
{
#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
//axisX.enableMotor();
//axisX.setMotorStep();
//delayMicroseconds(500);
Expand Down Expand Up @@ -747,18 +747,16 @@ int Movement::moveToCoords(double xDestScaled, double yDestScaled, double zDestS
break;

case 2:
#if defined(FARMDUINO_EXP_V20)

serialBuffer += "R89";
serialBuffer += " X";
serialBuffer += axisX.getLoad();
serialBuffer += " Y";
serialBuffer += axisY.getLoad();
serialBuffer += " Z";
serialBuffer += axisZ.getLoad();
serialBuffer += CurrentState::getInstance()->getQAndNewLine();

#endif
//#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
//serialBuffer += "R89";
//serialBuffer += " X";
//serialBuffer += axisX.getLoad();
//serialBuffer += " Y";
//serialBuffer += axisY.getLoad();
//serialBuffer += " Z";
//serialBuffer += axisZ.getLoad();
//serialBuffer += CurrentState::getInstance()->getQAndNewLine();
//#endif
break;

default:
Expand All @@ -767,14 +765,14 @@ int Movement::moveToCoords(double xDestScaled, double yDestScaled, double zDestS

serialMessageNr++;

#if !defined(FARMDUINO_EXP_V20)
#if !defined(FARMDUINO_EXP_V20) && !defined(FARMDUINO_V30)
if (serialMessageNr > 1)
{
serialMessageNr = 0;
}
#endif

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)

if (serialMessageNr > 2)
{
Expand Down Expand Up @@ -1400,56 +1398,22 @@ void Movement::checkAxisVsEncoder(MovementAxis *axis, MovementEncoder *encoder,
#if defined(FARMDUINO_EXP_V20)
void Movement::checkAxisVsEncoder(MovementAxis *axis, MovementEncoder *encoder, float *missedSteps, long *lastPosition, long *encoderLastPosition, int *encoderUseForPos, float *encoderStepDecay, bool *encoderEnabled)
{

//
// /**/
// /*
// Serial.print("R99");
// Serial.print(" XXX ");
// Serial.print(" cur pos ");
// Serial.print(axis->currentPosition());
// Serial.print(" last pos ");
// Serial.print(*lastPosition);
// */
//

//if (axis->stallDetected()) {
// Serial.print("X");
//}
//else
//{
// Serial.print(".");
//}

/**/
bool stallGuard = false;
bool standStill = false;
uint8_t status = 0;

if (*encoderEnabled) {

//TMC2130X.read_STAT();

status = axis->getStatus();

stallGuard = status & FB_TMC_SPISTATUS_STALLGUARD_MASK ? true : false;
standStill = status & FB_TMC_SPISTATUS_STANDSTILL_MASK ? true : false;

if (stallGuard || standStill) {
//Serial.print(".");
// In case of stall detection, count this as a missed step
(*missedSteps)++;
axis->setCurrentPosition(*lastPosition);


//if (int(*missedSteps) % 10 == 0) {
// Serial.println();
// Serial.print(*missedSteps);
// Serial.print("/");
// Serial.print(axis->currentPosition());
// Serial.println();
//}

}
else {
// Decrease amount of missed steps if there are no missed step
Expand Down Expand Up @@ -1570,7 +1534,7 @@ void Movement::loadMotorSettings()
/**/

/*
#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
loadSettingsTMC2130();
#endif
*/
Expand Down Expand Up @@ -1722,7 +1686,7 @@ bool Movement::endStopsReached()
void Movement::storePosition()
{

#if !defined(FARMDUINO_EXP_V20)
#if !defined(FARMDUINO_EXP_V20) && !defined(FARMDUINO_V30)
if (motorConsEncoderEnabled[0])
{
CurrentState::getInstance()->setX(encoderX.currentPosition());
Expand Down Expand Up @@ -1751,7 +1715,7 @@ void Movement::storePosition()
}
#endif

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
CurrentState::getInstance()->setX(axisX.currentPosition());
CurrentState::getInstance()->setY(axisY.currentPosition());
CurrentState::getInstance()->setZ(axisZ.currentPosition());
Expand Down
2 changes: 1 addition & 1 deletion src/Movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Movement
void handleMovementInterrupt();
void checkEncoders();

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
void initTMC2130();
void loadSettingsTMC2130();
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/MovementAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void MovementAxis::test()

}

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)

unsigned int MovementAxis::getLostSteps()
{
Expand Down Expand Up @@ -611,7 +611,7 @@ void MovementAxis::setDirectionUp()
//#endif

/*
#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
// The TMC2130 uses a command to change direction, not a pin
if (motorMotorInv)
Expand Down Expand Up @@ -660,7 +660,7 @@ void MovementAxis::setDirectionDown()

//#endif
/*
#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
// The TMC2130 uses a command to change direction, not a pin
if (motorMotorInv)
Expand Down Expand Up @@ -941,7 +941,7 @@ void MovementAxis::resetMotorStepWrite46()
PORTL &= B11110111;
}

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
//// TMC2130 Functions

void MovementAxis::setMotorStepWriteTMC2130()
Expand Down
6 changes: 3 additions & 3 deletions src/MovementAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MovementAxis
public:
MovementAxis();

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
TMC2130_Basics *TMC2130A;
TMC2130_Basics *TMC2130B;
#endif
Expand Down Expand Up @@ -92,14 +92,14 @@ class MovementAxis
char channelLabel;
bool movementStarted;

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
void initTMC2130();
void loadSettingsTMC2130(int motorCurrent, int stallSensitivity, int microSteps);
uint16_t getLoad();

#endif

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
void setMotorStepWriteTMC2130();
void setMotorStepWriteTMC2130_2();
void resetMotorStepWriteTMC2130();
Expand Down
6 changes: 3 additions & 3 deletions src/MovementEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void MovementEncoder::loadMdlEncoderId(MdlSpiEncoders encoder)

void MovementEncoder::setPosition(long newPosition)
{
#if defined(RAMPS_V14) || defined(FARMDUINO_V10)
#if defined(RAMPS_V14) || defined(FARMDUINO_V10) || defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
position = newPosition;
#endif

Expand Down Expand Up @@ -277,7 +277,7 @@ float MovementEncoder::getMissedSteps()

void MovementEncoder::checkMissedSteps()
{
#if !defined(FARMDUINO_EXP_V20)
#if !defined(FARMDUINO_EXP_V20) && !defined(FARMDUINO_V30)
if (encoderEnabled)
{
bool stepMissed = false;
Expand Down Expand Up @@ -307,7 +307,7 @@ void MovementEncoder::checkMissedSteps()
#endif

/*
#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
if (encoderEnabled) {
if (axis->stallDetected()) {
Expand Down
2 changes: 1 addition & 1 deletion src/TMC2130.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "TMC2130.h"

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)

//void loadTMC2130ParametersMotor(Trinamic_TMC2130 *myStepper, int microsteps, int current, int sensitivity)
void loadTMC2130ParametersMotor(TMC2130_Basics *tb, int microsteps, int current, int sensitivity)
Expand Down
2 changes: 1 addition & 1 deletion src/TMC2130.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "pins.h"
#include "Board.h"

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
#include "TMC2130_Basics.h"

static TMC2130_Basics TMC2130X(X_CHIP_SELECT);
Expand Down
14 changes: 7 additions & 7 deletions src/farmbot_arduino_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "farmbot_arduino_controller.h"

/**/
//#if !defined(FARMDUINO_EXP_V20)
//#if !defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
#include "TimerOne.h"
//#endif

Expand Down Expand Up @@ -52,7 +52,7 @@ unsigned long interruptDurationMax = 0;
bool interruptBusy = false;
int interruptSecondTimer = 0;

//#if !defined(FARMDUINO_EXP_V20)
//#if !defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
void interrupt(void)
{
if (!debugInterrupt)
Expand Down Expand Up @@ -284,7 +284,7 @@ void checkParamsChanged()
}


#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
Movement::getInstance()->loadSettingsTMC2130();
#endif

Expand Down Expand Up @@ -503,7 +503,7 @@ void setPinInputOutput()
}
#endif

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
void setPinInputOutput()
{
Serial.print(COMM_REPORT_COMMENT);
Expand Down Expand Up @@ -621,13 +621,13 @@ void startInterrupt()
// Interrupt management code library written by Paul Stoffregen
// The default time 100 micro seconds

//#if !defined(FARMDUINO_EXP_V20)
//#if !defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
Timer1.attachInterrupt(interrupt);
Timer1.initialize(MOVEMENT_INTERRUPT_SPEED);
Timer1.start();
//#endif

//#if defined(FARMDUINO_EXP_V20)
//#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
// Serial.println("set timer");
// TIMSK2 = (TIMSK2 & B11111110) | 0x01; // Enable timer overflow
// TCCR2B = (TCCR2B & B11111000) | 0x01; // Set divider to 1
Expand Down Expand Up @@ -735,7 +735,7 @@ void startServo()
ServoControl::getInstance()->attach();
}

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)

/**/
//static Trinamic_TMC2130 controllerTMC2130_X(X_CHIP_SELECT);
Expand Down
4 changes: 2 additions & 2 deletions src/farmbot_arduino_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "MemoryFree.h"
#include "Debug.h"

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
#include "TMC2130.h"
#endif

Expand Down Expand Up @@ -49,7 +49,7 @@ void setup();
void setPinInputOutput();
void startSerial();

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
void loadTMC2130drivers();
void loadTMC2130parameters();
void startupTmc();
Expand Down
2 changes: 1 addition & 1 deletion src/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@

#endif

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)

// X1-AXIS
#define X_STEP_PIN 26 // X1_STEP_PIN
Expand Down
2 changes: 1 addition & 1 deletion src/src.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void setup()

readParameters();

#if defined(FARMDUINO_EXP_V20)
#if defined(FARMDUINO_EXP_V20) || defined(FARMDUINO_V30)
loadTMC2130drivers();
startupTmc();
loadTMC2130parameters();
Expand Down

0 comments on commit ffe3573

Please sign in to comment.