SCARA-Laser. Part 2. Reinventing the Wheel
Intro
Once I figured out the kinematics, I went scouring the internet for existing solutions and found my project already ready. Well, almost.
https://howtomechatronics.com/projects/laser-engraving-with-diy-arduino-scara-robot-complete-guide/ – laser engraver on SCARA-kinematics with Arduino Mega controller. Exactly what I wanted. But this article would not exist if I had simply downloaded the models, printed them out and assembled them according to the instructions.
List of everything you need
4x Smooth Rod – 10mm 400mm
1x Lead screw trapezoidal – 8 mm 400 mm (you can, of course, use a stud, but trapezoidal is better)
4x Linear Bearings 10mm
1x Thrust ball bearing
2x Thrust ball bearing 35x52x12mm
5x Radial ball bearing 8x22x7mm
Bolts and nuts M3, M4 and M5 of various lengths
Stepper Motor – NEMA 17
Stepper Motor Driver DRV8825
RAMPS 1.6 board
Arduino MEGA
Limit switch
DC power supply
Laser module
3D models and printing
To begin with, I slightly modified the author's model, removing all unnecessary things, namely the additional rotary axis of the laser (well, why rotate the laser around its axis?). The second change is that I expanded the control module. The third is that I replaced the laser module, and in addition the bracket for it. The fourth is that I moved one of the end triggers: the author's mistake.
Once everything was modeled, I went to print. I printed on a Flying Bear Ghost 5 3D printer with PETG plastic. It won't leak from the stepper motors heating up during operation and is less demanding of print settings, compared to ABS. It took about three days and two kilogram spools. Important – set shrinkage compensation and density of at least 30 percent. The rest is up to your taste and printer.
Models here: https://drive.google.com/open?id=15yxUuZh-IG0YdzL7neZ2oXOIsCN8d9CC&usp=drive_fs
Changes in electronics
I took the DRV 8825 drivers and the LASER_TREE laser module with 5W optical power, the rest I left as the author had.
Assembly and setup(TRANSLATION)
Now we have a pile of parts like this in front of us.
![Finished parts Finished parts](https://habrastorage.org/getpro/habr/upload_files/1c4/ac4/ec5/1c4ac4ec5fe13ee6720d8aa0772150b0.png)
In my opinion, the author has a comprehensive picture for a Russian person, replacing the assembly instructions:
![Fasteners Fasteners](https://habrastorage.org/getpro/habr/upload_files/103/e31/775/103e31775bf5667d87e40ccec7c84bf7.png)
You just need a claw throw out forget, install the laser module. Don't forget to insert well-lubricated bearings into the rotary mechanism.
![](https://habrastorage.org/getpro/habr/upload_files/09c/e80/ecd/09ce80ecd6e96d00d9ad1266b13cb642.png)
Next we go from the bottom up. We will install the rotary platform and guides.
![](https://habrastorage.org/getpro/habr/upload_files/5f8/eb8/bd6/5f8eb8bd6ee7c1f4a3fe452b25c36f39.png)
Next, assemble the arm itself. Carefully insert the linear bearings, the plastic may crack. It is better to mount the wiring and belts right away.
![](https://habrastorage.org/getpro/habr/upload_files/b29/de1/ce3/b29de1ce3a88005de740307254953955.png)
![](https://habrastorage.org/getpro/habr/upload_files/1d2/b26/16d/1d2b2616dd701f849e42865109482bbb.png)
![](https://habrastorage.org/getpro/habr/upload_files/deb/e1d/286/debe1d286e4867ddcf3dc5275e84dc74.png)
And then the author goes on Error! With this arrangement of the end trigger, the calculation of kinematics is significantly complicated. The trigger must be directed against the straight position of the hand.
![](https://habrastorage.org/getpro/habr/upload_files/891/f00/79a/891f0079aa8358d9e559ed049a9de9cf.png)
We skip the installation of the drive we don’t need and install the laser module.
![](https://habrastorage.org/getpro/habr/upload_files/fed/0d3/9b5/fed0d39b5a9baffdef026647e3748af0.png)
Now we put our hand on the guides and start assembling the upper part.
![](https://habrastorage.org/getpro/habr/upload_files/5e5/450/126/5e54501269d01781289af49fec3d9841.png)
![](https://habrastorage.org/getpro/habr/upload_files/0e1/82a/484/0e182a484c0135a27863faeb9953ea93.png)
![](https://habrastorage.org/getpro/habr/upload_files/91d/799/9a9/91d7999a9b8a8eb3fef795c29e45b92e.png)
Now we connect all the electronics.
![Connection diagram of electronic components. Connection diagram of electronic components.](https://habrastorage.org/getpro/habr/upload_files/ab9/d53/921/ab9d5392178466a1e6a936652c4aa017.png)
The author got the following picture:
![Author's SCARA.. Author's SCARA..](https://habrastorage.org/getpro/habr/upload_files/ff8/742/af4/ff8742af4de686c5f2a1737d407813d4.png)
![My version. I'll tell you about the display later. My version. I'll tell you about the display later.](https://habrastorage.org/getpro/habr/upload_files/f39/80a/4ea/f3980a4eacd5a631eacb1e5fa8fc2df2.jpg)
Next, I started setting up the drivers. It wasn't difficult, the main thing is to choose a good screwdriver. My Vref was 0.7V. For those who don't know, for the stepper motor driver to work correctly, you need to set up the limiting voltage Vref. This is done very simply: measure the voltage between GND and the potentiometer on the driver, and adjust it with the same potentiometer.
As I said, I will be using Marlin firmware, which is one of the most widely used open source firmware for 3D printers, which also has options for laser engraving and SCARA robot customization. We can download Marlin firmware either from its official website or from Github.com.
![Marlin Firmware for Controlling SCARA Laser Engraver Robot](https://habrastorage.org/getpro/habr/upload_files/2e5/4cd/43f/2e54cd43f75e3dc72bea9b749660b380.webp)
To install Marlin firmware on the Arduino MEGA board, we will use PlatformIO IDE instead of Arduino IDE. Since Marlin firmware is large and complex, Arduino IDE may sometimes give errors and fail to compile it.
![PlatformIO for downloading Marling firmware](https://habrastorage.org/getpro/habr/upload_files/87c/469/270/87c4692704c2159c586b9d58096637e0.webp)
PlarformIO is built on top of the Visual Studio Code editor and can be installed as an extension to it. This means that we first need to install Visual Studio Code, then find PlatformIO in the extension manager and install it from there.
![](https://habrastorage.org/getpro/habr/upload_files/8a6/803/203/8a6803203fbac00181c2e698e6d2d36d.webp)
Once the installation is complete, we can click the “Open Project” button, go to the Marlin folder we downloaded and unzipped, and click “Open Marlin”.
![Marlin Open Firmware with PlatformIO](https://habrastorage.org/getpro/habr/upload_files/285/c21/9f7/285c219f7352e5ea9136fb9070c38c3c.webp)
This will load all the Marlin files into the editor and we can open and edit them. The two main files where we do all the customizations to suit our machine are the Configuration.h and Configuration_adv.h files.
![Editing marling firmware config h-file in platformio](https://habrastorage.org/getpro/habr/upload_files/649/44d/340/64944d340bbbe5b611184e3c5589c9af.webp)
In fact, before opening the Marlin folder, we should first go to the Configuration repository on Github.com, where we can download some pre-tested configuration files that work for us. In the Examples folder, we should go to the SCARA folder and copy these two configuration files and paste them into our Marlin folder.
Setting up Marlin firmware(TRANSLATION)
So, once we open the Marlin folder with the “SCARA” configuration files again, we can open the Configuration.h file and edit some parameters to suit our machine. The first thing to do here is to select the type of SCARA robot we have.
/**
* MORGAN_SCARA was developed by QHARLEY in South Africa in 2012-2013.
* Implemented and slightly reworked by JCERNY in June, 2014.
*/
//#define MORGAN_SCARA
/**
* Mostly Printed SCARA is an open source design by Tyler Williams. See:
* https://www.thingiverse.com/thing:2487048
* https://www.thingiverse.com/thing:1241491
*/
#define MP_SCARA
#if EITHER(MORGAN_SCARA, MP_SCARA)
// If movement is choppy try lowering this value
#define SCARA_SEGMENTS_PER_SECOND 100
// Length of inner and outer support arms. Measure arm lengths precisely.
#define SCARA_LINKAGE_1 228.15 // Arm 1 lenght - 228(mm)
#define SCARA_LINKAGE_2 136.2 // Arm 2 lenght - 136.5(mm)
// SCARA tower offset (position of Tower relative to bed zero position)
// This needs to be reasonably accurate as it defines the printbed position in the SCARA space.
#define SCARA_OFFSET_X 300 // (mm)
#define SCARA_OFFSET_Y 150 // (mm)Язык кода: Arduino ( arduino )
“MORGAN_SCARA” is for a parallel SCARA robot, and “MP_SCARA” is for a serial SCARA robot like ours. This is based on Tyler Williams' open source code, which implements inverse kinematics on G-codes generated for regular Cartesian systems.
![Kinematic formulas. SCARA laser engraver with inverse kinematics](https://habrastorage.org/getpro/habr/upload_files/9cf/528/572/9cf528572e072ee2e4098671ad278f40.webp)
Here we need to enter the length of the robot arms, and in this case it is 228 mm for the first arm and 136.5 mm for the second arm. The next parameter we need to set is the zero position of the working bed. This value is entered using the SCARA_OFFSET_X and Y values, and it is the distance from the turret or the first joint relative to the zero position of the bed.
There is one more set of parameters that we need to adjust to suit our machine, and that is MANUAL_X_HOME_POS for X and Y. These values represent the X and Y distances from the end effector of the robot arm or laser when it is in the home position, relative to the zero bed position we set earlier. To get these values, I made a simple sketch in SOLIDWORKS with two lines representing the two arms of the SCARA robot.
![Setting up Marlin firmware for a SCARA laser engraver robot](https://habrastorage.org/getpro/habr/upload_files/c78/012/f4a/c78012f4a70250806f833bfc827a5d5d.webp)
From here you can set the desired zero position of the bed and get values for the MANUAL_X_HOME_POS variables.
Next we need to define the limit switch connectors. In our case we have one limit switch for each axis, which is in the minimum position.
#define USE_XMIN_PLUG
#define USE_YMIN_PLUG
#define USE_ZMIN_PLUGЯзык кода: Arduino ( arduino )
In addition to this, we need to define X_HOME_DIR as -1, which specifies the direction of the limit switches when returning to the home position.
// Direction of endstops when homing; 1=MAX, -1=MIN
// :[-1,1]
#define X_HOME_DIR -1
#define Y_HOME_DIR -1
#define Z_HOME_DIR -1Язык кода: Arduino ( arduino )
Here we also need to check if all __MIN_ENDSTOP_INVERTING variables are set to “FALSE”.
Next we need to adjust the DEFAULT_AXIS_STEPS_PER_UNIT values to suit our machine.
#define DEFAULT_AXIS_STEPS_PER_UNIT { 177.7777777, 142.2222222, 400, 93 }Язык кода: Arduino ( arduino )
These values indicate how many steps the program should send to the stepper drivers to move the motor one unit, which in this case is one degree of joint rotation. Here's how I calculated these values for my SCARA robot.
![Setting the default axis steps to one in Marlin for a NEMA 17 stepper motor](https://habrastorage.org/getpro/habr/upload_files/9cf/15e/4db/9cf15e4dba94695a72ec8707af32c070.webp)
NEMA 17 stepper motors take 200 steps to make a full rotation, but since we are using a resolution of 16 steps, this means we need to send 3200 steps to the driver to make the motor make a full 360 degree rotation. Additionally, for the first joint, we have a speed reduction of 20:1, which means we need 64,000 steps to make a full rotation. If we divide this value by 360, we get the number 177,777, which is actually the number of steps the program needs to send to the driver to rotate the joint one unit, or one degree.
The second arm has a speed reduction of 16:1, so the value will be 142.222. For the Z-axis, we have a lead screw with a pitch of 8 mm, which means that one full revolution of the motor will result in a linear movement of 8 mm. One unit here is equal to one mm, so we need to divide 3200 steps by 8, and this gives us a value of 400, which is the number of steps needed to move the Z-axis one unit, or one mm. The fourth value here is for the extruder stepper motor, but since we don’t have an extruder here, we don’t need to change that.
The direction of the stepper motor depends on how we connected the wires. If we made a mistake, we can either swap the wires or change it here in the software by setting the INVERT_X_DIR variables to TRUE.
// Invert the stepper direction. Change (or reverse the motor connector) if an axis goes the wrong way.
#define INVERT_X_DIR false
#define INVERT_Y_DIR false
#define INVERT_Z_DIR falseЯзык кода: Arduino ( arduino )
We need to make a few more changes to get this Marlin firmware working. Since Marlin is primarily a firmware for classic Cartesian printers, the SCARA mode it supports has a few small bugs that haven't been resolved yet at the time of this project. Here are the changes I made to get it working.
In scara.cpp, line 75 I replaced MORGAN_SCARA with MP_SCARA. In motion.cpp I had to comment out lines 1716 and 1717, in cofiguration.h I had to comment out VALIDATE_HOMING_ENDSTOPS, and in configuration_adv.h I had to uncomment QUICK_HOME.
Actually, even with these changes, the homing still didn't work 100% correctly, but I'll explain the workaround I used to get it working.
However, we can now click on the Upload button located at the bottom left corner of the editor and the Marlin firmware will be installed on the Arduino board.
Test runs
Having connected the miracle unit to Repetier-Host, I sent it for a test run. Unlike the author, everything worked for me the first time, but I was not satisfied with the quality – the drivers are jerky, something is always heating up on the expansion board (although it shouldn't!), the logic of moving the firmware is very strange and not optimal. Here is a short video:
https://youtube.com/shorts/CicuKRPfQDo?si=gdIla80R8wzqYMv7
Conclusion
Having suffered with setting up someone else's, I realized that it is easier to make my own. Therefore, I plan to refuse ready-made firmware. The entire project will go on Full-Python, which means that as a controller in a pair with RPI 5 for processing machine vision, I will take RPI Pico without a graphics core. I will also order new TMC2208 drivers and independently design a board for them. By the way, there will be part 4 about this, and in the next part we will talk a little about machine vision.