wezhunter / ESP32_LinuxCNC_MotionController_RealTime

ESP32 hardware based real-time LinuxCNC motion controller
GNU General Public License v3.0
11 stars 7 forks source link

ESP32UDP - ESP32 + Native RMII or SPI Ethernet LinuxCNC Real time High Speed Smooth Motion Controller - 200khz Step Pulse Frequency for Multi Axis solutions

Hardware based external step generator and IO interface for LinuxCNC over native RMII Ethernet or W5500 SPI Ethernet on a dual core ESP32 for almost any board.
The hardware is connected to LinuxCNC via Ethernet.
The controller operates in position mode at low speed and at higher speeds in velocity mode.

Reliable high speed, high precision multi-axis motion in hardware - smooth and fast up-to 200khz per stepper (400khz total)
It screams...

Ultra Speed Motion

NOTE - 28th Feb 2024

There is a work in progress release which is currently being worked on offline due to the nature of rapid development and size of changes. The new release adds smooth motion on ramp up, ESP32-S2 & S3 USB support and many bug fixes. It's advised to wait until that is released before experimenting with this

Board, motor and IO pin config via the serial console is deprecated in the next release in favour of a responsive WebUI. Basic serial console commands will remain for troubleshooting purposes. Configuration Export & Import to JSON will exist

NOTE 3rd March 2024

Validated that multi-axis 300kHz pulse generation (combined) is possible via RMT on both ESP32-S2 and S3 (USB Virtual Ethernet only).
"Legacy" (not really) ESP32 optimisations need to be done to achieve the same on Native Ethernet ESP32's.
This is still at the early experiemental stages but looks promising thus far.

Update 4th/5th March 2024

Development continues, a specific type of ESP32-S3 module that was used during development had a booloader that was automatically loaded by the Arduino framework but not for others. This has slowed development somewhat since new hardware is required to be certain this does not impact testing.
This is no longer an issue and new hardware below works.

For testing USB purposes, the following board will now be used:

A video showcasing 400kHz output on the S3 dual core via USB: S3 USB 400kHz

Credits

Features

Major Refactor - Feb 2024

DISCLAIMER

This is currently an experimental firmware and should NOT be used on any production machinery. If using on a machine then you should be prepared for it to break or obliterate your machine, unless you've benchtested it sufficiently. I accept no responsibility for any damages or injuries caused as a result of using this project. Use at your own risk.

NOTES

Wiring Guides & Board Type Config

Please see /docs/Wiring.md for wiring
Serial Console doc is SerialCommands.md

TODO

Please see Github Issues for an up-to date list

Reporting Problems or Providing Feedback

Please report any issues using github Issues and they should typically be responded to within 24 hours

Feature Requests or Pull Requests

For feature requests or ideas please create an Issue
If contributing then please fork and create a appropriately named branch in your own repo
Submit a Pull Request and will be merged if it tests out fine

Precompiled Firmware

Two precompiled builds exist - One for SPI Ethernet and one for Native RMII Ethernet
Download required firmware from github release section in this repo and flash using standard ESP32 tools
Use the serial command line interface to configure your board type 'boardconf' or use one as a template and configure your own motors, inputs and outputs using the CLI

Install & Build

Clone this repository and open it with platformIO in Visual Studio Code.
See Config.h for example board types choose a Environment for your ethernet type and flash

LinxCNC Settings

On LinuxCNC Host
Set your ethernet NIC that ESP32 is connected to 192.168.111.2/24 or any address other than 192.168.111.1 within the /24 subnet
ESP32 has a static ip of 192.168.111.1. This can be changed in Config.h

Hardware

Any ESP-WROOM/WROVER-32 board with RMII Ethernet Phy (e.g LAN8720) or a W5500 SPI Ethernet module attached to SPI interface with including Interrupt pin

LinuxCNC driver

sudo apt-get install linuxcnc-uspace-dev build-essential
sudo halcompile --install esp32udp.comp

LinuxCNC HAL pins

esp32udp.0.position_cmd (in - float) commanded position in position units
esp32udp.1.position_cmd
esp32udp.2.position_cmd

esp32udp.0.velocity_cmd (in - float) commanded velocity in position units/s
esp32udp.1.velocity_cmd
esp32udp.2.velocity_cmd

esp32udp.0.position_fb (out - float) feedback position in position units
esp32udp.1.position_fb
esp32udp.2.position_fb

esp32udp.0.velocity_fb (out - float) feedback velocity in position units/s
esp32udp.1.velocity_fb
esp32udp.2.velocity_fb

esp32udp.out.00 (in - bit) digital output
esp32udp.out.01
esp32udp.out.02
esp32udp.out.03
esp32udp.out.04
esp32udp.out.05

esp32udp.pwm.00 (in - float) PWM output 0...1
esp32udp.pwm.01
esp32udp.pwm.02
esp32udp.pwm.03
esp32udp.pwm.04
esp32udp.pwm.05

esp32udp.in.00 (out - bit) digital input
esp32udp.in.01
esp32udp.in.02
esp32udp.in.03
esp32udp.in.04
esp32udp.in.05
esp32udp.in.06

esp32udp.ready (out - bit) module state
esp32udp.enable (in - bit) module enable
esp32udp.packets_lost_tx (out - s32) lost TX packets
esp32udp.last_pkt_rx_time_ms (out - s32) Last Packet RX Time in MS (up-to 5s when idle)
esp32udp.send_pkt (out - s32) TX Packet queue counter
esp32udp.udp_seq_number (out - s32) UDP sequence number from ESP32, useful for monitoring

LinuxCNC HAL parameters

esp32udp.0.scale (rw - float) steps per position unit
esp32udp.1.scale
esp32udp.2.scale

esp32udp.0.accel (rw - float) acceleration in position units/s2
esp32udp.1.accel
esp32udp.2.accel

esp32udp.pwm.00.freq (rw - u32) PWM frequency in Hz 0..65000
esp32udp.pwm.01.freq
esp32udp.pwm.02.freq
esp32udp.pwm.03.freq
esp32udp.pwm.04.freq
esp32udp.pwm.05.freq

PWM usage

If the esp32udp.pwm.xx.freq parameter is set to 0, the esp32udp.out.xx pin works and the esp32udp.pwm.xx pin does not.
If the value of the esp32udp.pwm.xx.freq parameter is not 0, the esp32udp.out.xx pin does not work and the esp32udp.pwm.xx pin does.