Go Down

Topic: Controlling 3-axis robot arm with RAMPS 1.4 and Arduino Mega (Read 283 times) previous topic - next topic

malanosa

I am working on a project that involves controlling a 3-axis robot arm (driven by NEMA 17 stepper motors) through an Arduino MEGA and RAMPS 1.4. The RAMPS 1.4 board uses Pololu A4988 motor drivers.

I am wondering if anyone has any advice regarding the easiest or best way to program the movement. It looks like most people run a firmware called Marlin with the RAMPS 1.4, which allows the motors to be programmed using G-code. Would this be a better approach than simply trying to directly program the motors/robot arm directly through the arduino editor?

To me, the arduino editor seems less intimidatin, but I know that it might be easier once it's set up to run on G-code.

Any advice would be greatly appreciated.

Thanks!

Northof49

I am currently doing exactly what you are asking about.  My robot arm is a dobot clone.  I am using ramps 1.4, Arduino mega and A4998 drivers.

You need to decide what your goals are in terms of controlling the robot.

If you run Marlin, it greatly simplifies the use of G code for control.  However, with Marlin, or any other software designed for 3D printing, you will lack inverse kinematics for anything other than a SCARA arm.  In other words, when the G code tells the arm to move in the X axis, instead of moving solely in the X axis as a 3D printer that has its motors and movements laid out in cartesian coordinates would, the arm will move one of its joints that you have designed as X.  That movement however will be not solely in one cartesian direction.  When you move one joint of a robot arm, the end movement will be in multiple directions, affecting Y and Z for example.

I found numerous discussions on the internet about modifying Marlin's various files to add in custom inverse kinematics, but I never found anyone who had done it, nor sufficient description of the various Marlin files to understand what all needs modifying.

I have used the AR-2 software, with a modified version of Arduino software, and it works great for learning and repeating complex motions, but I was never successful in setting up the inverse kinematics for a configuration that worked with a 3 axis arm, instead of the 6 axis that it was designed for.  It works great for moving the arm to a location, operating a servo for a claw for instance, and recording that point as a stored location, and adding more and more movement to create a complex script that can be repeated over and over, or repeated with offsets, or modified based on sensor input (that part I never tried).

I don't have a lot of time this afternoon to write a more detailed answer on the various types of software I have tried and the results I have gotten, but if you are interested in my various attempts, I will continue.

Here is a link to my work so far with my dobot clone arm:

https://forum.arduino.cc/index.php?topic=576820.0

It's not perfect, there is some bug in the circle drawing part of the program that I have to sort out, as it sometimes seems to draw a circle in a clockwise motion instead of counter cw, or vice versa when using the circle commands G2 or G3.

malanosa

Thanks, that makes sense! And unfortunately means this is going to be a lot trickier than I had anticipated!

I'll look into what you've already done and try to get caught up, but I am definitely interested in learning more specifics of what you've tried and what you've accomplished.

Northof49

How is the arm configured?  Can you post a link to an image of something similar?  Is it like a paletizing robot arm, where the wrist stays horizontal?  Does it have a motor at each joint?  Or two motors at the shoulder, and a linkage to the next joint?

What sort of tasks will you want the arm to do?  Does it need to interpret G Code that is generated from Cad or inkscape to create drawings or objects?  Or was the G Code suggestion simply a way to script movement?

malanosa

It has two motors at the shoulder and linkages to the joints, and the wrist joint stays horizontal. It's a fairly simple design as seen here.


I'd like the arm to clamp an object and then move it back and forth (in one plane) along a sanding/polishing wheel. I was wondering about G code simply as a way to script the movement. Would that be a simple way for scripting movement, or is there something that would be simpler?

Northof49

Because it has two motors at the shoulder (I will call those motor 2 and 3) and linkages to the joints, when you move the first (lower) linkage, it affects the second linkage unless you make motor #3 follow motor #2 to neutralize that effect.  No big deal, just something to keep in mind when writing the software.  Any movement with motor 2 must be added or subtracted from motor 3.  A problem you don't get when the motors are located at each joint.


In order to have the end effector move in a straight line on a single plane, you need to incorporate a line drawing algorithm, such as Bresenhams.  Why you may wonder?  If you simply move the end effector from point X1, Y1 to X2, Y2, it will follow an arc during the movement owing to the circular nature of the movement of linkages that pivot about a centre point.

You could use a non-inverse kinematics solution like Marlin, but the G Code you feed it would have to contain the multiple points along the straight line.   Hundreds to thousands if you want it to move smoothly and straight.   I am not sure how you would generate that code. 

If you want to use my code, it already accounts for both of the above problems, the movement using G1 is all processed through Bresenham's algorithm to make it move in a straight line, but the inverse kinematics in my code are for an arm with the dimensions of my arm, and the inverse kinematics part would potentially have to be tweaked to compensate for the different lengths of your arm.  You would be on your own in adjusting the formulas if needed, as i didn't write them.  I got them from a guy in indonesia who wrote them for a dobot arm.  His code was a one shot affair where you manually calibrated the arm and fed it one set of coordinates and it moved there.  No self calibration, no G code, no circular movement, no bresenham's straight line movement.  I took just the IK part of his code and built my program from there.

The AR2 software plus my Arduino modification works great for creating a loop that repeats over again for a fixed count.  The inverse kinematics however are not there, so the end effector movement will not likely be straight line.


One thing I've come to appreciate is how complicated robot arm movement is, if you want something other than joystick like control.

malanosa

If you want to use my code, it already accounts for both of the above problems, the movement using G1 is all processed through Bresenham's algorithm to make it move in a straight line, but the inverse kinematics in my code are for an arm with the dimensions of my arm, and the inverse kinematics part would potentially have to be tweaked to compensate for the different lengths of your arm. 
Is the code you are referring to here an Arduino sketch? I think it would be great if I could base my program off of your Arduino sketch, if that is what you are referring to. I don't know how difficult a time I would have tweaking the inverse kinematics to suite my particular robot, but I'd definitely give it a try.

The AR2 software plus my Arduino modification works great for creating a loop that repeats over again for a fixed count.  The inverse kinematics however are not there, so the end effector movement will not likely be straight line.
Just to make sure I understand correctly, using the AR2 software with your Arduino modification would be a different option than the code you are referring to above, correct? I wasn't familiar with the AR2 robot until you mentioned it and I looked it up. Seems like it might almost be easier to build an identical robot to the AR2 and use that software. Perhaps I should have done some more research before buying the hardware!

Thanks for all your help so far!

Northof49

The AR2 robot arm uses a python or PC based software to create the GUI on your PC, and an Arduino program on the mega to receive the instructions and control the arm.  It does all the inverse kinematics on your pc.  I modified the Arduino program he wrote so that it would work with ramps and have posted it up.

The separate Arduino program that I wrote, does all the inverse kinematics on the Arduino itself.  You communicate with it using the serial monitor, or using the short python code I wrote, it will read script from a file.  The scripts contain something similar to G Code, but not in the exact format of standard G Code.

Go Up