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.
In my opinion, the author has a comprehensive picture for a Russian person, replacing the assembly instructions:
You just need a claw throw out forget, install the laser module. Don't forget to insert well-lubricated bearings into the rotary mechanism.
Next we go from the bottom up. We will install the rotary platform and guides.
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.
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.
We skip the installation of the drive we don’t need and install the laser module.
Now we put our hand on the guides and start assembling the upper part.
Now we connect all the electronics.
The author got the following picture:
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.
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.
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.
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”.
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.
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.
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.
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.
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.