05.08.2013 Views

Automatic Pouring Robot Project Progress Report for ECSE-4962 ...

Automatic Pouring Robot Project Progress Report for ECSE-4962 ...

Automatic Pouring Robot Project Progress Report for ECSE-4962 ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Automatic</strong> <strong>Pouring</strong> <strong>Robot</strong><br />

<strong>Project</strong> <strong>Progress</strong> <strong>Report</strong> <strong>for</strong> <strong>ECSE</strong>-<strong>4962</strong> Control<br />

Systems Design<br />

Akilah Harris-Williams<br />

Adam Olmstead<br />

Philip Pratt-Szeliga<br />

Will Roantree<br />

March 30, 2005<br />

Rensselaer Polytechnic Institute


Abstract<br />

This report contains our progress towards the develop of a prototype system to smoothly pour<br />

water from a bottle into a cup using closed-loop control. <strong>Progress</strong> is being made towards the<br />

completion of the system. After some delays, the mechanical system is nearing completion.<br />

We are also nearing completion of the non-linear model. This includes compensation of the<br />

variable intertia and center of mass of the bottle. Initial control has begun on a model<br />

linearized about the point of highest inertia. Finally, the sensor subsystem can now acquire<br />

and process images on the fly. We are looking to complete the system by the end of the<br />

semester.


Contents<br />

1 Introduction 4<br />

2 Preliminary Results 5<br />

2.1 Physical System Design and Construction . . . . . . . . . . . . . . . . . . . 5<br />

2.2 System Modeling and Parameter Identification . . . . . . . . . . . . . . . . . 6<br />

2.2.1 Inertia Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . 6<br />

2.2.2 Friction Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . 7<br />

2.2.3 Linearized Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10<br />

2.3 Model Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11<br />

2.4 Controller Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />

2.5 Sensor Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />

2.5.1 Image Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />

2.5.2 Image Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17<br />

3 Summary of <strong>Progress</strong> 19<br />

3.1 Plan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19<br />

3.2 Schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19<br />

3.3 Cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21<br />

3.4 Unanticipated Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22<br />

3.5 Prognosis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23<br />

4 Statement of Contribution 24<br />

A Mechanical System SolidWorks 26<br />

B Simulation Block Diagrams 27<br />

C Friction ID MATLAB Code 29<br />

C.1 Static Friction Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . 29<br />

C.2 Coulomb and Viscous Friction Identification . . . . . . . . . . . . . . . . . . 31<br />

D Image Acquisition MATLAB Code 34<br />

E Image Processing MATLAB Code 36<br />

1


List of Figures<br />

2.1 Model Coordinate System . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7<br />

2.2 Simulink Diagram <strong>for</strong> Friction Identification . . . . . . . . . . . . . . . . . . 8<br />

2.3 Friction Identification Data <strong>for</strong> Pan Axis . . . . . . . . . . . . . . . . . . . . 9<br />

2.4 Orientation of Bottle <strong>for</strong> Linearization . . . . . . . . . . . . . . . . . . . . . 10<br />

2.5 Simulation Results <strong>for</strong> 100 mL of Water . . . . . . . . . . . . . . . . . . . . 12<br />

2.6 Simulation Results <strong>for</strong> 500 mL of Water . . . . . . . . . . . . . . . . . . . . 13<br />

2.7 Step Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />

2.8 Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />

2.9 Color Detection with Threshold Values . . . . . . . . . . . . . . . . . . . . . 17<br />

2.10 Color Detection with Modified Threshold Values . . . . . . . . . . . . . . . . 18<br />

A.1 SolidWorks Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26<br />

B.1 Simulink Diagram of Pan-Tilt Simulation: Complete System . . . . . . . . . 27<br />

B.2 Simulink Diagram of Pan-Tilt Simulation: Pan-Tilt System . . . . . . . . . . 27<br />

B.3 Simulink Diagram of Pan-Tilt Simulation: Pan-Tilt Dynamics Subsystem . . 28<br />

B.4 Simulink Diagram of Pan-Tilt Simulation: Gravity Loading Subsystem . . . 28<br />

2


List of Tables<br />

2.1 Identified Friction Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9<br />

2.2 Webcam Timing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />

2.3 Image Processing Threshold Values . . . . . . . . . . . . . . . . . . . . . . . 18<br />

3.1 Updated Schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21<br />

3.2 Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22<br />

3.3 Raw Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22<br />

3.4 Labor Costs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22<br />

3


Chapter 1<br />

Introduction<br />

The <strong>Automatic</strong> <strong>Pouring</strong> <strong>Robot</strong> will smoothly pour a user-specified amount of water from a<br />

bottle into a cup using closed-loop control. We are aiming to design a system that can pour<br />

the desired amount of liquid within 10 mL of the desired value. We also want to pour at a<br />

reasonable rate, such that the cup could be filled in 20 seconds, corresponding to a flow rate<br />

of 45 mL/s. Some industrial applications addressed by this problem include pouring molten<br />

metal into casting and pouring hazardous materials or chemicals. A currently available<br />

commercial product <strong>for</strong> a similar task is the D&A101 Autopour, which pours molten metal<br />

into piston gravity castings.[5] The Autopour uses an open-loop controller to tilt the ladle.<br />

To accomplish our task, we will mount a bottle on a pan/tilt mechanism with MATLAB /<br />

Simulink controlled motors. Models of the bottle, the tilt mechanism and the water inside<br />

the bottle will be created in SolidWorks. Using Visual Basic and the SolidWorks API, we<br />

will calculate mass and inertial tensor properties of each model <strong>for</strong> varying tilt angles and<br />

water volumes. [2] From these properties we will interpolate a dynamic model of the system<br />

and then design a closed-loop controller.<br />

During the pour, volume updates to the dynamic model are required. To do this update we<br />

will measure the cup water volume and subtract this measurement from the initial bottle<br />

water volume. Measurement of the cup water volume will be accomplished using a webcam.<br />

Using a color detection algorithm, the webcam will measure the current height of the cup<br />

water and MATLAB will calculate the cup water volume.<br />

This problem is a challenging one due to a variety of factors. The system’s gravity loading<br />

changes constantly with time, due to the liquid’s motion within the bottle. Also, by making<br />

the pouring system closed loop, as opposed to the strictly open loop solutions currently<br />

available, we are stepping into new grounds. There is also a fair amount of sensor error, so<br />

designing a finely tuned controller to pour the desired amount of liquid will be a challenging<br />

task.<br />

4


Chapter 2<br />

Preliminary Results<br />

2.1 Physical System Design and Construction<br />

The mechanical system, as previously discussed, went through a series of evolutions. The<br />

final design was chosen because it kept the system as compact as possible, reducing rotating<br />

mass and material needed to construct it. The pieces that are attached to the frame, the<br />

gears, motors, and bottle, were all placed within a somewhat tight tolerance of each other<br />

in order to accomplish this. Although these pieces can come in very close contact with each<br />

other, they never actually meet, and thus, the system is as compact as it can be.<br />

The first step in constructing the mechanical system was getting the side pieces <strong>for</strong> the tilt,<br />

the base <strong>for</strong> the tilt, and the base <strong>for</strong> the pan machined. These pieces can be seen as the<br />

aluminum pieces in the figure of the entire mechanical system shown in Appendix A. Many<br />

options were examined when considering the machining of these pieces, and the decided upon<br />

approach was to use the school’s waterjet. The waterjet can cut metal with great precision,<br />

based on the CAD drawings. Since the mechanism was full of sometimes complex geometry<br />

that had to be machined perfectly, we decided the waterjet was the best approach, not only<br />

because of its precision, but also because of the speed with which it operates. An un<strong>for</strong>eseen<br />

challenge that presented itself with this approach, however, was user error. Having used the<br />

waterjet with a different operator previous to CSD, we were familiar with its use. However,<br />

<strong>for</strong> this project, we had to contact use a different person. Although the actual cutting with<br />

the waterjet took less than an hour, the process itself took almost 3 weeks. The operator<br />

was given the CAD drawings, and it took a week <strong>for</strong> him to get to them. When he cut<br />

them the first time, he cut them the wrong size. As he did not cut them until spring break,<br />

we did not find out until a week later. Once this problem was discovered, he was given the<br />

CAD drawings again, and another week later, we had the final pieces. The total price <strong>for</strong><br />

machining with the waterjet was $35, a good bit less than the original estimate of $50-100.<br />

The pieces were taken to the lab once they were acquired. Rafael assisted us in drilling the<br />

proper holes <strong>for</strong> construction. Holes were drilled <strong>for</strong> the attachment of bearings, encoders,<br />

5


and axles. Some of the tolerances on the waterjet were off, and so some of the pieces had<br />

to be drilled or milled where a waterjet had already cut a hole or slot. This, again, was an<br />

un<strong>for</strong>eseen challenge, but easily overcome.<br />

2.2 System Modeling and Parameter Identification<br />

The modeling of our system is particularly unique. Rather than modeling an object with a<br />

constant properties, our system has variable inertia. This is due to the fact that the water<br />

moves around in the bottle as the tilt angle is increased. In addition to this, as liquid is<br />

poured out of the bottle, the volume of water, and there<strong>for</strong>e overall mass, changes. This<br />

results in a system with both variable values of inertia and center of mass.<br />

To deal with this problem, an automated program was written to find the changing mass<br />

properties of the bottle, the tilt mechanism and the water using the Solidworks API. The<br />

mass properties found are the mass, center of mass, and principle moment of inertia. A nonlinear<br />

Simulink model uses center of mass, mass and principle moment of inertia to simulate<br />

gravity loading and frictional effects. To complete the simulation, the Coulomb and Viscous<br />

friction <strong>for</strong> the final assembled mechanical system must be determined when its assembly is<br />

finished.<br />

2.2.1 Inertia Identification<br />

A Visual Basic program to automate the extraction of center of mass, mass and moment<br />

of inertia properties from Solidworks is operational. The program steps through the angles<br />

1 ◦ , 10 ◦ , 20 ◦ , 30 ◦ , 40 ◦ , 50 ◦ , 60 ◦ , 70 ◦ , 80 ◦ , 89 ◦ , 91 ◦ , 100 ◦ , 110 ◦ , 120 ◦ , 130 ◦ , 140 ◦ , 150 ◦ , 160 ◦ ,<br />

170 ◦ and 179 ◦ . For each of these angles, the program finds the height of water that will<br />

match a volume of 100 mL, 200 mL, 300 mL, 400 mL and 500 mL. For each of these one<br />

hundred data points, the program generates a lookup table matrix corresponding to center<br />

of mass in the Z direction, mass and principle axis of inertia in the X direction. Figure 2.1<br />

shows the coordinate system used in the modeling and simulation. The center of mass, mass<br />

and principle axis of inertia <strong>for</strong> varying angles and volumes are determined, and this data<br />

is entered into a 2D lookup table in Simulink, which interpolates the output value <strong>for</strong> any<br />

intermediary input values that it may receive.<br />

A non-linear Simulink model of the bottle, tilt mechanism and water is nearly complete.<br />

The gravity loading subsystem is complete. It incorporates a changing mass and center of<br />

mass in the Z direction. These properties change with respect to the current tilt angle and<br />

the current volume of water in the bottle.<br />

6


coordinate_system.bmp (BMP Image, 536x613 pixels) file://///sambasrv/prattp/public_html/controlsysdesign/papers/progr...<br />

2.2.2 Friction Identification<br />

Figure 2.1: Model Coordinate System<br />

In order to get an accurate non-linear model of the system, the friction in the system needs<br />

to be identified. Friction exists between all moving parts in the system, such as the axle and<br />

the bearings, the belts and the pulleys, and even inside the motors. If accurately determined,<br />

this friction can be accounted <strong>for</strong> and cancelled in the model. There are three types of friction<br />

in the system that we will estimate experimentally: static, coulomb and viscous.<br />

Static friction, sometimes referred to as “stiction,” is the <strong>for</strong>ce that exists between any two<br />

objects at rest. This friction must be overcome be<strong>for</strong>e the object(s) can move. In our case,<br />

static friction exists between the bearings and the axle. To experimentally determine this<br />

value, xPC target was used to interface with the motors, using the Simulink diagram shown<br />

below in Figure 2.2. A script was then used, which simply applies various constant torque<br />

1 of 1 3/30/2005 2:35 PM<br />

values, until the axle begins to rotate. First, a coarse pass was done in torque increments<br />

of 0.01 Nm. Then, once the axle rotates, a finer pass was done in 0.001 Nm increments to<br />

find the value of the static friction to the nearest 0.001 Nm. The script used to identify the<br />

7


static friction is shown in Appendix C.1.<br />

Step<br />

Step1<br />

Step2<br />

Step3<br />

−K−<br />

Gain1<br />

−K−<br />

Gain3<br />

Saturation<br />

Saturation1<br />

1PCIM−DAS1602/16<br />

ComputerBoards<br />

2 Analog Output<br />

PCI−QUAD04<br />

Comp. Boards<br />

Inc. Encoder<br />

PCI−QUAD04<br />

PCIM−DAS1602 16 PCI−QUAD04<br />

Comp. Boards<br />

Inc. Encoder<br />

PCI−QUAD04 1<br />

Count<br />

Count<br />

2*pi/(1024*4)<br />

2*pi/(1024*4)<br />

Gain2<br />

Figure 2.2: Simulink Diagram <strong>for</strong> Friction Identification<br />

Gain<br />

3<br />

Pos1<br />

4<br />

Out1<br />

K (z−1)<br />

Ts z<br />

Discrete Derivative<br />

K (z−1)<br />

Ts z<br />

Discrete Derivative1<br />

Once the static friction is determined, a different script is used to determine the coulomb<br />

and viscous friction values <strong>for</strong> the pan axis. Using the same Simulink diagram, this script<br />

measures the velocity with respect to time <strong>for</strong> a range of input torques. An initial, hightorque<br />

(10 V <strong>for</strong> 0.25s) pulse is given to the motor to break static friction, and then the<br />

desired torque was applied. Then the velocity values are recorded <strong>for</strong> 10 seconds, as the<br />

motor to settles to its steady-state velocity.<br />

For each constant input torque, the recorded velocity values are passed through a lowpass<br />

filter to remove noise, and then a steady-state value is determined by averaging the last 10%<br />

of the values together. The coulomb friction is the first torque value at which the steadystate<br />

velocity is non-zero, within a specified tolerance. The viscous friction is the slope of<br />

the least-squares best fit line of torque vs. steady-state velocity <strong>for</strong> all nonzero values of the<br />

latter. [6] The MATLAB code used to generate the friction data is shown in Appendix C.2.<br />

The results <strong>for</strong> the initial friction testing on the unloaded pan axis are summarized below in<br />

Table 2.1. This table shows the identified friction values <strong>for</strong> the pan axis. Only this axis has<br />

been tested because the mechanical system has not been completed, and we cannot there<strong>for</strong>e<br />

test it <strong>for</strong> the final friction values. The torque versus steady-state velocity plot used to find<br />

these values is shown below in Figure 2.3.<br />

8<br />

Vel1<br />

1<br />

2<br />

Vel2


Applied Torque (Nm)<br />

0.15<br />

0.1<br />

0.05<br />

0<br />

−0.05<br />

−0.1<br />

−0.15<br />

Static<br />

Forward Reverse<br />

Pan 0.078 Nm 0.076 Nm<br />

Tilt N/A N/A<br />

Coulomb<br />

Forward Reverse<br />

Pan 0.05573 Nm 0.06251 Nm<br />

Tilt N/A N/A<br />

Viscous<br />

Pan<br />

Forward<br />

8.0146x10<br />

Reverse<br />

−4 Nm s<br />

rad<br />

9.1426x10−4 Nm s<br />

Tilt N/A<br />

rad<br />

N/A<br />

Table 2.1: Identified Friction Data<br />

Torque vs. Steady−State Velocity<br />

−0.2<br />

−50 −40 −30 −20 −10 0 10 20 30 40 50<br />

Steady−State Velocity (rad/s)<br />

Figure 2.3: Friction Identification Data <strong>for</strong> Pan Axis<br />

9


2.2.3 Linearized Model<br />

The above Simulink models represents the full, non-linear model of our system. However,<br />

when designing the controller, we must linearize the model to simplify the design process.<br />

The dynamics of our system are particularly hard to model due to the changing inertia.<br />

There<strong>for</strong>e, we will design <strong>for</strong> the worst case in our controller, so the system is linearized<br />

about the point with the highest inertia. The equation of motion <strong>for</strong> the model is:<br />

(Ixx + N 2 Im) ¨ Θ = mg cos( π<br />

2 + α − Θ) − (Fv ˙ Θ + Fcsgn( ˙ Θ)) (2.1)<br />

The strategy we used to create the linear model is to linearize the non-linear model about<br />

a tilt angle and water volume when the inertia is largest. The angle and water volume we<br />

have linearized about is 90◦ linear_bottle.bmp (BMP Image, 583x350 and pixels) 500 mL respectively. file://///sambasrv/prattp/public_html/controlsysdesign/papers/progr...<br />

This orientation is shown in Figure<br />

2.4<br />

Figure 2.4: Orientation of Bottle <strong>for</strong> Linearization<br />

This results in the system described by the state-space model shown in Equation 2.2.<br />

˙x =<br />

⎡<br />

0<br />

⎢<br />

⎣ 0<br />

0<br />

0<br />

⎤ ⎡ ⎤<br />

0<br />

1<br />

⎥ ⎢ ⎥<br />

−0.0001 ⎦ x + ⎣ 0 ⎦ u<br />

0 0.001<br />

y =<br />

−4.454 1<br />

<br />

0 0 1 <br />

x<br />

10<br />

(2.2)


2.3 Model Verification<br />

To verify the non-linear model of our system, simulations were run using Simulink. The<br />

block diagrams of the system contained in Appendix B show the Simulink block diagrams<br />

that represent our system. An initial simulation of tilt angle <strong>for</strong> the new mechanical system<br />

incorporating tentative friction values and gravity is complete. In simulation, the bottle<br />

can rotate from 0 to 180 degrees and a volume of 0 to 500 milliliters of water can be<br />

selected. Compared to the draft simulation in the project proposal, the current simulation<br />

has improved. The equations of motion <strong>for</strong> gravity loading are now understood. The parallel<br />

axis theorem is applied to the moment of inertia to align it with the output coordinate system.<br />

Two initial simulations of the tilt angle, Θ, including changing center of mass, mass and<br />

moment of inertia have been completed. These simulations were run and verified intuitively<br />

to make sure that the results make sense. The two simulations are <strong>for</strong> a bottle holding water<br />

volumes of 100 mL and 500 mL respectively. Simulation plots <strong>for</strong> angular position (Θ),<br />

angular velocity (ω), and angular acceleration (α) are shown in the figures below.<br />

In the 100 mL simulation, the bottle begins at 0 ◦ and falls to a steady state of 48.1 ◦ past<br />

vertical. Intuitively, this simulation result shown in Figure 2.5 is logical. At time zero,<br />

gravity overcomes Coulomb friction and accelerates the motion of the bottle away from the<br />

original position. Viscous friction slows the angular motion when velocity is nonzero and<br />

acts with the dynamic gravity loading to settle theta. There is little inertia when filled with<br />

100mL of water and oscillation past the steady state is minimal.<br />

11


Angular Position (deg)<br />

Angular Velocity (deg/s)<br />

Angular Acceleration (deg/s²)<br />

60<br />

40<br />

20<br />

0<br />

0 10 20 30<br />

Time (s)<br />

40 50 60<br />

10<br />

5<br />

0<br />

−5<br />

0 10 20 30<br />

Time (s)<br />

40 50 60<br />

10<br />

5<br />

0<br />

−5<br />

0 10 20 30<br />

Time (s)<br />

40 50 60<br />

Figure 2.5: Simulation Results <strong>for</strong> 100 mL of Water<br />

12


In the 500 mL simulation, the bottle begins at 0 ◦ , falls to 89 ◦ below the tilt axis, oscillates,<br />

and rises back to a steady state of 53.4 ◦ . This simulation result is also logical. At time<br />

zero, gravity overcomes Coulomb friction and accelerates the motion of the bottle away from<br />

the original position. Be<strong>for</strong>e the max angular displacement, the large inertia effect pushes<br />

the bottle past the horizontal. Viscous friction and the large gravity loading act to settle<br />

theta. Shown below in Figure 2.6 is a plot of the angular displacement, angular velocity and<br />

angular acceleration of the tilt axis <strong>for</strong> the 500mL simulation.<br />

Angular Position (Deg)<br />

Angular Velocity (Deg/s)<br />

Angular Acceleration (Deg/s²)<br />

100<br />

50<br />

0<br />

0 10 20 30<br />

Time (s)<br />

40 50 60<br />

40<br />

20<br />

0<br />

−20<br />

0 10 20 30<br />

Time (s)<br />

40 50 60<br />

20<br />

10<br />

0<br />

−10<br />

0 10 20 30<br />

Time (s)<br />

40 50 60<br />

2.4 Controller Design<br />

Figure 2.6: Simulation Results <strong>for</strong> 500 mL of Water<br />

Using the linear model discussed in section 2.2.3, a controller can be designed to control the<br />

motion of the pan and tilt axes. The plant, is a complex model with dynamic gravity loading<br />

based on changing inertia tensors. In a control sense, this means that the system’s poles will<br />

be changing continually. There<strong>for</strong>e, a robust controller is very desirable in this application.<br />

The controller will be designed using frequency response methods, in conjunction with rootlocus<br />

to determine the desired gain. This will allow us to design fairly large stability margins,<br />

which are needed so that the moving poles don’t disrupt the control too greatly. [1] A<br />

traditional PID controller does not allow this flexibility in designing the margins, as only<br />

13


the gains are being tuned. In a lead/lag controller, the poles and zeros of the controller can<br />

be moved around in addition to the gains, allowing the magnitude and phases of the plant<br />

to be manipulated.<br />

When designing the controller, it is important to keep in mind the controller specifications.<br />

They include a small overshoot: less than 5%, a small settling time: less than 3% and a<br />

steady-state error less than 0.1. Rise time is not a crucial factor <strong>for</strong> our design, because the<br />

sensing subsystem responds much slower than the rest of the system, which necessitates a<br />

relatively slow, smooth pouring. The controller is designed based on the worst case inertia<br />

(largest) because of the constant movement, change in the center of mass, and change in the<br />

water volume.<br />

For the lead-lag compensator, we have to go through various equations to design the controller<br />

to the specifications. The transfer function of a lead controller can be generalized as<br />

follows:<br />

W (s) =<br />

1 + a1τ1s 1 + a2τ2s<br />

1 + τ1s 1 + τ2s<br />

where a1 < 1<br />

a2 > 1<br />

(2.3)<br />

In order to get the phase angle, frequency and gain, the following equations below were used:<br />

Phase Angle: Φmax = sin −1 ( a2 − 1<br />

) − 5◦<br />

a2 + 1<br />

Frequency: ωm = 1<br />

√<br />

τ2 a2<br />

(2.4)<br />

(2.5)<br />

Gain: (am)dB = (a1)dB + 1/2(a2)dB = (a1)dB + 1/2(1/a1)dB = 1/2(a1)dB (2.6)<br />

The design process is then simply as follows:<br />

1. Choose K to satisfy the steady-state requirements, K = 1<br />

ess<br />

2. Draw a Bode Diagram of KG(s)<br />

3. Determine the new crossover frequency, ωc<br />

Using this above design method, the following controller was designed. However, the system<br />

that we are working with is a completely digital system. There<strong>for</strong>e, our controller must be<br />

discretized. The Bilinear (Tustin) trans<strong>for</strong>mation is used to discretize the above continuous<br />

controller at a sampling frequency of 1 kHz using the Control System Toolbox. This emulation<br />

design results in a discrete controller. The step response of this controller is shown<br />

in Figure 2.7. As can be seen, the system responds slowly, but smoothly. This is consistent<br />

with our requirements. The frequency response is shown in Figure 2.8.<br />

14


step.bmp (BMP Image, 613x356 pixels) file:///C:/Documents%20and%20Settings/olmsta/Desktop/Dropbox/...<br />

freq.bmp (BMP Image, 603x351 pixels) file:///C:/Documents%20and%20Settings/olmsta/Desktop/Dropbox/...<br />

2.5 Sensor Development<br />

2.5.1 Image Acquisition<br />

Figure 2.7: Step Response<br />

Figure 2.8: Frequency Response<br />

Several systems that have tackled the pouring problem have all done so with an open loop<br />

controller. However, we are providing feedback to the system with a webcam to determine<br />

15<br />

1 of 1 3/30/2005 6:08 PM


the volume currently in the cup. From this volume, the system will be able to determine<br />

the desired angular position of the tilt axis. The correlation between the current volume<br />

and the angular position will be done with an experimentally determined lookup table. Our<br />

controller will track this position, and the bottle will pour in the process.<br />

The first step of the sensor development is to acquire images from the webcam. To do so,<br />

we are using MATLAB’s Image Acquisition Toolbox. A MATLAB script is used to grab<br />

images from the webcam. A video input object is created, and it is configured to continually<br />

take images as fast as possible with logging enabled. [3] As soon as an image is ready, it is<br />

grabbed from memory and sent to the image processing function, which returns the highest<br />

row of pixels filled with water. This data is sent to xPC target, where a lookup table is<br />

used to correlate the pixel data to the actual volume, via the TCP/IP link. This process is<br />

repeated continually. The script used to do this is shown in Appendix D.<br />

The speed at which images can be grabbed and processed and sent to xPC target is the<br />

bottleneck <strong>for</strong> the system. There<strong>for</strong>e, the timing of the sensing is very important. Timing<br />

tests were done to see how well the webcam per<strong>for</strong>ms in comparison to its nominal framerate<br />

of 30 fps. First, the framerate was measured with no other operations per<strong>for</strong>med. Then, the<br />

camera was continually polled in MATLAB. Next, image processing was added to the test.<br />

Finally, a test was done with acquisition, processing, and sending to xPC target. For each<br />

case, the experiment was repeated 10 times, with each run acquiring 100 frames. The average<br />

period and its standard deviation were determined. The timing results are summarized in<br />

Table 2.2.<br />

Mean Period Standard Deviation Average FPS<br />

No Logging 68.3 ms 18.8 ms 14.63<br />

Logging 70.9 ms 27.4 ms 14.1<br />

Processing 71.0 ms 25.4 ms 14.09<br />

xPC Communication 134.9 ms 75.2 ms 7.42<br />

Table 2.2: Webcam Timing Data<br />

As seen, the camera, even when only acquiring images and saving them to memory, runs at<br />

14.64 fps, less than half of its advertised framerate. When the data is continually saved to<br />

the workspace, the average period does not increase much, but the standard deviation of the<br />

times increases drastically. Image processing, surprisingly has very little effect. However,<br />

communication with xPC target proved to be a large bottleneck and inconsistency by both<br />

halving the framerate and doubling the deviation. This is most likely due to the laptop<br />

computer multitasking between TCP/IP communication and image acquisition in MATLAB.<br />

To try and reduce this fluctuation, the image acquisition will be written as a function rather<br />

than a script, so that it will be pre-compiled. Also, a T40 laptop will be used rather than<br />

the T22 that was used <strong>for</strong> the timing testing.<br />

The primary implication of this slow framerate is that the pouring speed will have to be<br />

limited. If the system pours too quickly with a slow framerate, then there is a chance that<br />

the system will over pour be<strong>for</strong>e the sensing subsystem can tell it that it went too far.<br />

16


2.5.2 Image Processing<br />

Once the images are acquired, they are sent to a function that determines the highest pixel<br />

row. This data is later correlated to the volume. Color detection is used to determine this<br />

value. This method finds the pixels that are red, as determined by a tunable threshold value<br />

<strong>for</strong> component intensities. The images taken from the webcam are conveniently stored in<br />

the RGB <strong>for</strong>mat, so we can look <strong>for</strong> pixels that have a high R component and lower G and<br />

B components. [4] To facilitate this, the water used in this project will be dyed red with<br />

food coloring, allowing the algorithm to search <strong>for</strong> red in the image. A downside to color<br />

detection is a relatively high sensitivity to noise. For this reason, the viewing conditions are<br />

fixed and the algorithm tuned to it. The cup will be completely surrounded by white to<br />

improve contrast <strong>for</strong> the webcam.<br />

The function to find the highest row of pixels is rather straight<strong>for</strong>ward. The MATLAB code<br />

can be found in Appendix E. First of all, since the webcam has a better horizontal resolution<br />

than vertical resolution (288x352), the images will be rotated 90 ◦ clockwise from the upright<br />

position. A certain band in the middle of the cup is focused on so that no pixels outside<br />

the boundary of the cup will be considered. These boundaries have yet to be finalized, as<br />

the fixed location of the webcam is yet to be decided. Then the average pixel value <strong>for</strong> each<br />

column within these boundaries is found, and that value is applied to threshold component<br />

color values. These values were determined on a sample setup. Figure 2.9 shows an the<br />

image used to calibrate the threshold values. The image on the bottom is one where all<br />

black pixels are those that were found to be “red” by the threshold values, with the original<br />

shown on the top as a reference.<br />

Original Image<br />

(a) Original Image<br />

Threshold Values Applied<br />

(b) First Threshold Values Applied<br />

Figure 2.9: Color Detection with Threshold Values<br />

Figures 2.9 & 2.10 show the effect of different threshold values on the detection of the red<br />

pixels. Just using a simple single set of threshold values results in the image in the first<br />

figure. Notice how an area of the liquid is not detected, which is due to the way the light<br />

17


Original Image<br />

(a) Original Image<br />

Second Threshold Values Applied<br />

(b) Second Threshold Values Applied<br />

Figure 2.10: Color Detection with Modified Threshold Values<br />

shined on the cup when the image was taken. The second set of threshold values includes<br />

an “or” <strong>for</strong> when the red value saturates. This helped improve detection of all the water<br />

pixels, while not adding any new unwanted pixels. Table 2.3 below briefly summarizes the<br />

threshold values use to detect the red pixels in the images above. These threshold values are<br />

applied to the mean pixel of each row in the above<br />

GT or LT Pixel Value or GT or LT Pixel Value<br />

Red > 140 == 255<br />

Green < 150 < 200<br />

Blue < 140 < 160<br />

Table 2.3: Image Processing Threshold Values<br />

18


Chapter 3<br />

Summary of <strong>Progress</strong><br />

3.1 Plan<br />

The overall goal of our project has remained the same: to pour a specified amount of water<br />

into a cup. Originally, we had hoped to pour the liquid very quickly into the cup. However,<br />

we are limited by the speed of our sensing subsystem, which is only running at approximately<br />

7.5 frames per second. There<strong>for</strong>e, in order to maintain the accuracy of the pouring, we need<br />

to slow it down.<br />

In the proposal we also had plans to possibly move the cup’s location while not pouring and<br />

have the system pan to the cup’s new position. However, our primary ef<strong>for</strong>ts are currently<br />

on the accurate pouring with the tilt axis, and we will most likely not have the time to<br />

implement this feature.<br />

3.2 Schedule<br />

<strong>Progress</strong>, with respect to the original schedule, has been uneven. A large portion of this is<br />

due to the fact that the waterjet took much longer than expected (more than two weeks)<br />

to get us the parts <strong>for</strong> the mechanical system. We only received the parts a few days prior<br />

to the writing of this memo, but we are almost done with the assembly of the system. The<br />

only remaining thing that we are waiting on <strong>for</strong> the completion of the mechanical system is<br />

a tilt gear belt, which has been ordered. The only two tasks that still need to be done with<br />

the mechanical system are to integrate the mechanical system with the pan-tilt mechanism,<br />

and to mount the webcam to a fixed location so we can have accurate sensor data.<br />

The delay in the mechanical system has caused delays in other areas as well. Most notably<br />

is with the model validation. The final friction values have yet to be indentified, since the<br />

19


system is not completed. We were unable to run any verification experiments with the model,<br />

other than comparing the model to what “should” happen intuitively. This is a top priority<br />

<strong>for</strong> the when the mechanical system is finished. The verification experiments that we run<br />

will consist primarily of comparing actual data to the simulated data. Using xPC target,<br />

we can collect position data from the encoders <strong>for</strong> the actual system when excited by an<br />

arbitrary input. We will compare this data to the simulated position data, and iteratively<br />

improve the model if needed. The various simulations that we will compare are the model<br />

unloaded, with an initial amount of water in it, and the settling after excitation by a short<br />

burst of constant torque.<br />

The sensor development also has been delayed due to the incomplete mechanical system.<br />

The MATLAB scripts have been developed and timing tests done <strong>for</strong> image acquisition and<br />

processing. However, we were unable to correlate any of the pixel data to the volume.<br />

The reason <strong>for</strong> this is that the webcam has yet to be mounted relative to the cup. It is<br />

important <strong>for</strong> the webcam to be in a fixed location when this determination is done, to<br />

ensure the accuracy of the sensing results. Due to the resolution of the camera, each pixel<br />

row represents around 1.33 mL. There<strong>for</strong>e, we need to keep it in a fixed location relative<br />

to the cup to ensure that the data is consistent. This correlation will be determined by<br />

pouring small increments of water into the cup (start with 5 mL increments, and make finer<br />

if needed), and then running the image processing algorithm on it. Data will be collected<br />

several times <strong>for</strong> each water level to average out any noise in the acquisition, and the data<br />

will then be fit to a curve, or a lookup table in Simulink, depending on the characteristics<br />

of the data. Once the webcam is mounted, we can also determine the boundaries that will<br />

be used to ignore all image in<strong>for</strong>mation outside the cup.<br />

The model and control integration will begin shortly after the model is validated. Simulated<br />

and actual results will be compared <strong>for</strong> the open and closed-loop response to various reference<br />

inputs. We need to still complete the following cycle: test controller on integrated system,<br />

iterate control design, and retest controller. Also, we need to generate a smooth trajectory<br />

<strong>for</strong> the controller to follow to avoid high-frequency vibrations in our system. We will most<br />

likely use a trapezoidal trajectory <strong>for</strong> our system to move from one point to an another.<br />

The updated schedule is shown below in Table 3.1. This shows all of the tasks that still need<br />

to be completed, and their new timeframes.<br />

20


Table 3.1: Updated Schedule<br />

Task Start Completion Leader<br />

Develop Mechanical System<br />

Fabricate new mechanical system 3/29/05 3/30/05 Will<br />

Integrate new mechanical system with Pan-Tilt 3/31/05 3/31/05 Will<br />

Friction Testing<br />

Execute script with new mechanical design 4/1/05 4/4/05 Akilah<br />

Incorporate friction data into existing model 4/4/05 4/5/05 Will<br />

Image Processing<br />

Correlate pixel data to beaker volume 3/30/05 3/31/05 Adam<br />

Develop pixel data to volume model 4/1/05 4/4/05 Adam<br />

Verify pixel data to volume model 4/4/05 4/5/05 Akilah<br />

Incorporate data into existing model 4/6/05 4/7/05 Akilah<br />

Simulation<br />

Add volume feedback to Simulink 3/30/05 4/4/05 Phil<br />

Experiment to get flow rates at various angles 4/1/05 4/4/05 Will<br />

Test model in Simulink 4/7/05 4/11/05 Adam<br />

Verify model on integrated system 4/11/05 4/13/05 Akilah<br />

Controller Design<br />

Tune lead-lag controller 4/13/05 4/15/05 All<br />

Test controller in Simulink 4/15/05 4/21/05 All<br />

Test controller on actual system 4/21/05 4/22/05 All<br />

Iterate control design 4/25/05 4/26/05 All<br />

<strong>Report</strong>s<br />

Final report work 4/21/05 5/4/05 All<br />

Final presentation work 4/21/05 5/4/05 All<br />

3.3 Cost<br />

The original cost schedule that was submitted <strong>for</strong> the proposal has proven to be accurate<br />

thus far. Only two additions have been made, which are the waterjet machining, which cost<br />

an additional $35, and a new tilt gear belt (which we were expecting to have provided, but<br />

we needed a new size). We also need to increase the amount of time <strong>for</strong> each group member<br />

on the project, as the original 50 will be insufficient <strong>for</strong> completing the project. An estimate<br />

of 80 will replace it. The updated cost schedules <strong>for</strong> parts, raw materials, and labor are<br />

shown below in Tables 3.2, 3.3 and 3.4, respectively.<br />

21


Table 3.2: Parts<br />

Item Quantity Cost Total Cost<br />

Cup 1 $1.25 $1.25<br />

Bottle 1 $1.45 $1.45<br />

Red Dye 1 $1.00 $1.00<br />

Logitech WebCam 1 $29.95 $29.95<br />

3” Universal Exhaust Clamp 1 $3.24 $3.24<br />

Pan Belt 1 $3.92 $3.92<br />

Pan Gear A 1 $9.97 $9.97<br />

Pan Gear B 1 $22.02 $22.02<br />

Tilt Belt 1 $4.00 $4.00<br />

Tilt Gear A 1 $7.95 $7.95<br />

Tilt Gear B 1 $22.02 $22.02<br />

Pittman Motor GM9234S017 2 $97.59 $195.18<br />

Total $301.95<br />

Table 3.3: Raw Materials<br />

Item Quantity Cost Total Cost<br />

1/4” Aluminum Plate 500 in 2 $0.16 /in 2 $80.00<br />

Sand <strong>for</strong> Waterjet 1 $5.00 $5.00<br />

Total $85.00<br />

3.4 Unanticipated Challenges<br />

Certain unanticipated challenges have presented themselves throughout the progress of this<br />

report. The first, and most complex, is the modeling <strong>for</strong> the system. The inertia modeling<br />

<strong>for</strong> this system has proven to be quite difficult. The differing inertia of the liquid in the<br />

bottle has complicated the modeling to an unexpected degree. Although the difficulty of the<br />

modeling of this system took us by surprise, we are certain that we have a grasp on it now.<br />

The next unanticipated challenge was a problem with help from outside the course. In order<br />

to maximize the accuracy of the machining of the mechanical system, it was decided that<br />

the main parts of system would be machined using a waterjet, which is computer controlled,<br />

Table 3.4: Labor Costs<br />

Description Hours Cost Total Cost<br />

Akilah Harris-Williams (Engineer) 80 $25.00 $2000<br />

Adam Olmstead (Engineer) 80 $25.00 $2000<br />

Philip Pratt-Szeliga (Engineer) 80 $25.00 $2000<br />

Will Roantree (Engineer) 80 $25.00 $2000<br />

Jim Schatz (Waterjet Operator) 1 $30.00 $30.00<br />

Total $8030<br />

22


and driven by engineering drawings. The parts were ready to be returned a week after<br />

the material and the drawings were dropped off with the operator, even though the actual<br />

machining took less than an hour. Un<strong>for</strong>tunately, the parts were ready to be returned at<br />

the beginning of spring break, when no one was around to receive them. When the group<br />

members returned from the break, and got the parts, it was discovered that they were<br />

machined incorrectly, and needed to be machined again. This took another week, turning<br />

an hours worth of work into a 3 week process.<br />

Another unanticipated challenge was with the machining of the mechanical system. When<br />

the waterjet cuts pieces of aluminum plate, it does not leave a perpendicular edge. Instead,<br />

it leaves a slight angle. For most applications, this is inconsequential. However, <strong>for</strong> this<br />

system, the bottom edges of the sides of the tilt mechanism were stricken with this angle,<br />

and had to be further machined, as they are supposed to sit flat against the base of the tilt<br />

mechanism. When the TA was assisting us with this process, there was a problem with the<br />

mill, delaying progress of the system <strong>for</strong> a few hours. Once the problem was resolved, the<br />

parts were machined correctly, and the system was assembled.<br />

Finally, the control design is also more challenging than expected. This is due exclusively to<br />

the complexity and dynamic nature of our system. The variable inertia has made it difficult<br />

to design a controller that is robust enough to pour quickly in one case without overshooting<br />

too much in another case. For this reason, we may have to pour fairly slowly in cases where<br />

it is not needed.<br />

3.5 Prognosis<br />

Our <strong>for</strong>ecast <strong>for</strong> the remainder of the project is that the system will be able to pour liquid<br />

into a cup, as originally specified in the design memo. The system will not have any of the<br />

proposed additions, due to a limited time budget. However, provided that certain obstacles<br />

are overcome, the group feels confident in its ability to complete a system that will accurately<br />

pour liquid into a cup, without spilling, while tracking the amount that is being poured.<br />

23


Chapter 4<br />

Statement of Contribution<br />

Akilah worked on the controller design and tuning. This includes linearizing the model about<br />

the operation point and designing the lead-lag controller.<br />

Adam worked on the friction identification, the webcam development including acquisition<br />

and processing. He also worked on the organization, <strong>for</strong>matting, and proofreading of this<br />

report, and the Plan, the Cost, test procedures in Schedule, and part of the Unanticipated<br />

Challenges sections.<br />

Phil worked on the modeling and. This includes developing the Simulink block diagram<br />

<strong>for</strong> the non-linear model, identification of the inertia and center of mass properties from<br />

SolidWorks, and gravity and friction simulation of the model. He also updated the schedule.<br />

Will worked on the design of the mechanical system, getting the parts machined, assembling<br />

the system, and did some threshold value tuning on the webcam. Also wrote the majority<br />

of Unanticipated Challenges and Prognosis.<br />

Akilah Harris-Williams Adam Olmstead<br />

Phil Pratt-Szeliga Will Roantree<br />

24


Bibliography<br />

[1] Prof. Joe Chow. Course notes. Control System Engineering, 2004.<br />

[2] SolidWorks Corporation. Api support. http://www.solidworks.com/pages/services/<br />

APISupport.html.<br />

[3] The MathWorks Inc. Image acquisition toolbox user’s guide. http://www.mathworks.<br />

com/access/helpdesk/help/toolbox/imaq/.<br />

[4] The MathWorks Inc. Image processing toolbox user’s guide. http://www.mathworks.<br />

com/access/helpdesk/help/toolbox/images/.<br />

[5] Dana Advanced Automated Systems. Casting robot d&a101. http://www.novindana.<br />

com/da101.shtml.<br />

[6] Prof. John Wen. Lecture 4. Control System Design Course Notes, 2005.<br />

25


Appendix A<br />

Mechanical System SolidWorks<br />

Figure A.1: SolidWorks Model<br />

26


Appendix B<br />

Simulation Block Diagrams<br />

Set Parameters<br />

0<br />

Input Torque<br />

0.0001<br />

Original Volume<br />

1<br />

tau<br />

2<br />

volume<br />

Saturation<br />

tau<br />

volume<br />

theta<br />

volume_out<br />

Pan−tilt dynamics<br />

theta<br />

volume<br />

Image Processing Simulation<br />

volume_out<br />

Figure B.1: Simulink Diagram of Pan-Tilt Simulation: Complete System<br />

tau<br />

theta<br />

thetadot<br />

volume<br />

Subsystem<br />

thetaddot<br />

volume_out<br />

180/pi<br />

Gain<br />

theta_ddot<br />

To Workspace2<br />

Theta2 ddot scope<br />

1<br />

s<br />

thetaddot −> thetadot<br />

1<br />

s<br />

thetadot−>theta<br />

theta_dot<br />

To Workspace<br />

Theta2 dot scope<br />

Saturation<br />

(180 deg)<br />

Figure B.2: Simulink Diagram of Pan-Tilt Simulation: Pan-Tilt System<br />

27<br />

180/pi<br />

Gain1<br />

180/pi<br />

Gain2<br />

1<br />

theta<br />

2<br />

volume_out<br />

Terminator<br />

theta<br />

To Workspace1<br />

Theta2 scope


2<br />

theta<br />

3<br />

thetadot<br />

4<br />

volume<br />

1<br />

tau<br />

theta<br />

volume<br />

G(theta)<br />

Gravity Load<br />

thetadot Friction Matix<br />

F(qdot)<br />

IXX<br />

u[1]/(u[2]+N2^2*Im2)<br />

2<br />

volume_out<br />

Fcn1<br />

1<br />

thetaddot<br />

Figure B.3: Simulink Diagram of Pan-Tilt Simulation: Pan-Tilt Dynamics Subsystem<br />

2<br />

1<br />

theta<br />

volume<br />

center of mass Z (u[1])<br />

mB (u[2])<br />

−u[2]*g*u[1]<br />

Figure B.4: Simulink Diagram of Pan-Tilt Simulation: Gravity Loading Subsystem<br />

28<br />

G2<br />

1<br />

G(theta)


Appendix C<br />

Friction ID MATLAB Code<br />

C.1 Static Friction Identification<br />

% Adam Olmstead<br />

% Team 1 <strong>ECSE</strong>-4692<br />

% Static Friction Identification<br />

% 2-28-05<br />

% Initialize Variables<br />

torque_sat=1.0557;<br />

stat_fric=zeros(1,2);<br />

clear temp_vel;<br />

temp_vel=zeros( tg.get(’stoptime’)/0.001+1,1 );<br />

%%%% Static friction testing<br />

% Remove initial impulse if it’s there<br />

setparam(tg,24,0);<br />

setparam(tg,31,0);<br />

setparam(tg,25,0);<br />

setparam(tg,32,0);<br />

% Loop <strong>for</strong> both motor directions<br />

<strong>for</strong> i=-1:2:1<br />

% Do a rough pass to find to nearest tenth<br />

<strong>for</strong> tor=0.01:0.01:torque_sat<br />

setparam(tg,27,sign(i)*tor);<br />

start(tg);<br />

29


end<br />

while tg.get(’ExecTime’)0<br />

break<br />

end<br />

pause(3);<br />

% Assign value to nearest tenth<br />

coulomb_tor=tor;<br />

% Pause to let motor stop<br />

pause(3);<br />

end<br />

% Do a finer pass to find nearest thousandth<br />

<strong>for</strong> tor=coulomb_tor:-0.001:coulomb_tor-0.02<br />

setparam(tg,27,sign(i)*tor);<br />

start(tg);<br />

while tg.get(’ExecTime’)


C.2 Coulomb and Viscous Friction Identification<br />

% Adam Olmstead<br />

% Team 1 <strong>ECSE</strong>-4692<br />

% Friction Identification Script<br />

% 2/28/05<br />

% Initialize Variables<br />

vss_sat=0.11;<br />

count=0;<br />

tests=5;<br />

% Torque and Time Vectors<br />

torque=-vss_sat:0.001:vss_sat;<br />

time=0:0.001:tg.get(’stoptime’);<br />

% Hold average velocity values <strong>for</strong> each torque value<br />

clear vels;<br />

vels=zeros( tg.get(’stoptime’)/0.001+1,2*vss_sat/0.01+1 );<br />

% Hold velocity values recorded be<strong>for</strong>e averaging<br />

clear temp_vel;<br />

temp_vel=zeros( tg.get(’stoptime’)/0.001+1,tests );<br />

%%%% Friction Testing Data Collection<br />

% Only one set of motors being tested at a time<br />

setparam(tg,31,0);<br />

setparam(tg,32,0);<br />

% Loop to gain data from motors at various torque values<br />

<strong>for</strong> tor=-vss_sat:0.001:vss_sat<br />

% Hit the system with an impulse to break coulomb friction<br />

setparam(tg,24,sign(tor)*1.0557);<br />

% Command the desired torque at 0.25 seconds<br />

setparam(tg,25,0.25);<br />

setparam(tg,27,sign(tor)*(1.0557-abs(tor)));<br />

% Run the motors 5 times to reduce errors<br />

<strong>for</strong> j=1:1:tests<br />

% Begin the motor and wait <strong>for</strong> the motors to run<br />

start(tg);<br />

while tg.get(’ExecTime’)


end<br />

end<br />

end<br />

% Store data from that run<br />

temp_vel(:,j)=tg.outputlog(:,1);<br />

% Wait <strong>for</strong> motors to stop completely<br />

pause(3);<br />

pause(3);<br />

% Store the average values into final<br />

count=count+1;<br />

vels(:,count)=mean(temp_vel’)’;<br />

%%%% Friction Calculation<br />

% Create a lowpass filter to remove noise<br />

[num,den]=butter(10,0.04);<br />

clean=filter(num,den,vels2);<br />

% Plot the family of filtered steady state velocity curves<br />

plot(time,clean);<br />

xlabel(’Time (s)’);<br />

ylabel(’Velocity (rad/s)’);<br />

title(’Velocity vs Time <strong>for</strong> Various Input Torques’);<br />

% Find the steady state velocities <strong>for</strong> each run<br />

vss=mean(clean(ceil(0.9*length(clean)):length(clean),:));<br />

% Plot the torque vs. steady state velocities<br />

figure,plot(vss,torque,’x’);<br />

hold,plot(zeros(1,2),stat_fric,’x’);<br />

xlabel(’Steady-State Velocity (rad/s)’);<br />

ylabel(’Applied Torque (Nm)’);<br />

title(’Torque vs. Steady-State Velocity’);<br />

% Generate the best fit lines<br />

ind1=min(find(vss>0.95*vss(1)))-1;<br />

ind2=max(find(vss0.003));<br />

ind4=max(find(vss


fit2=polyfit(vss(ind1:ind2),torque(ind1:ind2),1);<br />

% Add the best fit line to the plot<br />

plot(vss(ind1:ind2+1),polyval(fit2,vss(ind1:ind2+1)));<br />

plot(vss(ind3-1:ind4),polyval(fit1,vss(ind3-1:ind4)));<br />

hold;<br />

% Return the friction values<br />

coulomb_fric=[polyval(fit2,0) polyval(fit1,0)];<br />

viscous_fric=[fit2(1) fit1(1)];<br />

33


Appendix D<br />

Image Acquisition MATLAB Code<br />

% Adam Olmstead<br />

% Team 1 <strong>ECSE</strong>-4692<br />

% Image Acquisition Script<br />

% Create an image acquisition object<br />

vid=videoinput(’winvideo’,1);<br />

% Causes videoinput to loop endlessly until stopped<br />

set(vid,’TriggerRepeat’,Inf);<br />

% Initialize variables<br />

res=vid.VideoResolution;<br />

res=[res(2) res(1) 3];<br />

filt=ones(res(1)*res(2),1);<br />

data=[];<br />

time=[];<br />

%start(tg);<br />

% Start image acquisition<br />

start(vid);<br />

% Using <strong>for</strong> loop <strong>for</strong> testing. In final project, will be changed to an<br />

% infinite loop, unless broken by the user<br />

<strong>for</strong> i=1:100<br />

% Used <strong>for</strong> timing analysis<br />

tic<br />

% Wait <strong>for</strong> a frame to be available (system bottleneck is the<br />

34


end<br />

% framerate of the webcam)<br />

while vid.FramesAvailable==0<br />

end<br />

% Save the last acquired frame (if more than one)<br />

data=getdata(vid,get(vid,’FramesAvailable’));<br />

image=data(:,:,:,size(data,4));<br />

% Call the image processing function<br />

pixrow=howmuch(image);<br />

% Send the data to xPC target<br />

setparam(tg,27,pixrow);<br />

% Add the time from the beginning of the loop to the time log<br />

time=[time; toc];<br />

% Stop the video<br />

stop(vid);<br />

35


Appendix E<br />

Image Processing MATLAB Code<br />

function pixrow=howmuch(I);<br />

%PIXROW=HOWMUCH(I);<br />

% Function takes in an RGB <strong>for</strong>matted image from the webcam. It analyzes<br />

% this image and returns the highest pixel row that contains liquid. This<br />

% is done using color detection of the red-dyed water<br />

%<br />

% Author: Adam Olmstead <strong>for</strong> <strong>ECSE</strong>-4692 Rensselaer Polytechnic Institute<br />

% Set the boundaries <strong>for</strong> the pixels<br />

leftbound=10;<br />

rightbound=size(I,1)-leftbound;<br />

% Set color component thresholds<br />

redthresh=255;<br />

greenthresh=255;<br />

bluethresh=255;<br />

% Only look at the a certain portion of the cup. The image should be on its<br />

% side (knob to left), as the horizontal resolution of our camera is better<br />

% than the vertical resolution<br />

I=I(leftbound:rightbound,:,:);<br />

avg=mean(I(:,:,:));<br />

% Apply threshold values to the averages. Finding the max will find the<br />

% rightmost pixel column whose average meets the threshold requirements.<br />

% This corresponds to the highest point in the cup<br />

pixrow=max( find(avg(:,:,2)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!