Sunday 28 March 2021

Connect up the 7i85 - get X & Z encoders working - SUCCESS!

I need to enable the additional encoders - for the X and Z axes - as I am planning to use them to close the position control loop. 

Telling LinuxCNC to expect more encoders:
Initially I told LinuxCNC that I have only one encoder on the machine (the spindle encoder in the 7i76) so firstly I will need to change this line in the main hal file:

loadrt [KINS]KINEMATICS

loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS
loadrt hostmot2
loadrt hm2_pci config=" num_encoders=4 num_pwmgens=0 num_stepgens=2 sserial_port_0=00xxxx"
setp hm2_5i25.0.watchdog.timeout_ns 5000000
loadrt pid names=pid.x,pid.z,pid.s

Then the encoders can be seen within halshow:

 

Note that encoder #01 is the "dummy" twin for the spindle encoder. It can't be used but it seems you have to count it as one of your required encoders. So the first encoder on the 7i85 board is actually encoder #02. I have that down as the X axis (cross slide), so the Z axis is going to be encoder #03. This is one of those foibles that's designed to catch out noobs like me. Luckily Mr Mesa helped on that one before I wasted too much time.

Drawing the magnetic strip past the read head generates the position signal shown. That's a good start at least.

Fitting the encoder and magnetic strip:
Now let's fix the encoder read head to the saddle body and attach the magnetic strip to the underside of the cross slide.

Wow - look at those super horney timing pulleys!!


I previously machined the underside to take the strip so it wouldn't foul the read head. This needs to be nice and clean, as it uses a self adhesive backing.


Like this. There's also a thing stainless steel cover strip that fits over the top. Yes, the read head "sees" the magnetic strip through that.


Then refit it and......check it actually works. Yes! Now to set it up...

HAL and INI file changes:
In order to use closed loop positional feedback, you obviously need the encoder and servo to speak the same language when it comes to distances.

The encoder is a "5um" scale ie the fundamental distance between markers is 20um but with a quadrature signal, you can resolve 4 times that. So the encoder scale factor is 200 "counts per machine unit" (mm).

The servo is set up for 2500 steps per rev (in the servo drive) and is driving a 5mm pitch ballscrew through a 2:1 reduction drive (16t:32t timing pulleys, remember?). So we have 1000 "steps per machine unit" (mm). 

The output from the stepgen component is a direct position in mm. But the output from the encoder position is encoder counts. In my case, I have a "5um" encoder scale, so that equates to 200 counts per machine unit. Or in fact -200 counts per machine unit, since the encoder counts down as the position increases.

I need to scale the encoder output to match the stepgen output. Turns out you need to set the scale factor with this line. It picks up the value of INPUT_SCALE (here -200) and applies it to the encoder driver. This was the missing element.

setp    hm2_5i25.0.encoder.02.scale [JOINT_0]INPUT_SCALE
Success:
Then the output of the encoder position pin matches the output. Whoopee - and the encoder feedback works!

Finally, the PID parameters need to be dialled right back. The initial P term is 1000(!!), so it seems to make sense to set that to 1.0, while the I and D are already set at zero.

No comments:

Post a Comment

Final assembly and test of the spindle nose adaptor - RESULT!!

After the recent distraction caused by the 3D scanner, resurrecting the 3D printer and buggering about with the throttle bodies for my Honda...