60
Beirut Master 4000 By Team 2 Larry Cole Vinay Shah Danish Zia Bert Hallonquist ECSE-4460 Control System Design Final Project Report Monday, May 2, 2005 Rensselaer Polytechnic Institute

Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

Beirut Master 4000

By

Team 2 Larry Cole Vinay Shah Danish Zia

Bert Hallonquist

ECSE-4460 Control System Design Final Project Report

Monday, May 2, 2005

Rensselaer Polytechnic Institute

Page 2: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

ii

Abstract This document describes the procedure used to design the Beirut Master 4000, a fully automated robot designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim the launcher along the pan and tilt axis. Motor control is achieved by a set of PID controllers. A pneumatic launcher is used to launch the ball. Visual feedback is provided via a webcam mounted over the target area. Image processing algorithms are used to detect the impact location of the ball. A learning algorithm analyzes the error between the actual and desired ball impact location and determines a new set of pan and tilt angles. The design outlined in this document is specific for the development of Beirut Master 4000, however much of the information presented here can be applied to various other tasks. An iterative learning algorithm can be used to converge to a solution whenever a rough model is available. However, accurate feedback and system repeatability is crucial for such an algorithm to be successful.

Page 3: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

iii

Table of Contents Abstract……………………………………………………………………………………………………ii Introduction................................................................................................................................................. 1 Professional and Societal Consideration..................................................................................................... 3 Design Procedure ........................................................................................................................................ 4

Modeling and Control ............................................................................................................................. 4 Parameter Identification...................................................................................................................... 4 Controller Design................................................................................................................................ 5

Launching System................................................................................................................................... 6 Feedback System .................................................................................................................................... 9 Learning Algorithm .............................................................................................................................. 10

Design Details ........................................................................................................................................... 12 Modeling and Control ........................................................................................................................... 12

Parameter Identification.................................................................................................................... 12 Controller Design.............................................................................................................................. 12

Launching System................................................................................................................................. 17 Mounting........................................................................................................................................... 17 Barrel and Propulsion ....................................................................................................................... 17 Automation ....................................................................................................................................... 19

Feedback System .................................................................................................................................. 20 Camera Mounting ............................................................................................................................. 21 Feedback System Initialization ......................................................................................................... 21 Translation to World Frame.............................................................................................................. 22 Capturing the Ball ............................................................................................................................. 23 Automatic Feedback ......................................................................................................................... 23 Manual Feedback .............................................................................................................................. 26

Learning Algorithm .............................................................................................................................. 26 Design Verification................................................................................................................................... 31

Controller .............................................................................................................................................. 31 Launching System................................................................................................................................. 33 Feedback System .................................................................................................................................. 34 Learning Algorithm .............................................................................................................................. 34

Costs.......................................................................................................................................................... 35 Conclusions............................................................................................................................................... 36 References................................................................................................................................................. 37 Appendices................................................................................................................................................ 38

Appendix A: Tables .......................................................................................................................... 38 Appendix B: MATLAB Scripts ........................................................................................................ 39 Appendix C: Simulations.................................................................................................................. 53 Appendix D: Contributions….……………………………………………………………………...55 Appendix E: Resumes………………………………………………………………………………56

Page 4: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

iv

List of Figures Figure 1 System Overview......................................................................................................................... 1 Figure 2 Flowchart of design approach ..................................................................................................... 4 Figure 3 PASCO Projectile Launcher........................................................................................................ 7 Figure 4 Experiment using spring loaded launcher ................................................................................... 7 Figure 5 Ping pong ball gun....................................................................................................................... 8 Figure 6 Experiment using compressed air launcher................................................................................. 8 Figure 7 Pan axis velocity curves ............................................................................................................. 12 Figure 8 Tilt axis velocity curves............................................................................................................. 12 Figure 9 Pan axis velocity versus torque ................................................................................................. 13 Figure 10 Tilt axis velocity versus torque................................................................................................ 13 Figure 11 Single axis model used for parameter identification algorithm verification ........................... 13 Figure 12 Pan axis root locus plot............................................................................................................ 14 Figure 13 Tilt axis root locus plot............................................................................................................ 14 Figure 14 Pan axis bode plot.................................................................................................................... 15 Figure 15 Tilt axis bode plot.................................................................................................................... 15 Figure 16 Pan axis simulated step response............................................................................................. 15 Figure 17 Tilt axis simulated step response............................................................................................. 15 Figure 18 Two axis closed looped discrete PID controllers .................................................................... 16 Figure 19 Pan axis step response ............................................................................................................. 16 Figure 20 Tilt axis step response ............................................................................................................. 16 Figure 21 Launcher Mount ...................................................................................................................... 17 Figure 22 Launching system setup .......................................................................................................... 18 Figure 23 Valve dimensions (in inches) .................................................................................................. 18 Figure 24 Parallel Port Pinout on Female Connector [13]....................................................................... 19 Figure 25 Voltage input and output of circuit.......................................................................................... 20 Figure 26 Parallel Port to Air Valve circuit ............................................................................................. 20 Figure 27 Feedback Initialization ............................................................................................................ 21 Figure 28 Image/World Frame Relationship ........................................................................................... 22 Figure 29 Ball Path Seen by Camera ....................................................................................................... 23 Figure 30 Binarized Image of Ball Path .................................................................................................. 24 Figure 31 Ball Path .................................................................................................................................. 24 Figure 32 Categorized Path of Ball- (a) Before Impact (b) After Impact................................................ 25 Figure 33 Point of Impact ........................................................................................................................ 25 Figure 34 Manual Feedback..................................................................................................................... 26 Figure 35 Newton-Raphson Method, Side View..................................................................................... 29 Figure 36 Newton-Raphson Method, Top View...................................................................................... 29 Figure 37 Schröder Method, Side View .................................................................................................. 29 Figure 38 Schröder Method, Top View ................................................................................................... 29 Figure 39 Schröder Method, Side View .................................................................................................. 30 Figure 40 Schröder Method, Top View ................................................................................................... 30 Figure 41 Model verification model file.................................................................................................. 32 Figure 42 Pan axis velocity comparisons................................................................................................. 32 Figure 43 Tilt axis velocity comparisons................................................................................................. 32 Figure 44 Pan position tracking ............................................................................................................... 33 Figure 45 Tilt position tracking ............................................................................................................... 33 Figure 46 Initial velocity determination experiment ............................................................................... 33

Page 5: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

v

List of Tables Table 1 Controller specifications ............................................................................................................... 2 Table 2 Summary of friction parameters ................................................................................................. 13 Table 3 Comparison of actual and experimentally determined parameters............................................. 13 Table 4 Summary of parameters for pan and tilt axis.............................................................................. 14 Table 5 Summary of initial controller gains for pan and tilt axis ............................................................ 15 Table 6 Summary of controller performance for step response on simulated non-linear plant............... 15 Table 7 Summary of final controller gains for pan and tilt axis .............................................................. 16 Table 8 Summary of controller performance for step response on physical plant .................................. 16 Table 9 Cost of Beirut Master 4000......................................................................................................... 35

Page 6: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

1

Introduction The aim of this project is to design a pan and tilt mechanism that will successfully hit a target minimizing the number of iterations. Our goal is to hit the target within eight tries because this was found to be the average number of attempts for a human player to successfully hit the cup. The ball launcher will be placed on the pan and tilt device provided. A controller will position the launcher to the correct angles. After the ball is fired, a feedback system will determine whether the target is hit. If the target is missed, a learning algorithm will find new pan and tilt angles in order to reduce the error and converge to a solution where the target is hit. This process will be repeated until a hit has been confirmed by the feedback system. Our motivation was to create a machine that can automatically master the game of Beirut, a popular game among college students where players must throw ping pong balls into cups. However, the concept of the iterative learning algorithm has several applications outside of the scope of our project. This implementation can be used for military applications. Using satellite imaging, the algorithm can be used to iteratively learn how to hit targets with artillery. The robotics industry is interested in using iterative learning algorithms to develop robots capable of self correction. In addition, this design can be used to create robots that would be used in practicing various ball sports, such as table tennis, and baseball to perfect hitting certain ball trajectories.

Figure 1 System Overview

Page 7: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

2

In order to quickly and effectively position the motor a pair of PID controllers were designed, one for each axis. The desired response of our motors is one in which overshoot, rise time, settling time, and steady state error are minimized. These goals were transformed to a set of specifications as shown in Table 1. Table 1 Controller specifications Maximum Overshoot (Mo) < 10 % Rise time (tr) < 0.2 seconds Settling time (ts) < 0.5 seconds Steady state error (ess) < 1 % Overshoot can be a problem when the motors are commanded to positions close to their physical limits. If the overshoot is too high the system can collide with itself and thus as a result physical damage may occur. A slight error in the position of the launcher will result in a much larger error in the impact location of the projectile due to the distance between the launcher and target area. Thus, minimizing steady state error is of vital importance. The rise time specification will ensure the motors are positioned rapidly, however more importantly is the settling time specification because only after the motors have settled can the ball be fired. The launcher system is composed of a launcher body, mounted on the pan and tilt device. The propulsion of the balls is accomplished by air pressure. An electronic air valve is opened and closed from a control signal sent via the parallel port and commanded by MATLAB. The feedback system uses a Logitech QuickCam Messenger camera mounted on a PVC pipe frame to capture images of the target area. Initially, the target is found using thresholding. When the ball is fired, a combination of image processing techniques determines the landing location of the ball. This location is converted into cylindrical coordinates for the learning algorithm. The iterative learning algorithm is based on the root-finding methods that enable the system to reduce the error and converge to a solution within eight tries. The algorithm uses the Schröder root-finding method in conjunction with projectile physics to correct for the error between the target and the landing location of the ball.

Page 8: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

3

Professional and Societal Consideration The learning algorithm can be applied to other fields to obtain solutions. For example, it may be applied to military applications. If trying to destroy a target using artillery a learning algorithm can be used to determine which launch angles are necessary to hit the target. Oftentimes the use of new technology for military application raises ethical issues. The learning algorithm is designed to reduce the number of failed attempts which in turn will reduce the number of innocent casualties in war. The visual feedback system can be tweaked slightly and implemented for military use by using satellite imaging as the camera. The system can be used to determine the site of the missile explosion and compare it to the coordinates of the desired target. There are several machines on the market today that currently play ping pong. The Beirut Master 4000 is different than these machines because the Beirut Master 4000 is capable of learning how to hit a target using visual feedback. The commercial machines use pre-programmed algorithms to determine the location of each launch. However, since the Beirut Master uses visual feedback, it can provide a new twist on the game by self correcting in play. The choice of using air as the method of launching as opposed to spinning disks or springs has an added safety benefit. Air requires fewer movable parts. For a spinning disk or spring loaded launcher there is a possibility of injuring oneself by accidentally putting a finger in the launching apparatus. By having fewer moving parts the chance of injury is reduced.

Page 9: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

4

Design Procedure

Modeling and Control

Figure 2 Flowchart of design approach

In order to meet the specifications described above the design approach as outlined in Figure 2 was followed.

Parameter Identification Before design work can begin a model of the system is required. Based on some principals of physics, equation (1) was developed as a dynamic model of a single axis [1].

sin ( )eff m v cJ N mgl B B Signθ τ θ θ θ= + − − (1)

Where Jeff is the effective load inertia, N is the gear ratio (25.2), mτ is the motor torque, m is the mass, g is gravity, l is the center of gravity of the load, vB is the viscous friction, and cB is the Coulomb fiction. The motor torque can be calculated as follow:

No

Parameter Identification

Dynamic Model

Model Verification

Controller Design

Non-linear Simulation

Acceptable?

Plant Verification and Tuning

Yes

Page 10: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

5

m t iVNK Kτ = (2) Where, V is the input voltage, N is the gear ratio once again, Kt is the torque constant (.0436 N*m/A in our case) and Ki is the amplifier gain (0.1 Amp/volt). Thus the first task is to identify the remaining unknown parameters, the viscous and Coulomb friction, the effective inertia, and the gravity loading term mgl. Experiments were designed to isolate and thereby identify some of these parameters as described in the design details [2] . Another approach to parameter identification lumps all these parameters into four parameters, a1- a4.

Equation (1) is now transformed to:

1 2 3 4( ) sina a Sign a V aθ θ θ θ= − − + + (3) A least squares estimation algorithm can then be used to determine all the parameters with one set of input and output data. This is a fast and convenient method for fully identifying the system parameters. However, the downside to this approach is that the accuracy of the resulting values is dependant on the type of input exciting the system. This algorithm also returns a set of Eigen-values for each of the parameters which can be used to determine how accurate the identified parameters are [3]. In order to ensure the validity of the algorithm and to determine which input sufficiently excites the system, the algorithm was first run on the model. This was done by inputting estimated values for the various parameters and exciting the model with various inputs. If the algorithm is able to accurately identify the inputted parameters then the algorithm is validated and the input is deemed to sufficiently excite the system. Through this approach it was found that different inputs did better at identifying certain parameters than others. Thus, various inputs were used to complete parameter identification on the plant. Both methods, identifying specific parameters through experimentation and full system identification through least squares algorithm, were used to determine and validate the identified parameters. First values of viscous and Coulomb friction were identified through experimentation. Next by comparing equation (3) with equation (1) the following relationships can be developed.

1 v eff = B /Ja (4)

2 c eff = B /Ja (5)

3 t i eff = K K N/Ja (6)

4 eff = mgl/Ja (7) By dividing a3 by the product of the known values of Kt, Ki, and N an estimate for the effective inertia can be found. Multiplying the estimate for the effective inertia by a1 and a2 results in estimates for the effective viscous and Coulomb friction respectively. By comparing these values with the ones found through experimentation the parameters can be validated. Another method of validating the parameters is to excite both the model and plant with the same set of inputs and compare the results. If the model is accurate the responses will match.

Controller Design Initially three types of controllers were considered, the classical PID controller, a finite settling time (also known as a ripple free) controller, and a full state feedback controller. Finite settling time

Page 11: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

6

controllers typically require very large gains or very slow sample times which is not acceptable for our design. A full state feedback controller typically requires accurate estimations of the states of the system. However, velocity estimations have limited accuracy and therefore the full state feedback would have limited control. Due to relative ease of PID controller design and the confidence that it would sufficiently meet our requirements exploration of the other controllers was discontinued. To design the PID controller first our model was linearized. This allowed us to do root locus and frequency domain analysis. Using the information developed from these analyses an initial value for the proportional gain, kp was chosen. Since the Coulomb friction, a damping term, was eliminated when linearizing the model a kp was picked which resulted in a very large overshoot for the linear model. When simulated on the linear model there was little to no overshoot because of the damping due to Coulomb friction. Step response analysis was conducted using Professor Joe Chow’s tstats function [4]. This function was used to determine overshoot, rise time, settling time, and steady state errors as a result of a step input. Using this information, the controller was tuned to meet our specifications. The proportional gain was first adjusted to outperform the rise time specification. Then the derivative term was added to decrease the overshoot and dampen oscillations, this however also resulted in an increase in the rise time. The integral term was adjusted to eliminate steady state errors but also increased overshoot. These values were continuously adjusted until all the specifications had been met. Once the controller had been designed on the model it had to be tested on the actual plant. Similar tuning was required in order to get the best response.

Launching System The launching system is composed of the air supply, an electronic valve, circuitry to control this valve, a mount, and the launching barrel. The launching system pneumatically powered which cause compressed air to build up in the area where the ping pong balls are stored. This pressure build up will be behind the ball and will push the ball forward. In order to ensure launch repeatability, control is placed on the valve to be open and closed for a specific amount of time to ensure consistent pressure. This method is desirable because a compressed air launcher can be automated fairly easily. To automate it one needs only to find a way to electronically control the flow of air and to ensure that only one ball gets fired at a time. In addition, this system seems to offer better chances at repeatability than other methods. Having made this claim however, we must first look at some of the other launching possibilities that were considered and compare them to the system we chose. In addition to a compressed air method, there were many options available as to how the launching system could be created. The choices available to us included launching using motor-driven spinning disks, a spring loaded system, compressed air pulses, rotational ‘arm’ swinging motion, a hydraulic system, or even the use of gunpowder to fire an object. Because there were so many options available to us some research was needed before reaching a decision. After some research it was discovered that three main types of launchers are generally more viable to implement than other types. These are compressed air systems such as ours, spring loaded launchers, and motor driven launchers. The following is a summary of the research results, and some analysis of each item. There are some spring loaded launchers available on the market. The company “Pasco” sells short-range and long-range projectile launchers. These are spring loaded launchers which claim to have the following features: High durability in that the precision of the launcher doesn’t change even after being fired a large number of times (over 4000). The device supposedly has flexible ranges, however the company doesn’t specify the range. Also the device reportedly has flexible launch positions due to

Page 12: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

7

stable stands, and a fixed firing height at any launch angle, which eliminates launch height as a variable. Price: £363.00.

Figure 3 PASCO Projectile Launcher

For our project flexible ranges are not of concern because we will be mounting the launcher on a pan-and-tilt and letting that device adjust the direction. Fixed firing height is desirable, as well as the high repeatability of this device. However, because we want the process to be automated, this device is difficult to work with because it requires constant manual reloading. Also this device is too costly for our budget. Spring loaded launchers have been used in experiments in the past. Figure 4 shows one such experiment. In this experiment it is shown that vertical motion of projectiles is independent of horizontal motion.

Figure 4 Experiment using spring loaded launcher

Page 13: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

8

For compressed air systems we found the following type of product. Ping pong ball guns [5] are currently available as launching devices. This device is manually fired; one needs to operate the pump in order to cause the air to compress.

Figure 5 Ping pong ball gun

An example of past experimental uses of compressed air launching systems is shown below.

Figure 6 Experiment using compressed air launcher

After considering the products on the market as well as the experiments that have been run using projectile launchers, we were able to narrow down the field of possibilities. We can throw out ideas such as gunpowder and rotational swinging arms because for the former it is not easily implemented, and the latter will create too much uncertainty in launch results. It was considered best to use a spring loaded system or a compressed air system because those are the two main types used in previous experiments and resulted in the best repeatability. However, in terms of automating the process, the spring loaded method is not as viable as either the compressed air method or the motor driven launching method. This is because a spring loaded system must be re-cocked and reloaded each time. Motor

Page 14: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

9

driven ball launchers did not have the repeatability obtained by the pneumatic launchers. Therefore the most desirable method was to use the compressed air system. To design a fully automated system, the air valve was to be automated so that the launcher only fires one ball at a time. The valve requires a DC voltage signal of about 5 V to turn on, and can draw up to 0.4 A. Various ways of accomplishing this task were researched, including using a LabJack, the serial port, the audio out port on the PC, and the parallel port. The parallel port was chosen due to several reasons. The LabJack and other products commercially sold that are capable of controlling an analog output through scripting are quite expensive. On the other hand, the parallel port is included in almost all PCs used today. The parallel port can also output logic high/low continuously to any of the eight data pins it uses. There are also commands within the programming language of C that could be used to change the data pins using scripts. [6] The parallel port pins can be controlled through scripts within the programming language of C using built in commands. However, in order to use these pins in MATLAB a Freeware java class called Parport used. This class is imported into MATLAB, and allows one to control the parallel port pins using M-script. The logic signal from the parallel port is a 60 Hz signal that is centered at 0 V when the pin is low and approximately 2.3 V when the pin is high. In order to output the required DC signal, a low pass filter is required to filter out the high frequency content. In addition, the center voltage needs to be amplified to approximately 5 V with the capacity of handling at least 0.4 A. Since the parallel port can only handle 2.6 mA [7], this task is accomplished by an OPA548T high power operational amplifier. This amplifier can handle currents of up to 3 A continuously so it is able to run drive the air valve for long periods of time. It is used in a non-inverting amplifier configuration to output the desired voltage when the parallel port is at logic high. [8]

Feedback System The feedback system is designed to accurately determine the location of the ball when it hits the target area. This task is divided into two steps, first to acquire the frames of the video containing the ball, then to analyze those images to find the point of impact. Initially piezo devices were to be installed on the aluminum sheet to record the time of impact. When the ball hits the aluminum with the piezo attached the impact results in a voltage spike. The time that this spike occurs is recorded and compared to the time that the camera began recording. There was a delay between the time the piezo reacts to the bounce, and a delay that the camera begins recording. Unfortunately, the delay of the camera is variable. For this reason, this implementation was not possible. The original method to determine the point of impact was to check the size of the ball. As the ball approaches the ground the size of the ball in the frames decreases. By picking the frame where the ball is the smallest, the point of impact can be approximated to the centroid of the ball in that frame. Unfortunately the ball is traveling too fast to capture a good image of it. The camera needs to operate at a much higher frame rate, and the ball needs to travel slower. Another method that was researched was to pick two frames; the first frame with the ball and the last frame with the ball and fit lines to the ball path within each of them. The point of impact would be

Page 15: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

10

approximated by the intersection of these lines. This did not work because oftentimes the first and last frames containing the ball would not be enough to accurately approximate a line of the path of the ball. A refinement to this approach was to only pick the two frames that the blur of the ball was largest in. This was more robust than the previous approach, but occasionally the frame just as the ball hit the target area would be chosen. When this happens the feedback was always inaccurate because the change in direction of the ball in the frame significantly alters the line fitted. The mean squared error for this frame is significantly higher than the others which lead to the next iteration in the design approach. The next attempt was to fit a line to each frame containing the ball. Then eliminate the frame with the highest mean squared error. Then pick the two lines that have the greatest difference in slope. The point of impact was estimated as the point that these two lines intersect. Although this eliminated the problem of the frame with the ball as it bounces, it brings back the problem of the lines fitted to frames that barely contain the ball. After this attempt failed, the current method of automated feedback was developed. This method classifies each pixel of the path of the ball as either before or after the bounce occurred. Using this information two lines are fitted to each of these paths. The ball impact location is determined to be the intersection of these two lines.

Learning Algorithm In order to hit the cup with the ball, a learning algorithm that will converge to the target is used. This algorithm takes in the error from the target, in addition to the previous pan and tilt angles used and outputs new pan and tilt angles for the next shot. The learning algorithm continues to output new angles after every shot, until a hit has been confirmed by the feedback system. The goal is to converge to the target in eight shots or less. Several types of learning algorithms were investigated. A root-finding algorithm was picked to be implemented because these algorithms quickly converge to a solution. These algorithms are designed to determine the zero crossings of functions that have no closed form solution. An initial guess of the root is first given and based upon the resulting error a new approximation is found. Root-finding algorithms were chosen because at the very least they give the correct direction to take when choosing new angles, thus greatly reducing the possibility of diverging from the target. The two root-finding algorithms explored in detail were the Newton-Raphson method, and the Schröder method. These two were chosen because they almost always converge to the root as proven in simulation. They only become unstable if the approximated root is near a horizontal slope. Equation (8) shows the Newton-Raphson method, while Equation (9) represents the Schröder method. [9]

(8)

(9) In the case of our system, the function f (xn) represents the error between the position of the target and the position of where the ball lands. The variable xn+1 corresponds to the new pan or tilt angle that is to be approximated in order to reduce the error. Therefore, xn is the pan or tilt angle that resulted in the error f (xn). The functions f(xn) and f(xn) are based on projectile physics and are the first and second

Page 16: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

11

order derivatives of the landing position of an ideal launch environment with respect to the launch angles. Another design consideration was to represent the target coordinates as well as the landing coordinates in a cylindrical coordinate system, rather than a Cartesian one. In this system, the origin was placed at the launcher, and a zero angle was defined as the hypothetical line connecting the origin and the camera. This was done to decouple the projectile equations per axis. Thus, the radial distance r was only dependant on the tilt angle, and the angular coordinate only depended on the pan angle. Both the Newton-Raphson method and the Schröder method are based on the Taylor series. However, the Newton-Raphson method takes only the first order terms into account, while the Schröder method takes the second order term into account as well. The extra information provided by the second order derivative resulted in a faster convergence to a solution as demonstrated by simulation. In addition, the Schröder method only becomes unstable if the first derivative of the error function and the function itself or its second order derivative is near zero. Thus the Schröder method was implemented in the final design.

Page 17: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

12

Design Details

Modeling and Control

Parameter Identification As mentioned in the design procedure above, two methods were used for parameter identification and then compared to validate the results. The first method only found values of friction parameters while the second method fully identified the system. Friction parameters were identified by noting the relationship between steady state velocities due to constant torque inputs to the system. First a MATLAB script, found in Appendix B.1, was written to acquire all the necessary data. Data was gathered for a set of voltages within the saturation bounds of the motor. Each voltage experiment was run five times and then averaged to cancel out any zero mean noise to the system. A 10 volt 1.5 second pulse was initially inputted to the system in order to overcome the stiction of the system. The velocity of the system was calculated by a finite difference on the output position of the system. This velocity was then filtered using a 12th order Butterworth filter with a cut of frequency of .065fs which is equal to a cut off of 65 Hz. The resulting torque due to a given input voltage was calculated according to Equation (2). The velocities versus time of the pan and tilt motor are shown in Figure 7 and Figure 8 respectively. Torque versus steady state velocity is shown in Figure 9 and Figure 10. The value used for the steady state velocity was simply the last value in the time history of each of the velocity curves. Using these values, graphs of steady state velocity versus torque were generated. A linear regression was preformed for both operating regions of each motor. The viscous friction for both the positive and negative region for each axis is equal to the slope of each of these line segments. The Coulomb friction is the value at which these line segments intersect the torque axis. Table 2 summarizes the friction parameters for the system.

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

x 104

-25

-20

-15

-10

-5

0

5

10

15

20

25

Vel

ocity

(ra

ds/s

ec)

time (ms)

Friction Identification: Pan Motor

Figure 7 Pan axis velocity curves

0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000-25

-20

-15

-10

-5

0

5

10

15

20

25

Vel

ocity

(rad

s/se

c)

time (ms)

Friction Identification: Tiltmotor

Figure 8 Tilt axis velocity curves

Page 18: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

13

-20 -15 -10 -5 0 5 10 15 20-0.1

-0.08

-0.06

-0.04

-0.02

0

0.02

0.04

0.06

0.08

0.1

velocity (rads/sec)

torq

ue (N

*m)

Friction Indentification: Pan Motor

Figure 9 Pan axis velocity versus torque

-25 -20 -15 -10 -5 0 5 10 15 20 25-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

0.15

velocity (rads/sec)

torq

ue (N

*m)

Friction Indentification: Tilt Motor

Figure 10 Tilt axis velocity versus torque

Table 2 Summary of friction parameters Pan Motor Positive Negative Viscous (N.m.s/rad)

0.00066913 0.00069303

Coulomb (N.m)

0.080058 -0.071475

Tilt Motor Positive Negative Viscous (N.m.s/rad)

0.0015316 0.0016016

Coulomb (N.m)

0.075495 -0.077283

1

Out1

a1

cos

voltage2

Sign

1s

1s

Integrator

a2

a4

a31

In1

position

v iscous f riction

thetadd

Coulomb f riction

grav ityloading

Figure 11 Single axis model used for parameter identification algorithm verification The second approached used a least squares estimation algorithm to determine the system parameters [3]. In order to ensure this algorithm would work it was tested on a model, as shown Figure 11, with known parameters based on initial estimates. Table 3 shows the results generated when testing the model with estimated values for the parameters and a 0.1 to 0.5 Hz chirp input. Table 3 Comparison of actual and experimentally determined parameters a1 a2 A3 a4 Actual .7874 78.7352 108.1 0 Experimentally Determined

.6922 76.983 100.6 0.00595

Continued investigation showed that a ramp input was the best type of input to determine a4, a chirp input to determine a1, and a pulse input for determining a2 and a3. Multiple data sets were collected in

Page 19: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

14

order to fully identify the parameters of the system. A script was written to run the algorithm on all the data sets and generate a report. The report included the resulting parameters generated by the algorithm for the given inputs with its corresponding Eigen-values which is related to the accuracy of the results. This script can is displayed in Appendix B.4. Table 4 summarizes the parameters found for both axes. Table 4 Summary of parameters for pan and tilt axis a1 a2 a3 a4 Pan Axis 0.07 7.5 11 0 Tilt Axis .9 42 57 -4.2

Controller Design Since most analysis of systems is only applicable to linear systems, our model had to be linearized. The following transfer functions resulted for the pan and tilt axis respectively [10]:

4.163e-017 s + 11s^2 + 0.07 s

(10)

4.441e-016 s + 57s^2 + 0.9 s + 4.2

(11)

Figure 12 and Figure 13 show the root locus of these systems and Figure 14 and Figure 15 show the bode plots.

Figure 12 Pan axis root locus plot

Figure 13 Tilt axis root locus plot

Page 20: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

15

Figure 14 Pan axis bode plot

Figure 15 Tilt axis bode plot

It is apparent from both the root locus and bode plots that both axis has an infinite gain margin. This allowed for using large gains without the system becoming unstable. A gain which resulted in significant overshoot was picked for both the pan and tilt axis. The gain was picked at 30 for both the pan and tilt axis. This would result in an approximate overshoot of 100% on the linear system, however for the non linear system the response only had a slight overshoot. This is due to the Coulomb friction. Values for derivative and integral terms were developed using the procedure outlined in the design procedure. Table 5 summarizes the values of the controller gains for both axes. Table 5 Summary of initial controller gains for pan and tilt axis kp kd ki Pan Axis 30 .003 .002 Tilt Axis 30 .85 0 The response of the system to a step input to the non-linear model with the controller implemented is shown in Figure 16 and Figure 17 for the pan and tilt axis respectively.

Figure 16 Pan axis simulated step response

Figure 17 Tilt axis simulated step response

Table 6 Summary of controller performance for step response on simulated non-linear plant Mo tr ts ess Pan Axis 9.6% .198s .45s .955% Tilt Axis 4.56% .198s .348s .425% The controller was then tested on the plant using the Simulink diagram shown in Figure 18.

Page 21: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

16

2

Tiltpos

1Panpos

z

1

Unit Delay1

z

1

Unit Delay

0

Tilt Kp

0

Tilt Ki

0

Tilt Kd

Step1

Step

0

Pan Kp

0

Pan Ki

0

Pan Kd

PCIM-DAS1602/16ComputerBoardsAnalog Output

1

2

PCIM-DAS1602 16

PCI-QUAD04Comp. BoardsInc. Encoder

Count

PCI-QUAD04 1

PCI-QUAD04Comp. BoardsInc. Encoder

Count

PCI-QUAD04

K Ts

z-1Integrator1

K Ts

z-1Integrator

1/0.001

Gain3

-2*pi/(1024*4)

Gain2

1/0.001

Gain1

-2*pi/(1024*4)

Gain

-1

-1

y(n)=Cx(n)+Du(n)x(n+1)=Ax(n)+Bu(n)

Butterworth Fi l ter2

y(n)=Cx(n)+Du(n)x(n+1)=Ax(n)+Bu(n)

Butterworth Fi l ter1

Figure 18 Two axis closed looped discrete PID controllers After some additional tuning of the controllers, responses which significantly outperformed the simulated responses were achieved. Table 7 Summary of final controller gains for pan and tilt axis kp kd ki Pan Axis 30 8.5 1 Tilt Axis 30 1.3 .82 Step responses on the physical plant are show in Figure 19 and Figure 20. The step size for the tilt axis was 0.5 radians due to its limited range before colliding with itself.

Figure 19 Pan axis step response

Figure 20 Tilt axis step response

Table 8 Summary of controller performance for step response on physical plant Mo tr ts ess Pan Axis 6.611% .1123s .245s .0155% Tilt Axis 6.458% .0684s .248s .0155% The final controllers surpassed our expectations in its overall performance. Due to exceptional results of the PID controllers, further investigation on other controllers ceased.

Page 22: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

17

Launching System

Mounting In order to mount the launching mechanism to the pan and tilt device a mounting plate had to be attached to the tilt shaft. This was done by machining two clamps so they have a flat base. An aluminum plate was screwed into the flat portion of the clamps. The launcher itself is positioned on the mounting plate, and held in place by two U-bolts. The full mount of the launcher is shown in Figure 21.

Figure 21 Launcher Mount

The U-bolts must fit closely to the launching tube. It they are too tight, the tube will be deformed which will lead to inaccurate launching. If they are too loose, the tube will slide which will ruin the calibration of the entire system. To prevent sliding while maintaining the form of the tube rubber was attached to the portions of the U-bolts touching the tube. The rubber increases the friction between the tube and the U-bolt. Also, as the U-bolts are tightened the rubber deforms before the tube does. This allows for a tighter fit without deforming the tube.

Barrel and Propulsion The launcher makes use of the compressed air in the laboratory. From the compressed air tank we run a 3/8 in. inner diameter tube to a device which splits the air flow. Tubing attached to both outlets of this split device then travel to separate step down devices, causing the tubing size to change to 1/8 in. inner diameter. One end of the split then goes to an electronically controlled proportional valve, while the other travels to the main launcher body. The following figure illustrates this system:

Page 23: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

18

Figure 22 Launching system setup

The tubing step down devices are necessary because the valve and launcher body can only support the smaller size tubing, while the compressed air tank in the lab only supports the larger tubing. This system operates by using the valve to control the air flow to the main launcher body. When the valve is open pressure cannot build up in the launcher and instead diffuses into the room. When the valve is closed then pressure is allowed to build up in the launcher body until a ball is fired. The launcher body consists of a simple tube which properly fits around the ping pong balls so that the air pushes the ball outwards. At the end of the tube there is a choking device so that the ball becomes stuck and only ejects from the tube if the air pressure inside the tube reaches a certain level. In this way the initial velocity of the projectile is approximately the same every time. Multiple balls are able to be in the tube at one time, so that the device need not be reloaded every time. The valve used is a proportional valve, so that we can control the airflow by applying the proper voltage to it. The valve has wire connectors, a control voltage of 0 to 5 volts, an orifice of 0.0250 inches, a maximum current drawn of 0.37 amps, and a rated pressure of 100psi. [6] In addition, the valve has the specifications (measured in inches) as shown in Figure 23:

Figure 23 Valve dimensions (in inches)

Page 24: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

19

The inlet and outlet ports for valve are threaded holes of size 10-32 in. as shown in the figure above. Barbs are then screwed into these holes and the tubing is then attached to the barb. The barbs available which can fit into this size hole were limited. This is the reason why the tubing size needed to be stepped down for the process to work. The launcher body was constructed from the parts of a ping pong ball gun which is shown in Figure 5. The front handle was removed as well as the back end of the gun. Only the single tube with the balls in it and the squeezing nozzle were required for our purposes. The back of this launcher connects to tubing with an inner diameter of 1/8 of an inch. This was accomplished by using a steel tap of 10-32 thread size to create a threaded hole in the back of the launcher. We could then place the same barb into the back of this launcher as the one that screws into the valve. In this fashion, the launcher also supports only tubing of 1/8 in inner diameter.

Automation The parallel port is configured with eight data ports labeled D0 through D7 as can be seen in Figure 24. To control these pins in MATLAB a Freeware Java class called Parport was imported. Using this class, each of the parallel port pins can be controlled individually through a MATLAB script. Instructions on how to install and use this class can be found in [11]. The MATLAB script “sendlaunchsignal.m” found in Appendix B.20 uses this java class to send a temporary logic low to the valve in order to launch one ball. The time that the signal remains at low depends on the air pressure going to the valve, and should be adjusted with varying pressure.

Figure 24 Parallel Port Pinout on Female Connector [13]

To convert the parallel port logic signal into a 0-5 V DC signal, a low pass filter as well as an operational amplifier was needed. Since we require a DC signal, a very low cutoff frequency is required with a sharp drop between the pass band and stop band. To accomplish this, a Sallen-Key unity gain RC low pass filter is used. This method takes advantage of an operational amplifier to employ a second order low pass filter that is close to unity gain in the pass band. The cut off frequency is given by Equation (12), where R1, R2, C1 and C2 can be seen in the low-pass filter portion of the final circuit in Figure 26. [12]

0 21 2 1 2

1 15.11

2 2 (220 ) (0.2 )(0.1 )f Hz

R R C C k uF uFπ π= = =

Ω (12)

This low cutoff frequency leaves mostly the DC portion of the logic signal of 0 V low and 2.3 V high. In order to amplify the logic high to 4.6 V, a non-inverting amplifier configuration is used with a voltage gain of two. The OPA548T is used when implementing this circuit. The output from this op-amp is then inputted to the valve. [14]

Page 25: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

20

Using the program B2 Spice with the schematic in Figure 26, a simulation of the circuit is conducted. A 60 Hz sinusoidal signal that is offset by 2.3 V and has a 1.0 V amplitude is used to simulate the signal from the parallel port. The voltage across the valve is taken and graphed in Figure 25. Even though there is still some oscillation across the valve, it is not enough to affect the valve significantly. In addition, the current drawn from the parallel port is no more than 10 A, thus ensuring operation without any damage to the parallel port.

Figure 25 Voltage input and output of circuit

Figure 26 Parallel Port to Air Valve circuit

Feedback System The feedback system uses a Logitech webcam mounted four feet above the ground and eight feet away from the launcher to view each attempt at hitting the target. The target is located on a padded aluminum sheet. The location of the camera is critical for the accuracy of the feedback system. Slight deviations

Page 26: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

21

from these distances will result in inaccurate results because the inverse kinematic equations are based on these measurements.

Camera Mounting The camera is mounted on a PVC pipe frame four feet above the center of the target area. It is connected to the PVC frame by two zip ties. This is located eight feet away from the launcher.

Feedback System Initialization Prior to any launching an initial snapshot of the target area is taken (Figure 27 (a)). This image is converted to a grayscale image by averaging the red, green, and blue, color components at each pixel. This grayscale image is binarized using 190 as the threshold value. This is accomplished by setting all pixels with a grayscale value greater than 190 to one (white), and all others to zero (black). This is shown in Figure 27 (b). This image will also be used to determine if the ball hits the target. The centroid of the binarized image is found and this is the point the launcher will be aiming for. The results of this method are shown in black in Figure 27 (c).

(a) (b)

(c)

Figure 27 Feedback Initialization

(a) snapshot (b) binarization (c) final point

Center of Target Area

Initial Snapshot Target Area

Page 27: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

22

After obtaining the target area and the aiming point, the coordinates in the image plane must be translated to the world frame in polar coordinates.

Translation to World Frame The camera and launcher are set up so the distance between the launcher and the camera is a distance d and the camera is elevated at a distance h. The camera is centered at the pixel (144,176) in the image plane. The origin of the image plane is located at a far corner from the launcher. The angle between the desired point and the launcher is denoted as Φ and its distance is r. These dimensions are illustrated in Figure 28.

Figure 28 Image/World Frame Relationship

The equations for r and Φ also depend on the angles that the camera is able to view, Θ, in both the x and y directions. To find these angles a simple test was run. A five inch piece of tape was place in both the x and y directions below the camera at various heights, h’. The total number of pixels in each row or column of the tape, P, was recorded. The total number of pixels in each row or column of the image is denoted by N. The aperture angle of the camera can be found by Equation(13).

)'2

5(sin 1

PhN−=Θ (13)

The angles were calculated at different heights are averaged. The angles used were, Θ in the x direction is 0.2614 radians, and Θ in the y direction is 0.3218 radians. The raw data from this test is available in Appendix A.1. The physical distances of a pixel (x,y) can be found using Equations (14), and (15).

144

sin)144()( x

x

xhxD

Θ−= (14)

176

sin)176()( y

y

yhyD

Θ−= (15)

Using the values found by the previous equations, the distance r, and angle Φ, of pixel (x,y) from the launcher can be found using Equations (16) and (17).

22 )())((),( yDxDdyxr yx ++= (16)

Page 28: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

23

))(

)((tan),( 1

dxD

yDyx

x

y

+=Φ − (17)

Capturing the Ball Upon launching a ball, the camera records two seconds of video at 30 frames per second. After the video is recorded, each frame after the 20th is subtracted by the next frame. The 20th frame was picked as a starting point because the first 10 frames undergo an auto focus operation that results in varying brightness between frames. For the most part each pixel maintains the same intensity. There are some minor variations caused by the lighting. When a ball comes into the frame, the difference is greater. To pick which frames contain the ball, the sum of the difference at each pixel is calculated. If this sum is greater than 300, then the ball is in the frame and is kept for further processing. If it is not, then it is rejected. The Beirut Master 4000 feedback system operates in two modes, manual and automatic. The system gives the user an option to pick the mode of operation after viewing the location determined by the automatic feedback.

Automatic Feedback Automatic feedback relies on the target area being angled slightly. This is because the frame rate is too slow to capture the ball without blurring. There are various image processing techniques to eliminate image blur, but the average number of frames with the ball is only three. Even if the blur is removed, 3 frames are not enough to accurately determine a point of impact. Angling the target area has two critical results. When the ball hits it changes direction, and it slows down. The ball traveling slower has more time in the field of view. It also allows for more light to bounce off the ball into the camera, which results in greater pixel intensities at the ball location. All the frames containing the ball are added together. The result of this process is in an image of the path of the ball as seen by the camera operating at 30 frames per second (Figure 29). This path will be converted to a series of segmented arcs, and eventually two lines fitted to the path of the ball before and after the bounce.

Figure 29 Ball Path Seen by Camera

Ball Path

Page 29: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

24

To segment the ball path to a series of arcs first the image of the path is binarized. Every pixel in the image greater than 30 is set to one and every other pixel is set to zero. This will leave an image of the path of the ball without the intensity levels plus, in some cases some random noise caused by slight variations in the lighting from frame to frame. This is shown in Figure 30.

Figure 30 Binarized Image of Ball Path

This noise in the image is eliminated by performing an erosion operation on the image 3 times. This operation slides a 3 by 3 pixels kernel over every pixel in the image with the value of 1. If this 3 by 3 kernel completely overlaps the foreground (all pixels with the value of 1), then the pixel in the center of the kernel remains as a foreground element. If even one pixel in the kernel does not overlap the foreground of the image, then the pixel in the center of the kernel in the image is set to zero. The basic outcome of this operation is that the edge pixels of the foreground are eliminated each time it is performed. If this operation is performed enough times, then the entire foreground will be eliminated. Since the noise is much less than the ball, performing this operation three times will eliminate the noise. With the noise eliminated the center path of the ball can be found, Figure 31. This is done by finding the medial axis of the ball using a thinning operation. This works by eliminating the edge pixels from the foreground while maintaining 8-connectivity between the foreground areas. Pixels are said to be 8-connected when if they are touching each other either above, below, to the left or to the right, or diagonally.

Figure 31 Ball Path

As stated earlier, the entire target area is angled so that the ball will slow down. This leads to a change in pixel intensities. The pixel intensity of the ball prior to the bounce ranges from 30-70, whereas the

Image of Ball Path

Binarized Image of Ball Path

Page 30: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

25

intensity after the bounce ranges from 80-100, depending on the initial velocity of the ball. This is used to categorize each pixel in the path of the ball center as a pixel before or after the bounce. Each pixel in the path of the ball center (Figure 31) is checked with the pixel in the path of the ball seen by the camera (Figure 29). If the intensity falls below a certain threshold, then the pixel is classified as a “before” pixel. If the intensity falls above a certain threshold, then the pixel is classified as an “after” pixel. The camera aperture opens, takes in some light then closes to take a frame. The intensity of the ball just as the aperture opens or closes is less than the small instant that it is open. For this reason the edges of the ball blur tend to have lower intensity values than the center. In some cases the lowered intensity values may cause a pixel that should be considered after the bounce as being before the bounce. Fortunately the ball, upon hitting the target area does not completely reverse the direction it travels. The path of the ball, based on its velocity and the angle at which the target area is placed will always travel in a path going higher in the image. Therefore, all pixels marked as “before” pixels that occur higher than the lowest “after” pixel are deleted. Figure 32 shows the images of “before” and “after” pixels.

(a) (b)

Figure 32 Categorized Path of Ball- (a) Before Impact (b) After Impact

After the pixels in the path of the ball are categorized, lines are fitted to the “before” and “after” pixels using a least squares approximation. The intersection of these two lines is the point where the ball bounced. Figure 33 shows the intersection point for the current example. This pixel location is compared to the image of the target (Figure 27 (b)). If the pixel falls within the image of the target, then the shot is a success and the program stops. If the pixel does not match up then the pixel is converted to polar real world coordinates and is sent to the learning algorithm to plan the next shot.

Figure 33 Point of Impact

Path After BouncePath Before Bounce

Point of Impact

X: 59 Y: 144Index: 255RGB: 1, 1, 1

Page 31: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

26

There are several setbacks to the automatic feedback system. If the ball does not appear in the field of view of the camera then no feedback can be sent. Also, if the ball hits near the edge of the field of view, then there is a chance that the line fitted to the before or after pixels will be inaccurate. For these reasons there is a need to implement manual feedback. After each shot the system outputs the coordinates calculated by the automatic feedback system and asks the user whether or not this is accurate. If it is not, the user has the option to use manual feedback to plan the next shot.

Manual Feedback Manual feedback does not rely on the target area being angled. The frames with the ball in them are found using the same method as automatic feedback. A frame with the ball in it will come up to give the user an idea of what direction the ball was traveling in. The figure is converted to a coordinate plane with an origin (0,0) at the pixel just above and to the right of the actual image. The user can click on the figure where the ball bounced. A small blue cross will by placed on the figure and that pixel location will be converted and sent to the learning algorithm (Figure 34).

Figure 34 Manual Feedback

For manual feedback to work the user has to be paying attention to each shot. However the allowable range for accurately feeding back information to the learning algorithm is significantly increased. The ball can bounce in the edges of the image and the feedback can still work. Actually, since the whole figure is converted to a coordinate plane, the ball does not have to bounce in the field of view of the camera at all.

Learning Algorithm To implement any learning algorithm, first the expected landing position of the ball as a function of the launch angles was needed. Using basic projectile physics, these two equations were developed. Since a cylindrical coordinate system was used, each equation is only dependent on one launch angle, either the pan angle or the tilt angle. The radial coordinate r as a function of the tilt angle 1 can be seen in Equation (18), while Equation (19) represents the angular coordinate as a function of the pan angle 2.

( )2 20 1 0 1 0 1sin sin 2 cosV V gh V

rg

Θ + Θ + Θ= (18)

2ϕ = Θ (19)

Page 32: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

27

In Equation (18), V0 is the initial velocity of the ball, g is the gravitational acceleration, and h is the height of the launcher above the target. All these values remain constant. The two resulting independent equations also means that each new calculated angle is dependent only on one of the two cylindrical coordinates. This simplifies the calculation of the new angles to be used, since there is only one coordinate variable in each equation to be differentiated. The basic equations to calculate the new pan and tilt angles are formulated for both the Newton-Raphson method and the Schröder method. Equation (20) is the calculation for the new tilt angle using the Newton-Raphson method, and Equation (21) is the calculation for the new pan angle using the same method. Similarly, Equations (22) and (23) represent the calculations for the new tilt and pan angles using Schröder’s method.

( )1( 1) 1( )

1( )

desired kk k

k

r rdr

d

+

−Θ = Θ +

Θ

(20)

( )2( 1) 2( )

2( )

desired kk k

k

dd

φ φϕ+

−Θ = Θ +

Θ

(21)

( )

( )

1( )1( 1) 1( ) 2

2

21( ) 1( )

desired kk

k k

desired kk k

drr r

d

dr d rr r

d d

+

− Θ Θ = Θ +

+ − Θ Θ

(22)

( )

( )

2( )2( 1) 2( ) 2

2

22( ) 2( )

desired kk

k k

desired kk k

dd

d dd d

φφ φ

φ φφ φ+

− Θ Θ = Θ +

+ − Θ Θ

(23)

In order to use these equations, the first and second order derivatives of Equations (18) and (19) are needed. Since the Newton-Raphson method only requires the first order derivatives, initially only these are taken. These derivatives were taken in MATLAB and confirmed in Maple as well as hand calculations. Equations (24) and (25) show the first order derivatives of Equations (18) and (19), respectively.

( )

20 1 1

0 1 0 12 20 1

1

2 20 1 0 1 0 1

V sin( )cos( )V cos( ) V cos( )

V sin( ) 2

V sin( ) V sin( ) 2 V sin( )

ghdrd g

gh

g

Θ Θ Θ + Θ Θ + =

Θ

Θ + Θ + Θ−

(24)

2

1d

dφ =

Θ (25)

Page 33: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

28

After substituting these two equations back in Equations (20) and (21), the learning algorithm using the Newton-Raphson method is completed. Since the derivative of the angular coordinate with respect to the pan angle is one, the new pan angle calculation for the Newton-Raphson method is based only on the error. Next, the second order derivatives were found using MATLAB and again confirmed in the same approach as the first derivative. Equations (26) and (27) show the first order derivatives of Equations (18) and (19), respectively.

( )

4 2 2 2 2 2 20 1 1 0 1 0 1

0 1 0 12 2 3/2 2 2 2 22 0 1 0 1 0 1

21

20 1 1

0 1 0 1 2 22 20 1 0 1 0 10 1

V cos sin V cos V sinV sin V cos

(V sin 2 ) V sin 2 V sin 2

V sin cos2 V cos V sin

V sin V sin 2 V cosV sin 2

gh gh ghd rgd

ghgh

g g

Θ Θ Θ Θ − Θ − + − Θ Θ + Θ + Θ + =

Θ

Θ Θ − Θ + Θ − Θ + Θ + ΘΘ +

(26)

2

22

0d

dφ =

Θ (27)

Substituting these two equations back completes the learning algorithm using the Schröder method. It is noted that since the second derivative of the angular coordinate with respect to the pan angle is zero, the Newton-Raphson method for the pan angle is the same as that of the Schröder method. However, the formula to obtain the new tilt angle for the Schröder method is much more complicated than that of the Newton-Raphson method. In order to test the two different algorithms, a physics model was created to simulate the motion of the ball as affected by disturbance (drag, spin). The model was based on basic projectile physics with the addition of three coefficients, two of which simulate “drag” and the third adds a “spin” disturbance. Two coefficients (Kz and Kr) attenuate the velocity of the z and r axis as shown in Equations (28) and (29). The third coefficient (K) creates a “spin” by attenuating the coordinate as shown in Equation (30). The model can be seen in Appendix C.1 and the two M-files used to simulate each algorithm can be found in Appendices B.6 and B.7.

( 1) 0 1 ( )sinz k z z kV V K V+ = Θ − (28)

( 1) 0 1 ( )cosr k r r kV V K V+ = Θ − (29)

1 0 ( )k r kV Kϕϕ ϕ+ = − (30) Both algorithms were tested for a variety of desired coordinates and coefficients. Figure 35 through Figure 38 show the outputs of a typical simulation using the physics model. Additional runs can be found in Appendix C.2. The black squares represent the target, and the lines represent the various trajectories taken by the ball. After conducting several tests, it was determined that the algorithm using the Schröder’s root-finding method is more efficient at correcting for the radial distance from the launcher. In most tests conducted, the algorithm using Schröder’s method converged faster than the Newton-Raphson algorithm by at least one shot. Thus the Schröder algorithm was implemented. However the number of attempts never exceeded four when using either of the two algorithms.

Page 34: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

29

Figure 35 Newton-Raphson Method, Side View

Figure 36 Newton-Raphson Method, Top View

Figure 37 Schröder Method, Side View

Figure 38 Schröder Method, Top View

As soon as the launcher was completed, the Schröder algorithm was implemented. After completion of the launching system, the range of tilt angles that the learning algorithm employs was changed from (0o, 90o) to (-90o, 45o). This is because the launcher shoots at a higher velocity than was initially expected. Therefore the tilt angle is generally aimed down because larger tilt angles resulted in balls colliding with the environment, i.e. ceiling and walls. After thorough testing, it was also noted that when the ball undershoots the target, the algorithm does not correct the tilt angle enough. In order to rectify this, a gain was applied to the correction factor in the tilt angle when the ball undershoots the target. Several tests were conducted and gain of 1.75 was found to be the most efficient. A simulation using the final algorithm used is shown in Figure 39 and Figure 40. The final algorithm that was implemented can be seen in Appendix B.16.

Page 35: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

30

Figure 39 Schröder Method, Side View

Figure 40 Schröder Method, Top View

Page 36: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

31

Design Verification Controller Throughout the design process it was vital to verify that the models and algorithms used were accurate. Since a majority of the design process is based on the model, verification measures were used to ensure the accuracy of the model. Not only was the model verified, but the algorithm to identify the parameters was also verified. This was done by testing the algorithm on a model with known parameters as described in the design details. The algorithm also had a self verification by comparing the Eigen-values corresponding to each of the parameters. By using two approaches for parameter identification, verification was also done by comparing the results of the two approaches. From the least squares estimation method, the effective inertial can be found by Kt,Ki,N/ a3 as described in the design procedure. For the pan axis this yields a value of .009988. The effective viscous friction is equivalent to a1 multiplied by the effective inertia, which equals .0006992. This value is comparable to the pan viscous friction found earlier by the other approach (0.00066913 for positive motion and 0.00069303 for negative motion). Similarly the effective Coulomb friction can be found by multiplying the effective inertia by a2 which results in a value of 0.0749 which is also comparable to the previous results (0.080058 and -0.071475 for positive and negative motion) . The same approach can be used to verify the results for the tilt axis. The resulting Coulomb and viscous friction for the tilt was axis was found to be 0.001735 and 0.08096. These friction values are slightly higher than the ones found using the previous method (0.0015316 and 0.0016016 for positive and negative viscous friction and 0.075495 and -0.077283 for positive and negative Coulomb friction). This maybe due to the fact that the initial experiments to determine the friction was done without the load on the motor. The launching apparatus is likely the cause of this slight increase in friction. To further verify the model comparisons between actual and simulated results for various inputs were made. Comparisons were made on the velocity term because a slight error in velocity accumulates and thus as a result large deviations between simulated and actual positions occurred. Accuracy of the position term is important for determining the amount of gravity loading. Knowing that our model can not match velocity perfectly and slight errors will occur, the model was modified slightly, as shown in Figure 41, to ensure accurate position data was used to calculate the gravity loading term.

Page 37: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

32

a1

cos

voltage2

data2

Sign

1s

1s

Integrator

a2

a4

a3

posinput

FromWorkspace1

input

FromWorkspace

position

v iscous f riction

thetadd

Coulomb f riction

grav ityloading

Figure 41 Model verification model file

Actual position data obtained when exciting the plant is inputted back into the system to accurately calculate the gravity loading term. A set of velocity comparisons for both axes is shown in Figure 42 and Figure 43.

Figure 42 Pan axis velocity comparisons

Figure 43 Tilt axis velocity comparisons

Step response analysis was initially used to describe the performance of the controllers. This suggested an excellent performance of the controller. Another method of analyzing the controllers performance is to view its ability to track a command input. Figure 44 and Figure 45 shows position tracking for the two axes. Tracking of the commanded position is achieved for both axes.

Page 38: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

33

Figure 44 Pan position tracking

Figure 45 Tilt position tracking

Launching System Testing needed to be done to determine the initial velocity of the balls when fired. To find the initial velocity we decided to set up an experiment to extract the information based on physics equations of motion. We set the launcher to a horizontal position so that all initial velocity would be in the x-direction given our coordinate frame. The only acceleration would be that of gravity pulling in the negative y-direction. We decided to neglect deceleration due to the air drag on the ball, because we simply needed a rough estimate of the initial velocity which is close enough so that our model can calculate initial guesses for launch angles when firing for the first time. We then fired multiple balls over a distance of 10 feet. It was notable that the launcher was fairly repeatable, with all balls landing within a couple inches of each other over this distance. The average height the ball dropped while traveling this distance was recorded.

Figure 46 Initial velocity determination experiment

The following simple physics equations were used to describe the above situation.

Page 39: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

34

*id v t= (31)

Where d is the distance from the launcher to the wall, vi is the initial velocity and t is time. This equation describes the motion of the ball in the x-direction. The equation of the y-direction motion is show below.

*2

2a

l t= (32)

Where l is the distance the ball fell, and a is the acceleration due to gravity. l was experimentally found to be 0.9525 meters. Solving for time and substituting in, we can get an equation with vi and known constants.

*

2

22 i

a dl

v= (33)

Solving for vi yields:

*

*

2

2i

a dv

l= (34)

The initial velocity for the launcher turned out to be 7.266 m/s. The calculation of the initial velocity did not by itself verify the launching system design. This is because the average initial velocity does not say anything about the solidity of the design to fit our needs. However, the process of this experiment verified the usefulness of the launching system by showing that the launcher did fire with a fairly consistent initial velocity, which caused balls to strike a wall in a repeatable fashion. The balls struck approximately the same spot 10 feet away, within up to 3 inches of each other. Thus the experiment as a whole was instrumental in verifying our design for the launcher. The java class Parport was verified by using a logic probe to monitor the output data pins on the parallel port while changing the pins between high and low in MATLAB. In addition, the output to the air valve was verified by monitoring the signal using an oscilloscope. This was further confirmed with the successful implementation of the automated launching system.

Feedback System The feedback system was verified by comparing the images received with the point of impact determined by the feedback system. By overlaying the image point determined over the images of the path of the ball the accuracy of the feedback system can be verified to sufficient margins of error, (within a quarter of an inch).

Learning Algorithm The learning algorithm was verified by testing the algorithm in simulation. A model file was created which emulated the system. The simulation proved that the Schröder root-finding algorithm was the best option because it resulted in the fastest convergence. This was also validated through experimentation.

Page 40: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

35

Costs

A summary of costs is show in Table 9. Two separate columns are displayed, one for our teams out of pocket expenses and one cost which resembles a commercial cost. Our personal costs exceeded our initial budget by approximately 50 dollars. This is due to the higher than estimate price for the aluminum sheet and valve. Table 9 Cost of Beirut Master 4000

Items our cost commercial MATLAB 0.00 1900.00 Simulink 0.00 2800.00 MATLAB image acquisition toolbox 0.00 900.00 MATLAB image processing toolbox 0.00 900.00 XPC Target 0.00 4000.00 Assorted resistors/op amps 1.00 7.00 Tubing 10.54 10.54 Electronic Valve 39.95 39.95 Tap 3.29 3.29 step up tubing 1.93 1.93 Barbs 0.48 0.48 Ping Pong Ball Launcher 29.95 29.95 Pan motor 0.00 97.59 Tilt motor 0.00 97.59 pan/tilt gears 0.00 61.96 pan/tilt belts 0.00 7.92 flat plate 10.37 10.37 2 U-bolts 5.84 5.84 assorted screws 1.78 1.78 assorted nuts 0.24 0.24 2 clamps 0.00 17.86 Webcam 0 39.95 pvc pipe and connections 11.24 11.24 3' by 3' aluminum sheet 35.00 35.00 Padding 4.99 4.99 Epoxy 3.99 3.99 Labor Vinay * 0.00 6412.50 Labor Danish * 0.00 6412.50 Labor Bert * 0.00 6412.50 Labor Larry * 0.00 6412.50 Total 160.59 36639.46 *15 hours per week for 15 weeks at $28.50 per hour

Page 41: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

36

Conclusions Our initial objective of creating a machine to win at the game of Beirut was met. Our project is able to close in on the target and strike it as consistently as the uncertainty of the launcher will allow (approximately 50% of the time). In order to meet our objective the project was split into four subprojects. We needed a controller to command the pan-and-tilt mechanism to desired launch angles. We needed an accurate and repeatable launcher. A feedback system was required to record the launch results. And finally we needed an efficient learning algorithm to determine new launch angles. Our learning algorithm does quickly converge if given a rough model of the physical situation. Since the launcher does not fire at a consistent velocity most of the time, the learning algorithm takes longer to converge to the solution. However, as long as a complete misfire does not occur, the target is still hit in an average of four tries, and the cup is hit in an average of five tries. Thus the goal of winning the game within eight shots is achieved. The learning algorithm itself can be improved further by using root-finding methods that go beyond the second order derivative. However, in order to see any direct improvement in the implementation, the launcher will be required to have better repeatability. The PID controllers implemented significantly exceeded our specifications. The launcher was positioned in approximately a quarter of a second with a negligible steady state error. Due to the success of the PID controllers, investigation of other types of controllers was not explored. This may have resulted in improved control. The launcher is operational, and repeatable to an accuracy that insures a good success rate for our machine, when compared to actual Beirut players. One improvement upon this system would be to modify the launcher nozzle in a fashion which lowers the initial velocity of the emitted ball. In addition to this, if we had developed a way to perfectly regulate the air flow coming into the system it would have increased the repeatability of the launch. A reliable method of feedback was developed using a web-cam. The feedback system relies on the change of direction and velocity of the ball. The algorithm requires that the ball does not bounce in the outer edges of the field of view of the camera. If these requirements are met, the automated feedback system performs very well. However, if these requirements are not met a manual feedback system is setup to account for these shortcomings. A web-cam with a better resolution would allow for a larger field of view. An improved frame rate would reduce the error by having shorter segments to fit to lines. Overall, the project was a great success. All of our objectives were met and a Beirut playing machine was created.

Page 42: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

37

References [1] R. J. Schilling. Fundamentals of robotics, analysis and control. Prentice Hall, 1990. [2] “DC Motor Specifications Sheet”. Internet. (2002) Available: http://www.pennmotion.com/pdf/lcg_bulletin.pdf, Feb. 2005. [3] Wen, John T. “ECSE 4460 Control System Design, Spring 2005”. Internet. (2005) Available: http://www.cat.rpi.edu/~wen/ECSE446S05/identification.pdf, Feb. 2005. [4] J. H. Chow, D. K. Frederick, and N. W. Chbat, Discrete Time Control Problems Using MATLAB, 1st Edition. Brooks/Cole Publishing Company, 2003. [5] “Ball-Shooting Burp Gun”. Internet. (2005) Available: http://amos.shop.com/amos/cc/pcd/4614366/prd/6715663/ccsyn/260, Feb. 2005. [6] “The Proportional Valve”. Internet. (2005) Available: http://www.clippard.com/store/byo_electronic/byo_proportional_valves.asp, Feb. 2005. [7] Engdahl, Tomi. “Parallel Port Interfacing Made Easy”. Internet. (2005) Available: http://www.epanorama.net/circuits/parallel_output.html, April 2005. [8] “OPA 548: High Voltage, High Current Operational Amplifier”. Internet. (2005) Available: http://focus.ti.com/lit/ds/symlink/opa548.pdf, April 2005. [9] “Root-Finding”. Internet. (2004) Available: http://mathworld.wolfram.com/topics/Root-Finding.html, Feb. 2005. [10] G. F. Franklin, J.D. Powell, and A. Emami-Naeini, Feedback Control of Dynamic Systems, 4th Edition, Addison-Wesley, 2002. [11] Portillo, Juan G. “Parallel Port Access through Java”. Internet. (2005) Available: http://www.geocities.com/Juanga69/parport/, April 2005. [12] Foote, Peter. “Sallen-Key Second Order Filter”. Internet. (May 23, 1999) Available: http://www.t-linespeakers.org/tech/filters/Sallen-Key.html, April 2005. [13] “Single Channel Parallel Port”. Internet. (2005) Available: http://www.dpie.com/pcmcia/spp100.html, April 2005. [14] R. C. Dorf and J. A. Svoboda. Introduction to Electric Circuits, 5th Edition. John Wiley & Sons, 2001.

Page 43: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

38

Appendices

A.1 Field of View Angles Height (in) X1 X2 Pixelated Distance Pixels/inch inches/pixel inches/row theta Vertical Theta Average

18 29 183 154 30.8 0.032467532 9.35064935 0.262753 0.261470812 24 38 156 118 23.6 0.042372881 12.2033898 0.257059 30 53 147 94 18.8 0.053191489 15.3191489 0.258178 36 77 155 78 15.6 0.064102564 18.4615385 0.259306 42 93 158 65 13 0.076923077 22.1538462 0.266894 48 104 162 58 11.6 0.086206897 24.8275862 0.261594 54 118 169 51 10.2 0.098039216 28.2352941 0.264512

Height (in) Y1 Y2 Pixelated Distance Pixels/inch inches/pixel inches/row theta Horizontal Theta Average

18 105 263 158 31.6 0.03164557 11.1392405 0.314587 0.321762859 24 132 249 117 23.4 0.042735043 15.042735 0.318761 30 147 240 93 18.6 0.053763441 18.9247312 0.320891 36 150 227 77 15.4 0.064935065 22.8571429 0.32305 42 152 217 65 13 0.076923077 27.0769231 0.328205 48 151 209 58 11.6 0.086206897 30.3448276 0.321607 54 178 229 51 10.2 0.098039216 34.5098039 0.325239

Page 44: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

39

B.1 frictionexp.m % Script to obtain data for friction identification % Written by: Vinay Shah 2/25/05 voltagelist=[-.98 -.94 -.9 -.84 -.79 -.765 -.76 -.75 -.74 -.735 -.73 -.725 .745 .75 .755 .76 .765 .79 .84 .87 .9 .94 .98]; clear data; for i=1:length(voltagelist) A = voltagelist(i) for j=1:5 setparam(tg,21,sign(A)*10); % set 10 volt pulse start(tg); pause(1.5); % pulse duration of 1.5 seconds setparam(tg,21,A); pause(20); stop(tg); setparam(tg,21,0); pause(1); temp = tg.outputlog(:,1); size(temp) data(i,j,:) = temp(1001:20000); display('set position and press a key...'); reset motor pos pause; end save(['panmotor',num2str(A),'.mat'],'voltagelist','data')

%save often in case MATLAB crashes end

B.2 graphvelocity.m %Generate velocity time history curves for both pan and tilt axis %Written by: Vinay Shah 3/28/05 filelist ='panpositive', 'pannegative', 'tiltpositive', 'tiltnegative'; titlelist ='Pan Motor', 'Tiltmotor'; for k=1:4 load(filelistk); figure(2+ ceil(k/2)) hold on clear ssvalues; clear torques; for i = 1:length(voltagelist) r = rand; g = rand; b = rand; thetadot = 1000*diff(mean(squeeze(data(i,:,:)))); [fa, fb] = butter(12,.065); output = filter(fa,fb, thetadot); ssvalues(i) = output(length(output)); torques(i) = voltagelist(i) * 4*6.3*.0436*0.1; plot(output,'Color',[r,g,b],'linewidth',2); end if ~mod(2,2) ylabel('Velocity (rads/sec)') xlabel('time (ms)'); title(['Friction Identification: ', titlelistceil(k/2)]); hold off;

Page 45: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

40

end end

B.3: frictionanalysis.m % Create torque versus steady state velocity graphs % Written by: Vinay Shah 3/29/05 figure(1) hold on load panpositive; [p1,s1]=polyfit(ssvalues,torques,1); lxpoint(1) = ssvalues(1); lxpoint(2) = ssvalues(length(ssvalues)); lypoint(1) = p1(1)*lxpoint(1) + p1(2); lypoint(2) = p1(1)*lxpoint(2) + p1(2); plot(lxpoint,lypoint) plot(ssvalues,torques,'xg'); disp(['Pan Positive Viscous friction : ',num2str(p1(1))]); disp(['Pan Positive Coulomb friction : ',num2str(p1(2))]) load pannegative; [p2,s2]=polyfit(ssvalues,torques,1); lxpoint(1) = ssvalues(1); lxpoint(2) = ssvalues(length(ssvalues)); lypoint(1) = p2(1)*lxpoint(1) + p2(2); lypoint(2) = p2(1)*lxpoint(2) + p2(2); plot(lxpoint,lypoint) plot(ssvalues,torques,'xr'); disp(['Pan Negative Viscous friction : ',num2str(p2(1))]); disp(['Pan Negative Coulomb friction : ',num2str(p2(2))]) lxpoint(1) = 0; lxpoint(2) = 0; lypoint(1) = p1(2); lypoint(2) = p2(2); plot(lxpoint,lypoint) xlabel('velocity (rads/sec)'); ylabel('torque (N*m)'); title('Friction Indentification: Pan Motor') figure(2); hold on load tiltpositive; [p2,s2]=polyfit(ssvalues,torques,1); lxpoint(1) = ssvalues(1); lxpoint(2) = ssvalues(length(ssvalues)); lypoint(1) = p2(1)*lxpoint(1) + p2(2); lypoint(2) = p2(1)*lxpoint(2) + p2(2); plot(lxpoint,lypoint) plot(ssvalues,torques,'xg'); disp(['Tilt Positive Viscous friction : ',num2str(p2(1))]); disp(['Tilt Positive Coulomb friction : ',num2str(p2(2))]); load tiltnegative;

Page 46: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

41

[p1,s1]=polyfit(ssvalues,torques,1); lxpoint(1) = ssvalues(1); lxpoint(2) = ssvalues(length(ssvalues)); lypoint(1) = p1(1)*lxpoint(1) + p1(2); lypoint(2) = p1(1)*lxpoint(2) + p1(2); plot(lxpoint,lypoint) plot(ssvalues,torques,'xr'); disp(['Tilt Negative Viscous friction : ',num2str(p1(1))]); disp(['Tilt Negative Coulomb friction : ',num2str(p1(2))]); xlabel('velocity (rads/sec)'); ylabel('torque (N*m)'); title('Friction Indentification: Tilt Motor') lxpoint(1) = 0; lxpoint(2) = 0; lypoint(1) = p1(2); lypoint(2) = p2(2); plot(lxpoint,lypoint) B.4: paramiden.m % Parameter Identification Script % Written by: Vinay Shah 3/25/2005 % Model Parameters N = 4*6.3; Kt = .0436; Ki = 0.1; Jl = .0041547; Jm = 1.6e-6; Bveff = 1.57e-3; Bceff = .078; m = .045; g = -9.81; l = 0.02; Jeff = Jl+ N*N*Jm; % Actual values of parameters a1-a4 A1 = Bveff/Jeff A2 = Bceff/Jeff A3 = Kt*Ki*N/Jeff A4 = m*g*l/Jeff %excite system with specific input sim('pantilt'); %determine velocity data from position data ts = 1/1000; avetheta = data; velocities = diff(avetheta)/ts; [b,a] = butter(12,.065); fvel = filter(b,a,velocities); % parameter identification algorithm thetadots = fvel; thetas = avetheta; thetadot0 = thetadots(1:length(thetadots)-1); thetadot1 = thetadots(2:length(thetadots)); voltagelist = voltage(3:length(voltage));

Page 47: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

42

theta0 = thetas(2:length(thetas)-1); theta1 = thetas(3:length(thetas)); b = -thetadot0.^2 + thetadot1.^2; A = zeros(length(thetadots)-1,4); A(:,1) = -ts*(thetadot1.^2 + thetadot0.^2); A(:,2) = -ts*(abs(thetadot1) + abs(thetadot0)); A(:,3) = 2*(voltagelist.*(theta1 - theta0)); A(:,4) = -2*(cos(theta1) - cos(theta0)); %calculate experimentally determined values of parameters a1-a4 xvars = pinv(A)*b %check the validity of these values eigenvaluesofA = eig(A'*A) conditionofA = cond(A) B.5: Modelver.m % Parameter Identification Verification Script % Written by: Vinay Shah 4/22/2005 datafiles = dir('pi*.mat'); % List of data sets % Pan Axis parameters a1 = 0.07; a2 = 7.5; a3 = 11; a4 = 0.00; pos_satlimit = .95; neg_satlimit = -1.08; for j = 1:length(datafiles) % For all data sets fname = datafiles(j).name(1:length(datafiles(j).name)-4); load(datafiles(j).name) load(fname) % set up input for simulation ts = 1/1000; time = ts:ts:length(voltage)*ts; input = [time' voltage]; posinput = [time' data]; % Calculate experimental velocity avetheta = data; velocities = diff(avetheta)/ts; [b,a] = butter(12,.065); fvel = filter(b,a,velocities); % Simulate model sim('pantiltparam'); % Calculate simulated velocities svelocities = diff(data2)/ts; fvels = filter(b,a,svelocities); % Plot outputs figure(j); startp = 1;

Page 48: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

43

endp = 19000; t = 0:.001:(endp-startp)*.001; plot(t,fvel(startp:endp),'r'); hold on; plot(t,fvels(startp:endp),'b'); hold off; title([fname,' Velocity Comparision']); legend('Actual','Simulated'); ylabel('rads/sec'); xlabel('time (s)'); end B.6: la_newton-raphson.m

%Learning Algorithm using Newton-Raphson method clear all; rd = 1.5; phid = -pi/4; maxdiffr = 0.045; maxdiffphi = 0.025; iterations = 0; Kz = 0.1; Kr = 0.1; Kphi = 0.1; Vo = 4.767; h = 1.016; g = 9.8; theta1 = atan2((-h*(Vo^2+g*h-(Vo^4+2*Vo^2*g*h-rd^2*g^2)^(1/2))/(h^2+rd^2)+g)/Vo/((Vo^2+g*h-(Vo^4+2*Vo^2*g*h-rd^2*g^2)^(1/2))/(h^2+rd^2))^(1/2),((Vo^2+g*h-(Vo^4+2*Vo^2*g*h-rd^2*g^2)^(1/2))/(h^2+rd^2))^(1/2)*rd/Vo); theta2 = phid; while(1) iterations = iterations + 1; dfrdtheta1 = (Vo*cos(theta1)+1/(Vo^2*sin(theta1)^2+2*g*h)^(1/2)*Vo^2*sin(theta1)*cos(theta1))*Vo*cos(theta1)/g-(Vo*sin(theta1)+(Vo^2*sin(theta1)^2+2*g*h)^(1/2))*Vo*sin(theta1)/g; dfphidtheta2 = 1; sim('ballmotioncylind'); hold on; grid off; figure(1); title('Newton-Raphson method'); xlabel('r(m)'); ylabel('z(m)'); plot(r,z); figure(2); title('Newton-Raphson method'); polar(phi,r); if(abs(rd-finalr) > maxdiffr) theta1 = theta1 + (rd - finalr)/(dfrdtheta1); end; if(abs(phid-finalphi) > maxdiffphi) theta2 = theta2 + (phid - finalphi);

Page 49: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

44

end; if((abs(rd-finalr) < maxdiffr) & (abs(phid-finalphi) < maxdiffphi)) break; end; end; hold off B.7: la_schroder.m clear all; rd = 1.5; phid = -pi/4; maxdiffr = 0.045; maxdiffphi = 0.025; iterations = 0; Kz = 0.1; Kr = 0.1; Kphi = 0.1; Vo = 4.767; ; h = 1.016; ; g = 9.8; theta1 = atan2((-h*(Vo^2+g*h-(Vo^4+2*Vo^2*g*h-rd^2*g^2)^(1/2))/(h^2+rd^2)+g)/Vo/((Vo^2+g*h-(Vo^4+2*Vo^2*g*h-rd^2*g^2)^(1/2))/(h^2+rd^2))^(1/2),((Vo^2+g*h-(Vo^4+2*Vo^2*g*h-rd^2*g^2)^(1/2))/(h^2+rd^2))^(1/2)*rd/Vo); theta2 = phid; while(1) iterations = iterations + 1; dfrdtheta1 = (Vo*cos(theta1)+1/(Vo^2*sin(theta1)^2+2*g*h)^(1/2)*Vo^2*sin(theta1)*cos(theta1))*Vo*cos(theta1)/g-(Vo*sin(theta1)+(Vo^2*sin(theta1)^2+2*g*h)^(1/2))*Vo*sin(theta1)/g; d2frd2theta1 = (-Vo*sin(theta1)-1/(Vo^2*sin(theta1)^2+2*g*h)^(3/2)*Vo^4*sin(theta1)^2*cos(theta1)^2+1/(Vo^2*sin(theta1)^2+2*g*h)^(1/2)*Vo^2*cos(theta1)^2-1/(Vo^2*sin(theta1)^2+2*g*h)^(1/2)*Vo^2*sin(theta1)^2)*Vo*cos(theta1)/g-2*(Vo*cos(theta1)+1/(Vo^2*sin(theta1)^2+2*g*h)^(1/2)*Vo^2*sin(theta1)*cos(theta1))*Vo*sin(theta1)/g-(Vo*sin(theta1)+(Vo^2*sin(theta1)^2+2*g*h)^(1/2))*Vo*cos(theta1)/g; dfphidtheta2 = 1; sim('ballmotioncylind'); hold on; figure(1); title('Schroder'); xlabel('r(m)'); ylabel('z(m)'); plot(r,z); figure(2); title('Schroder'); polar(phi,r); if(abs(rd-finalr) > maxdiffr) theta1 = theta1 + (rd - finalr)*(dfrdtheta1)/((dfrdtheta1)^2+(rd - finalr)*(d2frd2theta1)); end;

Page 50: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

45

if(abs(phid-finalphi) > maxdiffphi) theta2 = theta2 + (phid - finalphi); end; if((abs(rd-finalr) < maxdiffr) & (abs(phid-finalphi) < maxdiffphi)) break; end; end; hold off

B.8: Bm4000.m % Team 2 - Beirut Master 4000 % Sunday, April 3rd 2004 % Control Systems Design Spring 2005 [bA bB bC bD] = butter(12,.065); launchpause = 2.9; %set amount of time to close valve import parport.ParallelPort; %import the Parport java class lpt1=ParallelPort( hex2dec('378') ); %set lpt1 as the parallel port lpt1.write(1); %open the valve %set initial values n = sprintf('\n'); cuphit = 0; currpanD = 0; currtiltD = 0; panD = 0; tiltD = 0; setparam(tg, 10,1); % pan integral gain setparam(tg, 11,8.5); % pan derivative gain setparam(tg, 12,30); % pan kp gain setparam(tg, 47, 0); % pan step end setparam(tg, 13,1.3); % tilt derivative gain setparam(tg, 14,.82); % tilt integral gain setparam(tg, 15,30); % tilt kp gain setparam(tg, 50, 0); % pan step end [cupX cupY] = dCupxy; % determine cup location target=dtarget; % determine target location disp(['Please initialize system and press a key.',n]) pause; lpt1.write(1); [cupR cupPhi] = recttopol(cupX, cupY); lpt1.write(1); [panD tiltD] = dInitialThetas(cupR, cupPhi); % determine initial guess for desired pan and tilt while ~cuphit commandpos; command pan and tilt motors, wait until pos reached lpt1.write(1); pause(1); sendlaunchsignal; % launch the ball

Page 51: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

46

stop(tg); ball=autofeedback(vid) % determine location of ball ball(1)=ceil(ball(1)); ball(2)=ceil(ball(2)); correct=input('Is this correct? 1=yes, 0=no '); % coordinates accurate? if correct==0 % if the not then resort to manual feedback ball = rbline ball=round(ball); [ballR ballPhi] = recttopol(ball(2), ball(1)) % convert to polar else [ballR ballPhi] = recttopol(ball(1), ball(2)) % convert to polar end lpt1.write(1); if ball(1)>1 & ball(1)<288 & ball(2)>1 & ball(2)<352 %check to see if the launch is successful if target(ball(1),ball(2))==1 cuphit=1; end end %use learning algorithm to determine next set of desired angles [panD, tiltD] = nextGuess(panD, tiltD, ballR, ballPhi, cupR, cupPhi); panD = panD - currpanD; tiltD = tiltD - currtiltD; end disp('Woohoo!!!'); %Display victory text y = wavread('woohoo.wav'); wavplay(y, 22500); %Play victory sound B.9: Autofeedback.m function H=autofeedback(video) % returns pixel location of ball in the image plane i=15; % initial conditions a=1; k2=0; while i<59 % find frames with the ball i=i+1; out=binarize(video(:,:,1,i+1)-video(:,:,1,i),10); % subtract frames if sum(sum(out))>300 % if difference is substantial then save frame b(a)=i; a=a+1; elseif a>1 % if a frame with ball already captured % and current frame does not have the ball stop checking the video i=61; if i==60 disp('missed playing area') end end end if i==61 % if the video has the ball continue processing for i=1:length(b) % create an image of the ball path stream(:,:,i)=video(:,:,1,b(i)+1)-video(:,:,1,b(i)); end s=size(stream);

Page 52: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

47

path=zeros(s(1),s(2)); for i=1:length(b) path=uint8(path)+uint8(stream(:,:,i)); end imshow(path) out=bounce(path); % determine bounce location H=out; else H=0; End

B.10: binarize.m function I=binarize(image,T) % image is gray scale % T is threshold value found from thresh.m for(i=1:288) for(j=1:352) if(image(i,j)<T) image(i,j)=0; else image(i,j)=1; end end end I=image; B.11: bounce.m function I=bounce(path) % find the location of the ball when it hits target area %%input is an image of the ball path found in autofeedback.m line=binarize(path,40); % threshold the image line=bwmorph(line,'erode',3); % remove noise line=bwmorph(line,'thin',inf); % find the path of the center of the ball s=size(path); % set up initial variables before=zeros(s(1),s(2)); after=before; [x y]=find(line==1); % find the location of all pixels in the ball path maxintensity=max(max(path)); % find the cutoff intensity m=maxintensity/2+15; L=length(x); % categorize pixels before and after bounce for i=1:L if path(x(i),y(i))>m+5 after(x(i),y(i))=1; elseif path(x(i),y(i))<m-5 before(x(i),y(i))=1; end end [x y]=find(after==1); % eliminate stray pixels classified as before the bounce that occur in pixels above

Page 53: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

48

% the first "after" pixel before(1:max(x),:)=zeros(max(x),352); after=bwmorph(after,'clean'); % remove stray pixels before=bwmorph(before,'clean'); [xb yb]=find(before==1); % fit lines to pixels before and after the bounce [xa ya]=find(after==1); pb=polyfit(yb,xb,1); pa=polyfit(ya,xa,1); y0=(pa(2)-pb(2))/(pb(1)-pa(1)); % find the intersection of the two lines x0=y0*pa(1)+pa(2); I=[x0 y0]; B.12: Commandpos.m %% commandpos.m %% input = panD, tiltD %% output = currpanD, curtiltD setparam(tg, 47, panD); % pan step end setparam(tg, 50,-tiltD); % tilt step end start(tg); % excite plant pause(1); currpanD = panD; currtiltD = tiltD; lpt1.write(1); B.13: dCupxy.m function [cupX, cupY]=dCupxy % Determine center of target obj=videoinput('winvideo'); % start camera image=getsnapshot(obj); % take picture new=zeros(288,352); image=rgb2gray(image); % convert picture to grayscale for i=1:288 % threshold the picture for j=1:352 if image(i,j)>200 new(i,j)=1; end end end [x y]=find(new==1); % find location of all pixels in the target cupX=sum(x)/length(x); % calculate the centroid cupY=sum(y)/length(y); flushdata(obj) % stop camera delete(obj) clear obj B.14: dInitialThetas.m %Define dInitialThetas function %cupR = radial distance to cup/target %cupPhi = angular coordinate to cup/target function [panD, tiltD] = dInitialThetas(cupR, cupPhi)

Page 54: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

49

rd = cupR; phid = cupPhi; Vo = 7.366; ; h = .9525; ; g = 9.81; %Set constants %Find initial guesses based on physics equations theta1 = atan2((-h*(Vo^2+g*h+(Vo^4+2*Vo^2*g*h-rd^2*g^2)^(1/2))/(h^2+rd^2)+g)/Vo/((Vo^2+g*h+(Vo^4+2*Vo^2*g*h-rd^2*g^2)^(1/2))/(h^2+rd^2))^(1/2),((Vo^2+g*h+(Vo^4+2*Vo^2*g*h-rd^2*g^2)^(1/2))/(h^2+rd^2))^(1/2)*rd/Vo); theta2 = phid; %Set values to return tiltD = theta1 panD = theta2 B.15: dTarget.m function I=dtarget % get an image of the target to compare to other shots obj=videoinput('winvideo'); % start the camera image=getsnapshot(obj); % take a picture new=zeros(288,352); image=rgb2gray(image); % convert the picture to grayscale for i=1:288 % threshold the image for j=1:352 if image(i,j)>200 new(i,j)=1; end end end flushdata(obj) % stop the camera delete(obj) clear obj I=new; % output the binary image of the target B.16: nextGuess.m %Define nextGuess function %panD = last pan angle used %titlD = last tilt angle used %ballR = radial distance of landing location %ballPhi = angular coordinate of landing location %cupR = radial distance to target %cupPhi = angular coordinate to target function [panD, tiltD] = nextGuess(panD, tiltD, ballR, ballPhi, cupR, cupPhi) rd = cupR; phid = cupPhi; %Set cup size as threshold maxdiffr = 0.045; maxdiffphi = 0.025; %Set constants Vo = 7.366; ; h = .9525; ; g = 9.81; theta1 = tiltD; theta2 = panD; %Determine first and second order derivatives

Page 55: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

50

dfrdtheta1 = (Vo*cos(theta1)+1/(Vo^2*sin(theta1)^2+2*g*h)^(1/2)*Vo^2*sin(theta1)*cos(theta1))*Vo*cos(theta1)/g-(Vo*sin(theta1)+(Vo^2*sin(theta1)^2+2*g*h)^(1/2))*Vo*sin(theta1)/g; d2frd2theta1 = (-Vo*sin(theta1)-1/(Vo^2*sin(theta1)^2+2*g*h)^(3/2)*Vo^4*sin(theta1)^2*cos(theta1)^2+1/(Vo^2*sin(theta1)^2+2*g*h)^(1/2)*Vo^2*cos(theta1)^2-1/(Vo^2*sin(theta1)^2+2*g*h)^(1/2)*Vo^2*sin(theta1)^2)*Vo*cos(theta1)/g-2*(Vo*cos(theta1)+1/(Vo^2*sin(theta1)^2+2*g*h)^(1/2)*Vo^2*sin(theta1)*cos(theta1))*Vo*sin(theta1)/g-(Vo*sin(theta1)+(Vo^2*sin(theta1)^2+2*g*h)^(1/2))*Vo*cos(theta1)/g; dfphidtheta2 = 1; %Determine the correction to the tilt angle, apply seperate gains for %increasing/decreasing angles if(abs(rd-ballR) > maxdiffr) if(abs(theta1) < abs(theta1 + (rd - ballR)*(dfrdtheta1)/((dfrdtheta1)^2+(rd - ballR)*(d2frd2theta1)))) theta1 = theta1 + (rd - ballR)*(dfrdtheta1)/((dfrdtheta1)^2+(rd - ballR)*(d2frd2theta1)); elseif((abs(theta1) >= abs(theta1 + 1.75*(rd - ballR)*(dfrdtheta1)/((dfrdtheta1)^2+(rd - ballR)*(d2frd2theta1))))) theta1 = theta1 + 1.75*(rd - ballR)*(dfrdtheta1)/((dfrdtheta1)^2+(rd - ballR)*(d2frd2theta1)); end; end; %Determine the correction to the pan angle if(abs(phid-ballPhi) > maxdiffphi) theta2 = theta2 + (phid - ballPhi); end; %Set values to return tiltD = theta1; panD = theta2; B.17: parallelinit.m import parport.ParallelPort; lpt1=ParallelPort( hex2dec('378') ) % adress 0x378 is usually starting address of LPT1, % can be checked via windows system settings status=dec2bin(lpt1.read) % read status pins % if nothing connected: '01111111' % if all grounded: '10000111' % (highest) bit 7: pin 11 Busy INVERTED % bit 6: pin 10 Acknowledge % bit 5: pin 12 Out of Paper % bit 4: pin 13 Selected % bit 3: pin 15 I/O Error % bit 2: % bit 1: % bit 0:

B.18: rbline.m function [p1,p2]=rbline(varargin) % stores location of clicked pixel switch nargin

Page 56: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

51

case 0 h=gca; case 1 h=varargin1; axes(h); otherwise disp('Too many input arguments.'); end cudata=get(gcf,'UserData'); % current UserData hold on; k=waitforbuttonpress; p1=get(h,'CurrentPoint'); % wait for user to click p1=p1(1,1:2); % extract x and y lh=plot(p1(1),p1(2),'+:'); % plot a "+" at the point udata.p1=p1; udata.h=h; udata.lh=lh; B.19: recttopol.m function [cupR, cupPhi]=recttopol(x,y) %convert pixel location to world frame Dx=2*48.5*(144-x)*sin(0.26147)/288; Dy=2*48.5*(y-176)*sin(0.321776)/352; cupR=sqrt((96+Dx)^2+Dy^2)*0.0254; cupPhi=atan2(Dy,Dx+96);

B.20: sendlaunchsignal.m %Initialize the camera obj=videoinput('winvideo'); set(obj,'framespertrigger',60); lpt1.write(0); %Close the valve %Wait to store frames tic while (toc<(launchpause/3)) end start(obj); %Begin storing frames %Wait to open the valve tic while (toc<(2*launchpause/3)) end lpt1.write(1); %Open the valve [vid time]=getdata(obj); %Save the image sequence flushdata(obj) %Clear obj to free memory delete(obj) clear obj

B.21: tstats.m

Page 57: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

52

function [Mo,tp,tr,ts,ess] = tstats(t,y,ref) % Takes a time vector and a corresponding % step-response vector and returns time-domain % performance measures. %Inputs: t - time vector % y - step response corresponding to t % ref - reference level at steady-state %Outputs: Mo - percent overshoot % tp - time to peak % tr - rise time (10% - 90%) % ts - settling time (2%) % ess - percent steady-state Error % %If the reference level, 'ref', is not specified, 1.0 is assumed. %%%%%%%%%%%%%%%%%%% tstats.m %%%%%%%%%%%%%%%%%%%% % Discrete-Time Control Problems using % % MATLAB and the Control System Toolbox % % by J.H. Chow, D.K. Frederick, & N.W. Chbat % % Brooks/Cole Publishing Company % % September 2002 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if nargin < 3 ref = 1; disp('reference value set = 1.0') end % [maxy,itp] = max(y); tp = t(itp); Mo = 100*(maxy - ref)/ref; i10 = min(find(y>=0.1*ref)); i90 = min(find(y>=0.9*ref)); if i10 > 0 & i90 < length(y) delt = t(2)-t(1); t10 = t(i10) - delt*(y(i10)-0.10*ref)... /(y(i10)-y(i10-1)); t90 = t(i90) - delt*(y(i90)-0.90*ref)... /(y(i90)-y(i90-1)); tr = t90 - t10; else tr = -9.9999; end % is = max(find(abs(y - ref*ones(size(y)))/ref>0.02)); if is < length(y) ts = t(is + 1); else ts = -9.9999; end % ess = abs(100*(y(length(y)) - ref)/ref); %%%%%%%%%%

Page 58: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

53

C.1: Ball Trajectory Physics Model

C.2: Comparison of Newton-Raphson and Schröder Methods

Page 59: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

54

Page 60: Beirut Master 4000 - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/team2_final_report.pdf · designed to launch a ball into a cup in the least amount of iterations. Two motors are used to aim

55

D. Contributions All team members worked equally in the production of this report. Bert Hallonquist worked on the launching system and the conclusion. Larry Cole worked on the launcher mounting, feedback system, and the professional and societal considerations. Danish Zia worked on the introduction, the learning algorithm, and the valve automation. Vinay Shah worked on the modeling and control, the abstract, and did proofreading of the report. ______________________________ ___________________________ Larry Cole Vinay Shah ______________________________ ____________________________ Danish Zia Bert Hallonquist