bdring / Grbl_Esp32

A port of Grbl CNC Firmware for ESP32
GNU General Public License v3.0
1.7k stars 531 forks source link

Information about $ codes #110

Closed GandalfOp closed 5 years ago

GandalfOp commented 5 years ago

Hello, I'm trying to execute some GRBL codes from the code lines, just as if I would send them from the Universal Gcode Sender (for example:)

if (Start_Button == 1) { "Send $FM" "Send $F" "Send $F=/mycode }

I would not do that "literally", since I'll be using interruptions on the start button, then activating a global variable from the inside, and using a watch to execute my code when this global variable triggers.

Is there any way to "Send $FM"? Otherwise, are those commands stored into memory adresses? That way I could call the adress directly.

Thanks a lot!

GandalfOp commented 5 years ago

I would Label this as a question, not really an issue.

bdring commented 5 years ago

I am out of town again until Monday. You should use the WebUI branch and see command.txt to see how SD commands work.

WebUI will merge to master soon.

Slixxor commented 5 years ago

@GandalfOp You will need to send indiviudual commands and wait for a corresponding "ok" to be returned from the controller before sending the next command. If you need to send a sequence of commands and it isn't a G-code file job I would create flags in your software for the different groups of commands you are waiting on a response from with a global counter value to manage your current command in the sequence. It's foolproof this way.

If you regularly poll the "?" command I would recommend to add a timer to catch any command timeouts or effectively manage any commands that return responses that start with "<".

Please see the example from our GRBL tool i've witten in vb.NET. I have an enum that sets what status i'm editing settings for. It then sends the corresponding group of commands in sequence between 'ok' responses.

'Accel settings Case ChipState.UpdatingAccelSettings If Dataval.StartsWith("ok") = True Then AccelInt += 1 Select Case AccelInt Case 1 SP.SendAsciiStringLine("$111=" & numYMax.Value) Case 2 SP.SendAsciiStringLine("$112=" & numZMax.Value) Case 3 SP.SendAsciiStringLine("$120=" & numXAccel.Value) Case 4 SP.SendAsciiStringLine("$121=" & numYAccel.Value) Case 5 SP.SendAsciiStringLine("$122=" & numZAccel.Value) Case 6 Accelint = 0 CurrState = ChipState.Idle MsgBox("Acceleration and maximum speeds per axis have been set successfully.", MsgBoxStyle.Information, "Settings updated") End Select

bdring commented 5 years ago

@GandalfOp

I think the best way to do this would be to create another channel for commands. If you look at the serialCheckTask() you will see that it can read commands from several sources (serial, bluetooth, wifi, telnet).

Adding another source like, "local_control", would allow Grbl to read commands from a queue. Buttons, etc, could add commands to the queue.

It is important to allow Grbl to control the reading of these commands. You can't immediately push most commands, because Grbl's buffer is likely to be full or not ready to perform a new command.

You can look at the other sources as examples of how to implement a new one. It could be a part of a larger project to add a comprehensive local control panel, with LCD, etc. I don't have time right now to do this and adding a local display goes against my basic vision of Grbl_ESP32 (The best local display is a wireless connection to your phone or PC)

GandalfOp commented 5 years ago

Great! Thanks a lot, this is gonna be so helpful! Will try to add local_control so that way, if done correctly, It will automatically do what @Slixxor says. I did not think about it originally, but you're right, we need to wait until the "ok" is returned...

Thanks a lot!

bdring commented 5 years ago

I recently played with adding macro buttons. I wanted to simplify one of my machines for a public event.

image

One button homes the machine and the other two run files off the SD card.

The code is currently in the kinematics branch. Here are the features.

GandalfOp commented 5 years ago

Great! Will try to run my codes that way! Thanks a lot! Edit: I used the Kinematics option, disabling #define USE_KINEMATICS since I'm using a cartesian plotter, and works great (at least vitrually! Need to connect the motors still) Thnx a lot!

GandalfOp commented 5 years ago

Hello and sorry for answering a closed issue, but I changed the pin map to make it work on the ESP32 CNC board, and I can only make it work wiring it tho the pin 13, and it activates only while the pin is pressed (switch, not button single press) The strange thing is that when I do it on the Universal GcodeSender only with 1 press on the button it virtually activates the whole gcode, while the same program wired to the motors needs the button to be permanently pressed.

Any info I could use about that?

Thanks!