This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ME 461 Laboratory #7
Open Loop Motor Control and Friction Compensation Goals: 1. Write functions for controlling PMDC motors using PWM signals and motor bridges. 2. Calculate rotational velocity using encoder signals. 3. Develop a nonlinear controller to compensate for friction in the motors. NOTE: By now you should be aware that using floating‐point numbers on a 16 MHz, 16‐bit fixed‐point microcontroller is usually a bad idea. Well, beginning in this lab, we are going to break the rules. There are two reasons for doing this: one, it will reduce the complexity of our programs since floating‐point numbers are easy to work with; two, we will be using slow enough sample rates that the time used for floating‐point calculations will be acceptable. Important: Since we will be spending more time making computations, it is necessary to slow down the rate at which the timer ISR is called to no faster than every 5 milliseconds for the remainder of the labs. Exercise 1: (30 points) In this exercise you will create a function to send (torque) commands to the motors. As you probably could have guessed, you will be using a PWM signal and an H‐bridge to control each of the motors. The configuration hardware related to the Allegro A3953 motor bridges is shown below. VCC V+ (Battery) VCC A3953 REF
OUTA VBB VBB
47uF A3953 V 47uF MODE
SENSE Motor2 CC REF
680pF VCC V+ (Battery) MCU
P2.5 PHASE 24.9k P4.2/TB2 ENABLE GND OUTB
P4.0 P4.1/TB1 PHASE 24.9k 680pF ENABLE
GND VCC 2.2k
Amp Enable Motor Controller Schematic You are going to use a 20 kHz PWM signal to drive the motors. Write a function, e.g. Init_PWM, that initializes the pins connected to the motor bridges and configures Timer B for 20 kHz PWM output on pins 4.1 and 4.2. If you are unsure of how to configure Timer B, refer to the user’s guide and your code from Lab 2, where you configured Timer A. You should configure the pins connected to the PHASE terminals as general‐purpose outputs. Call this function from the main function of your program before setting the GIE bit (the same place you called Init_LS7266 in the previous lab). Write a function, e.g. Motor_PWM, that returns no parameters but accepts as inputs the motor number (1 or 2) and a floating‐point number in the range [‐10,10] representing the control effort (torque) to send to the motor. Your function should map ‐10 to full negative torque and +10 to full positive torque. Since we are sending PWM signals to the ENABLE pin of the A3953, this means you will need to set the direction pin (PHASE) based on the sign of the control effort. The magnitude of the control effort will determine the duty cycle of the PWM signal you send to the H‐bridge. The duty cycle should vary linearly with the magnitude of the control effort so that |u| = 0 → 0% duty cycle and |u| = 10 → 100% duty cycle. Your function should also perform a saturation check by limiting the control effort to +10 if it is greater than +10 and ‐10 if it is less than ‐10. Call the Motor_PWM function every 50ms in the Timer A ISR. Test your functions by sending several open‐loop commands from the PC to the robot. The sign and magnitude of the wheel speed should agree with your intuition. That is, a positive control effort should spin the wheels forward, and a negative control effort should spin them backward. If this is not the case, adjust the sign of the input passed to Motor_PWM in the ISR. Also ensure that larger‐magnitude inputs effect larger torques. Demonstrate to your TA. Exercise 2: (20 points) Now, add code to calculate the velocity of the wheels. Read the values of the two encoder counters every 50ms using the functions you developed in Lab 6. Using the backward difference rule, calculate the velocity of the wheels and convert it to rad/s (recall the number of quadrature counts per rotation of the wheels). The backward difference rule is shown below for reference. TS is the sample time. vk = xk − xk −1 TS (Backward difference rule) Be aware of the different types we are using (float, long, int) and remember the implicit type conversion rules; use type casting where necessary. Your final velocity result should be a floating‐point number. We will find it convenient in the future to work with linear velocity instead of angular velocity. Convert the angular velocity to linear velocity in ft/sec using a wheel radius of 2 inches. Print the velocities of the two wheels to the serial port and demonstrate to your TA for various control efforts. There is an inherent problem with using the encoder counter to compute velocities. When the counter “rolls over”, that is, when the count value reaches the limit of signed 24‐bit precision (±223), computing the velocity will produce an enormous result. Clearly this can be catastrophic, especially when using integral control as we will in the future. In your program, check to see if the computed velocity is greater than some large number (50 ought to do, since the robots’ top speed is roughly 1.7 ft/sec). If the velocity is large, replace the newly computed velocity with the velocity calculated at the previous time step. Show your TA your rollover protection code. Exercise 3: (50 points) You are now going to identify coulomb and viscous friction coefficients and implement a friction compensation algorithm to make your robot behave more like an ideal linear plant. This exercise should be performed with the robot on the floor near your bench. For various control inputs, record the average wheel velocity in the table below. If there is a large difference in friction between the two motors (to the point that the robot drastically deviates from a straight line), you will have to adjust the control input to one of the motors so that the wheels spin at the same rate. In this case, record the adjusted control values in the second column. Motor 1/Motor 2 Input (PWM units) Average linear velocity (ft/s) ‐3.5 ‐3.0 ‐2.5 ‐2.0 ‐1.5 0.0 1.5 2.0 2.5 3.0 3.5 The reason for using only a small range of the possible control efforts is that the speed of the motors saturates around u = 3.0. If you notice a deviation from the linear relationship in the data you collect, you should only use the linear portion of the control effort – velocity data. Generate a plot of control effort vs. average wheel speed (you will have two plots if you had to adjust control effort values for one of the motors). Fit two linear regressions to the data, one for . Your plot should look like the example below. The y‐intercepts of the regressions are and one for the coulomb friction constants and the slopes are the viscous coefficients. Record the values in the table below. Friction Nonlinearity in Motors Motor 1 Coulomb Friction Motor 2 (if needed) Viscous Friction Coulomb Friction Viscous Friction cpos = bpos = cpos,2 = bpos,2 = cneg = bneg = cneg,2 = bneg,2 = In your program, implement a controller that supplements the control effort based on the current velocity of the robot. If the robot is moving forward, use the positive coefficients, and if it is moving backward, use the negative ones. Your compensation algorithm should resemble the following. if v1 > 0 u1 = cpos + bpos × v1 else if v1 < 0 u1 = cneg + bneg × v1 Test your program with the robot on the floor. Give the robot a little shove forward. With a little tuning, it should coast as if no friction is present. If the robot speeds forward, scale the coefficients down by a constant, and if it hardly moves, scale them up. It is possible that you will have to scale one set of coefficients (negative or positive, motor 1 or motor 2) differently than the other(s). The goal is that the robot would move at the same (constant) initial velocity you impart, within the limits of saturation. Demonstrate to your TA. ...
View Full Document
This note was uploaded on 11/07/2011 for the course ME 461 taught by Professor Staff during the Spring '08 term at University of Illinois, Urbana Champaign.
- Spring '08