Welcome! Log In Create A New Profile

Advanced

Servo control and automatic bed levelling

Posted by andy-net 
Servo control and automatic bed levelling
August 27, 2012 07:29PM
Ok, so I realise this isn't for everybody, but I'm throwing this up in case anyone is interested.

This started as a wild idea I had on Buback's thread (help brainstorm a better bed leveling adjustment mechanisim). The basic idea being that if you had 4 servos (one for Nopheads Genius Z Probe and three continuous servo's for levelling, you should in theory be able to automatically adjust the levelling of the bed, and alter the bed Z height, taking much of the pain away from the bed-height calibration issues that plague many people. If you'll excuse my crude 3d artwork, here's a rough mock up of what I planned.


So I went out and bought 3 x Continuous rotation servo's and Dug out 1 x Standard Servo and plugged these into the ramps 1.4. I then jumpered the +5v and VCC pins and the servo's powered up.

I created a simple little test sketch to make sure all the servo's worked, I fed in a sin wave and it all checked out, check out the video here: Youtube Video of Servos in action


So far so good! Getting Marlin to play nice was a little tougher. I threw in a reference to the standard arduino servo libraries, but it came up with some errors because the standard libraries use some overlapping vector names (apparently!). So I copied Servo.h and Servo.cpp into new tabs in Marlin called MarlinServo.h and MarlinServo.cpp and made the changes I'll detail below to the firmware and there it was, 4 x servo's controlled by GCODE.

So far I've set up the following Gcodes for testing:


    M601 - set servo_0 position/angular speed e.g. M601 S180 = full cw / M601 S90 = off / M601 S0 = full ccw
    M602 - set servo_1 position/angular speed e.g. M602 S180 = full cw / M602 S90 = off / M602 S0 = full ccw
    M603 - set servo_2 position/angular speed e.g. M603 S180 = full cw / M603 S90 = off / M603 S0 = full ccw
    M604 - set servo_3 position/angular speed e.g. M604 S180 = full cw / M604 S90 = off / M604 S0 = full ccw
    M605 - set all servos to 90, used for calibration, continuous servos should now be stationary, 180 degree servos should be at midpoint

So I can control my servos. Next I can start working on the retractable Z probe and creating my mounting mechanism. The rest should just be a tiny bit of matrix maths and hopefully I'm done.

I'll post the other marlin changes below.

Even if this all ends up as a futile effort, I've learnt something and I hope if nothing else that this helps anyone else looking to work with servos.
Re: Servo control and automatic bed levelling
August 27, 2012 07:35PM
So first I copied the contents of Servo.h and Servo.cpp from arduino-0023\libraries\Servo into new tabs in Marlin called MarlinServo.h and MarlinServo.cpp. Then I commented out the following lines:

L100

#ifndef WIRING // Wiring pre-defines signal handlers so don't define any if compiling for the Wiring platform
// Interrupt handlers for Arduino 
// #if defined(_useTimer1)
// SIGNAL (TIMER1_COMPA_vect) 
// { 
//   handle_interrupts(_timer1, &TCNT1, &OCR1A); 
// }
// #endif

Then I went on to make the following changes.


--- pins.h --- L303

#ifdef AUTO_BED_ADJUSTMENT
  #define SERVO_0 11
  #define SERVO_1 6
  #define SERVO_2 5
  #define SERVO_3 4
#endif

--- Configuration.h L203
#define AUTO_BED_ADJUSTMENT

---Marlin.pde L115
// M600 - move bed levelling servos plus or minus in degrees e.g. M600 -1 1 0 (m600 servo_1 servo_2 servo_3)
// M601 - set servo_0 position/angular speed e.g. M601 S180 = full cw / M601 S90 = off / M601 S0 = full ccw 
// M602 - set servo_1 position/angular speed e.g. M602 S180 = full cw / M602 S90 = off / M602 S0 = full ccw 
// M603 - set servo_2 position/angular speed e.g. M603 S180 = full cw / M603 S90 = off / M603 S0 = full ccw
// M604 - M604 - set servo_3 position/angular speed e.g. M604 S180 = full cw / M604 S90 = off / M604 S0 = full ccw 
// M605 - set all servos to 90, used for calibration, continuous servos should now be stationary, 180 degree servos should be at midpoint

--Marlin.pde L41
#include "MarlinServo.h"

-- Marlin.pde L140

#ifdef AUTO_BED_ADJUSTMENT

  Servo servoController_0;
  Servo servoController_1;
  Servo servoController_2;
  Servo servoController_3;

#endif  


--Marlin.pde L318

#ifdef AUTO_BED_ADJUSTMENT
  servoController_0.attach(SERVO_0);
  servoController_1.attach(SERVO_1);
  servoController_2.attach(SERVO_2);
  servoController_3.attach(SERVO_3);

  // Set servos to midpoint - Important for continuous rotation servos so they are stationary initially
  servoController_0.write(90);
  servoController_1.write(90);
  servoController_2.write(90);
  servoController_3.write(90);
#endif



---Marlin.pde :1295
#ifdef AUTO_BED_ADJUSTMENT
    
    case 600: // M600 - move bed levelling servos plus or minus in degrees e.g. M600 -1000 350 0 (m600 servo_1 servo_2 servo_3)
    {
            // TODO
    }
    
    break;
    case 601://  M601 - set servo_0 position/angular speed e.g. M601 S180 = full cw / M601 S90 = off / M601 S0 = full ccw 
    {
      if (code_seen('S')) servoController_0.write(code_value());
    }
    break;
    case 602: // M602 - set servo_1 position/angular speed e.g. M602 S180 = full cw / M602 S90 = off / M602 S0 = full ccw 
    {
      if (code_seen('S')) servoController_1.write(code_value());
    }
    break;
    case 603: // M603 - set servo_2 position/angular speed e.g. M603 S180 = full cw / M603 S90 = off / M603 S0 = full ccw
    {
      if (code_seen('S')) servoController_2.write(code_value());
    }
    break;
    case 604: // M604 - set servo_3 position/angular speed e.g. M604 S180 = full cw / M604 S90 = off / M604 S0 = full ccw 
    {
      if (code_seen('S')) servoController_3.write(code_value());
    }
    break;
    case 605: // M605 - set all servos to 90, used for calibration, continuous servos should now be stationary, 180 degree servos should be at midpoint
    {
      servoController_0.write(90);
      servoController_1.write(90);
      servoController_2.write(90);
      servoController_3.write(90);
    } 
    break;    
#endif    

Re: Servo control and automatic bed levelling
August 27, 2012 09:37PM
This is actually pretty neat. Possibly a bit overkill as the compensations could probably be done well in software as long as the bed is close to flat. If it can be made simple and cheap enough though it may be worth pursuing.


Help improve the RepRap wiki!
Just click "Edit" in the top-right corner of the page and start typing.
Anyone can edit the wiki!
Re: Servo control and automatic bed levelling
September 18, 2013 08:11PM
This is a great idea. I would like to know where this project stands since the last comment was a year ago. I am currently working on a similar project.
Re: Servo control and automatic bed levelling
September 19, 2013 04:43PM
isn't controlling 2 servo's under the bed enough?
Re: Servo control and automatic bed levelling
September 19, 2013 05:07PM
I was also wondering what is the benefit of hardware compensation. Software compensation could be done as a simple g-code preprocessing script and seems to work pretty well
[youtu.be]

... as long as your firmware supports moving x,y,z simultaneously

But I can see the fun of the project smiling smiley

Victor
Re: Servo control and automatic bed levelling
September 19, 2013 05:19PM
possenier Wrote:
-------------------------------------------------------
> isn't controlling 2 servo's under the bed enough?


No, 3 points is the least; 4 would be best. Engineering 101 ^^
cheers
Re: Servo control and automatic bed levelling
September 19, 2013 05:30PM
tleneel Wrote:
-------------------------------------------------------
> No, 3 points is the least; 4 would be best.
> Engineering 101 ^^
> cheers

But one point can be fixed, and the other two controlled to get a level platform, unless you also want to be able to change the overall height of the platform.


Help improve the RepRap wiki!
Just click "Edit" in the top-right corner of the page and start typing.
Anyone can edit the wiki!
Re: Servo control and automatic bed levelling
September 19, 2013 05:36PM
true depends how you take your measures.
Re: Servo control and automatic bed levelling
September 19, 2013 06:07PM
Isn't this a bit absurd for a once a week adjustment?

Done in software? Have software compensate for an 2 or more angles at a time
driving the Z axis up and down constantly? In open source firmware?
How about compensating for the flow out of the extruder, if a layer
is uneven or polymer not flowing, or leaving nerdels.

Buy a $250000 straysys or 3D system printer with $25000 software package?

But in 10 years all this will be in a 3D printer for $99
Re: Servo control and automatic bed levelling
September 19, 2013 06:31PM
cozmicray Wrote:
-------------------------------------------------------
> Isn't this a bit absurd for a once a week
> adjustment?

Maybe, but I remember when printer paper came in perferated sheets with alignment holes on either side. Now the paper comes in single sheets and the printer aligns the paper automatically.

To get 3d printers to the level of a consumer device, automatic bed leveling is a must have.
Re: Servo control and automatic bed levelling
September 19, 2013 08:14PM
I think this is a great idea

I don't think you even need continuous rotation servos, I mean how far out of alignment does your bed get? Mine never needs more than like a quarter turn of the screws.

Also, you don't need any servos for the z-probe [www.thingiverse.com]
Re: Servo control and automatic bed levelling
September 19, 2013 09:32PM
The design I am going for will have two servos and one fix point. The system hopefully act as an endstop as well and will be able to give a precise measurement of how far away the nozzle is to the bed.

As to the bed becoming out of alignment. The most annoying thing is leveling the bed and adjusting the starting height. I have to move several printers to various events and places. Every move makes them out of alignment, especially the repraps with two z motors.

To have a system that can level and home with a higher accuracy than a piece of paper will be huge for the 3D printer community. The average person will not take the time to calibrate one of these printers, self calibration will open this up to a bigger audience.
Re: Servo control and automatic bed levelling
September 20, 2013 12:09PM
Nice idea, I like it, bed levelling is a major hassle.
I see one issue with this approach, and that is Y axis weight.
If you could make the servos part of a snap-on, removable jig, that issue would be solved.

/Andreas
Re: Servo control and automatic bed levelling
September 20, 2013 03:34PM
Also, if you have a z-probe you don't need servos. Just move the head over on top of the motor and turn the motor until it trips.

You can get away with some pretty simple motors if you do that, I think.
Anonymous User
Re: Servo control and automatic bed levelling
February 26, 2015 07:39PM
This is great idea, thank you!

It would be very useful for large print bed, e.g. 1 X 1 meter, which is heavy and not a good idea to load the motor all the time.
Re: Servo control and automatic bed levelling
February 27, 2015 04:03PM
Quote
SheldonE
cozmicray Wrote:
-------------------------------------------------------
> Isn't this a bit absurd for a once a week
> adjustment?

Maybe, but I remember when printer paper came in perferated sheets with alignment holes on either side. Now the paper comes in single sheets and the printer aligns the paper automatically.

To get 3d printers to the level of a consumer device, automatic bed leveling is a must have.

You really think adjusting the BED is better than implementing a low cost head height detection system that allows for fully automated calibration across the entire bed? Such a device is certainly possible but requires a larger scale of economy to be actually developed properly. This is a "what I can do now" (yet interesting) band aid solution.
Re: Servo control and automatic bed levelling
October 13, 2015 03:56PM
By any chance could you share your sketch or answer a couple questions I have ?
Re: Servo control and automatic bed levelling
October 13, 2015 04:06PM
I proposed a system for large CoreXY or HBot 3D printers a while back that used three Z stepper motors, driven independently, to do both Z movement and bed levelling. But nobody else.seemed to think it was a good idea.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: Servo control and automatic bed levelling
October 16, 2015 04:50AM
Quote
dc42
I proposed a system for large CoreXY or HBot 3D printers a while back that used three Z stepper motors, driven independently, to do both Z movement and bed levelling. But nobody else.seemed to think it was a good idea.

Its a good idea, I have been using that on my 1cbm non functional prototype printer (proof of concept)... But I have been levelling hotend gantry to the bed as that's fixed but removable, the idea is going to make it to my first functional prototype (will be unveiled in the new year)
Sorry, only registered users may post in this forum.

Click here to login