Welcome! Log In Create A New Profile

Advanced

Receiving Message When Movement is Done.

Posted by Twistx77 
Receiving Message When Movement is Done.
February 17, 2016 01:59PM
Hi,

I'm trying to use the Ramps+Marlin to make a pick and place and I want to be able to move the head using a Joystick. I already got that part working. The problem is I need to know when the Marlin have finished doing a movement. Is there a way to get anything every time the board is finished doing somehing? I know I can request the position and check if it is were is supposed to, but that is not as efficient since I have to request one or maybe many times the position. I could also calculate the time but I would really want to receive a command like DONE.

If it isn't possible, could you tell me if there is any documentation about the code's organization? I know how to code in C but my big problem is understanding how the code is organized.

Thank you.
Re: Receiving Message When Movement is Done.
February 17, 2016 02:38PM
There isn't enough information to answer your question. If the Joy Stick is under computer control and the computer is sending serial commands to Marlin, you can wait for the OK to come back. But if the Joy Stick is connected to the LCD Panel, you won't be getting an OK. In that case we would have to figure out something else. Probably you could watch how much movement is left on the move in the Stepper Interrupt Service Routines.
Re: Receiving Message When Movement is Done.
February 17, 2016 02:51PM
Hi,

Thank you for answering.

I have written a Java application that can control the Marlin and the Joystick is connected to the PC (Java App). I receive the ok but it seems to me that the ok is received just after the command is sent and not when the command have been executed and finished.
Re: Receiving Message When Movement is Done.
February 17, 2016 03:43PM
Quote
Twistx77
I have written a Java application that can control the Marlin and the Joystick is connected to the PC (Java App). I receive the ok but it seems to me that the ok is received just after the command is sent and not when the command have been executed and finished.

Well, it depends on what you mean by 'executed' and 'finished'. Take a closer look at this function:

void process_next_command() {
  current_command = command_queue[cmd_queue_index_r];
...
  ok_to_send();
}

This is where all commands get processed. At the very end of the function, it sends the OK to say it is done doing the command. I think where the confusion is coming from is on movement commands, they are parsed and the stepper motors are told what needs to be done. It takes time for that to happen. But the processor is done figuring out what has to happen and is ready to go process the next command while the movement completes.

OK... With all that said, here is how the firmware knows movement is complete. It is in Planer.cpp:

FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }

You would want to delay calling that ok_to_send() at the end of process_next_command() until blocks_queued()==0. Maybe something like this:

void process_next_command() {
  current_command = command_queue[cmd_queue_index_r];
...
  while( blocks_queued() )
     idle();
  ok_to_send();
}

If this code is just for you... That might get you very close to what you want. But for the main stream code base I don't think this is going to be acceptable because it will stop us from looking ahead and getting an early start on any commands that are already buffered up and waiting to be done. High speed printers are going to start to stutter.

Edited 1 time(s). Last edit at 02/17/2016 03:44PM by Roxy.
Re: Receiving Message When Movement is Done.
February 18, 2016 07:26AM
Thank you very much.

I think that helps me a lot.

I will try to see if it works as I want to.

Have a nice day. If anyone is interested I can add the results once I have tested.
Sorry, only registered users may post in this forum.

Click here to login