Endstop for extramotor does not work

Hello,

I have an extra motor with an mechanical endstop to change the tools. I use an Arduino Due with the radds board.  The extra motor works well without problems. But with the G203 command to home the extra motor, the endstop triggers, but does not stop the motor. Then I have to reset the printer.

I already tested the endstop for the x-axis with the same settings and there the endstop worked. I also tested it with the X-Max pin, but also the endstop does not trigger.

I hope somebody can help me. I have absolutely no idea what the problem can be.

#define NUM_MOTOR_DRIVERS 1
//#define MOTOR_DRIVER_x StepperDriverWithEndstop<int stepPin, int dirPin, int enablePin,bool invertDir, bool invertEnable,int endstop_pin,
// bool invertEndstop,bool minEndstop, bool endstopPullup> var(float steps per mm,float speed, float max.distance)
#define MOTOR_DRIVER_1(var) StepperDriverWithEndstop<35,33,37,0,1,ORIG_Z_MAX_PIN,0,1,1> var(20,10,110)

Thanks in advance

Comments

  • Homing is G205 P0 S0 E0 not G203.

    For clarity, you defined motor range to be 0 - 110 and at 0 you have the min end stop.

    Looking into the code in drivers.h line 125++ I think there is a bug

        void gotoPosition(float newPos) {
            bool up = false;
            if (newPos < 0)
                newPos = 0;
            if (newPos > maxDistance)
                newPos = maxDistance;
            enable();
            int32_t target = floor(newPos * stepsPerMM + 0.5f) - position;
            position += target;
            if (target > 0) {
                HAL::digitalWrite(dirPin, !invertDir);
            } else {
                target = -target;
                up = true;
                HAL::digitalWrite(dirPin, invertDir);
            }

    is how it should look like. You see I changed the 2 lines with up = to the opposite. Please try that and report if it then works.
  • Thank you for your response.

    I changed the settings in drivers.h, but without success. I have still the same problem

  • Probably endstop is not set up correctly. Go to Drivers.cpp and modify commandG203 so it outputs endstop status. Then test untriggered and triggered what it returns. Also did you wire endstop against gnd? With pullup it must be against gnd to work at all.

    // G203 P<motorId>            - Report current motor position
    void commandG203(GCode& code) {
        int id = 0;
        if (code.hasP())
            id = code.P;
        if (id < 0)
            id = 0;
        if (id >= NUM_MOTOR_DRIVERS)
            id = 0;
        Com::printF(PSTR("Motor"), id);
        Com::printF(PSTR(" Pos:"), motorDrivers[id]->getPosition());
        Com::printFLN(" Endstop Hit:", motorDrivers[id]->endstopHit());
    }

  • I changed this settings, but also without success. Does somebody has another idea?


  • I always get the attached failure: Exit Status 1 - void command G203
  • I think from the error message redefinition of... that you added my replacement code but did not remove the old wrong version so you have now 2 identical functions which is not allowed. So remove the wrong code and compilation should work.
  • Thank you for your fast response.

    But I do not understand it.

    Do you mean, that I have two G203 functions in my code? I can only find one function, where should the second function be?

    Can you explain it more in detail?

    Thank you very much.

  • You have 2 times void commandG203(GCode& code) {...} in Drivers.cpp the old original and my corrected version that you have added. At least it is what I think happened due to the error message.
  • Thank you. But now I have the following failure error. The class MotorDriverInterface has no momber named endstop hit.  What is my problem now? I have no idea.
  • Ok, change in Drivers.h 

    class MotorDriverInterface {
    public:
    virtual void initialize() = 0;
    virtual float getPosition() = 0;
    virtual void setCurrentAs(float newPos) = 0;
    virtual void gotoPosition(float newPos) = 0;
    virtual void enable() = 0;
    virtual void disable() = 0;
    virtual void home(bool goToCurrent, bool onlyIfNotHomed) = 0;
    virtual bool endstopHit() = 0;
    };

    I added the "virtual bool endstopHit() = 0;" line so it finds the function.
    Hope it then compiles completely.

    Alternatively remove the line. We only added it so you can see the status of the endstop for testing, so it is no functional requirement.
  • Now it compiles completely. But still the same problem. The motor does not stop, when the endstop is triggered.

    I am sure that my settings in configuration.h are right for the additional motor.

    Can you help me?

  • Run M119 to see state off, then trigger it and run M119 again and it should be shown enabled with your mods. Then you know reading the end stop works at least. Only after that start searching deeper for problems.

    // bool invertEndstop,bool minEndstop, bool endstopPullup> var(float steps per mm,float speed, float max.distance)
    #define MOTOR_DRIVER_1(var) StepperDriverWithEndstop<35,33,37,0,1,ORIG_Z_MAX_PIN,0,1,1> var(20,10,110)


    you have said it is min endstop and homing should happen in that direction.

    Also note that end stop is only tested during homing, so only
    G205 P<motorId> S<0/1> E<0/1> - Home motor, S1 = go back to stored position, E1
    = home only if endstop was never met, meaning it was never homed with motor.

    will check for end stop. All other commands will ignore it anyway.
  • With the M119 command and the triggered endstop, the state off all endstops is off. 
    We are sure that our endstop is working because we tested it on the x-axis, where it was working. We use a mechanical endstop (https://youprintin3d.de/hardware/endstops/444/endstop-microswitches-omron-d2f-01fl.html).
    For the endstop of the extra motor, we use the same settings as for the endstops of the working axis. 

    By homing with the G205 command, the motor is moving into the right direction towards the min-endstop. But the endstop does not trigger.

    We do not know why the state of our endstop always is off.
  • My bad. Did not see that the extra motor endstop is not returned by M119 - so what do you see there when you say it is off. There should be no z max endstop visible. Defining it as endstop for z would be wrong. You already define it in motor configuration so there it gets defined as input with pullup. On the other side if you have configured it there it should still show signal correctly also being used for z position as well which is the error.

    G203 P0
    should report motor position and end stop status with your modification from above.
  • When we send M119 we have no z-max endstop. We only defined the endstop for the additional motor in the motor configuration.

    With the G203-command, we receive the current motor position, but no endstop status.

    We assume, that the error is somewhere in a sub-programm.

  • It should do with my mods. Meanwhile I have them implemented in the current dev version, so please redownload the dev version and try again. Guess your modifications were not correct so maybe also the one testing for endstop. Redownloading fixed version should be the easiest way.
  • I redownloaded and tested the new version. But still the same mistake, the endstop does not trigger. With the G203 command it always returns: Motor0 Pos 0.00. 
    Do you have an idea why?
  • Sounds like you did not download the dev version. Dev version will always return a end stop status. Here how the code in Drivers.cpp looks like:

    void commandG203(GCode& code) {
        int id = 0;
        if (code.hasP())
            id = code.P;
        if (id < 0)
            id = 0;
        if (id >= NUM_MOTOR_DRIVERS)
            id = 0;
        Com::printF(PSTR("Motor"), id);
        Com::printF(PSTR(" Pos:"), motorDrivers[id]->getPosition());
        Com::printFLN(" Endstop Hit:", motorDrivers[id]->endstopHit());
    }

    You see no condition if endstop hit should appear. But I see that it will not work on 8 bit. Should be
        Com::printFLN(PSTR(" Endstop Hit:"), motorDrivers[id]->endstopHit());

    Will fix that when I'm back. So if you have 8 bit board modify it.
  • Sorry, my mistake. Now I downloaded the dev version. We have a 32 bit board, so we did not changed anything. With the dev Version it always Returns: Motor0 Pos0.00 Endstop hit 0. 
    The endstop hit always returns 0, also when it is triggered. And the motor also does not stop when the endstop is triggered. Why?
  • Well if G203 always returns 0 it means triggering end stop is not registered on the pin monitored. That homing does not stop in that case is understandable. So main question here is why does the signal not change. Wrong pin number? End stop defect? 
    In initialize I see it getting initialized
    HAL::pinMode(endstopPin, endstopPullup ? INPUT_PULLUP : INPUT);

    and reading looks also correct:

        bool endstopHit() {
            return invertEndstop ? !HAL::digitalRead(endstopPin)
                                 : HAL::digitalRead(endstopPin);
        }

    So double check that the pin number is correct which is most likely the reason. Also test with multimeter if voltage on the pin changes.
  • I checked the pin number several times. The pin number is correct. I also tested other pins for the endstop. But always the endstop is not triggering. And I am sure, that the endstop is not defect. 
  • Then only when initialized does not get called makes sense. Modify

    bool endstopHit() {
    HAL::pinMode(endstopPin, endstopPullup ? INPUT_PULLUP : INPUT);
            return invertEndstop ? !HAL::digitalRead(endstopPin)
                                 : HAL::digitalRead(endstopPin);
        }

    for testing. That way pin is always set as input for every test. Not good for final version as setting mode is slow. But to be sure it is set correctly before reading.

    Also what is your definition for it in configuration.h? If pin number is at wrong position it will also not work.
  • we checked the mechanical endstop for addtional motor on the x- and y-axis axis and it works. We used a working endstop from an axis and changed it for the extra motor driver part, but the endstop is still not triggering. When we use G203 We get an answer like this Motor0 Pos5.00 EndstopHit:0.


    Is it possible that this special configuration is not compatibel with a mechanical endstop?

    We assume that the error is somewhere in a subprogram. 


  • Mechanical endstop is fine.

    Didi you do the test with modified endstopHit function as suggested? That is the most basic test to ensure it is correct regarding pin number and invert. It will even overwrite any othe rfunction accidentially using same pin for different functions.

  • Yes, we tested the modified endstopHit function. But with no success. Still the same Problem!
  • Makes no sense to me. No idea what is then going wrong here. I mean it is a simple read of a pin state that was set as input. All defined where it gets used. Only thing might be testing with a very explicit test

    bool endstopHit() {
      pinMode(Z_MAX_PIN, INPUT_PULLUP);
      return READ(Z_MAX_PIN);
    }

    use !READ(Z_MAX_PIN); if signal is wrong polarized.
    That way you explicitly use z max pin. Eventually switch to y max pin for testing.
Sign In or Register to comment.