Git Product home page Git Product logo

Comments (12)

MitchBradley avatar MitchBradley commented on July 16, 2024

The only way with the current code is to first issue $X to go from home state to idle state, then issue $H

from fluidnc.

zengfanfan avatar zengfanfan commented on July 16, 2024

no, it's not home state, it's hold state (on feed_hold_pin)
and $x do nothing but stuck the console.

actually i can reset the state to idle by pressing Ctrl+X, and then run $Home.
but how can i do it programmatically? why the code below doesnt work:

static void protocol_do_origin() {
    if (state_is(State::Homing) || state_is(State::Cycle) || state_is(State::Jog) || state_is(State::ConfigAlarm)) {
        log_warn("Ignore home event at state " << (uint8_t)sys.state);
        return;
    }

    // [bug] press home btn when paused
    if (!state_is(State::Idle) && !state_is(State::Alarm)) {
        log_warn("Reset before homing at state " << (uint8_t)sys.state);
        protocol_do_rt_reset();
        // why it doesn't do homing after ?
    }

    // works fine at `Idle` state
    log_info("Do homing by pin at state " << (uint8_t)sys.state);
    static char cmd[] = "$Home";
    settings_execute_line(cmd, allChannels, WebUI::AuthenticationLevel::LEVEL_ADMIN);
}

from fluidnc.

MitchBradley avatar MitchBradley commented on July 16, 2024

Sorry, there were lots of mistakes in my post above. I just woke up and haven't had my coffee yet. I meant to say ctrl-x to get from hold to idle.

The reason your code doesn't work is probably related to the timing of the event processing. protocol_do_rt_reset() ends by sending restartEvent to be executed later. Your code is running as an event handler, so the event dispatch cannot run until your code returns.

One way to fix it might be to use the event system instead of trying to run the event handlers directly. Instead of calling protocol_do_rt_reset(), call protocol_send_event(&rtResetEvent) , Also create a event that does the homing step and send it. Then the event handler will run all the steps in sequence.

from fluidnc.

zengfanfan avatar zengfanfan commented on July 16, 2024

Oh, wish you a good day, Mr. Bradley .
It's midnight here.
Thank you for responding, I will try it later.

from fluidnc.

MitchBradley avatar MitchBradley commented on July 16, 2024

I am not guaranteeing that my proposed approach will work without problems. What you are trying to do is complicated because of the historical design of the Grbl state machine. The problem is the use of reset to exit from Hold state. Grbl uses reset to do several things that have conflicting requirements:

  1. Set up the system for initial use and issue a signon message for the sender to see
  2. Immediately stop a job that is running
  3. Stop a job that is in hold state
  4. Exit from critical state after a limit alarm

Reset is a very "heavyweight" operation that reinitialized many variables - perhaps too many for some uses. I have often wanted to fix this problem, but the chances of breaking something is very high.

from fluidnc.

zengfanfan avatar zengfanfan commented on July 16, 2024

It's ok, any suggestion will be appreciated.
The problem is driving me crazy.

from fluidnc.

zengfanfan avatar zengfanfan commented on July 16, 2024

It do homing (state=home) but goes the wrong directions (all three axes wrong),
and says a few seconds later: ALARM: Homing Fail Approach.
—— the limit switch is at the other side...

Any idea?

new code:

static void protocol_do_home() {
    log_info("Handle home event at state " << (uint8_t)sys.state);
    static char cmd[] = "$Home";
    settings_execute_line(cmd, allChannels, WebUI::AuthenticationLevel::LEVEL_ADMIN);
}

static NoArgEvent homeEvent { protocol_do_home };

static void protocol_do_origin() {
    if (state_is(State::Homing) || state_is(State::Cycle) || state_is(State::Jog) || state_is(State::ConfigAlarm)) {
        log_warn("Ignore home event at state " << (uint8_t)sys.state);
        return;
    }

    // [bug] press home btn when paused
    if (!state_is(State::Idle) && !state_is(State::Alarm)) {
        log_warn("Reset before homing at state " << (uint8_t)sys.state);
        protocol_send_event(&rtResetEvent);
        // why it goes wrong direction when homing ?
    }

    // works fine at `Idle` state
    log_info("Do homing by pin at state " << (uint8_t)sys.state);
    protocol_send_event(&homeEvent);
}

NoArgEvent originPinEvent { protocol_do_origin };
NoArgEvent pausePinEvent { protocol_do_pause };

logs:

*** firmware uploaded and boot finish ***

Grbl 3.0 [FluidNC v3.0.x (noGit) (wifi) '$' for help]
[MSG:INFO: ALARM: Unhomed]
<Alarm|MPos:0.000,0.000,0.000|FS:0,0>
*** press Home button ***
[MSG:INFO: Do homing by pin at state 1]
[MSG:INFO: Handle home event at state 1]
[MSG:Homed:Z]
[MSG:Homed:XY]
*** press 1.nc button ***
[MSG:INFO: Running macro macro1: $SD/Run=1.nc]
[MSG:/sd/1.nc file job succeeded]
<Hold:0|MPos:103.198,103.198,49.980|FS:0,0>
[MSG:WARN: Reset before homing at state 5]
[MSG:INFO: Do homing by pin at state 5]
[MSG:INFO: Handle home event at state 0]

Grbl 3.0 [FluidNC v3.0.x (noGit) (wifi) '$' for help]
<Home|MPos:378.198,378.198,-30.020|FS:0,0>
[MSG:INFO: ALARM: Homing Fail Approach]
ALARM:9

from fluidnc.

MitchBradley avatar MitchBradley commented on July 16, 2024

If you send $message/level=debug you will see more details of the homing process

from fluidnc.

zengfanfan avatar zengfanfan commented on July 16, 2024

It's still the timing.
If I add some delay (like 100ms), it goes the right direction.

But it stuck at settings_execute_line()->do_command_or_setting->Command::action->home_all->home->do{}while with state 'Home':

    do {
        protocol_execute_realtime();
    } while (state_is(State::Homing)); // It stuck in this loop

It never get to 'Idle' after homed xyz:

[MSG:WARN: Reset before homing at state 5]

Grbl 3.0 [FluidNC v3.0.x (16M) (wifi) '$' for help]
[MSG:INFO: Handle home event at state 0]

<Home|MPos:108.045,108.045,80.375|FS:60,0|Ov:100,100,100>
[MSG:Homed:Z]
[MSG:Homed:XY]

<Home|MPos:0.000,0.000,80.000|FS:0,0|Ov:100,100,100>

new code with delay:

static void protocol_do_home();
static NoArgEvent homeEvent { protocol_do_home };
static int64_t homeEventStart = 0;

static void protocol_do_home() {
    // wait at least 100ms, or it will home at the wrong direction.
    if (millis() - homeEventStart < 200) {
        protocol_send_event(&homeEvent);
        return;
    }

    log_info("Handle home event at state " << (uint8_t)sys.state);
    static char cmd[] = "$Home";
    settings_execute_line(cmd, allChannels, WebUI::AuthenticationLevel::LEVEL_ADMIN);
    log_info("Homed, state=" << (uint8_t)sys.state); // never get here when homing at hold state
}

static void protocol_do_origin() {
    if (state_is(State::Homing) || state_is(State::Cycle) || state_is(State::Jog) || state_is(State::ConfigAlarm)) {
        log_warn("Ignore home event at state " << (uint8_t)sys.state);
        return;
    }

    if (!state_is(State::Idle) && !state_is(State::Alarm)) {
        log_warn("Reset before homing at state " << (uint8_t)sys.state);
        protocol_send_event(&rtResetEvent);
        homeEventStart = millis();
        protocol_send_event(&homeEvent);
        return;
    }

    // log_info("Do homing by pin at state " << (uint8_t)sys.state);
    protocol_do_home();
}

NoArgEvent originPinEvent { protocol_do_origin };

from fluidnc.

zengfanfan avatar zengfanfan commented on July 16, 2024

I managed to fix it by creating another task with the same priority.
When button pressed, send event to the task, and the task will send event back, and do some delay between of course.

from fluidnc.

MitchBradley avatar MitchBradley commented on July 16, 2024

You could probably do the same thing with a freertos timer. They use much less RAM than a task. There is an example in Motors/Servo.cpp

from fluidnc.

zengfanfan avatar zengfanfan commented on July 16, 2024

OK

from fluidnc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.