PID Tunig

For a few weekends now I have been 'dry-running' the servo electronics that are going to replace stepper motors on the cnc mill. So far the servos are working in closed loop, I can control the VFD forward/reverse and set the RPM, I can read in a spindle-encoder to verify the RPM and also do rigid tapping. The coolant relay works. There's a jogwheel that can be used for jogging the machine or adjusting spindle/feed-override.

Still on the to-do list are limit switches, home switches and homing, improvements to the E-stop loop, and linking up some pendant buttons.

I did a little PID-tuning today with one servo motor just sitting on the bench - no load. The final PID parameters when the motor is hooked up to the machine are probably going to be different from these, but at least I got some experience with tuning. I'm using the Mesa m5i20 to read encoder counts and output PWM to pico-systems servo amplifiers. The servos have 1000-line encoders so I get 4000 counts per revolution. The ballscrews are 2.5mm/revolution, so one encoder count corresponds to 0.000625 mm.

When tuning I did a 200 mm long G0 (rapid) move which allowed the motors to get up to max speed which was set to 6000 mm/min. With the servo directly coupled to the 2.5mm/rev screw that corresponds to 2400 RPM. When coasting at 6 m/min the DAC output was at around 8.7, so this is about as fast as the motors will go (unloaded). In the machine I might not be able to reach 6 m/min. Below some hal-scope screenshots that show how the pid-error changes when tuning the PID parameters.

First I tried only Pgain. The error clearly shows the three phases of the EMC2 trapezoidal trajectory generator. There's an initial acceleration phase during which the error grows, then the cruise phase where it stays constant, and then a deceleration phase at the end. The following error is big, more than 1mm. Obviously I've set FERROR and MIN_FERROR quite high in my ini file so EMC2 doesn't respond with a following error and stop all motion.

Next I tried increasing the 1st order feed-forward, or FF1, parameter. That worked well, and the error is cut more than ten fold!

So FF1 is a good thing? More of that then! Well not quite. Here I've increased FF1 to 0.2 and get sustained oscillations at the end of the move.

It's back to FF1=0.1 and a little D-term to the rescue for damping out the oscillations. Seems to work quite well.

Finally I ramped up the Igain. That helps to reduce the cruise-phase error a lot, but there still remains some following error during the accel/decel phases. There are spikes at the beginning and end of the accel/decel phases which I should try to get rid of. I guess some spikes will always remain since EMC2's trajectory planner outputs a trajectory which is only once differentiable (i.e. the velocity plot has 'sharp corners', and the acceleration plot has discontinuities, see pic here). I'm also using the inverse-deadband component to compensate for the open-loop response of the motors (see next post).

The maximum error is around 0.02 mm, or ca 32 encoder counts. I'm hoping the motors will perform at least as good as this when in the machine!

M95, M96, and M105

A little left of Regulus and where Saturn is right now in Leo there's a group of three Messier objects: Two spiral galaxies M95 (magnitude 11.4), and M96 (magnitude 10.1), and an elliptical galaxy M105 (magnitude 10.2).

This is a stack of around ten 8 s exposures through an EF 70-200/4L set to 200mm and full aperture. Resolving details from the galaxies will require a longer focal length and much longer total exposure time. Focus is pretty good, and stars appear as points even in the corners - but the image shows severe vignetting. I need to learn how to use flat-frames to correct for that.

For those of you that don't spot the galaxies immediately from the pic above :), below I've indicated their positions:

WordPress 2.5

WordPress 2.5 is out, and I've upgraded. Most of the shiny new stuff is on the admin side only, and so the outward look of the site remains.

The upgrade went smoothly, with the usual tweaks to style.css for the ever changing header image and to put the blog title in the left upper corner.

I've started tagging my posts, and there's a new tag-cloud at the top of the sidebar. I'll use it as a way of sub-categorizing posts without actually creating new categories. Once it's been in use for a while it will be useful for searching too.

Another recent update to the site is the list of WWW-links in the sidebar ("Anders' Web tips"). It's an RSS feed of the links I mark as 'shared' in google reader. Hope you like them!

Hard disks are not forever

Just had a 2-3 year old SATA drive fail on me. If you're reading this, go and take backups of critical data. Do it. Now.

This is the cnc-mill controller machine so hopefully no critical data was lost. Some notes on the EMC2 install process, just in case I need to do it all over again sometime soon...

  • Install WinXP on a 50 Gb NTFS partition
  • Installed Ubuntu 6.06LTS from CD. Manual partition, 50 Gb for root file system, 2 Gb for swap.
  • Ubuntu update manager suggests 301 updates (278M) to install. I'm in Finland, but strangely my sources.list points me to au.something servers. Reboot.
  • Install EMC2 using emc2-install.sh. Reboot.
  • 'latency-test' shows reasonable jitter values - good.
  • Configure X to enable 1280x1024 resolution: 'sudo dpkg-reconfigure xserver-xorg'. Answer lots of techy-questions, remember to add the correct screen resolution and the correct keyboard (pc102). I wasn't able to log in the first time I tried this because I had chosen an incorrect keyboard type/layout.

VFD control board

This small PCB is going to sit between the M5i20 optoisolators and the VFD that runs the spindle on the mill.

Starting from the lower edge of the card there are three outputs that drive optoisolators on the VFD through BC337 transistors. On the VFD they are wired to Forward Start/Stop, Reverse Start/Stop, and External Fault.

The next signal goes in the opposite direction, from VFD to EMC. The VFD has a general purpose analog output which can be programmed to monitor motor current, power, etc. Since the m5i20 doesn't have analog inputs I'm using the V-2-f converter AD654. It's hidden below the board since it was only available in surface mount. As seen below it seems to work nicely. I designed the output to be at 1000 Hz with 10V input, but I'm only supplying 12 V to the AD654 which means the output goes all funny somewhere after 8 V input. Maybe the VFD software can scale the 0-10V output, or I can put a voltage divider in front of the AD654 to get maximum 8 V input. I need to come up with a HAL config that reads a general purpose IO pin and figures out the frequency (think big green/red pyVCP spindle load meter in AXIS).

The top two connections are for the frequency reference, a pulse train, and for an NC E-stop relay.

This card together with a spindle encoder should allow for rigid-tapping.

Clear skies - Finally!

It's been cloudy almost every night for about three weeks now, but finally today a half-decent sky-watching night. The moon is full, so my moon pictures were predictably quite bland. I tried to search for some messier objects, but with a poor finder-scope and 25mm being the widest eyepiece that didn't work out too well (even with Stellarium on the laptop right beside me...). Here's the best of around 10 shots of Saturn.

102mm refractor, f=1000mm (~F/10), 2x Barlow, Canon 20D, 1/3 s exposure at ISO100

Timing build_kdtree()

Drop-cutter requires a fast way of searching for triangles under the tool. A kd-tree (4-dimensional in this case) is suggested by Yau et al. I've tried to implement one here (look in trunk/Project2). Just ran some timing tests using Stopwatch() on it, and indeed the build_kdtree() function which takes a pile of triangles as input and generates a kd-tree seems to run in O(N*log(N)) time as it should.

I've never drawn this type of plot before, and I was surprised at how close N*log(N) is to N - in a loglog plot they are almost equal!

This is a recursive function. I wonder if there's a good way of multi-threading recursive functions? My laptop is dual-core and a modern desktop PCs is likely a quad-core - so let's try to write these things multi-threaded from the start.

Next up is a function for doing the orthogonal range-search for triangles that lie under the tool. That's supposed to run in O(N^(1-1/D)+K) time, where D is the dimension of the tree and K is the number of reported triangles - so O(N^(3/4)+K) in this case. I'll try to get that done during the weekend.