teemuatlut / TMCStepper

MIT License
501 stars 196 forks source link

ESP32 & TMC5160 BOB 1.2 #225

Open rauber-hotzenplotz opened 2 years ago

rauber-hotzenplotz commented 2 years ago

Hallo

Im trying to use the XTARGET and the motion controller to control my stepper motor.

teemuatlut posted an example for the exakt same problem.

https://github.com/teemuatlut/TMCStepper/issues/157#issuecomment-721960004

Unfortunatly it doesnt work for me. It might be a small problem, but my knowledge is limited...

i get this error:

In function 'void setup()': ESP32BOBSPI:23:3: error: 'TMC5160_n' has not been declared TMC5160_n::IOIN_i::IOIN_t ioin{driver.IOIN()}; ^ ESP32BOBSPI:23:35: error: expected primary-expression before '>' token TMC5160_n::IOIN_i::IOIN_t ioin{driver.IOIN()}; ^ ESP32BOBSPI:23:45: error: expected primary-expression before 'ioin' TMC5160_n::IOIN_i::IOIN_t ioin{driver.IOIN()}; ^ ESP32BOBSPI:25:7: error: 'ioin' was not declared in this scope if (ioin.version == 0xFF || ioin.version == 0) { ^ ESP32BOBSPI:31:18: error: 'ioin' was not declared in this scope Serial.println(ioin.version); ^ ESP32BOBSPI:46:10: error: 'class TMC5160Stepper' has no member named 'A1' driver.A1(1000); ^ ESP32BOBSPI:47:10: error: 'class TMC5160Stepper' has no member named 'V1' driver.V1(50000); ^ ESP32BOBSPI:51:10: error: 'class TMC5160Stepper' has no member named 'D1' driver.D1(1400); ^ exit status 1 'TMC5160_n' has not been declared

i only changed TMC5160Stepper driver(SPI, csPin, r_sense); to TMC5160Stepper driver(VSPI, csPin, r_sense);

#include <Arduino.h>
#include <TMCStepper.h>

constexpr uint16_t csPin = 10;
//constexpr uint16_t enPin = 2;
constexpr float r_sense = 0.075;

void setup() {
    delay(250);
    Serial.begin(115200);
    while(!Serial);
    Serial.println("\nTMCStepper TMC internal motion controller example.\nCompiled " __DATE__ " " __TIME__);
    Serial.println("Start...");

    pinMode(csPin, OUTPUT);
    //pinMode(enPin, OUTPUT);
    digitalWrite(csPin, HIGH);
    //digitalWrite(enPin, LOW);

    TMC5160Stepper driver(SPI, csPin, r_sense);
    SPI.begin();

    TMC5160_n::IOIN_i<TMC5160Stepper>::IOIN_t ioin{driver.IOIN()};

    if (ioin.version == 0xFF || ioin.version == 0) {
        Serial.println("Driver communication error");
        while(true);
    }

    Serial.print("Driver firmware version: ");
    Serial.println(ioin.version);

    if (ioin.sd_mode) {
        Serial.println("Driver is hardware configured for Step & Dir mode");
        while(true);
    }
    if (ioin.drv_enn) {
        Serial.println("Driver is not hardware enabled");
        while(true);
    }

    driver.toff(3);
    driver.rms_current(800);
    driver.en_pwm_mode(true);

    driver.A1(1000);
    driver.V1(50000);
    driver.AMAX(500);
    driver.VMAX(200000);
    driver.DMAX(700);
    driver.D1(1400);
    driver.VSTOP(10);
    driver.RAMPMODE(0);
    driver.XTARGET(-51200);

    while(true) {
        delay(1000);

        auto xactual = driver.XACTUAL();
        auto xtarget = driver.XTARGET();

        char buffer[256];
        sprintf(buffer, "ioin=%#-10lx xactual=%7ld\n",
            driver.IOIN(),
            xactual
            );
        Serial.print(buffer);

        if (xactual == xtarget) {
            driver.XTARGET(-xactual);
        }
    }
}

void loop() {}
teemuatlut commented 2 years ago

Which branch are you using? The example given uses the newer architecture that is not yet in the master branch.

rauber-hotzenplotz commented 2 years ago

thank you for the quick reply .

I was using the master branch.

I just installed the 'TMCStepper-Release_v1' and deleted 'TMCStepper-master' which slightly changes the error messages...

In function 'void setup()': ESP32BOBSPI:23:3: error: 'IOIN_t' is not a member of 'TMC5160_n::IOIN_i' TMC5160_n::IOIN_i::IOIN_t ioin{driver.IOIN()}; ^ ESP32BOBSPI:25:7: error: 'ioin' was not declared in this scope if (ioin.version == 0xFF || ioin.version == 0) { ^ ESP32BOBSPI:31:18: error: 'ioin' was not declared in this scope Serial.println(ioin.version); ^ ESP32BOBSPI:46:10: error: 'class TMC5160Stepper' has no member named 'A1' driver.A1(1000); ^ ESP32BOBSPI:47:10: error: 'class TMC5160Stepper' has no member named 'V1' driver.V1(50000); ^ ESP32BOBSPI:51:10: error: 'class TMC5160Stepper' has no member named 'D1' driver.D1(1400); ^ ESP32BOBSPI:52:10: error: 'class TMC5160Stepper' has no member named 'VSTOP' driver.VSTOP(10); ^ exit status 1 'IOIN_t' is not a member of 'TMC5160_n::IOIN_i'

teemuatlut commented 2 years ago

This compiles but I haven't had the time to test it.

#include <Arduino.h>
#include <TMCStepper.h>

constexpr uint16_t csPin = 10;
//constexpr uint16_t enPin = 2;
constexpr float r_sense = 0.075;

TMC5160Stepper driver(SPI, csPin, r_sense);

void setup() {
    delay(250);
    Serial.begin(115200);
    while(!Serial);
    Serial.println("\nTMCStepper TMC internal motion controller example.\nCompiled " __DATE__ " " __TIME__);
    Serial.println("Start...");

    //pinMode(enPin, OUTPUT);
    //digitalWrite(enPin, LOW);

    driver.begin();

    TMC5160Stepper::IOIN_t ioin{ driver.IOIN() };

    if (ioin.version == 0xFF || ioin.version == 0) {
        Serial.println("Driver communication error");
        while(true);
    }

    Serial.print("Driver firmware version: ");
    Serial.println(ioin.version);

    if (ioin.sd_mode) {
        Serial.println("Driver is hardware configured for Step & Dir mode");
        while(true);
    }
    if (ioin.drv_enn) {
        Serial.println("Driver is not hardware enabled");
        while(true);
    }

    driver.toff(3);
    driver.rms_current(800);
    driver.en_pwm_mode(true);

    driver.a1(1000);
    driver.v1(50000);
    driver.AMAX(500);
    driver.VMAX(200000);
    driver.DMAX(700);
    driver.d1(1400);
    driver.vstop(10);
    driver.RAMPMODE(0);
    driver.XTARGET(-51200);
}

void loop() {
    delay(1000);

    auto xactual = driver.XACTUAL();
    auto xtarget = driver.XTARGET();

    char buffer[256];
    sprintf(buffer, "ioin=%#-10x xactual=%7d\n",
        driver.IOIN(),
        xactual
        );
    Serial.print(buffer);

    if (xactual == xtarget) {
        driver.XTARGET(-xactual);
    }
}
rauber-hotzenplotz commented 2 years ago

AWESOME !!! Thank you very much.

It works ! It lives. You were really helping me a lot.

(i made a small donation.)

cbaugher commented 2 years ago

Which branch are you using? The example given uses the newer architecture that is not yet in the master branch.

Hi, When will the new architecture make it into the master branch? If not fairly soon, how stable is the new architecture now?

C|

teemuatlut commented 2 years ago

There are a lot of changes and there doesn't seem to be major core breaking issues with the current release so I'm taking my time with it. I at least want to be sure that it works with the main platforms like AVR, LPC, STM and I'm slowly working towards building unit tests and CI for them. So essentially there's no timeline and it'll be released when it's good enough.

cbaugher commented 2 years ago

There are a lot of changes and there doesn't seem to be major core breaking issues with the current release so I'm taking my time with it. I at least want to be sure that it works with the main platforms like AVR, LPC, STM and I'm slowly working towards building unit tests and CI for them. So essentially there's no timeline and it'll be released when it's good enough.

Ok, fair enough. I only ask because I'm using it in a project that will have to be finished in the next couple months, and I would rather use an officially released version. If the new one was going to be released in the next couple weeks I would switch to it, but sounds like not, so I'll stick with the current release. Thanks C|