Skip to content
bdring edited this page May 5, 2021 · 21 revisions

Using the Servo Axis Feature

The servo axis feature allows you to use a hobby servo as an axis that is fully coordinated with stepper motors. You can use this feature on any and all axes. Here is a link to a short video about the feature.

Note: If you have a simpler use for a servo, the M67 & M68, analog output commands can quickly send a servo to a position.

Setup

In your machine definition file you need to define the I/O pins you want to use for the PWM and the millimeter range you want to map to the servo range. An example is shown below. Follow the same format for each axis you want. Note: the Z axis is used in all examples, but you can use this feature for any axis.

        // Required
	#define Z_SERVO_PIN 		      GPIO_NUM_14
        #define DEFAULT_Z_MAX_TRAVEL          5.0   // or change it live with $Z/MaxTravel=5.0
        #define DEFAULT_Z_HOMING_MPOS         5.0   // $Z/Homing/MPos=5.0

The above setup will create a z servo with a range of 0.0 to 5.0. You will see this by a line in your startup messages.

[MSG:Z  Axis RC Servo Pin:14 Pulse Len(3276,6553) Limits(0.000,5.000)]

Direction Reversal

You can reverse the direction of the servo just like you do with a stepper motor by adding the axis letter to the $Stepper/DirInvert= setting.

Calibration

Normally the PWM range is 1ms to 2ms. If your servo uses a wider range or you want to restrict the travel, you can adjust the calibration values. If $Z/RcServo/Cal/Max is 1.15, the maximum PWM would be 2.3ms (2ms x 1.15). These are settings that can be adjusted live. Go the the end you want to adjust and tweak the $Z/RcServo/Cal/Min or $Z/RcServo/Cal/Max values depending on the end you are at.

Note: Be careful, that your calibration values do not cause the servo to push against the physical range of the servo. It will damage the servo. If it is pushing against the physical stop, the servo will vibrate and get warm. Eventually it will overheat and fail.

Homing

If there is a homing cycle that includes an axis with a servo. The servo will rapidly move to the end of travel that is specified by the homing direction ($Homing/DirInver=)

Setting Speed

You can control the speed and acceleration of a servo, just like you can a stepper motor. The $Z/MaxRate settings will control the max speed and the $Z/Acceleration settings will control the acceleration. You can then control its speed (feedrate) though gcode, like any other axis.

It is a little trickier to tune the max speed and acceleration than a stepper motor. The servo will have its own max speed and acceleration. If you try to go faster, the servo will still work, but won't be able to keep up with the speed Grbl expects it to be running at. If the feedrate is slower than the servo's natural max. speed, the servo will follow that slower speed. The best approach is to slowly increase the speed until the servo does not appear to go any faster than the previous setting.

Enable / Disable

The servos will tightly hold position just like stepper motors. If you try to turn them by hand they will fight you. This can be also disabled like the stepper motors.

When motors disable due to the $Stepper/IdleTime setting or other reasons, the PWM signal will be turned off. Most servos will not hold position in this mode and can be moved by had. When they are enabled, the PWM will be set to the current axis position. If you manually moved the servo, you will see a quick move to the correct position.

Important Things to Consider

Keep in mind that most servos are a lot less accurate than stepper motors. They also might overshoot or jitter a bit. You can buy them form less than $2 to hundreds of dollars. You get what you pay for.

With that said, they are great for things that don't need to be too accurate, but still coordinated with the motors. Things like pens for drawing bots, dust shoes lift, etc. are good examples.

Clone this wiki locally