350 likes | 557 Views
Servo Motor Control. Basic computer control of motor position and velocity. Reading. Chapter 12. watch the motor movement. http://www.youtube.com/watch?v=7coUcEHxnYA - notice the choppy movement between taught points
E N D
Servo Motor Control Basic computer control of motor position and velocity
Reading • Chapter 12
watch the motor movement http://www.youtube.com/watch?v=7coUcEHxnYA - notice the choppy movement between taught points http://www.youtube.com/user/CompassAutomation?v=lpY2P4lDYwg - notice that the movements have been smoothed out
smooth movement starts slow, speeds up, finishes slow Position vs. time Velocity vs. time
How do you judge position? Encoder
How do you judge speed (velocity)? Attach motor shaft to small generator Use the motor to generate electricity Faster = more voltage/current Called a Tachometer
drive using position vs. time power to the motor
How do you teach a robot? • manually stepping through specific points
the problem You know "basically" where the robot arm should be, with a few points. Very choppy. To run smoothly in real time, you need thousands, actually a descriptive formula, p= f(t), and v= f(t)
we must smooth out the curve to this taught manually derived from a formula
how we solve it • Program 11 pts. Capture the (x,y) value of each point. y = [ 0 7.5 20 30 45 50 45 30 20 7.5 0 ] x = [ 0 10 25 30 40 50 60 70 75 90 100 ] • Find a polynomial equation that generates the same y's, from those x's (that is, an equation that matches the x,y curve). y = ax2 + bx + c, or more terms than that... • Generate 100s of x,y points using the formula
polynomials • 2nd order: y = ax2 + bx + c • 3rd order: y = ax3 + bx2 + cx + d • 4th order: y = ax4 + bx3 + cx2 + dx + e number of coefficients = order+1
step 1 y = [0 7.5 20 30 45 50 45 30 20 7.5 0 ] x = [0 10 25 30 40 50 60 70 75 90 100 ] figure(1) plot( x, y)
coeff = polyfit(x, y, n) • find a polynomial of the nth order that fits the x vs y vectors • coeff will be a column vector of n+1 values • if n = 2, then MATLAB will return coeff(1), coeff(2), and coeff(3) so that • vel = coeff(1) * x2 + coeff(2) * x + coeff(3) • remember : x = [0 10 25 30 40 50 60 70 75 90 100 ] vel = [ 11 new pts ]
order = 2 coeff = polyfit(x,y,2) vel = (coeff(1)*x.^2)+(coeff(2)*x)+coeff(3) coeff % -0.0182 1.8182 -5.0000 figure(2) plot(x, vel) note x.^2 means x2
order = 3 coeff = polyfit(x,y,3) vel = (coeff(1)*x.^3)+(coeff(2)*x.^2)+(coeff(3)*x) + coeff(4) figure(3) plot(x, vel)
order = 4 (5 coeffs) coeff = polyfit(x,y,4) vel =(coeff(1)*x.^4)+(coeff(2)*x.^3)+(coeff(3)*x.^2) + (coeff(4)*x) +coeff(5) figure(4) plot(x, vel)
order = 5 (6 coeffs) coeff = polyfit(x,y,5) vel = (coeff(1)*x.^5)+(coeff(2)*x.^4)+(coeff(3)*x.^3)+(coeff(4)*x.^2)+(coeff(5)*x) + coeff(6) figure(5) plot(x, vel)
order = 6 (7 coeffs) coeff = polyfit(x,y,6) vel = (coeff(1)*x.^6)+(coeff(2)*x.^5)+(coeff(3)*x.^4)+(coeff(4)*x.^3)+(coeff(5)*x.^2)+ (coeff(6)*x)+coeff(7) figure(6) plot(x, vel)
now plot for 1000 values of X x = [1: .1 :100] vel = (coeff(1)*x.^6)+(coeff(2)*x.^5)+(coeff(3)*x.^4)+(coeff(4)*x.^3)+(coeff(5)*x.^2)+ (coeff(6)*x)+coeff(7) figure(7) plot(x, vel)
Actual robot code % here's an actual robot curve v vs. t degrees = [0: 20: 360] radians = degrees*pi/180 % divide curve into 100 increments t = degrees/3.6 y1 = 25*(1-cos(radians)) %not a polynomial figure(8) plot(t,y1)
Actual robot code % position p vs. t degrees = [0: 20 :180] radians = degrees*pi/180 position = 20*(1-cos(radians)) t = degrees / 1.8 % move 1 degree in 1.8 sec figure(9) plot(t, position)
practice for the exam: %define an x row vector of 5 pts: x = [1:20:100] %get a y function of 5 pts y = 40*( 1-sin(x*pi/180) ) figure(10) plot( x, y)
polyfit to order = 2 coeff = polyfit(x,y,2) vel = (coeff(1)*x.^2)+(coeff(2)*x)+coeff(3) figure(11) plot(x, vel)
test that curve with 100 pts. x = [1:100] y = (coeff(1)*x.^2)+(coeff(2)*x)+coeff(3) figure(12) plot(x, y)
try 6th order %define an x row vector of 5 pts: x = [1:20:100] %get a y function of 5 pts y = 40*(1-sin(x*pi/180)) coeff = polyfit(x,y,6) vel = (coeff(1)*x.^6) + (coeff(2)*x.^5) +(coeff(3)*x.^4) + (coeff(4)*x.^3) + (coeff(5)*x.^2)+(coeff(6)*x)+coeff(7) figure(13) plot(x, vel)
warning Warning: Polynomial is not unique; degree >= number of data points. NOTE: the polynomial order must be less than the number of data points
try 4th order %define an x row vector of 5 pts: x = [1:20:100] %get a y function of 5 pts y = 40*(1-sin(x*pi/180)) coeff = polyfit(x,y,4) vel = (coeff(1)*x.^4) + (coeff(2)*x.^3) + (coeff(3)*x.^2)+(coeff(4)*x)+coeff(5) figure(14) plot(x, vel)
smooth it out x = [1:100] y = 40*(1-sin(x*pi/180)) coeff = polyfit(x,y,4) y = (coeff(1)*x.^4) + (coeff(2)*x.^3) + (coeff(3)*x.^2)+(coeff(4)*x)+coeff(5) figure(15) plot(x, y)