3DOF Ball On Plate Using Closed Loop Stepper Motor
3DOF Ball On Plate Using Closed Loop Stepper Motor
Table of Contents
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
Author:271828-
Hi! You can call me Matt. I'm a problem solver with interests in many fields. Sites like this are a great resource, therefore I will try to post some of my more
interesting projects when I have the time.
A good approximation for controlling the ball’s motion is to decouple the x and y directions on the plate. This allows for two separate independent control loops. One loop
controls the x-location of the ball and another controls the y-location. Each control loop for the x and y axis consists of two parts; an inner control loop and an outer loop.
The inner loop is responsible for running the stepper motors in closed loop for angle control. Motor angle is obtained from quadrature encoders on each stepper motor. A
set angle for the stepper motors is provided from the outer loop and the difference between the set angle and measured angle drives the stepper motor angular velocity.
The outer loop controls the actual ball position on the plate. The input to this loop is desired ball location and feedback is measured ball location. The ball location is
obtained using a 4-wire resistive touch screen on which the ball rolls. The difference and rate of change of the difference between the set and measured locations
determines the output angle that is fed into the inner control loop. The outer control loop takes on the form of a proportional-derivative (PD) controller, while all that is
needed for the inner loop is a proportional controller.
The output from the entire control system is the position of the ball on the plate. The position is controlled by adjusting ball acceleration. Ball acceleration is a function of
plate angle and plate angle is a function of stepper motor angle. Using the small angle approximation, a small change in motor angle from equilibrium should result in a
linearly related change in plate angle and therefore change in acceleration of the ball. This rudimentary approximation works quite well for controlling the ball even at
larger angles.
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
Step 1: Design Approach
The platform is designed to have three degrees of freedom. The stepper motors are set up in an equilateral triangle pattern. This configuration couples the x and y motion
but results in a simpler mechanical design to fully restrain the platforms position. The design also allows the platform to pivot around the location of the ball instead of just
the center. This approach should permit for more abrupt acceleration changes of the ball, as the ball goes through no vertical displacement during plate angle
adjustments. Currently the platform is only programed to pivot about the center.
Closed loop stepper motors were chosen because they work with existing 3D printer electronics. Adding feedback eliminates the missed step problem inherent to stepper
motors and allows for more accurate microstepping as the measured angle is controlled, not the step count.
TOOLS
CNC mill
manual lathe
drill press and bits
taps and drill bits for: #6-30, #8-32, m3-0.5
SAE and metric hex keys
screw drivers
electrical soldering supplies
computer with Arduino IDE installed
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
Step 3: Part Models
The included SolidWorks part models and drawing are for reference only. My intention is to provide enough detail for someone to make a similar project but not make an
exact copy. One should improve on the design and adapt it to fit one's needs.
File Downloads
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
top disk.SLDPRT (277 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'top disk.SLDPRT']
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
Step 5: CNC Mill 1/8 Inch Parts
Use the included SolidWorks models and reference drawing to generate machine code for the 1/8" aluminum plate and acrylic sheet. Parts were cut using a 1/8" two flute
carbide endmill with a 1/2" depth of cut. A 1/8" engraving bit was used to cut the pattern on top of the acrylic sheet.
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
Step 7: Turn Standoffs
Turn 6 pieces of 1/2" aluminum round to 1/2" long
Drill and tap (m3-0.5) one end of each piece to a depth of 1/4"
Chamfer the tapped end leaving a 0.2" diameter face
Reverse the part and drill/tap (#6-32) other end to a depth of 1/4"
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
Step 8: Drill Holes and Tap
Drill and tap the aluminum parts according to the provided drawing and solid models.
Before tapping the acrylic top sheet, glue the three small acrylic disks to the underside of the sheet aligned with the holes. Tap the holes in the acrylic after the
glue is set.
Tap the Traxxas rod ends using a #8-32 tap.
Attach the legs to the round 1/8" disk using the #6-32 button head screws.
Attach the standoffs to the motor arms using the #6-32 all thread pieces
Add the #6-32 socket head cap screws to the clamping end of the motor arms
Assemble the rod ends by pushing the balls into place
Attach the rod ends to the standoffs on the motor arms using the m3-0.5 screws
Attach the encoders to the backside of the stepper motors
Attach the stepper motors to the platform
Assemble the top triangular platform using m3-0.5 screws with the rod ends in place
Attach the arm Y pieces to the rod ends on the triangular platform using the 3 pieces of #8-32 all thread
Thread in the 12 pieces of #8-32 all thread into the arm Ys and remaining rod ends
Epoxy the 6 carbon tubes onto the threaded rods
After the epoxy is cured, slide the motor arms onto the stepper motor shafts and tighten the clamping screws
Fasten the top acrylic sheet to the triangular platform using 3 #8-32 x 1/2" socket cap screw
Adhere the touch screen to the acrylic sheet using thin double sided tape in the corners. Make sure the active side is up.
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
Step 10: Wire Electrical
The control electronics consist of easily obtained parts: an Arduino Mega 2560, RAMPS 1.4 3D printer control board and three DRV8825 stepper motor drivers. The three
stepper motors will be labeled A, B, and C.
Attach the Arduino Mega to the underside of the assembly using foam double sided tape. Make sure contact between traces on the Arduino and the aluminum
plate is not possible.
Modify two of the DRV8825 stepper motor drivers so that the STEP pin goes up instead of down. This will allow the pins to be connected to hardware timers on
the Arduino.
Insert the RAMPS 1.4 control board into the Arduino board and DRV8825 drives into the X, Y, and Z sockets on the RAMPS board with the two modified drivers in
the X and Y positions. The RAMPS should be set for 32 microsteps.
Connect stepper motor A to the X drive, motor B to the Y drive and motor C to the Z drive. If the motors spin the wrong direction when testing adjust the code or
wiring.
Make the following pin connections:
1. X driver step pin ----- D6
2. Y driver step pin ---- D5
3. motor A encoder a ----- D2
4. motor A encoder b ----- D3
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
5. motor B encoder a ----- D18
6. motor B encoder b ----- D19
7. motor C encoder a ----- D20
8. motor C encoder b ----- D21
9. 3X encoder +5V ----- +5V
10. 3X encoder GND ----- GND
11. touch screen X +5V ----- A12
12. touch screen X GND ----- 44
13. touch screen Y +5V ----- A10
14. touch screen Y GND ----- A5
15. quadrature knob a ----- 32
16. quadrature knob b ----- 47
17. quadrature knob button ----- 45
18. quadrature knob GND ----- GND
The stepper motors are powered from 12V DC supplied to the outer power connectors on the RAMPS board
Removing diode D1 might be necessary if the Arduino 5V regulator overheats as was occurring on my board. The Arduino will need separate power if D1 is
removed.
It is desirable to only take measurement when a touch is present. A third configuration is set to wait for
a touch condition and only enter the location measurement state when a touch is present. This is accomplished by setting the top or bottom side of the screen to ground;
setting the connected pins to output low. The other layer is connected to high impedance inputs with a pullup condition on one of the connected pins. The digital state of
the pullup pin is monitored until a touch on the screen pulls the layer low by connecting to the other grounded layer.
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/
Step 12: Control Methods
Stepper motors are normally operated in an absolute fashion where the amount of steps sent to the motor are tracked in order to determine motor movement. This
procedure has two unwanted qualities. The most obvious is lost steps. If the motor encounters a load sufficient to stop motion, the actual position is lost, as the
commanded steps no longer match the motors location. The less obvious problem is producing and counting motor steps when using microstepping at high speeds. A
typical stepper motor has 200 steps for a full revolution. This translates to 6400 steps for a full revolution if using 32 microstep controllers. When running the motors at
300 RPMs, an output of 32000 steps per second are needed per motor. Running three motors would result in almost 200K logic changes per second. Doing this level of
real-time processing on a 16MHz 8-bit microcontroller leaves no headroom for other tasks.
The solution is to offload the step generation to hardware level timers and compare registers while using encoders on the motors to directly measure movement. A closed
loop system can then be setup with the input value representing the difference between a desired motor angle and the measured angle from the encoder. The output
from the control loop would then set the motor’s RPM. The needed pulse train is generated from three 16-bit hardware timers with three compare registers. The timers
are setup with no pre-scaling producing a count rate of 16MHz that resets when the count equals the compare register. A corresponding output pin is toggled on timer
reset, generating a pulse train needed to move the stepper motor. The frequency of the pulse train is set by the size of the compare register and determines the RPM of
the motor. Scaled output from the stepper motor control loop can now be fed into the compare register to set motor RPM. With this method, all stepper motor signal
generation is accomplished at a hardware level leaving the microcontroller free for other tasks.
A proportional-derivative (PD) control loop is implemented in order to achieve staple ball positioning. An integral component was added, but not needed. The proportional
term in the control loop is simply the difference between the commanded location and the measured ball location multiplied by a proportional gain. The proportional term
results in smooth movement of the plate angle, as changes in ball location normally result in a large number. This is not true when calculating a simple first order
derivative dx ? [x(i) ? x(i?1)]/h as ball movement between measurements is small with relatively large noise. The behavior can be improved by increasing the time
between measurements but then the system response time becomes large. The solution is to use more of the balls history to better predict the current velocity. A good
approximation for the balls motion is constant acceleration as the plate’s angle is not rabidly changing. A second order accurate stencil using only past measurements to
predict the current derivative is desired. The stencil should have good noise rejection and time response behavior. Pavel Holoborodko has published such a list of stencils
for one sided derivative estimation from which a 16 point stencil was selected. The resulting derivative is significantly smoother than the simple case while maintaining
good system response time.
Both proportional and derivative components are added together such that the proportional part tilts the plate to accelerate the ball toward the set location and the
derivative component tilts the plate to slow the balls motion. The magnitude of each value can be set by adjusting the gain values until the system is critically damped.
Platform angles representing X and Y tilt need to be transformed into the three stepper motor angles. The X and Y axis are projected onto the three motor axis to
determine relative control weightings. This approach is only an approximation of the desired behavior but works as needed.
Consistent code execution rates are needed. This is achieved through the use of an interrupt routine that triggers every 1ms off of Timer0. Code execution flags are
activated in the interrupt routine that allow different portions of the code to run.
The PID library could be easily eliminated as only the proportional part is used for the stepper motor angle control.
The screen will need an initial calibration. In the beginning portion of the code under "touch screen stuff" calibration values can be entered. Uncomment
"Serial.print(measured_x_pos)" and "Serial.println(measured_y_pos)" at the bottom of main loop to display the raw screen readings. Touch the screen at the indicted
locations under the "touch screen stuff" section and enter the displayed values in the code. After calibration, re-comment the serial prints.
The quadrature control knob is used to adjust values during operation. The Arduino IDE serial monitor can be used to display the values. The first value displayed is the
main control loop time in uS. This value should not exceed 5mS as that is the call interval of the main loop. The quadrature push button is used to advance to the next
value. The next three values are the proportional, derivative, and integral gains. These values can be adjusted using the knob in order to achieve desired tuning. The ball
should quickly move to the set location with minimum overshoot. The values will be lost during power cycle so they should be manually entered in code after tuning is
complete. Offset values for the X and Y directions can be adjusted next. The ball will be offset from the desired position if the platform is not level and integral gain is not
used. Change the offset values to center the ball on the platform when "0 pattern" is set. Different ball patterns can be selected with 8 patterns currently programed using
parametric equations. The rate of ball movement is also adjusted with the "pattern rate" variable; smaller numbers equate to faster ball motion. The final value is "pattern
direction" which sets the direction of ball movement.
The provided code is functional but still a work in progress. Feel free to make improvements and share.
File Downloads
Advertisements
Comments
http://www.instructables.com/id/3DOF-Ball-on-Plate-Using-Closed-Loop-Stepper-Motor/