Sunday, March 14, 2010

Hydra Joins the Acceleration Party... with multiple heads

So after about a week and a half of work I uploaded a new release of the Hydra-MMM software and firmware to the sourceforge page this afternoon (https://sourceforge.net/projects/hydra-mmm/). Most of the work was done on the firmware because I got the crazy idea in my head that I wanted to be able to do accelerated movements in 3 dimensions. While this seems somewhat simple at first, I had a hell of a time getting it all to work out. Here are the main problems I ran into
  • If you have a constant acceleration with a non-zero initial velocity, the time interval for stepping cannot be directly determined. A quadratic equation needed to be used to solve for the time interval. This is due to the fact that the motor speed is dependent on the stepping interval (delay between steps), and the distance the machine travels is also dependent on this velocity as well as the constant specified acceleration.
  • (Solved) For some reason, every time I derive the kinematic equation to relate distance, velocity, and acceleration together I get a different result than that which is in the physics textbooks I have used in school. If V = delta x / delta t, and a = (V-Vo)/delta t, if you combine these you get a*deltat + Vo = V = deltax/deltat. Multiplying both sides by deltat, you get a*(deltat^2) + Vo*deltat - deltax = 0. The equation in my textbooks is 1/2*a*(deltat^2) + Vo*deltat - deltax = 0. I was forgetting that the V term is actually Vavg which would equal (V-Vo)/2 which answers the factor of 2 difference. Thanks for pointing this out guys!
  • Solving quadratic equations while moving is not a good idea. It was too slow and it was actually limiting my maximum speed (the delay from solving the equation was greater than the interval I was using for stepping). The whole idea of doing this is to allow for faster and smoother stepping so a change was needed. I decided the best way was to compute the acceleration scalers (% of desired speed) for each step and to store those in an array. See the next point.
  • Storing large arrays (200+ items) of floating point numbers eats up SRAM real fast. A 200 item float array requires 200*4 Bytes = 800 Bytes! That is almost all of the available memory on the ATmega168! To fix this I scaled the acceleration scalers up to integer values. The scalers only range from 0.0 to 1.0 so this was not hard to do and it cut the memory usage in half (integers only require 2 Bytes instead of 4 Bytes for floating point numbers).
  • I originally intended to have separate acceleration and deceleration calculations, but it proved to be must faster to just calculate the acceleration values and then duplicate those in reverse for deceleration. I also has a problem when solving the quadratic equation for negative acceleration. The radical is negative if Vo^2 < -2*a*deltax which can happen for deceleration. See the 2 figures below.
Figure 1 - Acceleration from 0 to 80 inch/min
Acceleration is smooth from 0 to 80 inch/min with no errors in the calculations.


Figure 2 - Deceleration from 0 to 80 inch/min
Note the circled section where there should be 2 or 3 more steps before getting to zero velocity, however, this is the area where the value inside the square root was negative and thus, it could not be calculated.
  • So again, it was must easier to just use the acceleration calculations where acceleration is positive and the value inside the square root can never be negative. To help with this problem, I also added a startup speed variable so the motors can start from a specified velocity. For example, if they have no problem jumping to 0 to 30 inch/min, start them at 30 and then ramp up to 80. While this change, as well as only calculating the positive acceleration values got around this problem, I am still intrigued why this was happening.
Eventually, I got everything working, however, it took much longer than I expected. The end result is pretty awesome and allows for a much smoother initial startup as the motors can start from a lower speed and slowly ramp up to the higher speed. Before this, they were just instantly trying to run at the desired feedrate and that made things pretty shaky. I can't wait to test this out of the machine once we get the X and Z axes fully operational (hopefully in the next 2 weeks). I now also have a great deal of respect for Adrian who also got this working on the Reprap front. I wonder if he had as many problems as I did??

Anyways, in addition to adding acceleration to the mix, I also added support for multiple toolheads (the end goal of the Hydra-MMM project). This includes functions for switching heads and tracking the location of each head while building. I still have more work to do with this, but the basic functionality is there. See the release notes below for all of the other new features added in the 1.3 release!

- Acceleration is now supported and computed using kinematics (no linear approximations here!). The computations are performed before each move and have been optimized to reduce CPU and SRAM usage.
- Added support for several T (toolhead) commands for managing up to 4 independent toolheads. See firmware for list of new commands. Also note that there are new parameters that must be declared if multiple toolheads are to be used. See the top of the firmware.
- Added support for physical max and min endstops on each axis
- Maximum software endstops added in case physical max endstops are not available
- PID temperature library and cpwStepper library are now options and can be excluded from the firmware if it is not desired
- GUI now supports M105 command to receive temperature from the firmware and print to screen
- Fixed bug with time to move calculation being dependent on the x axis
- Lots of optimization to get the firmware small enough to fit on the ATmega328 (reduced total firmware size more than 6KB!)
- Serial baud rate changed to 19200 for compatibility with Reprap and Makerbot hardware

As always, you can download the release files at the sourceforge project page: https://sourceforge.net/projects/hydra-mmm/

Let me know what you think!

6 comments:

  1. The reason you're getting a different result from the textbooks is that you're using a different definition of V. (I think that you end up in the same place as long as acceleration is constantish). The thing that equals delta-X/delta-T is V-avg, which (for constant accel) is halfway between the velocity at the beginning and the velocity at the end. I think the rest of it fall out from this.

    ReplyDelete
  2. That makes sense and it explains why there was a factor of 2 difference between them. Thanks for pointing this out. I went ahead and updated the firmware so the calculations should now be correct.

    ReplyDelete
  3. Just a quick update on some testing I have been doing. Using the 5V power supply that I currently have (I have a 27V one in the mail), I was only able to run the motors at ~85 inch/min before implementing any acceleration code. Anything higher than this and the motors would skip steps. After adding acceleration (30 inch/min starting speed with 100000 inch/min^2 max acceleration), I am now able to run the motors all the way up to 120 inch/min without skipping any steps! That's a significant difference! I suspect that my larger 27V power supply will help even more because a 5V power supply can only energize the motor coils so fast and has a limit on its maximum stepping frequency.

    ReplyDelete
  4. The Hydra MMM is a great design.
    I really appreciate if you could give me the following files to learn more about your design.
    Best regards,
    tonyphan4321@yahoo.com
    Frame rigidity and table deflection
    Guide rail strength and max deflection (used to size all rods)
    Machining forces placed on toolhead (milling and drilling)
    Sleeve bearing maximum stresses during operation
    ACME screw calculations for force, deflection, max rpm, resonance, and resolution
    Chopper driver MATLAB circuit analysis (loaded RL circuit with transient and decay)
    Several CAD concepts in Pro/Engineer each with a priced BOM for evaluation
    Barrel heater viability testing
    Thermal model of FDM extruder assembly
    Note: if anyone is interested in the actual files behind any of these analyses just let me know

    ReplyDelete
  5. Dzui, we have gigabytes of files so could you maybe be a little more specific about what you are looking for? As we get closer to a final design I will probably start to package up more of the work that we have done to release it to the public. If you need something in particular right now, such as how we calculated all our machining forces or something like that, I can send you that file in particular.

    ReplyDelete
  6. Clayton this is fantastic work! Thank you for sharing it. Looking forward to future releases.
    You should enter this in the better reprap project and you might win some money for your design.
    David

    ReplyDelete