Enter Your Project for a chance to win a Nano Grand Prize bundle for the most innovative use of Arduino plus a $400 shopping cart! Back to homepage | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
I'm jumping ahead a little to make sure I can add the required focusing functionality to the LaserGRBL program. I'm used to the method that 3D printers use to home their axes which is to move into the limit switches. After reading through the GRBL documentation I realized that moving into the hard limit switches actually causes an alarm condition which requires a reset. Since GRBL 0.9, a "probe" function has been added that is commonly used to set the Z-axis position, so I'm going to use that input rather the Zend input to signal that I've reached the focus position.
Here is a picture of the top of my controller board with the interface connector highlighted and the schematic that shows the Probe input.
I'll need to wire a digital output from the MicroView to the Probe input and program that output to switch high when the VL6180X measured distance is 39 mm.
Then I'll need to create a custom button within LaserGRBL to execute the alignment code. It turns out creating the custom button is straightforward. You right click in the button bar at the bottom and it brings up a dialog to create/edit the custom button.
Here is a screenshot of the LaserGRBL Control Panel:
You can see the custom "Z Focus" button that I created at the left.
And here is the custom button edit panel:
The gcode for testing is very simple.
G92 Z0 sets the current Z position to 0
G38.2 Z-10 F100 is the probe command that moves Z down -10 mm at a speed of 100 mm/min. The travel will stop when the "Probe" input is pulled low or Z-10 is reached - whichever comes first. An alarm will occur if the "Probe" input does not switch before the endpoint is reached.
G92 Z0 sets the new position to be Z0
The procedure will be to set the laser head so that the distance measurement is >= 45 mm and then hit the Z Focus button. The Z position should now be aligned when the head stops.
There's probably some tweaking that I need to do relative to the speed (feed rate) that the head moves down. Maybe do an initial align at higher speed and back off and align again at a slower speed.
Modified MicroView Code
MicroView_V6180X_InterleavedContinuous.ino
/* This example demonstrates how to use interleaved mode to take continuous range and ambient light measurements. The datasheet recommends using interleaved mode instead of running "range and ALS continuous modes simultaneously (i.e. asynchronously)". In order to attain a faster update rate (10 Hz), the max convergence time for ranging and integration time for ambient light measurement are reduced from the normally recommended defaults. See section 2.4.4 ("Continuous mode limits") and Table 6 ("Interleaved mode limits (10 Hz operation)") in the VL6180X datasheet for more details. Raw ambient light readings can be converted to units of lux using the equation in datasheet section 2.13.4 ("ALS count to lux conversion"). Example: A VL6180X gives an ambient light reading of 613 with the default gain of 1 and an integration period of 50 ms as configured in this sketch (reduced from 100 ms as set by configureDefault()). With the factory calibrated resolution of 0.32 lux/count, the light level is therefore (0.32 * 613 * 100) / (1 * 50) or 392 lux. The range readings are in units of mm. */ #include <MicroView.h> #include <Wire.h> #include <VL6180X.h> VL6180X sensor; float dist, sens, csens, offset = 5.0; int count; int probe_out; // probe output pin void setup() { probe_out = A0; // MicroView pin 7 pinMode(probe_out, OUTPUT); // set to output pin digitalWrite(probe_out, HIGH); // initialize high Wire.begin(); sensor.init(); sensor.configureDefault(); // Reduce range max convergence time and ALS integration // time to 30 ms and 50 ms, respectively, to allow 10 Hz // operation (as suggested by Table 6 ("Interleaved mode // limits (10 Hz operation)") in the datasheet). sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 05); //sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 10); sensor.setTimeout(500); // stop continuous mode if already active sensor.stopContinuous(); // in case stopContinuous() triggered a single-shot // measurement, wait for it to complete delay(300); //READOUT__AVERAGING_SAMPLE_PERIOD sensor.writeReg(0x10A, 0x08); // start interleaved continuous mode with period of 100 ms //sensor.startInterleavedContinuous(100); sensor.startRangeContinuous(10); Serial.begin(57600); uView.begin(); uView.clear(PAGE); uView.setFontType(0); uView.display(); //ideas // Look at docs to see how to improve accuracy // only use samples that converged // look into whether samples are used twice or other issues with the uncontrolled loop // allow more variability in the output of the sensor and average in the mcu // measure drift by connecting to the CNC machine to get precise moves count=100; } void loop() { //Serial.print("Ambient: "); //Serial.print(sensor.readAmbientContinuous()); //if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); } sens=sensor.readRangeContinuous(); csens =sens + offset; // uView.clear(PAGE); // uView.display(); // uView.setCursor(0,0); // uView.println("Distance:"); if(sens<255) { if( abs(csens-dist)>10.0) {dist=csens;} dist = .995* dist + .005 * csens; } count=count-1; if (count ==0) { count=100; //Serial.print("\t Range: "); Serial.print(dist); Serial.println(); uView.clear(PAGE); uView.setCursor(0,0); uView.println("Distance:"); uView.print(dist); uView.println(" (mm)"); uView.display(); if (dist <= 39.0) { digitalWrite(probe_out, LOW); } else { digitalWrite(probe_out, HIGH); } } if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); } }
Testing
I updated the MicroView program and mounted the assembly on the laser head. I am using the A0 pin as my "probe" signal so I wired that to the Probe input of the GRBL controller.
The first couple of tries failed with no probe detection so I thought that I had mis-wired the probe signal, but it turned out that I had set the feed rate so that it was too fast for the response time of the probe detection in the GRBL program. The setting that I was using was 100 mm/min. I saw that for mechanical probes examples they were using 10 mm/min but I thought that was because they were worried about over travel into a hard surface. I played with the speed a bit and determined that 20 mm/min worked reliably but because of the heavy averaging that I would overshoot the 39 mm target. I decided to do the initial align at 20 mm/min and then back off 2 mm and realign at at 2 mm/min.
Here is the updated button program:
Here's a quick video of the focus alignment. I apologize that the webcam doesn't focus well on the display.
So, I'm close but I still need to do the VL6180X sensor characterization and then tweak the program and the alignment control to get repeatable values. Before I do that I'm going to clean up the mounting and the wiring.