Mach4-Motor-Accel - a macro and post combo

Mach4-Motor-Accel makes it possible to set custom X/Y motor acceleration values from within Fusion 360, or by manually editing G-code. This is available per-toolpath, allowing for a mix of default and reduced (custom value) acceleration in a single G-code file. The option is located in the Post Properties tab of each toolpath’s Edit dialog. Instructions for manual entry are also included below. It’s recommended that you try a dry run first to ensure you understand the configuration and performance before cutting any material.

Note: Changes to motor acceleration are not fully accounted for by the Mach4 motion planner. Small deviations are possible. For most routing work this will probably not be measurable. With something like a laser, capable of extremely fine detail, you may notice some deviation. This is not tested for every conceivable combination of components and may not be for you.

I do not warrant functions contained in the program will meet your requirements or that the operation of the program will be uninterrupted or error-free. The program is provided “AS IS”, without warranty of any kind, express or implied.

Tested on Avid CNC Mach4 releases 2.3.5, 2.3.8, 2.4.2

What are the components of the tool?
  • A copy of the current Avid CNC post processor for Fusion 360 with added code to accept an acceleration value and output macro commands
  • A macro (m4000) that accepts a motor acceleration variable as ‘A’ (e.g. M4000 A35)
  • A macro (m4001) that resets motor acceleration to Avid CNC defaults (50 units/(sec^2))
How to Install:
  1. Download ZIP attachment
  2. Unzip file
  3. Copy m4000.mcs and m4001.mcs to your Mach4 profile Macros folder (typically C:\Mach4Hobby\Profiles\AvidCNC\Macros)
  4. Import Avid CNC-MA.cps post processor file into your Fusion 360 posts library
How do I use it?
  • Option A) - Fusion 360:

    1. Setup your toolpaths in the Manufacture workspace as usual.
    2. When editing any toolpath, you will have the option to enable and set a custom motor acceleration value in the dialog. Hover over the field for more info.
      motor_accel_dialog_sm
    3. Post process your setup or individual toolpath as usual.
  • Option B) - Manual (non-Fusion users):

    • Ignore the included post processor file.
    1. Post process your toolpaths as usual.
    2. Manually edit the code, inserting “M4000 A” (e.g. M4000 A35) at the beginning of a toolpath section you want it to apply to.
    3. Similarly, insert M4001 at the end of a toolpath section when you want to cancel the customization.
    • As a precaution, also consider insertion of M4001 at the end of the G-code, before final retract and shutdown.
Anything Else I Should Know?
  • There’s no impact to jogging performance/acceleration, only software control (like G-code file or MDI).
  • The custom acceleration values are not persistent. When you close Mach4, it defaults back to your original motor configuration.
  • This does not overwrite or modify the typical Configure > Control > Motors acceleration values.
  • The acceptable value range is 10 to 50 as defined in the CPS file.
  • Updates to your acceleration are logged in the History window in case you need to look back at the data.

Details for nerds:
  • The motor acceleration profile is calculated based off the configuration of motor 0 only.
  • Changes are applied to motors 0, 1 and 3 (X, Y1, Y2).
  • Motors 2, 4 (Z, A/U) and any others are not modified.
  • If you have customized your X and Y steps or acceleration using shared values, this should work. Please note the m4001 macro will reset the values to Avid default (50), but again this isn’t persistent, and you can change it.
  • If you have customized your X steps or acceleration to be different from your Y1/Y2, this probably isn’t for you.

Mach4-Motor-Accel.zip (16.7 KB)

Hmmm, are you recalculating the optimal chip load with these variation in acceleration? If so, how do you account for possible collisions?

No, and this being an admittedly complex topic, I intentionally left the code open to review for exactly the type of people who know to ask those questions. CV mode? CV Tuning? Feed Optimization? Exact Stop? Motion planning? Let’s crack open these topics and take the collective knowledge to the next level.

40% of this project was to explore Fusion’s post processor documentation. 40% was to learn how to handle parameters in the G-code via macros. The last 40% was to brush up on my math skills.

In the end, I hope curious folks will explore what’s there and find answers to their own questions, or come away with their own curiosities. I’m inspired by folks like @da-kengineer-meister, @subnoize and @corbin who share what they’ve learned so others may benefit.

2 Likes

Actually, the reason I ask is this very topic came up in the past when discussing the maximum acceleration configuration and those who believe that they could find some magic number that would eliminate the ringing in these 8020 machines.

I suggested that one could do this manually but you baked it into the post processor which is just another answer.

The way you should advertise this is folks should try your script instead of futzing with their max accel settings :rofl:

Yeah, you will get some rubbing and shortened tool life in a high volume shop but for those guys and gals in low volume and hobby work, they would potentially see less ringing.

Best of luck.

PS. I didn’t see the script part until just now. Lua in the middle of cut is scary stuff :stuck_out_tongue: You are a bolder person than I am :grin:

Yeah, I’ve read through that hub-bub about ringing. This really wasn’t intended to be a solution to a perceived problem. I’m pretty sure I started messing with this (one of many side projects) before the forum launched. I found that changing the motor accel in the typical way caused latency when jogging, and that made me uncomfortable. I also found many people are trying to hot-rod their machines, cutting at 250ipm into tight angles and stuff. It’s going to bump around if you slam 150lbs+ of gantry in reverse! Mostly the Vectric users - I don’t know if they’ve added new post options lately though. Fusion has us spoiled with options to address that most of the time.

If Autodesk would add the ability to apply FRO to the exit rather than just the approach I could finally finish my Fusion/Mach4/ESS plasma post.

1 Like

Yes, that is one of the annoying things about manually setting the motor acceleration in Mach4, you’re jogging can be like driving a cruize ship if you set it really low. Also, it saves it and you may forget to put it back. I like using the API’s in a macro like you’ve done because it won’t affect jogging and you can put it back to your default at the end of the g code file. If you have issues with timing (getting the acceleration API to finish its job before any movements happen in the Gcode), you can always add some delay with a G4 Pxx.
I have been thinking of adding it to my screen just to make it easier and not save when M4 is shut down.

1 Like

I have found two scriptable methods - the above method, and writing to the machine config file. This way allows real-time changes, while the other requires Mach to be in Disabled state because you have to write to the machine config. This started as a wizard using the latter method, and developed as I wanted a reason to use macros for something.

If I were rolling this for daily use I would probably add some input validation to the macro. The Fusion post has that built-in, but for anything besides that I’d want to make sure it halted outside of acceptable values.

Ya, I was going to use the API’s because that is a direct change, and isn’t permanent after shut down like editing the config file. On adjustable parameters that I have in my screen, I generally like them to go back to a default value at startup. To many times I forget otherwise the next day and things are running weird until I remember I changed something :slight_smile:

thanks David! I’m going to take a look at this – I think I could use it to slow down the acceleration just for my finishing passes. I’m still seeing some jitter showing up, and I think this might help

It definitely has cleaned up my Vcarved items. I used to have a lot of visible ripples on the deeper sidewalls that had to be sanded out. I now run all my laser and Vcarve work down around 15 i/s^2 and I don’t have to do any sanding on the carved portions now. The runtime difference in negligible, especially considering I don’t have to sand in the carving.

15, whoa that is lower than I thought it’d need to be! I did experiment with 25 before I welded on an additional brace on my table, and I was basing it on your video. I upped it back to 50 to see how much jitter I was still getting for my current project – definitely way better, but still present. I’ll probably drop it back down to 25, but I’ll also give 15 a try – particularly on my y-axis.

I really do like David’s approach of having it set on a per-tool basis…this is a great idea.

Corbin

Well, 25 or 30 is a big improvement over 50, and you might find that is good enough for you in carving. What you are carving (i.e. long lines with a few turns, or short vectors that are turning all the time), the size of your machine, the feed rate you are running, your table construction all matter. I generally run at 15 because I need to be there for good laser performance, and the runtime of the file isn’t going to be much different between 15 adn 25, so I just leave it at 15 most of the time. I will probably add something to the screen to make it quick to change though.
Once you get down below 10 though, the jogging is just supper sluggish, so if you have a need to be there (some types of super fine laser work does) then the macro is the best way to go for sure. Like you said, its nice to do it on a tool basis so the macro is nice for that reason too.

1 Like

I finally got around to adding this to my screen set. Once I looked at the API’s a little closer and tested them, I realized that there is one for the Gcode execution (the one you were using that has Motors in the name), and another for the jog. So when Mach4 starts, it must write the value thats in the motor config area to both the regular motor one, and the jogging one.

So I just added a screen feature to set the 3 axis acceleration values directly. This only does the one for Gcode execution, so the jogging is still nice and snappy. I call this once on startup to knock it down from the defaults in the motor config (I left those at 50 so the jogging would be responsive), but then the Gcode ones are written down to something lower, and I can always set them to whatever I want during a session by entering in the DRO and setting those values. Its nice to be able to update the acceleration quickly buy not have it affect jogging, and then it all goes back to a default at the next startup so I don’t forget to leave it at some value from the last time I needed it slower.

Thanks for the original post to get me thinking about a faster way to change these.

1 Like

Glad you were able to get some use out of it. Let us know if you discover any downsides or caveats for running your machine with these settings.

I’ve been running those settings for over a year with no issues. I do mostly Vcarving, 2.5D carving, and laser work and all of those have much reduced vibration at these reduced accelerations. I had been setting them via the mach 4 motor settings though until now, so my jogging was pretty sluggish.

2 Likes

have you released a new screen set with this in it Jim?

1 Like

I hadn’t because I had one more feature I was working on, but that one is taking a while so I’ll just hide it and release one with other two features. I’ll let you know when it’s up on my shared drive .

1 Like

good i’ll keep an eye out

Hi Brian,

I just uploaded the screen (rev 11) and updated the readme file that details what I added.

https://drive.google.com/drive/folders/1xB6J0RZIU1j8g951NkP-8HXC1swC2C-B?usp=drive_link
Under the foldel Mach4 screed stuff.

jim