Learning G-Code is quite interesting: it’s really old, really simple, and yet surprisingly complex if you want to get CNC cuts 100% perfect. Luckily my use-cases are much simpler, but I still would like to move 2 axis concurrently: e.g. move along the x-axis from 0 to 400mm, and rotate the a axis from 0 to 180 degrees so that they start and end together.
Adding a Servo
Step 1 is to connect a servo, which was not as easy as I thought since there’s no dedicated servo connector I can readily use on the DLC32. Luckily there are plenty pins to get GND, 5V and a PWM signal. This is the section I added to the config.yaml:
a: steps_per_mm: 10 max_rate_mm_per_min: 100000.0 acceleration_mm_per_sec2: 100000.0 max_travel_mm: 180.0 soft_limits: true homing: cycle: 0 mpos_mm: 0 positive_direction: false motor0: rc_servo: pwm_hz: 50 output_pin: gpio.25 min_pulse_us: 1000 max_pulse_us: 2000
IO25 is readily available on the EXP1 connector, so I used 5V, GND and IO25 from EXP1:
Now I can use G-Code like this:
- G0A90 to move the servo to the neutral position 90° (assuming 1ms=0°, 2ms=180°). The actual movement depends on the servo. Most move only 90° in total.
- G1X300A10F200 now does:
- Move to x=300mm and rotate a to 10° at a feed-rate of 200 mm/minute. If x=100 at the start, this movement will take 1 minute.
- During the movement, a ?<ENTER> will show the current positions:
? <Run|MPos:221.533,0.000,0.000,126.500|FS:200,0|Pn:PYZ> ok [...about 30 seconds later...] ? <Idle|MPos:300.000,0.000,0.000,10.000|FS:0,0|Pn:PYZ> ok