Skip to content

Commit 9bf671f

Browse files
authored
Merge pull request #30 from jschoch/dev
Dev
2 parents f55dbc6 + 5c4c1ae commit 9bf671f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2143
-829
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
.vscode/extensions.json
77

88
build/
9-
wifisecret.h
9+
wifisecret.h
10+
config.ini

README.md

+46-45
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
1-
## ESPels
1+
## ESPels: A simple electronic lead screw for the esp32.
22

3-
A simple electronic lead screw for the esp32
3+
__DANGER__
4+
There is no estop right now, not safe. Use at your own risk and hover over the lathe e-stop. The thing could go crazy and crash the carriage into the spindle at any moment. It shouldn't but bugs happen....
45

5-
* DANGER *
6-
There is no estop right now, not 100% safe. Ensure you can quickly stop the spindle and disengage the half nut. It shouldn't but bugs....
6+
This is currently in a "beta" state. There may be unfinished features, UI glitches, race conditions, crashes etc. Feedback is needed to imporove the project. Please use github issues with any questions, problems, or requests.
77

8-
[depricated: demo](https://www.youtube.com/watch?v=uXhqEe8Kw6M&list=PLvpLfzys-jPumkXZj8ZZn11zyY3UYtSkn&index=6)
8+
[ demo](https://www.youtube.com/watch?v=uXhqEe8Kw6M&list=PLvpLfzys-jPumkXZj8ZZn11zyY3UYtSkn&index=6)
9+
[latest frontend release](http://espels.s3-us-west-2.amazonaws.com/release_0_0_3/index.html)
910

10-
## Basics
11+
## Features
1112

12-
The basic architecture is the firmware does the motion control and the frontend does user interaction and configuration. The frontend is a react SPA (single page application) which uses websockets to connect to the firmware. The Frontend can live where ever you like, you can use the S3 link or you can host it in your own network. Once the files are loaded to your browser it only uses local networking. No silly firwall transitions or anything like that. You might ask why I don't serve the web content directly from the esp32 and the answer is simply development speed. This could be done with littlefs and an esp32 with enough storage.
13+
* Imperial or Metric
14+
* Revolution counter
15+
* Feed Mode:
16+
* Acts like a full time gear system for the leadscrew (like clough42's ELS)
17+
* MoveSync Mode:
18+
* Allows you to feed a fixed distance and stop
19+
* Bounce Mode:
20+
* Feeds at a cutting speed and then rapids back to the starting position
1321

14-
This repo contains the firmware. The frontend can be found here: [https://github.com/jschoch/espELSfrontend]
22+
### Planned Features
1523

16-
You can see the frontend built here: [http://espels.s3-us-west-2.amazonaws.com/dev0_0_3/index.html]
1724

25+
* Spindle angle DRO indicator
26+
* Broaching mode
27+
* Utilize bounce mode with spindle fixed for broaching keyways.
28+
* Virtual compound threading mode
29+
* This mode will offset threading passes to simulate a compound's angle infeed
30+
* TPI presets
31+
* General Presets ( ala touchDRO)
32+
* Hobbing Mode
33+
* Reuse codebase for configuring and running my hobbing controller
1834

1935
## Configuration
2036

37+
Copy config.ini.d to config.ini
2138

39+
40+
in config.ini update the WIFI_SSID, WIFI_PASSWORD Z_STEP_PIN, Z_DIR_PIN, EA, and EB for your encoder signals etc.
41+
=======
2242
Wifi: ssid and password need to be defined, this is default a file ../../wifisecret.h
2343

2444
```c
@@ -34,62 +54,43 @@ static const char* password = "";
3454

3555
Copy the "config.ini.default" to "config.ini" and update as needed. For example `'-D HOSTNAME="mx210latheELS"'` sets the hostname, EA, EB for your encoder signals.
3656

37-
See (Install.md) for more info on installation
57+
The webUI simply is a react.js application designed to be responsive, it can live anywhere and should run on your phone, tablet, laptop or PC. It connects to the firmware via websockets. No network out to the internets is needed. The s3 links are simply for convienence, you can serve the frontend yourself by copying the index.html or running `HOST=0.0.0.0 npm start`. I may eventually offer an option to serve it from esp32's directly (assuming there is flash available).
3858

59+
Once the firware is flashed you simply need to configure the frontend with the IP or dns of the firmware.
60+
![image](https://user-images.githubusercontent.com/20271/225640770-0720b314-eee3-4650-9613-717a55c63898.png)
3961

4062

63+
After that the "wifi" icon will turn from red to green once connected. You may want to continue to monitor the firmware's serial output the first time you connect. You will see something like this:
4164

42-
## Frontend
65+
![image](https://user-images.githubusercontent.com/20271/225632806-9f107f18-0247-4377-a290-8d14f369b59e.png)
4366

44-
![sample](https://user-images.githubusercontent.com/20271/104212553-33b6c200-53ea-11eb-899b-3ec2c22e56c2.png)
67+
Next you can click the red "venc On" button. This will turn on a virtual quadrature encoder to simulate the spindle moving. You will see the RPM: DRO field increase and the rev indicator will show the number of revolutions.
4568

46-
the webfrontend can be found here [https://github.com/jschoch/espELSfrontend]
69+
Finally click the "Selected Mode" dropdown to change the mode, select Feed Mode, or MoveSync Mode, change the parameters (pitch etc) and test away!
4770

71+
![image](https://user-images.githubusercontent.com/20271/225641162-c13e5c4c-d1a8-48b6-bdbc-2bdc5bf3bffc.png)
4872

4973

74+
## Lathe Setup
5075

76+
When installing on a lathe you will need an encoder with enough resolution. Testing has been done with a 600PPI -- 2400CPI encoder. While more encoder pulses will create more accuracy the algorithm used is limited to a max of 1 step per 1 encoder position. This limits the maximum pitch you can synchronize. Consider this and the maximum thread pitch your lathe can handle when selecting an encoder and stepper microstepping configuration.
5177

5278

79+
A closed loop stepper is highly recommended. The stepper online 1-CL57Y-24HE40 is a good kit for a small hobby lathe.
5380

54-
Plan:
5581

56-
1. [x] update DRO with toolRelMM
57-
1. [x] Slave Jog MM stepper mode
58-
2. [x] get stops working, slave jog to stop mode
59-
3. figure out how to sync thread start
60-
4. implement full threading cycle
82+
You may need to swap your encoder pins and or change your stepper driver's direction. The expectation is that when the spindle turns counter clockwise the "left" buttons should move the carriage Z-.
6183

62-
Cleanup:
6384

64-
1. rethink "modes", right now there are display_modes and state transitions. The GUI's mode selection should select the state machine mode needed.
65-
a. get rid of the menu thing.
85+
## Frontend
6686

87+
the webfrontend can be found here [https://github.com/jschoch/espELSfrontend]
6788

89+
## HOW
6890

69-
** TODO
91+
Initially I was planning on making a pcb with buttons to control everything. This is messy and hard to update. Now I'm using websockets and a react SPA to control everything. The websockets transmit json and msgPack for configuration and status updates. This is working very nicely.
7092

71-
- [ ] fix rapid stepper rtos crashes
72-
- [ ] lock UI on rapid move
73-
- [ ] add rapid cancel
74-
- [. ] Add rapid jog when Mod btn is pressed
75-
- [ ] Add optional encoder wheel input
76-
- [ ] Add virtual stops
77-
- [ ] Add feed to stop mode
78-
- [ ] Add feed to distance (mm) mode
79-
- [ ] Display distance to go
80-
- [ ] Add physical stops (adjustable hall sensors for example)
81-
- [ ] Add backlash compensation
82-
- [ ] turn on task monitoring and display via web ui
83-
- [ ] smooth filter EMA RPM for display
84-
- [ ] store position after disengaging slave so you can re-index if you re-engage
85-
- [ ] Add angle measure mode like a manual turned indexing plate.
86-
- [] bug with startup when spindle spinning it may have a hard time booting
87-
- [x] Add mm position to display
88-
- [x ] Add some js for frontend
89-
- [x ] Add HTML parameter updates
90-
- [x ] Turn web off when in feed modes
91-
- [x ] Add EEPROM saving of params
93+
This is currently using a version of the "didge" algorythm here (https://github.com/prototypicall/Didge/blob/master/doc/How.md_). The slope can't be > 1 so you may need to reduce your micro stepping to facilitate large thread pitches.
9294

9395

94-
Misc:
9596

TODO.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Critical
2+
- [ ] Bounce enters unknown mode, and is broken after moveCancel issues
3+
- [ ] Bounce may work unexpectedly when spindle is running in reverse
4+
- [ ] Add wifi reconnect logic
5+
- [ ] optional LED's, particularly for wifi connection status
6+
7+
8+
9+
Rest
10+
11+
** TODO
12+
13+
- [ ] lock UI on rapid move
14+
- [ ] add rapid cancel
15+
- [ ] Add physical stops (adjustable hall sensors for example)
16+
- [ ] Add backlash compensation
17+
- [ ] turn on task monitoring and display via web ui
18+
- [ ] smooth filter EMA RPM for display
19+
- [ ] Add angle measure mode like a manual turned indexing plate.

config.ini.template.ini

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[env:ESPels]
2+
#port that platformio will use to upload over usb
3+
upload_port = COM3
4+
5+
build_src_flags =
6+
#machine configuration
7+
'-D HOSTNAME="mx210lathe"'
8+
-D LEADSCREW_LEAD=2.0
9+
'-D WIFI_SSID="yourssidhere"'
10+
'-D WIFI_PASSWORD="yourwifipassword"'
11+
#motor configuration
12+
-D Z_STEP_PIN=13
13+
-D Z_DIR_PIN=12
14+
-D Z_NATIVE_STEPS_PER_REV=200
15+
-D Z_MICROSTEPPING=8
16+
#Spindle Encoder pins
17+
-D EA=25
18+
-D EB=26
19+
#choices are:
20+
#EXTERN //your hardware handles the pullup or pulldown, for example with a resistor to 3v3 or to gnd
21+
#INTERN_PULLDOWN //your encoder expects the MCU to pull low, and sends a high for a pulse
22+
#INTERN_PULLUP //your esp handles the pullup and your encoder pulls it down.
23+
#For most common quadrature encoders, choose Extern and apply 3.3v to your encoder pins through 1.5k to 4.7k ohm resistors */
24+
-D ENCODER_PULLUP_TYPE=EXTERN
25+
#ENCODER_QUADRATURE_MODE should be ON, unless you have a good reason not to. Otherwise your leadscrew will not track reverses.
26+
#valid values: ON, OFF
27+
-D ENCODER_QUADRATURE_MODE=ON
28+
-D ENCODER_RESOLUTION=2400 #this is counts per rev *4 for a quadrature encoder
29+
-D USESSD1306=1 #use the display or not. Recommend not, it doesn't have much functionality. Set to 1 to enable.
30+
-D error_led=21
31+
-D configured=true #ignore this, this just tells the config that you've configured your machine
32+
33+
[env:ota]
34+
#ip address of the esp when connected to your wifi, if you want to upload firmware remotely
35+
upload_port = 192.168.0.187
36+
37+
[env:ESPelsOTA]
38+
#ip address of the esp when connected to your wifi, if you want to upload firmware remotely
39+
upload_port = 192.168.1.28

nativeStatic.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Import("env")
2+
3+
#
4+
# Dump build environment (for debug)
5+
# print(env.Dump())
6+
#
7+
8+
env.Append(
9+
LINKFLAGS=[
10+
"-static",
11+
"-static-libgcc",
12+
"-static-libstdc++"
13+
]
14+
)

platformio.ini

+30-11
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,55 @@
11

2+
[platformio]
3+
extra_configs = config.ini
4+
25
[env:ESPels]
36
platform = espressif32
47
board = esp32dev
58
framework = arduino
69
monitor_speed = 115200
7-
;upload_port = com3
8-
;hostname = elsdesk
910
lib_deps =
10-
waspinator/AccelStepper@^1.64
11+
gin66/FastAccelStepper@^0.28.3
1112
thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.3.0
1213
thomasfredericks/Bounce2@^2.55
1314
bricofoy/YASM@^1.0.4
14-
;janelia-arduino/Vector@^1.2.0
15-
;me-no-dev/ESP Async WebServer@^1.2.3
1615
https://github.com/me-no-dev/ESPAsyncWebServer.git
1716
bblanchon/ArduinoJson@^6.19.4
1817
bblanchon/StreamUtils@^1.6.3
18+
madhephaestus/ESP32Encoder@~0.10.1
1919
monitor_filters = esp32_exception_decoder
20-
build_flags = -DCORE_DEBUG_LEVEL=3 -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -Wall -Wextra -Wunused
20+
build_flags = -DCORE_DEBUG_LEVEL=3 -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -Wall -Wextra -Wunused
2121
check_tool = cppcheck
2222
check_flags = -v
2323
check_skip_packages = yes
2424

25+
[env:ota_debug]
26+
extends = env:ESPels
27+
build_flags =
28+
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
29+
-D LOG_LEVEL=LOG_LEVEL_VERBOSE
30+
build_type = debug
31+
2532
[env:ESPelsOTA]
26-
extends = "env:ESPels"
33+
extends = env:ESPels
2734
upload_protocol = espota
28-
upload_port = 192.168.1.28
35+
upload_port = ${env:ota.upload_port}
2936

3037
[env:cppchecker]
3138
platform = espressif32
3239
board = esp32dev
3340
framework = arduino
34-
extends = "env:ESPels"
41+
extends = env:ESPels
3542
check_skip_packages = yes
43+
check_flags =
44+
cppcheck: --language=c++ --suppress=*:*pio\* --suppress=*:*neotimer\*
3645
check_patterns=
37-
src
46+
./src
3847

3948
[env:ctd]
4049
platform = espressif32
4150
board = esp32dev
4251
framework = arduino
43-
extends = "env:ESPels"
52+
extends = env:ESPels
4453
check_tool = clangtidy
4554
check_skip_packages = yes
4655
check_patterns =
@@ -51,7 +60,17 @@ check_patterns =
5160
[env:ESPelsTest]
5261
platform = native
5362
check_flags = --verbose --enable=all --std=c++11
63+
extra_scripts =
64+
nativeStatic.py
5465
lib_deps =
66+
ArduinoFake
67+
gin66/FastAccelStepper@^0.28.3
68+
thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.3.0
69+
thomasfredericks/Bounce2@^2.55
70+
bricofoy/YASM@^1.0.4
71+
https://github.com/me-no-dev/ESPAsyncWebServer.git
72+
bblanchon/ArduinoJson@^6.19.4
5573
bblanchon/StreamUtils@^1.6.3
74+
debug_test = test_stepper
5675

5776

src/main.cpp

+40-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
#include <Arduino.h>
1+
#ifdef UNIT_TEST
2+
#include "ArduinoFake.h"
3+
#else
4+
#include "Arduino.h"
5+
#endif
26

37
#define ARDUINOJSON_USE_LONG_LONG 1
48
#define ARDUINOJSON_USE_DOUBLE 1
59

610
#include "src/config.h"
11+
#include "src/moveConfig.h"
12+
#include "src/rmtStepper.h"
13+
#include "src/genStepper.h"
14+
#include "src/state.h"
715
#include "src/Encoder.h"
816
#include "Bounce2.h"
917
#include "esp_err.h"
@@ -16,20 +24,47 @@
1624
#include "src/BounceMode.h"
1725
#include "src/myperfmon.h"
1826
#include "src/Machine.h"
27+
#include "src/led.h"
28+
29+
// init static members
30+
31+
Gear::State GenStepper::State::mygear;
32+
rmtStepper::State GenStepper::State::zstepper;
33+
int GenStepper::State::nom;
34+
int GenStepper::State::den;
35+
int GenStepper::State::position;
36+
37+
int32_t MoveConfig::State::moveDistanceSteps ;
38+
bool MoveConfig::State::waitForSync ;
39+
bool MoveConfig::State::moveDirection ;
40+
int32_t MoveConfig::State::moveTargetSteps ;
41+
int MoveConfig::State::stopPos ;
42+
int MoveConfig::State::stopNeg ;
43+
bool MoveConfig::State::spindle_handedness ;
44+
double MoveConfig::State::pitch ;
45+
double MoveConfig::State::rapidPitch ;
46+
double MoveConfig::State::oldPitch ;
47+
//bool MoveConfig::State::isAbs ;
48+
bool MoveConfig::State::useStops ;
49+
int Gear::State::next;
50+
int Gear::State::prev;
51+
int Gear::State::last;
1952

2053
void setup() {
2154

55+
led_init();
2256
Serial.begin(115200);
2357

24-
init_encoder();
58+
2559

2660
init_motion();
2761

2862
init_machine();
2963

3064
init_controls();
3165

32-
setFactor();
66+
//setFactor();
67+
gs.setELSFactor(mc.pitch);
3368

3469
init_web();
3570

@@ -42,6 +77,8 @@ void setup() {
4277
}
4378
bounce_yasm.next(BounceIdleState);
4479

80+
init_encoder();
81+
4582

4683
Serial.println("setup done");
4784
}

0 commit comments

Comments
 (0)