HW3: Energy-Based Systems Modeling in Modelica ME6105 Modeling and Simulation in Design For: Dr. Christiaan Paredis By: Josh Anders, Mark Overmyer and Krista VanSciver 11/1/2011 2 HW3: Energy-Based Systems Modeling in Modelica TABLE OF CONTENTS Table of Figures .............................................................................................................................................................3 Table of Tables ...............................................................................................................................................................4 Report: Energy-based systems modeling in modelica ...................................................................................................5 Task 1: Define Your Goals and Problem Domain .......................................................................................................5 Problem, Context and Level of Abstraction ..........................................................................................................5 Specific Questions to Answer ...............................................................................................................................6 Simulation Problem Versus Design Problem ........................................................................................................7 Task 2: System and Simulation Specification ............................................................................................................7 Components and Component Interactions ..........................................................................................................7 Assumptions, Physical Phenomena and Abstractions ..........................................................................................8 Task 3: Create Your Models in Dymola......................................................................................................................9 The Motor/Power Supply Models ......................................................................................................................10 The Shaft and Tissue Model ................................................................................................................................14 The Controller Models ........................................................................................................................................16 Task 4: Verification ..................................................................................................................................................18 Motor Drive Verification .....................................................................................................................................18 Gearbox Verification ...........................................................................................................................................21 Controller Verification ........................................................................................................................................22 Task 5: Experimentation and Interpretation ...........................................................................................................22 Motor Experimentation and Interpretation .......................................................................................................22 Gearbox Experimentation and Interpretation ....................................................................................................28 Controller Experimentation and Interpretation .................................................................................................29 Task 6: Lessons Learned ..........................................................................................................................................34 Task 7: Project Web-Page ........................................................................................................................................35 Appendices ..................................................................................................................................................................36 Appendix A – Modelica Code ..................................................................................................................................36 Motor Assemblies ...............................................................................................................................................36 Shaft and Tissue ..................................................................................................................................................42 Controllers ..........................................................................................................................................................48 Appendix B – Detailed Test Results .........................................................................................................................51 PID Controller Testing .........................................................................................................................................51 Appendix C – Brushless DC Motor Model ...............................................................................................................55 Bibliography .................................................................................................................................................................63 November 1, 2011 Table of Figures TABLE OF FIGURES Figure 1: Early controller prototype ..............................................................................................................................8 Figure 2: High Level Device Model ..............................................................................................................................10 Figure 3: Representative DC motor model (Brushed DC 28DT12) ...............................................................................11 Figure 4: H-Bridge Modelica block ...............................................................................................................................12 Figure 5: PWM converter ............................................................................................................................................12 Figure 6: Simple battery layout ...................................................................................................................................13 Figure 7: Motor and Drive Sub-Assembly layout .........................................................................................................13 Figure 8: Gears and Shaft model .................................................................................................................................14 Figure 9: Main transection force profile with three disturbances ...............................................................................15 Figure 10: Tissue Model, which includes force profile. ...............................................................................................15 Figure 11: Determine_Output_Direction Model .........................................................................................................17 Figure 12: Basic_Controller Model ..............................................................................................................................18 Figure 13: Free Speed verification setup .....................................................................................................................19 Figure 14: Brushed Motor Speed Response ................................................................................................................19 Figure 15: Brushless Motor Speed response ...............................................................................................................20 Figure 16: Stall torque test setup ................................................................................................................................20 Figure 17: Brushed DC stall torque performance ........................................................................................................20 Figure 18: Brushless DC stall torque performance ......................................................................................................21 Figure 19: Preliminary Controller simulation results ...................................................................................................22 Figure 20: Model to experiment with PWM period ....................................................................................................23 Figure 21: Motor Speed at PWM periods of 1E-2, 1E-3 and 1E-4 seconds, respectively ............................................23 Figure 22: Motor rotational inertia test setup ............................................................................................................24 Figure 23: Transection Time increases linearly as motor inertia increases .................................................................25 Figure 24: Force vs. Time, Brushed DC ........................................................................................................................26 Figure 25: Current vs. Time, Brushed DC .....................................................................................................................26 Figure 26: Force vs. Knife Position, Brushed DC ..........................................................................................................27 Figure 27: Force vs. Time, Brushless DC ......................................................................................................................27 Figure 28: Current vs. Time, Brushless DC ...................................................................................................................27 Figure 29: Force vs. Knife Position, Brushless DC ........................................................................................................28 Figure 30: Knife Position and Force versus Time for Varying Gearbox Ratios .............................................................29 Figure 31: Transient system response to a PID controller ...........................................................................................31 Figure 32: Plots of No controller and P-Controller results for brushed motor ............................................................33 Figure 33: Plots of No controller and PD-Controller results for brushless motor .......................................................34 November 1, 2011 3 4 HW3: Energy-Based Systems Modeling in Modelica TABLE OF TABLES Table 1: Motor Verification Results .............................................................................................................................19 Table 2: Motor Verification Results .............................................................................................................................21 Table 3: Inertial Effects on Transection Time ..............................................................................................................24 Table 4: Performance Comparison, DC motors ...........................................................................................................26 Table 5: Summary of PID testing results for DC Brushed Motor .................................................................................33 Table 6: Summary of PID testing results for DC Brushless Motor ...............................................................................33 Table 7: PID Methodology Testing Results ..................................................................................................................51 Table 8: DC Brushed Motor PID Detailed Testing Results............................................................................................52 Table 9: DC Brushless Motor PID Detailed Testing Results ..........................................................................................54 November 1, 2011 Report: Energy-based systems modeling in modelica REPORT: ENERGY-BASED SYSTEMS MODELING IN MODELICA TASK 1: DEFINE YOUR GOALS AND PROBLEM DOMAIN PROBLEM, CONTEXT AND LEVEL OF ABSTRACTION Today, to provide some context, laparoscopic surgery minimizes patient risk, discomfort and post-op scarring by performing typical surgical procedures through one or more access ports made in the abdominal wall of a patient. Special devices exist to enable standard surgical tasks to be accomplished through the dimension constraints of the access ports. A Linear Transecting Clamp (LTC) is used for clamping and transecting tissue in laparoscopic procedures. LTC’s transect tissue by securing it between two transversely moving jaws and axially advancing a knife. To accomplish the axial transection, current LTC’s require surgeons to input high forces into passive mechanical mechanisms, which lead to fatigue. The problem statement can be clarified by the desire to create an actively driven (powered) Linear Transecting Clamp (LTC) that achieves minimum knife stalls, failures, transection time and length error, while minimizing device cost and maximizing device availability. Device cost can be measured through research into off-the-shelf component costs. Additionally, manufacturing methods can be factored in to provide a more complete picture. More specifically, to highlight some problem statement specifications, the knife of the LTC must move forward (distally) and backward (proximally) within a specified window when subjected to known tissue forces, which shall be disclosed later within this work. Additionally, a number of firings (45) and time between firings (30 seconds) is defined from homework #2. A home position is established at zero within an error of plus or minus two millimeters. The maximum position, and thus the true transection length, is defined as 200 millimeters, plus zero, minus four millimeters. Finally, the maximum knife force and mass are set to 150 Newtons and 0.1125 kilograms, respectively. The force necessary to transect tissue is characterized by two profiles: the main transection force profile and the impulse profile. Additionally, the knife of the device is subjected to a retraction profile. For all force profiles, compressive force on the knife will be indicated as positive. Profiles are available later in this document and are further outlined from homework #2. The level of abstraction will break the problem down into more simplistic sub-models as follows: LTC motors, LTC controllers, LTC gearboxes and LTC knife. The environment will be created by a modeled tissue medium based on aforementioned and outlined force profiles. As previously mentioned in homework #2, modifications to the knife, clamping mechanism or distal end-effector are not in scope, and will not be considered in the design decision. In summary, the sub-models to be created are as follows: Motors, Controllers, Gearboxes, and Knife and Tissues. November 1, 2011 5 6 HW3: Energy-Based Systems Modeling in Modelica SPECIFIC QUESTIONS TO ANSWER The following information, in some cases, restates the information provided in homework #2. However, additionally, information is also provided to clarify the specific questions to be answered in homework #3. When there is a conflict from homework #2 to homework #3, a justification is provided. From earlier (homework #2), the decision alternatives being considered for this project are: the motor type, the motor’s (or device’s) thermal management system, the rack and pinion ratios, and the type of feedback control loop. After further considerations of an energy-based model, the following will constitute our decision alternatives: the motor type, the gearbox ratios, and the type of feedback control loop. When considering the two deltas, it is important to note that a thermal management system was removed. As the motor heats up, the internal resistance will increase, creating a limit on the motor’s current, torque and ultimately output force. This will be neglected. Furthermore, the effects of heating in general, most notably on the motor and knife due to friction, have been removed. The basis for this removal lies primarily in the lack of specification for thermal properties available on the selected off the shelve motors to be defined later. Additionally, as requested based on homework #2 feedback, the thermal affects and potential management system have been removed in an effort to simplify the model and design questions to be asked. From homework #2, it was stated that motor types would be limited to DC motors, with a decision to either design toward an inexpensive, brush motor or a more expensive, high accuracy, controllable brushless motor. After further consideration, it was confirmed that these two motor types would be investigated. Along with the motor selection, a decision alternative, comes the design variable of the motor constant (K, measured in Newtons per Amperage). As the SI units suggest, this is commonly known as the current to torque ratio and defines the maximum force that the motor can output, and ultimately the maximum force at which the transecting knife can be driven thru the tissue. The motor’s voltage source, a second design variable, defines the maximum speed at which the knife can be driven. This speed, or time required to transect the necessary displacement value, coupled with the tissue (medium) thickness creates an interesting trade-off decision. A small thickness and large voltage source creates a scenario for minimum transection time. Inversely, a large thickness and small voltage source results in a maximum transection time. After playing with the energy-based model, these variables were ultimately replaced with motor pulse width modulation (PWM) period and motor rotational inertia. As the motor creates rotational mechanics, a rack and pinion design is responsible for taking this drive and converting it to linear translational mechanics to drive the knife through the tissue. The gear ratio of the rack and pinion design, another design variable, is responsible for determining the conversion of motor speed to speed of the knife through the tissue. However, after consideration of the motor’s rotational output, it was further determined that a more detailed gearbox was needed to effectively reduce and control the motor output. Thus, more generally, the term “gearbox ratio” will be used in place of “rack and pinion ratios”. November 1, 2011 Report: Energy-based systems modeling in modelica Lastly, the type of feedback is a critical design alternative. A simple, inexpensive, open-loop feedback controller could potentially suffice. However, with the constraints associated with the small displacement window, desired completion time and random media force spikes (described in homework #2), we hypothesized that a higher cost, proportional-integral-derivative (PID) loop feedback controller is more appropriate. After further review and study, it was determined that the following types of controller situations would be evaluated against the two aforementioned motor types: no controller, P-controller, PI-controller, PD-controller, and PID-controller. In summary, the new design questions to be answered are as follows: Which motor type is most effective for our application – an inexpensive, brush motor or a more expensive, high accuracy, controllable brushless motor? What are the impacts of altering the following motor design variables: PWM period and motor rotational inertia? What is the impact of altering the system’s gearbox ratios? What is the most beneficial type of PID controller, assuming a PID controller is required to improve achieving the design objectives? As a reminder, the design objectives that will be included in the energy-based model include transection time, or transection speed, the knife force, and the displacement accuracy. SIMULATION PROBLEM VERSUS DESIGN PROBLEM The simulation problem clearly fits in the context of the design problem previously defined in homework #2 and in the introductory section of this particular work. The goal is to model a motor-driven LTC that can act against tissue to perform a cutting action with a specified accuracy both spatial and over time. Our model includes a question regarding a type of motor, which is an integral part of a motor-driven LTC. Additionally, the type of controller is questioned within the model, which has a great impact of narrowing down the specific cut distance and cut time to accomplished said distance. Lastly, the model includes a gearbox, knife and environment, or tissue force profile, for accurately relating the remainder of the model to the design problem at hand – creating a driven Linear Transecting Clamp. TASK 2: SYSTEM AND SIMULATION SPECIFICATION COMPONENTS AND COMPONENT INTERACTIONS In order to move further with modeling in Dymola with the Modelica language, it is important to very simply and succinctly discuss the components and their interactions with one another. November 1, 2011 7 8 HW3: Energy-Based Systems Modeling in Modelica The components within the model can be broken down further into the following list: a selectable motor type (either brushed or brushless), gearbox, controller, knife and tissue (or, as defined by the Task 2 prompt, the environment that is not truly identified as a system component). Solely looking at the motor, or motor type, each motor outputs a motor current, motor angle, motor speed and, most importantly, a rotational mechanical output shaft, or the rotational flange of a shaft. This motor output shaft, or rotational energy, is input into a gearbox, which outputs a position sensor and a translational flange to a knife. The position input is fed into a controller, which provides forward and backward information back to the motor type, whether brushed or brushless, to determine which direction the motor should turn. Lastly, the knife is driven to act against a tissue medium or, a medium acts against the knife with an input force as modeled by a force curve to be disclosed in a latter section. A specific example of an early prototype controller specification can be found below. Figure 1: Early controller prototype ASSUMPTIONS, PHYSICAL PHENOMENA AND ABSTRACTIONS As mentioned previously, throughout our model we are neglecting the thermal affects and impacts of heat on the system. For example, as the motor heats up, the internal resistance will increase, creating a limit on the motor’s current, torque and ultimately output force. However, this is being neglected. Additionally, the friction of the tissue on the knife and the heat generation will be neglected and rolled into the model of tissue force on the knife. Another assumption made involves property similarities used from the brushless motor from a normal brushed motor explained below. The use of this carry-over is to generate some level of simplicity in an otherwise complex November 1, 2011 Report: Energy-based systems modeling in modelica model. The brushless motor will not account for multiple poles and constants. It will also not use controllers to direct current to the multiple poles. These tasks are outside of the scope of the current design problem and questions to be answered. The H-bridge used shall be a very simplified model, which, again, ignores the effects of heat. The additions of constraints such as heat, time responses and electrical components would make the H-bridge more realistic. However, again, this is outside the scope of the design problem. The tissue force model is assumed to be correct, accurate and representative of the actual forces that would be experienced by the knife as it cuts through human tissue. However, considering the variation from healthy skin to unhealthy skin, from person to person, from circumstance to circumstance, the profile used in this experimentation is likely to simplistic. A more realistic approach would likely involve the use of a Monte Carlo simulation. Lastly, for simplification, in several instances the impacts of inertia shall be excluded for simplicity purposes. An example of this can be found in the idealized gears and rolling wheel models within their respective sub-assembly. The physical phenomena and energy-domains that will be considered in the energy-based model include the following Dymola/Modelica categories: electrical, rotational mechanical, translational mechanical, and math operational blocks. The electrical domain shall be employed with the motor assembly. The rotational mechanical domain will be used with the motor as well, potentially needing to account for motor damping. The translational mechanical domain will be required while considering the transition of motor work to knife movement via the rack and pinion and gearbox design. Additionally, a function will need to be generated to represent the randomness of the force spikes generated from biological tissue variability. The math operational blocks will be used throughout, including in the controller design. As a summary, the physical phenomena abstracted away primarily include thermal and tissue variability affects. These phenomenon are abstracted away, as recommended from homework #2 review, in an effort to reduce the complex of the simulation and design problem. TASK 3: CREATE YOUR MODELS IN DYMOLA Figure 2 below shows the high level model created to simulate our device. The following sections will describe the indicated sub-systems in detail. November 1, 2011 9 10 HW3: Energy-Based Systems Modeling in Modelica basic_? Position Controller pWM_C? brushe? gears_? pWM_C? Motor/Power Supply Gearbox/Knife Tissue Figure 2: High Level Device Model THE MOTOR/POWER SUPPLY MODELS HW2 specified that a previously human powered device would be powered using motors. The sections below disclose custom Modelica blocks we developed to model DC motors and their controllers to provide the required automation. DC MOTOR Motor type is a key variable under consideration for this project. To investigate this variable, two motor models were created. Both models simulate the winding resistance, winding inductance, electrical to mechanical conversion factor, damping and rotor inertia. The first model uses characteristics of an off-the-shelf Brushed DC motor, 28DT12 (1). The second model uses characteristics of an off-the-shelf Brushless DC motor, 22BHM (1). Figure 3 below shows the layout of the generalized DC motor model. These two motors models were selected because they have similar physical packages, but represent two types of DC motors. The effect of heating on the motor winding resistance was not considered for this analysis, due to the lack of heat related specification. However, since temperature is linearly related to resistance, resistance is linearly related to current (all else the same), and current is linearly related to torque, adding heat effects would make this model more accurate, especially when prolonged use characteristics are needed. It is important to note that the model for the brushless motor uses equivalent properties for a normal brushed motor, for simplicity. It does not account for multiple poles or motor constants, nor does it include the necessary controllers used to direct current to the poles. An attempt to create a detailed model of the brushless motor is demonstrated in Appendix C. The model was never able to generate realistic results. However, it is important to November 1, 2011 Report: Energy-based systems modeling in modelica note the large amount of added complexity inherent in the use of a brushless motor. Any added performance will have to be weighed against the time and cost associated with such complexity. heatingResistor pin_p inductor L=.00075 k=.0325 emf pin_n inertia flange_b J=.0000020 Figure 3: Representative DC motor model (Brushed DC 28DT12) H-BRIDGE An H-bridge block was developed to allow for direction control of the motor models disclosed above. Figure 4 below shows that the H-bridge is comprised of simple switches (instead of the usual MOSFETS or similar). The negative and positive terminals are intended to be connected to a DC source (a battery in our case). The Motor_A and Motor_B terminals are connected to the electrical inputs of the motor blocks. By making the forward Boolean input high and the reverse Boolean low, the positive terminal is connected to the positive terminal of the motor, the negative is connected to ground and the motor spins in the positive direction. Reversing the Boolean inputs reverses the motor. The H-bridge block used in our modeling is a very simplified representation of an actual H-bridge. It was not in scope of our project, but adding heating effects, and the actual time responses and constraints of electrical components would make this block more accurate. November 1, 2011 11 12 HW3: Energy-Based Systems Modeling in Modelica Negativ? Positive? forw ard reverse Motor_A Motor_B Figure 4: H-Bridge Modelica block PWM CONVERTER Motor current control was accomplished through Pulse Width Modulation (PWM). A custom block was created to convert a real duty cycle value (number between 0 and 100) input from the motor controller to a Boolean PWM signal. The block consists of a modified pulse block and a greater than/equal to block with a threshold of 1. The modified pulse block takes the real duty cycle value in and outputs a pulse with said duty cycle at of a given period, and a height of 1. The job of this block would typically be accomplished by a microcontroller. Adding minimum period constraints (to reflect actual clock times) and clock errors (due to temperature and shock) would make this block more realistic. Duty_Cycle pulse PWM >= period=.001 Figure 5: PWM converter November 1, 2011 1 Report: Energy-based systems modeling in modelica SIMPLE DC BATTERY A Simple Battery was modeled using a constant voltage and a simulated internal battery resistance, and is shown in Figure 6 below. The voltage was set that the specified motor voltage for the off-the-shelf motors discussed above (24v). The internal resistance was a ball park figure for Lithium Ion cells. This model could be made more accurate by modeling the increasing in resistance due to temperature rise in the battery. However, insufficient information exists regarding the thermal properties to enable this within the scope of this assignment. pin_p pin_n resistor + - R=2.5 constantVolta? Figure 6: Simple battery layout MOTOR AND DRIVER SUB-ASSEMBLIES The components discussed above were assembled according to Figure 7 below. In Figure 7, sensors were added to measure current, rotor angle and rotor speed. Note that the forward and reverse inputs would be connected to external PWM converter blocks. Two versions of the model shown in Figure 7 were created, one for each of the DC motor blocks. That way, the sub-assemblies could be exchanged within the high level model to investigate the effect different motor types. dC24_s? Motor_Current forw ard h_Bridge angleSensor motor_angle speedSensor motor_speed w reverse output_? Figure 7: Motor and Drive Sub-Assembly layout November 1, 2011 13 14 HW3: Energy-Based Systems Modeling in Modelica THE SHAFT AND TISSUE MODEL The gear/shaft and tissue models were separated in Dymola for clarity and ease of use. GEARS AND SHAFT The model for the Gears and Shaft sub-assembly can be found below. s1 positionSensor s idealGear idealRollingW? mass Motor_C? knife_s? ratio=75 m=.2 damper d=.001 Figure 8: Gears and Shaft model The output shaft, a rotational flange of the selectable motor is fed into the model. As the revolutions per minute (RPM) is far too high for our application and critical system parameters (time and distance of cut, plus accuracy), the output is immediately met by an idealGear without inertia. This gear is modeled based on the off-the-shelf gearbox for the 28DT12 brushed motor and, as such, has a set number of available ratios (5.75, 17.4, 24, 33, 72.3, 99.8, 138, 190, 301, 416, 574, 792, 1090). At this point, the mechanics of the energy are still rotational. Therefore, an idealRollingWheel is implemented to convert the rotational energy into translational energy. From here, a mass is represented for the knife with a damper to a fixed object. A translational flange is representative of the knife that is acted upon by the following section describing the tissue resistance. Finally, a position sensor exports the knife position for motor control purposes previously described. TISSUE RESISTANCE As discussed in section 1, the tissue provides resistance against the knife during the transection process. The resistance used in this model is characterized by the main force profile shown below, which ranges from 0 to 100N, with an average sustained force of 70N. In addition, there is a nominal force of 20N acting against the knife during the retraction process. November 1, 2011 Report: Energy-based systems modeling in modelica Transection Force [N] 150 100 Nominal Transection Force [N] 50 Minimum Transection Force [N] 0 0 -50 50 100 150 200 250 Maximum Transection Force [N] Transection Position [mm] Figure 9: Main transection force profile with three disturbances To model the forces, we used the input from the knife position sensor (s) to 1) determine the position and 2) to determine if the velocity was positive or negative. If the velocity was positive, the model interpolated the appropriate force value based on the corresponding force values loaded in a combiTable in the Tissue model. If the velocity was negative, the model applied a constant force of 20N. The figure below is of the completed Tissue component model: Figure 10: Tissue Model, which includes force profile. November 1, 2011 15 16 HW3: Energy-Based Systems Modeling in Modelica THE CONTROLLER MODELS One of the design decisions articulated in homework #2 was to determine the type of feedback control to use with the model. The design objectives and requirements include: Controlling the position of the knife between 0 and 200 mm, with error tolerance of +0/-4 mm Providing a single cutting stroke to the maximum depth, then returning the knife to the home (0 mm) position Minimize cycle time Input to the controller model is knife position (s) Output from the controller model is forward / reverse duty cycle, since the Motor models were expecting this due to the inclusion of an H-bridge construct DETERMINE OUTPUT DIRECTION The first step in the design process was to generate the correct output to the Motor component so that the motor went forward for the cutting stroke, then reversed when the maximum depth was reached, then stopped when the knife returned to the home position. To model the forward cutting-stroke, we used the input from the knife position sensor (s) to 1) determine if the position was less than the maximum desired position and 2) to determine if the velocity was positive. If both of these conditions were true, the PID block was triggered, which sent a signal to the Go_Forward output connector. Since we planned to use a variable force profile to simulate the tissue resistance to the knife, we decided that a closed-loop PID controller design would likely provide the best performance results by our model. We intended to test the model both with and without the PID controller and compare the results. We have used the LimPID controller block from Modelica, rather than the simple (textbook) PID controller. The LimPID provides additional features, such as anti-windup compensation and set-point weighting for the proportional and derivative parts of the PID. Modeling the reverse stroke was a bit more complex. If the velocity was negative OR the knife position was greater than our maximum threshold AND the knife position was greater than zero (our home position), a signal was sent to the Go_Reverse output connector. To ensure that the device stopped when the knife returned to “home”, we added a terminate clause to the reverse path. The figure below is of the completed Determine_Output_Direction component model: November 1, 2011 Report: Energy-based systems modeling in modelica Figure 11: Determine_Output_Direction Model BASIC CONTROLLER The next step in the controller design was to convert the output of the Determine_Output_Direction component into a duty cycle form that the H-Bridge in the Motor component was expecting. This was simply done by multiplying the Go_Forward (or Go_Reverse) output by a constant (k=50) to generate the Forward_Duty_Cycle (or Reverse_Duty_Cycle) as appropriate. This was accomplished by the Basic_Controller component model, shown below: November 1, 2011 17 18 HW3: Energy-Based Systems Modeling in Modelica Figure 12: Basic_Controller Model TASK 4: VERIFICATION MOTOR DRIVE VERIFICATION The motor/controller blocks described in the Task 3 above were validated by ensuring their performance met the specifications of the off-the-shelf motors for free speed, mechanical time constant and stall force. Figure 13 below shows the test setup used to verify the free speed of the motors. Using the test setup, the Brushed DC motor produced the curve shown in Figure 14 below and the Brushless DC motor produced the curve shown in Figure 15 below. Figure 16 below shows the test setup used to verify stall current for the motor blocks, where the current source is set to the specified stall current. Using the test setup, the Brushed DC motor produced the curve in Figure 17 below and the Brushless motor produced the curve in Figure 18 below. The results of all verification activities are shown in Table 1 below. In Table 1, it can be observed that the measured values are close to the specification for all values except the time constant values. The error in the time constant is caused by the internal resistance of the battery used in the speed test setup. The resistance limits the high current drawn by the motor at initial startup, which increases the time constant. November 1, 2011 Report: Energy-based systems modeling in modelica Table 1: Motor Verification Results Motor Test Specification Measurement Unit % error Brushed Free Speed 712.0 726.0 rad/s 1.97 Brushless Free Speed 3082 2963 rad/s -3.87 Brushed Time Constant 0.012 0.020 S 66.7 Brushless Time Constant 0.003 0.025 S 733 Brushed Stall Torque 0.019 0.0120 Nm 2.63 Brushless Stall Torque 0.126 0.126 Nm 0.00 booleanConst? true brushe? booleanConst? false Figure 13: Free Speed verification setup Figure 14: Brushed Motor Speed Response November 1, 2011 19 20 HW3: Energy-Based Systems Modeling in Modelica Figure 15: Brushless Motor Speed response brushle? ground Figure 16: Stall torque test setup 0.0220 fixed.flange.tau 0.0215 0.0210 0.0205 0.0200 0.0195 0.0190 0.0185 0.0180 0.0175 0.0170 0.0 0.1 0.2 0.3 gears_and_Shaft.knife_surface.s Figure 17: Brushed DC stall torque performance November 1, 2011 0.4 0.5 Report: Energy-based systems modeling in modelica Figure 18: Brushless DC stall torque performance GEARBOX VERIFICATION To verify the gearbox model, the Shaft Validation area of the MainHW3 was utilized within the Dymola model. This area involved the capture of the Gears and Shaft model into a single custom component block. This block was feed by a k constant altered by a rotational source intended to convert the k constant input into an external torque on a flange. The output was fixed. A view of this setup is shown below. const torque gears_? tau k=.102 The two parameters used to demonstrate functionality where the k constant (or, in the large scheme, the motor input) and the gearbox ratio within the custom component block. The following results were found. Table 2: Motor Verification Results constant K (N-m) gear ratio knife surface force (N) 0 75 0 0.102 75 -1020 0.3 75 -3000 0.102 70 -952 0.102 75 -1020 0.102 100 -1360 Typically, the motor will be providing low force and high speed. Ideally, we want high force and low speed. This is the purpose for adding the gearbox to the LTC model. As expected, as the K constant is increased, or the input from the motor is increased, in the absence of a changing gearbox, the force of the knife is increased. Also, as expected, with a constant motor input and an increasing gear ratio, the speed is effectively reduced while the force is increased. Thus, we have completed verification with a gearbox acting as desired. November 1, 2011 21 22 HW3: Energy-Based Systems Modeling in Modelica CONTROLLER VERIFICAT ION To verify the controller models, Determine_Output_Direction and Basic_Controller, we used the Test_Area consolidated model. For verification, the PID block was configured as a P-controller, with k=1 so that we could study the interaction of the model components without the influence of the PID controller. The PID controller would be “tuned” (e.g., the parameters would be determined and tested) during Task 5: Experimentation and Interpretation. We also set our thresholds for our less than and greater than / equal to position blocks at .2, since our desired end position is .2 m. However, this caused significant overshoot in the knife position during simulation, so this was reduced to .149 for the preliminary model, which was tested with preliminary motor / knife models. Results of preliminary simulations, using the Test_Area consolidated model are below; the plot is of the threshold value = 0.193: Threshold value 0.2 0.197 0.196 0.195 0.194 0.193 Position (m) 0.2105 0.2043 0.20263 0.20122 0.20097 0.19944 Time for cutting (s) 2.33 2.29 2.28 2.27 2.27 2.26 Error (m) 0.0105 0.0043 0.00263 0.00122 0.00097 -0.00056 Figure 19: Preliminary Controller simulation results TASK 5: EXPERIMENTATION AND INTERPRETATION The main sub-systems of the powered linear transector are investigated in this section by perturbing their key inputs, recording the change in output and interpreting how that change will affect the performance of the device on the whole. MOTOR EXPERIMENTATION AND INTERPRETATION The key components of the motor and motor controller are investigated within this section. PULSE WIDTH MODULATION EXPERIMENTATION The motor controller for this device uses Pulse Width Modulation (PWM) to adjust the current to the model, in order to influence speed and position. To use PWM, a pulsed square wave of voltage is provided to the motor. If the period of the pulsed wave is small enough, the motor responds as if a smooth, reduced, current was applied. However, there is a limit the amount the period of a PWM pulse can be, which is usually constrained by the microcontroller. In our case, we are constrained by the solution step size – too small of a PWM period, and the number of solution steps necessary to accurately simulate the response will lead to unreasonable solution times. Therefore, it is desired to experiment with and optimize the PWM period. November 1, 2011 Report: Energy-based systems modeling in modelica 23 Figure 20 below shows a custom test setup used to experiment with PWM period. The setup uses a Boolean pulse wave of a configurable frequency to drive one of the motor/controllers introduced in Task 3 above. A torque source is attached to the rotor of the motor, with a output of half the motor’s stall torque. For this investigation, the Brushless DC motor was selected, because it is the most responsive, and therefore, the most susceptible to rough PWM pulses. booleanPulse const .0001 torque brushe? tau booleanConst? k=.063 false Figure 20: Model to experiment with PWM period The model in Figure 20 was then used to investigate PWM periods between 1E-2s and 1E-4s. The motor rotational velocity vs. time plots for three different PWM periods are shown below in Figure 21. In Figure 21, we observed an extremely rough steady state speed response when using a period of 1E-2s. For a period of 1E-3s, we observed a noticeably rough, but reasonably smooth response. For a period of 1E-4s, an absolutely smooth steady state motor speed was observed. However, the solution time for the 1E-4s, with the necessary solution steps to prevent clipping of the PWM wave, was over 60 seconds, a value that would only increase if this period was used for the full device model. Therefore, the 1E-3s period was selected for use in all future simulations. 1200 brushed_DC_35GL.speedSensor.w brushed_DC_35GL.speedSensor.w brushed_DC_35GL.speedSensor.w 1200 1000 1000 1000 800 800 800 600 600 600 400 400 400 200 200 200 0 0 0.00 0.04 0.08 0.12 0.16 0.00 0 0.20 0.04 0.24 0.08 0.12 0.16 0.00 0.20 0.04 0.24 0.08 Figure 21: Motor Speed at PWM periods of 1E-2, 1E-3 and 1E-4 seconds, respectively MOTOR ROTATIONAL INERTIA EXPERIMENTATION Many motor control applications call for the use of an encoder to track motor position. Unfortunately, because encoders attached to the shafts of the motor, they inherently add rotational inertia to the shaft. This section investigates the effect of adding rotational inertia to the motor shaft on the transection time of the system as a whole. November 1, 2011 0.12 0.16 24 HW3: Energy-Based Systems Modeling in Modelica In order to investigate inertial effects, the model shown in Figure 22 was created. In Figure 22, the high level model of the device (the brushed motor version) was modified to include an additional inertial element between the motor and gearbox rotational interface. That way, the new inertial could be directly modified, and the response recorded. Figure 22: Motor rotational inertia test setup The model shown in Figure 22 was run with inertias in multiples of the brushed motor shaft to create Table 3 and Figure 23 below. In Figure 23, we observed a linear increase in the transection time for each multiple of the shaft rotational inertia. This is a key trade-off to understand for sensor selection. Table 3: Inertial Effects on Transection Time Motor Shaft Inertia multiplier 1 Transection Time [s] 6.81 Difference from Baseline [s] 0 Percent Increase From Baseline 0 2 6.93 0.12 1.762114537 5 7.28 0.47 6.901615272 7 7.51 0.7 10.27900147 10 7.88 1.07 15.71218796 November 1, 2011 Report: Energy-based systems modeling in modelica 8 Transection Time 7.8 7.6 7.4 7.2 7 6.8 6.6 0 2 4 6 8 10 12 Motor Shaft Inertia Multiplier Figure 23: Transection Time increases linearly as motor inertia increases DC MOTOR TYPE (BRUSHED VS. BRUSHLESS) EXPERIMENTATION This section investigates the performance differences of the device level simulation when the Brushed and Brushless DC motors (introduced in Task 3) are used. Comparisons will be made between the time to make a complete transection, the position performance, and the current draw. For all simulations discussed, the gear ration in the shaft of the device was kept constant, and a PID controller tuned for each motor was used. November 1, 2011 25 26 HW3: Energy-Based Systems Modeling in Modelica Table 4 below compares key performance characteristics for simulation conducted with Brushed and Brushless DC motors. In November 1, 2011 Report: Energy-based systems modeling in modelica Table 4, it is clear that the brushless DC motor has a superior transection time to that of the Brushed DC. This is not a surprise, as the Brushless DC motor has a higher stall torque and free speed. The maximum current draw (initial current spike observed in current vs. time plots) is higher for the Brushless motor, since it has a lower winding resistance. This will need to be considered when designing a power supply – higher current usually means a higher price. The breaking current (highest current spike) is also higher for the Brushless motor. The breaking current is generated with a reverse voltage is put on the motor to rapidly slow it down. The higher breaking current is expected from the Brushless motor, because it has a higher voltage constant (acts as a more efficient generator) and has a higher speed. Again, this higher current spike will likely drive up power supply costs. Finally, November 1, 2011 27 28 HW3: Energy-Based Systems Modeling in Modelica Table 4 shows that, for a given Controller algorithm and shaft/tissue combination, the Brushless motor will overshoot more than the Brushed motor. This is to be expected, and PID tuning will resolve it. However, tuning the controller to achieve the same overshoot with the Brushless as achieved in the Brushed will increase the transection time for the Brushless. The observations in November 1, 2011 Report: Energy-based systems modeling in modelica Table 4 confirm that the Brushless motor has a higher power density, and therefore has better potential performance than the similarly sized Brushed motor. However, it is important to note that the increased performance inherent to the Brushless motor type comes at a cost of increased cost and complexity. November 1, 2011 29 30 HW3: Energy-Based Systems Modeling in Modelica Table 4: Performance Comparison, DC motors Performance Measurement Brushed DC Brushless DC Unit Relevant Figures Transection Time 6.2 2.6 Seconds Figure 24, Figure 27 Max. current draw 2.2 4.5 Amperes Figure 25, Figure 28 Max. breaking current 4.2 6.5 Amperes Figure 25, Figure 28 Position Overshoot 0.9 2.9 millimeters Figure 26, Figure 29 tissue.tissue_surface.f 100 80 60 40 20 0 -20 0 1 2 3 4 5 6 7 6 7 Figure 24: Force vs. Time, Brushed DC brushed_DC_28DT12_222E.currentSensor.i 4.0 3.6 3.2 2.8 2.4 2.0 1.6 1.2 0.8 0.4 0.0 0 November 1, 2011 1 2 3 4 Figure 25: Current vs. Time, Brushed DC 5 Report: Energy-based systems modeling in modelica Figure 26: Force vs. Knife Position, Brushed DC tissue.tissue_surface.f 100 80 60 40 20 0 -20 0.0 0.5 1.0 1.5 2.0 2.5 2.0 2.5 Figure 27: Force vs. Time, Brushless DC brushless_DC_imitation.currentSensor.i 7 6 5 4 3 2 1 0 0.0 0.5 1.0 1.5 Figure 28: Current vs. Time, Brushless DC November 1, 2011 31 32 HW3: Energy-Based Systems Modeling in Modelica Figure 29: Force vs. Knife Position, Brushless DC GEARBOX EXPERIMENTATION AND INTERPRETATION After review and initial simulations of the gearbox for the 28DT12 brushed motor, it was determined to experiment and comment on the following three gearbox ratios as measured as a transmission ratio of flange_a.phi/flange_b.phi: 33, 72.3 and 99.8. Initial study showed that anything less than these ratios created knife stalls as the torque was not great enough to cut through the tissue force profile. On the other hand, anything greater than these values resulted in high torque, but very low cutting speed that resulted in falling outside of the window of our experimentation interest (30 seconds) as defined from homework #2 as a travel time for the knife to go out from home and then return. The results of knife position and tissue force applied to knife are as following. Note that the DC brushed motor was used under constant properties. Thus, the only parameter that changed was the gearbox ratios to isolate a parameter of interest. tissue.knife_position tissue.tissue_surface.f 100 0.20 80 0.16 60 0.12 40 0.08 20 0.04 0 0.00 -20 0 2 4 6 8 10 0 Ratio: 33 November 1, 2011 2 4 6 8 10 Report: Energy-based systems modeling in modelica tissue.knife_position tissue.tissue_surface.f 100 0.20 80 0.16 60 0.12 40 0.08 20 0.04 0 0.00 -20 0 2 4 6 8 10 0 2 4 6 8 10 4 6 8 10 Ratio: 72.3 tissue.knife_position tissue.tissue_surface.f 100 0.20 80 0.16 60 0.12 40 0.08 20 0.04 0 0.00 -20 0 2 4 6 8 10 0 2 Ratio: 99.8 Figure 30: Knife Position and Force versus Time for Varying Gearbox Ratios From these profiles, we see a knife stall for the 33 ratio at approximately 3 seconds. The knife travels the desired distance then returns to home in approximately 4.5 seconds. Not enough torque was produced to overcome the tissue force profile. The ratio of 33 is eliminated from consideration. The ratio of 99.8 did complete the necessary travel without any apparent stalls in approximately 8.5 seconds. However, the off the shelve 72.3 also completed the same task in less than 6.5 seconds. The 72.3 gearbox ratio results in the most optimal range for torque conversion and cutting time in the absence of knife stalls and is thus recommended for further use in controller experimentation, tuning and interpretation. CONTROLLER EXPERIMENTATION AND INTERPRETATION This section is divided into two sub-sections. The first section reviews the characteristics of different types of controllers and their strengths and weaknesses. We also discuss transient response versus steady state trade-offs, and outline the methodology that was used to determine the parameters for the controller. The second section discusses our experimentation setup, experiment scenarios and results. November 1, 2011 33 34 HW3: Energy-Based Systems Modeling in Modelica PID CONTROLLER THEORY AND TUNING METHODOLOGY When considering the best controller for this application, it was useful to review the different types of controllers 1 and the strengths and weaknesses of each. For this application, we determined that a closed-loop feedback controller would be best since control of the knife position is critical to the application. The key measurement in our controller is the position; the objective is to move the knife to our maximum desired position as quickly as possible without over-shooting, then reverse the motor to return the knife to the home position. Proportional Controllers (P) The proportional controller is basically an amplifier of the error with an adjustable gain. The relationship of the output (u) to the error (e) is: 𝑢(𝑡) = 𝐾𝑝 𝑒(𝑡); Kp is the proportional gain. Integral Controllers (I) The integral controller is also known as reset control. The value of the output (u) is proportional to the error (e). Rather than measuring only the current error, as in proportional control, the integral controller measures (sums) the error over some interval of time. If the value of e doubles, then the value of u varies twice as fast. This relationship is shown by: 𝑡 𝑢(𝑡) = 𝐾𝑖 ∫0 𝑒(𝑡)𝑑𝑡 ; where Ki is the integral constant. Proportional plus Integral Controllers (PI) The proportional plus integral controller combines the features of both. The integral time adjusts the integral (reset) action, while a change in Kp affects both the proportional and integral parts. The relationship is: 𝑢(𝑡) = 𝐾𝑝 𝑒(𝑡) + 𝐾𝑝 𝑡 ∫ 𝑒(𝑡)𝑑𝑡; 𝑇𝑖 0 where Ti is the integral time. The inverse of Ti is the reset rate, which is the number of times per minute that the proportional part of the control is duplicated. The integral control used with a proportional control will remove offset or steady-state error, but may also lead to oscillatory response of the system. Proportional plus Derivative Controllers (PD) The derivative control action is called rate control and is where the controller output is proportional to the rate of change of the error. The derivative control has an advantage of being anticipatory, however, it has the disadvantage of amplifying noise and may saturate the actuator. The derivative control cannot be used alone since it is only effective during transient periods. 𝑢(𝑡) = 𝐾𝑝 𝑒(𝑡) + 𝐾𝑝 𝑇𝑑 1 Ogata, pp. 186 – 189; 219 - 224. November 1, 2011 𝑑𝑒(𝑡) 𝑑𝑡 ; where Td is the derivative time. Report: Energy-based systems modeling in modelica Derivative control action added to a proportional controller provides high sensitivity. Because it responds to the rate of change of error, it can produce significant correction before the error becomes too large. The derivative control adds damping to the system and tends to increase the stability. Proportional plus Integral plus Derivative Controllers (PID) The combination of all three control components has the advantages of each of the individual components. 𝑢(𝑡) = 𝐾𝑝 𝑒(𝑡) + 𝐾𝑝 𝑡 ∫ 𝑒(𝑡)𝑑𝑡 𝑇𝑖 0 + 𝐾𝑝 𝑇𝑑 𝑑𝑒(𝑡) 𝑑𝑡 Transient Response versus Steady-State In this application, analysis of a steady-state response is not relevant. Since we only have a single-cycle, with the knife approaching our target value, but not going over, we are primarily interested in the transient response characteristics of the system. For transient response, it is desirable that the transient response be sufficiently fast and sufficiently damped. The illustration below shows a typical system response to a PID controller 2; Mp is the maximum overshoot and tp is the time required to reach the maximum overshoot. In this application, it is desirable for Mp to get as close to 200 mm without going over and for tp to be as small as possible. Figure 31: Transient system response to a PID controller Tuning Methodology Since our model uses the Dymola LimPID object, we determined that the tuning methodology suggested by Dymola would be the best choice for tuning our model: “The parameters of the controller can be manually adjusted by performing simulations of the closed loop system (=controller + plant connected together) and using the following strategy: 2 Ogata, p 265 – 266. November 1, 2011 35 36 HW3: Energy-Based Systems Modeling in Modelica 1. 2. 3. 4. 5. 6. Set very large limits, e.g., yMax = Modelica.Constants.inf Select a P-controller and manually enlarge parameter k (the total gain of the controller) until the closed-loop response cannot be improved any more. Select a PI-controller and manually adjust parameters k and Ti (the time constant of the integrator). The first value of Ti can be selected, such that it is in the order of the time constant of the oscillations occurring with the P-controller. If, e.g., vibrations in the order of T = 10 ms occur in the previous step, stat with Ti = 0.01 s. If you want to make the reaction of the control loop faster (but probably less robust against disturbances and measurement noise) select a PID-controller and manually adjust parameters k, Ti, Td (time constant of the derivative block). Set the limits yMax and yMin according to your specification. Perform simulations such that the output of the PID controller goes in its limits. Tune Ni (Ni*Ti is the time constant of the anti-windup compensation) such that the input to the limiter block (= limiter.u) goes quickly enough back to its limits. If Ni is decreased, this happens faster. If Ni=infinity, the anti-windup compensation is switch off and the controller works bad.”3 Because maximum overshoot (Mp) is critical in this application, and must not be larger than 200 mm, the threshold values in the model will also be adjusted in conjunction with the suggested parameters in order to attain the appropriate PID performance. The tuning methodology was tested against early preliminary models; results of testing the methodology are included in Appendix B. EXPERIMENTATION RESULTS To determine the best performance of our model, we tested two scenarios, one with the DC brushed motor model and the other with the DC brushless motor model. For both of these scenarios, we used a fixed gearbox ratio of 72.3 and utilized the Dymola recommended tuning methodology described above. Our targeted maximum knife position is 200 mm, with a tolerance of +0 / -4 mm; key objectives are to minimize the cycle time while attaining position accuracy within acceptable tolerance levels. The sections below summarize the PID controller model testing results; detailed testing results are included in Appendix B. DC BRUSHED MOTOR The table below lists the best experimentation results for the DC brushed motor model, with a gear ratio of 72.3, attained in each category: 3 Dymola, LimPID Information. November 1, 2011 Report: Energy-based systems modeling in modelica 37 Table 5: Summary of PID testing results for DC Brushed Motor Type Position (m) Time Max Position (s) % Improvement Time Max Position Time Home Position (s) % Improvement Total Cycle Time No Controller 0.1999 3.6955 P-Controller 0.199 2.947 -20.25% 5.8405 -11.52% PI-Controller 0.199 2.947 -20.25% 5.9 -10.62% PD-Controller 0.199 2.947 -20.25% 5.8405 -12.00% PID-Controller 0.199 2.947 -20.25% 5.9024 -10.58% 6.6011 Conclusion: The model for the DC brushed motor attained the best performance using a simple P-controller. Using the P-controller provided an improvement of 20% in transection time and 11.5% improvement in overall cycle time. The PD-controller provided no additional improvement over the P-controller. The PI- and PID-controllers provided longer cycle times without providing better position control. The plots below illustrate the No Controller and P-Controller results: Figure 32: Plots of No controller and P-Controller results for brushed motor DC BRUSHLESS MOTOR The table below lists the best experimentation results for the DC brushless motor model, with a gear ratio of 72.3, attained in each category: Table 6: Summary of PID testing results for DC Brushless Motor Type Position (m) Time Max Position (s) % Improvement Time Max Position Time Home Position (s) % Improvement Total Cycle Time No Controller 0.1994 1.689 P-Controller 0.1991 0.85 -49.67% 1.7 -32.94% PI-Controller 0.1991 0.85 -49.67% 1.701 -32.90% PD-Controller 0.1991 0.85 -49.67% 1.695 -33.14% PID-Controller 0.1991 0.85 -49.67% 1.702 -32.86% 2.535 November 1, 2011 38 HW3: Energy-Based Systems Modeling in Modelica Conclusion: The model for the DC brushless motor attained the best performance using a PD-controller. Using the PD-controller provided an improvement of almost 50% in transection time and 33% improvement in overall cycle time. As with the brushed motor, the PI- and PID-controllers provided longer cycle times without providing better position control. The plots below illustrate the No Controller and PD-Controller results: Figure 33: Plots of No controller and PD-Controller results for brushless motor SUMMARY OF PID CONTROLLER MODEL TESTING Overall, the DC brushless motor model provided 71% faster cycle time than the brushed motor, reducing the transection time from ~3 seconds to less than 1 second, and reducing the overall cycle time from almost 6 seconds to less than 1.7 seconds. TASK 6: LESSONS LEARNED This assignment produced many lessons learned, both in the realm of motor-driven device design and energybased modeling on the whole. With regards to motor driven device design, this assignment was a first change for this group to execute basic motor control techniques like Pulse Width Modulation, H-Bridge Control, DC motor selection and PID controller optimization. One key learning was the large increase in complexity inherent in the control of a Brushless DC motor from that of a Brushed DC motor. This learning will help our group weigh the costs and benefits of both motor types in the future. With regards to energy-based modeling on the whole, this assignment brought home the need to divide models into a hierarchy of interchangeable systems and subsystems. At first, we modeled a small number of very large systems. We soon found that these complex systems were difficult to debug and validate. We eventually divided our complex models into simpler components. Another lesson learned came from our attempt to create a detailed model of a Brushed DC motor. The modeling was beyond the need of this assignment, and was not able to be used. However, attempting the modeling brought home the complexity costs associated with Brushless DC motors, which will be crucial in making price related design decisions. November 1, 2011 39 Finally, we learned that, while thinking of a design problem that may seem simplistic initially, it becomes more and more challenging as you attempt to model the design problem to achieve relevant information. As a specific example, the initial concept to include thermal affects in our model was thought to be relatively simplistic. However, after initial models and further considerations, it was realized that the problem was complex enough as it was and the thermal phenomena became an assumption. TASK 7: PROJECT WEB-PAGE We have updated our project web-page to include our models and experimentation results; a link to this document is also included: http://www.srl.gatech.edu/education/ME6105/Projects/Fa11/jkm/ November 1, 2011 40 HW3: Energy-Based Systems Modeling in Modelica APPENDICES APPENDIX A – MODELICA CODE MOTOR ASSEMBLIES Below is the code the high level DC brushless motor controller sub-assembly. model Brushed_DC_28DT12_222E "See : http://www.portescap.com/product-92.html#" Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor; Modelica.Electrical.Analog.Basic.Ground ground; Modelica.Mechanics.Rotational.Sensors.AngleSensor angleSensor; Modelica.Mechanics.Rotational.Sensors.SpeedSensor speedSensor; Modelica.Blocks.Interfaces.BooleanInput forward; Modelica.Blocks.Interfaces.BooleanInput reverse; Modelica.Blocks.Interfaces.RealOutput Motor_Current; Modelica.Mechanics.Rotational.Interfaces.Flange_a output_shaft; Modelica.Blocks.Interfaces.RealOutput motor_angle; Modelica.Blocks.Interfaces.RealOutput motor_speed; Motors.Brush_DC_28DT12_222E brush_DC_28DT12_222E; Motor_Components.H_Bridge h_Bridge; Motor_Components.DC24_simple_battery dC24_simple_battery; equation connect(currentSensor.i,Motor_Current); connect(angleSensor.phi,motor_angle); connect(speedSensor.w,motor_speed); connect(currentSensor.n,ground. p); connect(h_Bridge.Positive_Supply, currentSensor.p); connect(h_Bridge.reverse, forward); connect(h_Bridge.forward, reverse); connect(brush_DC_28DT12_222E.flange_b, output_shaft); connect(h_Bridge.Motor_A, brush_DC_28DT12_222E.pin_n); connect(h_Bridge.Motor_B, brush_DC_28DT12_222E.pin_p); connect(angleSensor.flange, brush_DC_28DT12_222E.flange_b); connect(speedSensor.flange, brush_DC_28DT12_222E.flange_b); connect(dC24_simple_battery.pin_p, h_Bridge.Negative_Supply); connect(dC24_simple_battery.pin_n, ground.p); end Brushed_DC_28DT12_222E; partial package Modelica.Icons.Package "Icon for standard packages" end Package; partial package Modelica.Icons.SensorsPackage "Icon for packages containing sensors" //extends Modelica.Icons.Package; end SensorsPackage; model Modelica.Electrical.Analog.Sensors.CurrentSensor "Sensor to measure the current in a branch" extends Modelica.Icons.RotationalSensor; Interfaces.PositivePin p "positive pin"; Interfaces.NegativePin n "negative pin"; Modelica.Blocks.Interfaces.RealOutput i "current in the branch from p to n as output signal"; equation p.v = n.v; p.i = i; n.i = -i; end CurrentSensor; partial package Modelica.Icons.InterfacesPackage November 1, 2011 Appendices "Icon for packages containing interfaces" //extends Modelica.Icons.Package; end InterfacesPackage; connector Modelica.Electrical.Analog.Interfaces.PositivePin "Positive pin of an electric component" Modelica.SIunits.Voltage v "Potential at the pin"; flow Modelica.SIunits.Current i "Current flowing into the pin"; end PositivePin; connector Modelica.Electrical.Analog.Interfaces.NegativePin "Negative pin of an electric component" Modelica.SIunits.Voltage v "Potential at the pin"; flow Modelica.SIunits.Current i "Current flowing into the pin"; end NegativePin; connector Modelica.Blocks.Interfaces.RealOutput = output Real "'output Real' as connector"; partial class Modelica.Icons.RotationalSensor "Icon representing a round measurement device" end RotationalSensor; model Modelica.Electrical.Analog.Basic.Ground "Ground node" Interfaces.Pin p; equation p.v = 0; end Ground; connector Modelica.Electrical.Analog.Interfaces.Pin "Pin of an electrical component" Modelica.SIunits.Voltage v "Potential at the pin"; flow Modelica.SIunits.Current i "Current flowing into the pin"; end Pin; model Modelica.Mechanics.Rotational.Sensors.AngleSensor "Ideal sensor to measure the absolute flange angle" extends Rotational.Interfaces.PartialAbsoluteSensor; Modelica.Blocks.Interfaces.RealOutput phi "Absolute angle of flange"; equation phi = flange.phi; end AngleSensor; partial model Modelica.Mechanics.Rotational.Interfaces.PartialAbsoluteSensor "Partial model to measure a single absolute flange variable" Flange_a flange "Flange of shaft from which sensor information shall be measured"; equation 0 = flange.tau; end PartialAbsoluteSensor; connector Modelica.Mechanics.Rotational.Interfaces.Flange_a "1-dim. rotational flange of a shaft (filled square icon)" SI.Angle phi "Absolute rotation angle of flange"; flow SI.Torque tau "Cut torque in the flange"; end Flange_a; model Modelica.Mechanics.Rotational.Sensors.SpeedSensor "Ideal sensor to measure the absolute flange angular velocity" extends Rotational.Interfaces.PartialAbsoluteSensor; Modelica.Blocks.Interfaces.RealOutput w "Absolute angular velocity of flange"; equation w = der(flange.phi); end SpeedSensor; connector Modelica.Blocks.Interfaces.BooleanInput = November 1, 2011 41 42 HW3: Energy-Based Systems Modeling in Modelica input Boolean "'input Boolean' as connector"; model MainHW3.Motor_Assemblies.Motors.Brush_DC_28DT12_222E "http://www.portescap.com/product-92-28DT12.html" EMF_2 emf(k=.0325); Modelica.Electrical.Analog.Basic.HeatingResistor heatingResistor(R_ref= 6.2, useHeatPort=false); Modelica.Electrical.Analog.Basic.Inductor inductor(L=.00075); Modelica.Electrical.Analog.Interfaces.PositivePin pin_p; Modelica.Electrical.Analog.Interfaces.NegativePin pin_n; Modelica.Mechanics.Rotational.Components.Inertia inertia(J=.0000020); Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b; Modelica.Mechanics.Rotational.Components.Fixed fixed; Modelica.Mechanics.Rotational.Components.Damper damper(d=.000001); equation connect(heatingResistor.n, inductor.p); connect(inductor.n, emf.p); connect(pin_p, heatingResistor.p); connect(pin_n, emf.n); connect(emf.flange, inertia.flange_a); connect(inertia.flange_b, flange_b); connect(damper.flange_a, emf.flange); connect(damper.flange_b, fixed.flange); end Brush_DC_28DT12_222E; model MainHW3.Motor_Assemblies.Motors.EMF_2 "Electromotoric force (electric/mechanic transformer)" parameter Boolean useSupport=false "= true, if support flange enabled, otherwise implicitly grounded"; parameter Modelica.SIunits.ElectricalTorqueConstant k(start=1) "Transformation coefficient"; Modelica.SIunits.Voltage v "Voltage drop between the two pins"; Modelica.SIunits.Current i "Current flowing from positive to negative pin"; Modelica.SIunits.Angle phi "Angle of shaft flange with respect to support (= flange.phi - support.phi)"; Modelica.SIunits.AngularVelocity w "Angular velocity of flange relative to support"; Modelica.Electrical.Analog.Interfaces.PositivePin p; Modelica.Electrical.Analog.Interfaces.NegativePin n; Modelica.Mechanics.Rotational.Interfaces.Flange_b flange; Modelica.Mechanics.Rotational.Interfaces.Support support if useSupport "Support/housing of emf shaft"; protected Modelica.Mechanics.Rotational.Components.Fixed fixed if not useSupport; Modelica.Mechanics.Rotational.Interfaces.InternalSupport internalSupport(tau=flange.tau); equation v = p.v - n.v; 0 = p.i + n.i; i = p.i; phi = flange.phi - internalSupport.phi; w = der(phi); k*w = v; flange.tau = -k*i; connect(internalSupport.flange, support); connect(internalSupport.flange,fixed. flange); end EMF_2; connector Modelica.Mechanics.Rotational.Interfaces.Flange_b "1-dim. rotational flange of a shaft (non-filled square icon)" SI.Angle phi "Absolute rotation angle of flange"; flow SI.Torque tau "Cut torque in the flange"; end Flange_b; connector Modelica.Mechanics.Rotational.Interfaces.Support "Support/housing of a 1-dim. rotational shaft" November 1, 2011 Appendices SI.Angle phi "Absolute rotation angle of the support/housing"; flow SI.Torque tau "Reaction torque in the support/housing"; end Support; model Modelica.Mechanics.Rotational.Components.Fixed "Flange fixed in housing at a given angle" parameter SI.Angle phi0=0 "Fixed offset angle of housing"; Interfaces.Flange_b flange "(right) flange fixed in housing"; equation flange.phi = phi0; end Fixed; model Modelica.Mechanics.Rotational.Interfaces.InternalSupport "Adapter model to utilize conditional support connector" input Modelica.SIunits.Torque tau "External support torque (must be computed via torque balance in model where InternalSupport is used; = flange.tau)"; Modelica.SIunits.Angle phi "External support angle (= flange.phi)"; Flange_a flange "Internal support flange (must be connected to the conditional support connector for useSupport=true and to conditional fixed model f or useSupport=false)"; equation flange.tau = tau; flange.phi = phi; end InternalSupport; model Modelica.Electrical.Analog.Basic.HeatingResistor "Temperature dependent electrical resistor" parameter Modelica.SIunits.Resistance R_ref(start=1) "Resistance at temperature T_ref"; parameter Modelica.SIunits.Temperature T_ref=300.15 "Reference temperature"; parameter Modelica.SIunits.LinearTemperatureCoefficient alpha=0 "Temperature coefficient of resistance (R = R_ref*(1 + alpha*(heatPort.T - T_ref))"; extends Modelica.Electrical.Analog.Interfaces.OnePort; extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort( T = T_ref, useHeatPort=true); Modelica.SIunits.Resistance R "Resistance = R_ref*(1 + alpha*(T_heatPort - T_ref))"; equation assert((1 + alpha*(T_heatPort - T_ref)) >= Modelica.Constants.eps, "Temperature outside scope of model!"); R = R_ref*(1 + alpha*(T_heatPort - T_ref)); v = R*i; LossPower = v*i; end HeatingResistor; partial model Modelica.Electrical.Analog.Interfaces.OnePort "Component with two electrical pins p and n and current i from p to n" SI.Voltage v "Voltage drop between the two pins (= p.v - n.v)"; SI.Current i "Current flowing from pin p to pin n"; PositivePin p "Positive pin (potential p.v > n.v for positive voltage drop v)"; NegativePin n "Negative pin"; equation v = p.v - n.v; 0 = p.i + n.i; i = p.i; end OnePort; partial model Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort "Partial model to include a conditional HeatPort in order to describe the power loss via a thermal network" parameter Boolean useHeatPort = false "=true, if HeatPort is enabled"; parameter Modelica.SIunits.Temperature T=293.15 "Fixed device temperature if useHeatPort = false"; Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort(T(start=T)=T_heatPort, Q_flow=-LossPower) if useHeatPort; Modelica.SIunits.Power LossPower "Loss power leaving component via HeatPort"; Modelica.SIunits.Temperature T_heatPort "Temperature of HeatPort"; equation November 1, 2011 43 44 HW3: Energy-Based Systems Modeling in Modelica if not useHeatPort then T_heatPort = T; end if; end ConditionalHeatPort; connector Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a "Thermal port for 1-dim. heat transfer (filled rectangular icon)" extends HeatPort; end HeatPort_a; partial connector Modelica.Thermal.HeatTransfer.Interfaces.HeatPort "Thermal port for 1-dim. heat transfer" Modelica.SIunits.Temperature T "Port temperature"; flow Modelica.SIunits.HeatFlowRate Q_flow "Heat flow rate (positive if flowing from outside into the component)"; end HeatPort; model Modelica.Electrical.Analog.Basic.Inductor "Ideal linear electrical inductor" extends Interfaces.OnePort; parameter SI.Inductance L(start=1) "Inductance"; equation L*der(i) = v; end Inductor; model Modelica.Mechanics.Rotational.Components.Inertia "1D-rotational component with inertia" import SI = Modelica.SIunits; Rotational.Interfaces.Flange_a flange_a "Left flange of shaft"; Rotational.Interfaces.Flange_b flange_b "Right flange of shaft"; parameter SI.Inertia J(min=0, start=1) "Moment of inertia"; parameter StateSelect stateSelect=StateSelect.default "Priority to use phi and w as states"; SI.Angle phi(stateSelect=stateSelect) "Absolute rotation angle of component"; SI.AngularVelocity w(stateSelect=stateSelect) "Absolute angular velocity of component (= der(phi))"; SI.AngularAcceleration a "Absolute angular acceleration of component (= der(w))"; equation phi = flange_a.phi; phi = flange_b.phi; w = der(phi); a = der(w); J*a = flange_a.tau + flange_b.tau; end Inertia; model Modelica.Mechanics.Rotational.Components.Damper "Linear 1D rotational damper" extends Modelica.Mechanics.Rotational.Interfaces.PartialCompliantWithRelativeStates; parameter SI.RotationalDampingConstant d(final min=0, start=0) "Damping constant"; extends Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPortWithoutT; equation tau = d*w_rel; lossPower = tau*w_rel; end Damper; partial model Modelica.Mechanics.Rotational.Interfaces.PartialCompliantWithRelativeStates "Partial model for the compliant connection of two rotational 1dim. shaft flanges where the relative angle and speed are used as preferred states" Modelica.SIunits.Angle phi_rel(start=0, stateSelect=stateSelect, nominal=phi_nominal) "Relative rotation angle (= flange_b.phi - flange_a.phi)"; Modelica.SIunits.AngularVelocity w_rel(start=0, stateSelect=stateSelect) November 1, 2011 Appendices "Relative angular velocity (= der(phi_rel))"; Modelica.SIunits.AngularAcceleration a_rel(start=0) "Relative angular acceleration (= der(w_rel))"; Modelica.SIunits.Torque tau "Torque between flanges (= flange_b.tau)"; Flange_a flange_a "Left flange of compliant 1-dim. rotational component"; Flange_b flange_b "Right flange of compliant 1-dim. rotational component"; parameter SI.Angle phi_nominal(displayUnit="rad")=1e-4 "Nominal value of phi_rel (used for scaling)"; parameter StateSelect stateSelect=StateSelect.prefer "Priority to use phi_rel and w_rel as states"; equation phi_rel = flange_b.phi - flange_a.phi; w_rel = der(phi_rel); a_rel = der(w_rel); flange_b.tau = tau; flange_a.tau = -tau; end PartialCompliantWithRelativeStates; partial model Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPortWithoutT "Partial model to include a conditional HeatPort in order to dissipate losses, used for textual modeling, i.e., for elementary models" parameter Boolean useHeatPort = false "=true, if heatPort is enabled"; Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort( final Q_flow=-lossPower) if useHeatPort "Optional port to which dissipated losses are transported in form of heat"; Modelica.SIunits.Power lossPower "Loss power leaving component via heatPort (> 0, if heat is flowing out of component)"; end PartialElementaryConditionalHeatPortWithoutT; model MainHW3.Motor_Assemblies.Motor_Components.H_Bridge Modelica.Electrical.Analog.Ideal.IdealClosingSwitch switch1(Ron=1, useHeatPort=false); Modelica.Electrical.Analog.Ideal.IdealClosingSwitch switch2(Ron=1, useHeatPort=false); Modelica.Electrical.Analog.Ideal.IdealClosingSwitch switch3(Ron=1, useHeatPort=false); Modelica.Electrical.Analog.Ideal.IdealClosingSwitch switch4(Ron=1, useHeatPort=false); Modelica.Electrical.Analog.Interfaces.PositivePin Motor_A; Modelica.Electrical.Analog.Interfaces.NegativePin Motor_B; Modelica.Electrical.Analog.Interfaces.PositivePin Positive_Supply; Modelica.Electrical.Analog.Interfaces.NegativePin Negative_Supply; Modelica.Blocks.Interfaces.BooleanInput reverse; Modelica.Blocks.Interfaces.BooleanInput forward; equation connect(switch2.p, switch3.p); connect(switch3.n, Motor_B); connect(switch4.p, Motor_A); connect(switch2.p, Negative_Supply); connect(reverse, switch4.control); connect(reverse, switch3.control); connect(switch1.control, forward); connect(switch2.control, forward); connect(switch4.p, switch2.n); connect(switch4.n, Positive_Supply); connect(switch1.n, Positive_Supply); connect(switch1.p, switch3.n); end H_Bridge; model Modelica.Electrical.Analog.Ideal.IdealClosingSwitch "Ideal electrical closer" extends Modelica.Electrical.Analog.Interfaces.OnePort; parameter SI.Resistance Ron(final min=0) = 1.E-5 "Closed switch resistance"; parameter SI.Conductance Goff(final min=0) = 1.E-5 "Opened switch conductance"; extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort( final T=293.15); November 1, 2011 45 46 HW3: Energy-Based Systems Modeling in Modelica Modelica.Blocks.Interfaces.BooleanInput control "true => p--n connected, false => switch open"; protected Real s(final unit="1") "Auxiliary variable"; constant Modelica.SIunits.Voltage unitVoltage= 1; constant Modelica.SIunits.Current unitCurrent= 1; equation v = (s*unitCurrent)*(if control then Ron else 1); i = (s*unitVoltage)*(if control then 1 else Goff); LossPower = v*i; end IdealClosingSwitch; model MainHW3.Motor_Assemblies.Motor_Components.DC24_simple_battery Modelica.Electrical.Analog.Interfaces.PositivePin pin_p; Modelica.Electrical.Analog.Interfaces.NegativePin pin_n; Modelica.Electrical.Analog.Basic.Resistor resistor(R=2.5); Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage(V=24); equation connect(constantVoltage.p, resistor.n); connect(resistor.p, pin_p); connect(constantVoltage.n, pin_n); end DC24_simple_battery; model Modelica.Electrical.Analog.Basic.Resistor "Ideal linear electrical resistor" parameter Modelica.SIunits.Resistance R(start=1) "Resistance at temperature T_ref"; parameter Modelica.SIunits.Temperature T_ref=300.15 "Reference temperature"; parameter Modelica.SIunits.LinearTemperatureCoefficient alpha=0 "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(T_heatPort - T_ref))"; extends Modelica.Electrical.Analog.Interfaces.OnePort; extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort( T = T_ref); Modelica.SIunits.Resistance R_actual "Actual resistance = R*(1 + alpha*(T_heatPort - T_ref))"; equation assert((1 + alpha*(T_heatPort - T_ref)) >= Modelica.Constants.eps, "Temperature outside scope of model!"); R_actual = R*(1 + alpha*(T_heatPort - T_ref)); v = R_actual*i; LossPower = v*i; end Resistor; partial package Modelica.Icons.SourcesPackage "Icon for packages containing sources" //extends Modelica.Icons.Package; end SourcesPackage; model Modelica.Electrical.Analog.Sources.ConstantVoltage "Source for constant voltage" parameter SI.Voltage V(start=1) "Value of constant voltage"; extends Interfaces.OnePort; equation v = V; end ConstantVoltage; SHAFT AND TISSUE GEARS AND SHAFT Below is the code for the gears and shaft sub-assembly. model Knife_Rack_Pinion_Medium "Knife_Rack_Pinion_Medium" Modelica.Mechanics.Translational.Components.IdealGearR2T idealGearR2T(ratio=.005) annotation (Placement(transformation(extent={{-22,-10},{-2,10}}))); November 1, 2011 Appendices Modelica.Mechanics.Rotational.Interfaces.Flange_a Motor_Connection "Flange of rotational shaft" annotation (Placement(transformation(extent={{-110,-10},{-90,10}}))); Modelica.Mechanics.Translational.Components.Mass mass(m=.2) annotation (Placement(transformation(extent={{6,-10},{26,10}}))); Modelica.Mechanics.Translational.Sensors.PositionSensor positionSensor annotation (Placement(transformation(extent={{48,30},{68,50}}))); Modelica.Blocks.Interfaces.RealOutput s1 "Absolute position of flange" annotation (Placement(transformation(extent={{76,30},{96,50}}))); Modelica.Mechanics.Translational.Components.Damper damper(d=.001) annotation (Placement(transformation(extent={{32,-28},{52,-8}}))); Modelica.Mechanics.Translational.Components.Fixed fixed annotation ( Placement(transformation( extent={{-10,-10},{10,10}}, rotation=90, origin={62,-18}))); Modelica.Mechanics.Rotational.Components.IdealGear idealGear(ratio=1090) "other ratios options include: 5.75, 17.4, 24, 33, 72.3, 99.8, 138, 190, 301, 416, 574, 792, 1090" annotation (Placement(transformation(extent={{-58,-10},{-38,10}}))); Modelica.Mechanics.Translational.Sources.Force force(useSupport=false) annotation (Placement(transformation(extent={{72,-56},{92,-36}}))); Modelica.Blocks.Tables.CombiTable1Ds combiTable1Ds( columns={2}, tableOnFile=false, table=[.000,0;.001, -5;.002, -10;.003, -15;.004, -20;.005, -25;.006, -30;.007, -35;.008, -40;.009, -45;.010, -50;.011, -55;.012, -60;.013, -65;.014, -70;.015, -75;.016, -80;.017, -85;.018, -90;.019, -95;.020, -99.9;.021, -85;.022, -65;.023, -50;.024, -50;.025, -65;.026, -70;.027, -70;.028, -70;.029, -70;.030, -70;.031, -70;.032, -70;.033, -71.123668;.034, -72.30569877;.035, -73.54756985;.036, -74.85075877;.037, -76.21674308;.038, -77.64700031;.039, -79.143008;.040, -80.70624369;.041, -82.33818492;.042, -84.04030923;.043, -85.81409415;.044, -87.66101723;.045, -89.582556;.046, -91.580188;.047, -93.65539077;.048, -95.80964185;.049, -98.04441877;.050, -100.3611991;.051, -70;.052, -70;.053, -70;.054, -70;.055, -70;.056, -70;.057, -70;.058, -70;.059, -70;.060, -70;.061, -70;.062, -70;.063, -70;.064, -70;.065, -70;.066, -70;.067, -70;.068, -70;.069, -70;.070, -70;.071, -70;.072, -70;.073, -70;.074, -70;.075, -70;.076, -70;.077, -70;.078, -70;.079, -70;.080, -70;.081, -70;.082, -70;.083, -70;.084, -70;.085, -70;.086, -68.876332;.087, -67.69430123;.088, -66.45243015;.089, -65.14924123;.090, -63.78325692;.091, -62.35299969;.092, -60.856992;.093, -59.29375631;.094, -57.66181508;.095, -55.95969077;.096, -54.18590585;.097, -52.33898277;.098, -50.417444;.099, -48.419812;.100, -46.34460923;.101, -44.19035815;.102, -41.95558123;.103, -39.63880092;.104, -70;.105, -70;.106, -70;.107, -70;.108, -70;.109, -70;.110, -70;.111, -70;.112, -70;.113, -70;.114, -70;.115, -70;.116, -70;.117, -70;.118, -70;.119, -70;.120, -70;.121, -70;.122, -70;.123, -70;.124, -70;.125, -70;.126, -70;.127, -70;.128, -70;.129, -70;.130, -70;.131, -70;.132, -70;.133, -70;.134, -70;.135, -70;.136, -70;.137, -70;.138, -70;.139, -70;.140, -70;.141, -70;.142, -70;.143, -71.123668;.144, -72.30569877;.145, -73.54756985;.146, -74.85075877;.147, -76.21674308;.148, -77.64700031;.149, -79.143008;.150, -80.70624369;.151, -82.33818492;.152, -84.04030923;.153, -85.81409415;.154, -87.66101723;.155, -89.582556;.156, -91.580188;.157, -93.65539077;.158, -95.80964185;.159, -98.04441877;.160, -100.3611991;.161, -70;.162, -70;.163, -70;.164, -70;.165, -70;.166, -70;.167, -70;.168, -70;.169, -70;.170, -70;.171, -70;.172, -70;.173, -70;.174, -70;.175, -70;.176, -70;.177, -70;.178, -70;.179, -70;.180, -70;.181, -72;.182, -77;.183, -82;.184, -87;.185, -92;.186, -93;.187, -100;.188, -102;.189, -100;.190, -95;.191, -80;.192, -60;.193, -30;.194, -25;.195, -23;.196, -19;.197, -15;.198, -10;.199, -5;.200, 0]) annotation (Placement(transformation(extent={{-58,-50},{-38,-30}}))); Modelica.Blocks.Continuous.Derivative Velocity2(T=.01) annotation (Placement(transformation(extent={{-82,-82},{-62,-62}}))); Modelica.Blocks.Math.Product product annotation (Placement(transformation(extent={{14,-56},{34,-36}}))); Modelica.Blocks.Math.BooleanToReal booleanToReal(realTrue=1, realFalse=0) annotation (Placement(transformation(extent={{-20,-82},{0,-62}}))); November 1, 2011 47 48 HW3: Energy-Based Systems Modeling in Modelica Modelica.Blocks.Logical.GreaterThreshold greaterThreshold annotation (Placement(transformation(extent={{-52,-82},{-32,-62}}))); Modelica.Blocks.Math.Gain gain(k=1) annotation (Placement(transformation(extent={{42,-56},{62,-36}}))); equation connect(mass.flange_b, positionSensor.flange) annotation (Line( points={{26,0},{26,20},{48,20},{48,40}}, color={0,127,0}, smooth=Smooth.None)); connect(positionSensor.s, s1) annotation (Line( points={{69,40},{86,40}}, color={0,0,127}, smooth=Smooth.None)); connect(mass.flange_b, damper.flange_a) annotation (Line( points={{26,0},{32,0},{32,-18}}, color={0,127,0}, smooth=Smooth.None)); connect(damper.flange_b, fixed.flange) annotation (Line( points={{52,-18},{62,-18}}, color={0,127,0}, smooth=Smooth.None)); connect(Motor_Connection, idealGear.flange_a) annotation (Line( points={{-100,0},{-58,0}}, color={0,0,0}, smooth=Smooth.None)); connect(idealGear.flange_b, idealGearR2T.flangeR) annotation (Line( points={{-38,0},{-22,0}}, color={0,0,0}, smooth=Smooth.None)); connect(idealGearR2T.flangeT, mass.flange_a) annotation (Line( points={{-2,0},{6,0}}, color={0,127,0}, smooth=Smooth.None)); connect(s1, combiTable1Ds.u) annotation (Line( points={{86,40},{86,64},{-66,64},{-66,-40},{-60,-40}}, color={0,0,127}, smooth=Smooth.None)); connect(s1, Velocity2.u) annotation (Line( points={{86,40},{86,72},{-90,72},{-90,-72},{-84,-72}}, color={0,0,127}, smooth=Smooth.None)); connect(booleanToReal.y, product.u2) annotation (Line( points={{1,-72},{8,-72},{8,-52},{12,-52}}, color={0,0,127}, smooth=Smooth.None)); connect(combiTable1Ds.y[1], product.u1) annotation (Line( points={{-37,-40},{12,-40}}, color={0,0,127}, smooth=Smooth.None)); connect(Velocity2.y, greaterThreshold.u) annotation (Line( points={{-61,-72},{-54,-72}}, color={0,0,127}, smooth=Smooth.None)); connect(greaterThreshold.y, booleanToReal.u) annotation (Line( points={{-31,-72},{-22,-72}}, color={255,0,255}, smooth=Smooth.None)); connect(product.y, gain.u) annotation (Line( points={{35,-46},{40,-46}}, color={0,0,127}, smooth=Smooth.None)); connect(gain.y, force.f) annotation (Line( points={{63,-46},{70,-46}}, color={0,0,127}, smooth=Smooth.None)); connect(force.flange, mass.flange_b) annotation (Line( November 1, 2011 Appendices points={{92,-46},{98,-46},{98,0},{26,0}}, color={0,127,0}, smooth=Smooth.None)); annotation ( Diagram(graphics)); end Knife_Rack_Pinion_Medium; OR model Gears_and_Shaft Modelica.Mechanics.Translational.Components.Mass mass(m=.2) annotation (Placement(transformation(extent={{14,0},{34,20}}))); Modelica.Mechanics.Translational.Components.Damper damper(d=.001) annotation (Placement(transformation(extent={{38,-52},{58,-32}}))); Modelica.Mechanics.Translational.Components.Fixed fixed annotation ( Placement(transformation( extent={{-10,-10},{10,10}}, rotation=90, origin={68,-42}))); Modelica.Mechanics.Rotational.Components.IdealGear idealGear(ratio=75) "other ratios options include: 5.75, 17.4, 24, 33, 72.3, 99.8, 138, 190, 301, 416, 574, 792, 1090" annotation (Placement(transformation(extent={{-74,0},{-54,20}}))); Modelica.Mechanics.Rotational.Interfaces.Flange_a Motor_Connection "Flange of rotational shaft" annotation (Placement(transformation(extent={{-110,-10},{-90,10}}))); Modelica.Mechanics.Translational.Sensors.PositionSensor positionSensor annotation (Placement(transformation(extent={{48,62},{68,82}}))); Modelica.Blocks.Interfaces.RealOutput s1 "Absolute position of flange" annotation (Placement(transformation(extent={{98,70},{118,90}}))); Modelica.Mechanics.Translational.Interfaces.Flange_a knife_surface annotation (Placement(transformation(extent={{90,-10},{110,10}}))); Modelica.Mechanics.Rotational.Components.IdealRollingWheel idealRollingWheel(radius=.0075) annotation (Placement(transformation(extent={{-28,0},{-8,20}}))); equation connect(mass.flange_b, positionSensor.flange) annotation (Line( points={{34,10},{34,52},{48,52},{48,72}}, color={0,127,0}, smooth=Smooth.None)); connect(mass.flange_b,damper. flange_a) annotation (Line( points={{34,10},{38,10},{38,-42}}, color={0,127,0}, smooth=Smooth.None)); connect(damper.flange_b,fixed. flange) annotation (Line( points={{58,-42},{68,-42}}, color={0,127,0}, smooth=Smooth.None)); connect(Motor_Connection,idealGear. flange_a) annotation (Line( points={{-100,0},{-84,0},{-84,10},{-74,10}}, color={0,0,0}, smooth=Smooth.None)); connect(mass.flange_b,positionSensor. flange) annotation (Line( points={{34,10},{34,52},{48,52},{48,72}}, color={0,127,0}, smooth=Smooth.None)); connect(positionSensor.s,s1) annotation (Line( points={{69,72},{80,72},{80,80},{108,80}}, color={0,0,127}, smooth=Smooth.None)); connect(mass.flange_b, knife_surface) annotation (Line( points={{34,10},{66,10},{66,0},{100,0}}, color={0,127,0}, smooth=Smooth.None)); connect(idealRollingWheel.flangeT, mass.flange_a) annotation (Line( points={{-8,10},{14,10}}, color={0,127,0}, smooth=Smooth.None)); November 1, 2011 49 50 HW3: Energy-Based Systems Modeling in Modelica connect(idealRollingWheel.flangeR, idealGear.flange_b) annotation (Line( points={{-28,10},{-54,10}}, color={0,0,0}, smooth=Smooth.None)); annotation (Diagram(graphics)); end Gears_and_Shaft; TISSUE Below is the code for the tissue sub-assembly. model Tissue Modelica.Mechanics.Translational.Sources.Force force(useSupport=false) annotation (Placement(transformation(extent={{62,26},{82,46}}))); Modelica.Blocks.Tables.CombiTable1Ds combiTable1Ds( columns={2}, tableOnFile=false, table=[.000,0;.001, -5;.002, -10;.003, -15;.004, -20;.005, -25;.006, -30;.007, -35;.008, -40;.009, -45;.010, -50;.011, -55;.012, -60;.013, -65;.014, -70;.015, -75;.016, -80;.017, -85;.018, -90;.019, -95;.020, -99.9;.021, -85;.022, -65;.023, -50;.024, -50;.025, -65;.026, -70;.027, -70;.028, -70;.029, -70;.030, -70;.031, -70;.032, -70;.033, -71.123668;.034, -72.30569877;.035, -73.54756985;.036, -74.85075877;.037, -76.21674308;.038, -77.64700031;.039, -79.143008;.040, -80.70624369;.041, -82.33818492;.042, -84.04030923;.043, -85.81409415;.044, -87.66101723;.045, -89.582556;.046, -91.580188;.047, -93.65539077;.048, -95.80964185;.049, -98.04441877;.050, -100.3611991;.051, -70;.052, -70;.053, -70;.054, -70;.055, -70;.056, -70;.057, -70;.058, -70;.059, -70;.060, -70;.061, -70;.062, -70;.063, -70;.064, -70;.065, -70;.066, -70;.067, -70;.068, -70;.069, -70;.070, -70;.071, -70;.072, -70;.073, -70;.074, -70;.075, -70;.076, -70;.077, -70;.078, -70;.079, -70;.080, -70;.081, -70;.082, -70;.083, -70;.084, -70;.085, -70;.086, -68.876332;.087, -67.69430123;.088, -66.45243015;.089, -65.14924123;.090, -63.78325692;.091, -62.35299969;.092, -60.856992;.093, -59.29375631;.094, -57.66181508;.095, -55.95969077;.096, -54.18590585;.097, -52.33898277;.098, -50.417444;.099, -48.419812;.100, -46.34460923;.101, -44.19035815;.102, -41.95558123;.103, -39.63880092;.104, -70;.105, -70;.106, -70;.107, -70;.108, -70;.109, -70;.110, -70;.111, -70;.112, -70;.113, -70;.114, -70;.115, -70;.116, -70;.117, -70;.118, -70;.119, -70;.120, -70;.121, -70;.122, -70;.123, -70;.124, -70;.125, -70;.126, -70;.127, -70;.128, -70;.129, -70;.130, -70;.131, -70;.132, -70;.133, -70;.134, -70;.135, -70;.136, -70;.137, -70;.138, -70;.139, -70;.140, -70;.141, -70;.142, -70;.143, -71.123668;.144, -72.30569877;.145, -73.54756985;.146, -74.85075877;.147, -76.21674308;.148, -77.64700031;.149, -79.143008;.150, -80.70624369;.151, -82.33818492;.152, -84.04030923;.153, -85.81409415;.154, -87.66101723;.155, -89.582556;.156, -91.580188;.157, -93.65539077;.158, -95.80964185;.159, -98.04441877;.160, -100.3611991;.161, -70;.162, -70;.163, -70;.164, -70;.165, -70;.166, -70;.167, -70;.168, -70;.169, -70;.170, -70;.171, -70;.172, -70;.173, -70;.174, -70;.175, -70;.176, -70;.177, -70;.178, -70;.179, -70;.180, -70;.181, -72;.182, -77;.183, -82;.184, -87;.185, -92;.186, -93;.187, -100;.188, -102;.189, -100;.190, -95;.191, -80;.192, -60;.193, -30;.194, -25;.195, -23;.196, -19;.197, -15;.198, -10;.199, -5;.200, 0]) annotation (Placement(transformation(extent={{-52,50},{-32,70}}))); Modelica.Blocks.Continuous.Derivative Velocity2(T=.01) annotation (Placement(transformation(extent={{-78,-30},{-58,-10}}))); Modelica.Blocks.Math.Product product annotation (Placement(transformation(extent={{-12,26},{8,46}}))); Modelica.Blocks.Math.BooleanToReal booleanToReal(realTrue=1, realFalse=0) annotation (Placement(transformation(extent={{-2,-30},{18,-10}}))); Modelica.Blocks.Logical.GreaterThreshold greaterThreshold annotation (Placement(transformation(extent={{-34,-30},{-14,-10}}))); Modelica.Blocks.Math.Gain gain(k=1) annotation (Placement(transformation(extent={{32,26},{52,46}}))); Modelica.Blocks.Interfaces.RealInput knife_position annotation (Placement(transformation(extent={{-128,-20},{-88,20}}))); Modelica.Mechanics.Translational.Interfaces.Flange_a tissue_surface annotation (Placement(transformation(extent={{92,-10},{112,10}}))); November 1, 2011 Appendices Modelica.Blocks.Logical.LessThreshold lessThreshold annotation (Placement(transformation(extent={{-34,-64},{-14,-44}}))); Modelica.Blocks.Math.BooleanToReal booleanToReal1( realTrue=1, realFalse=0) annotation (Placement(transformation(extent={{-2,-64},{18,-44}}))); Modelica.Blocks.Math.Product product1 annotation (Placement(transformation(extent={{40,-96},{60,-76}}))); Modelica.Blocks.Sources.Constant const(k=20) annotation (Placement(transformation(extent={{-62,-92},{-42,-72}}))); Modelica.Mechanics.Translational.Sources.Force force1( useSupport=false) annotation (Placement(transformation(extent={{68,-46},{88,-26}}))); equation connect(booleanToReal.y,product. u2) annotation (Line( points={{19,-20},{28,-20},{28,2},{-18,2},{-18,30},{-14,30}}, color={0,0,127}, smooth=Smooth.None)); connect(combiTable1Ds.y[1],product. u1) annotation (Line( points={{-31,60},{-26,60},{-26,42},{-14,42}}, color={0,0,127}, smooth=Smooth.None)); connect(Velocity2.y,greaterThreshold. u) annotation (Line( points={{-57,-20},{-36,-20}}, color={0,0,127}, smooth=Smooth.None)); connect(greaterThreshold.y,booleanToReal. u) annotation (Line( points={{-13,-20},{-4,-20}}, color={255,0,255}, smooth=Smooth.None)); connect(product.y,gain. u) annotation (Line( points={{9,36},{30,36}}, color={0,0,127}, smooth=Smooth.None)); connect(gain.y,force. f) annotation (Line( points={{53,36},{60,36}}, color={0,0,127}, smooth=Smooth.None)); connect(Velocity2.u, knife_position) annotation (Line( points={{-80,-20},{-84,-20},{-84,0},{-108,0}}, color={0,0,127}, smooth=Smooth.None)); connect(combiTable1Ds.u, knife_position) annotation (Line( points={{-54,60},{-74,60},{-74,0},{-108,0}}, color={0,0,127}, smooth=Smooth.None)); connect(force.flange, tissue_surface) annotation (Line( points={{82,36},{92,36},{92,0},{102,0}}, color={0,127,0}, smooth=Smooth.None)); connect(lessThreshold.y, booleanToReal1.u) annotation (Line( points={{-13,-54},{-4,-54}}, color={255,0,255}, smooth=Smooth.None)); connect(lessThreshold.u, Velocity2.y) annotation (Line( points={{-36,-54},{-46,-54},{-46,-20},{-57,-20}}, color={0,0,127}, smooth=Smooth.None)); connect(const.y, product1.u2) annotation (Line( points={{-41,-82},{-2,-82},{-2,-92},{38,-92}}, color={0,0,127}, smooth=Smooth.None)); connect(booleanToReal1.y, product1.u1) annotation (Line( points={{19,-54},{28,-54},{28,-80},{38,-80}}, color={0,0,127}, smooth=Smooth.None)); connect(product1.y, force1.f) annotation (Line( points={{61,-86},{60,-86},{60,-36},{66,-36}}, color={0,0,127}, smooth=Smooth.None)); connect(force1.flange, tissue_surface) annotation (Line( November 1, 2011 51 52 HW3: Energy-Based Systems Modeling in Modelica points={{88,-36},{92,-36},{92,0},{102,0}}, color={0,127,0}, smooth=Smooth.None)); annotation (Diagram(graphics)); end Tissue; CONTROLLERS DETERMINE OUTPUT DIRECTION Below is the code for the determine output direction sub-assembly. model Determine_Output_Direction Modelica.Blocks.Interfaces.RealInput Input_Rack_Position annotation (Placement(transformation(extent={{-112,-6},{-72,34}}))); Modelica.Blocks.Logical.LessThreshold LessThanMaxPosition(threshold=.149) annotation (Placement(transformation(extent={{-72,42},{-52,62}}))); Modelica.Blocks.Logical.And PositionAndVelocity annotation (Placement(transformation(extent={{-2,42},{18,62}}))); Modelica.Blocks.Continuous.Derivative Velocity annotation (Placement(transformation(extent={{-64,-2},{-44,18}}))); Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold( threshold=0) annotation (Placement(transformation(extent={{-32,10},{-12,30}}))); Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold1(threshold=.149) annotation (Placement(transformation(extent={{-60,-44},{-40,-24}}))); Modelica.Blocks.Logical.LessThreshold LessThanMaxPosition1(threshold=0) annotation (Placement(transformation(extent={{-32,-18},{-12,2}}))); Modelica.Blocks.Logical.Or or1 annotation (Placement(transformation(extent={{0,-36},{20,-16}}))); Modelica.Blocks.Math.BooleanToReal Target_Current( realFalse=0, realTrue= 1) annotation (Placement(transformation(extent={{26,42},{46,62}}))); Modelica.Blocks.Math.BooleanToReal Target_Current1( realFalse=0, realTrue= 1) annotation (Placement(transformation(extent={{62,-52},{82,-32}}))); Modelica.Blocks.Interfaces.RealOutput Go_Forward annotation (Placement(transformation(extent={{88,64},{108,84}}))); Modelica.Blocks.Interfaces.RealOutput Go_Reverse annotation (Placement(transformation(extent={{88,-52},{108,-32}}))); Modelica.Blocks.Logical.And PositionAndVelocity1 annotation (Placement(transformation(extent={{30,-62},{50,-42}}))); Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold2( threshold=0) annotation (Placement(transformation(extent={{-60,-70},{-40,-50}}))); Modelica.Blocks.Continuous.LimPID PID( yMin=0, wd=1, Ni=.9, Nd=10, yMax=Modelica.Constants.inf, wp=1, k=.5, Td=1.5, controllerType=Modelica.Blocks.Types.SimpleController.PD, Ti=0) annotation (Placement(transformation(extent={{56,42},{76,62}}))); equation connect(LessThanMaxPosition.y,PositionAndVelocity. u1) annotation (Line( points={{-51,52},{-4,52}}, color={255,0,255}, smooth=Smooth.None)); connect(Velocity.y,greaterEqualThreshold. u) annotation (Line( points={{-43,8},{-40,8},{-40,20},{-34,20}}, color={0,0,127}, smooth=Smooth.None)); connect(greaterEqualThreshold.y,PositionAndVelocity. u2) annotation (Line( November 1, 2011 Appendices points={{-11,20},{-8,20},{-8,44},{-4,44}}, color={255,0,255}, smooth=Smooth.None)); connect(Input_Rack_Position, LessThanMaxPosition.u) annotation (Line( points={{-92,14},{-76,14},{-76,52},{-74,52}}, color={0,0,127}, smooth=Smooth.None)); connect(Input_Rack_Position, Velocity.u) annotation (Line( points={{-92,14},{-76,14},{-76,8},{-66,8}}, color={0,0,127}, smooth=Smooth.None)); connect(greaterEqualThreshold1.u, Input_Rack_Position) annotation (Line( points={{-62,-34},{-76,-34},{-76,14},{-92,14}}, color={0,0,127}, smooth=Smooth.None)); connect(Target_Current1.y, Go_Reverse) annotation (Line( points={{83,-42},{98,-42}}, color={0,0,127}, smooth=Smooth.None)); connect(greaterEqualThreshold1.y, or1.u2) annotation (Line( points={{-39,-34},{-2,-34}}, color={255,0,255}, smooth=Smooth.None)); connect(LessThanMaxPosition1.y, or1.u1) annotation (Line( points={{-11,-8},{-8,-8},{-8,-26},{-2,-26}}, color={255,0,255}, smooth=Smooth.None)); connect(Velocity.y, LessThanMaxPosition1.u) annotation (Line( points={{-43,8},{-40,8},{-40,-8},{-34,-8}}, color={0,0,127}, smooth=Smooth.None)); connect(PositionAndVelocity1.y, Target_Current1.u) annotation (Line( points={{51,-52},{54,-52},{54,-42},{60,-42}}, color={255,0,255}, smooth=Smooth.None)); connect(or1.y, PositionAndVelocity1.u1) annotation (Line( points={{21,-26},{24,-26},{24,-52},{28,-52}}, color={255,0,255}, smooth=Smooth.None)); connect(Input_Rack_Position, greaterEqualThreshold2.u) annotation (Line( points={{-92,14},{-76,14},{-76,-60},{-62,-60}}, color={0,0,127}, smooth=Smooth.None)); connect(greaterEqualThreshold2.y, PositionAndVelocity1.u2) annotation (Line( points={{-39,-60},{28,-60}}, color={255,0,255}, smooth=Smooth.None)); when greaterEqualThreshold2.u<0 then terminate("Home position reached"); end when; connect(PositionAndVelocity.y, Target_Current.u) annotation (Line( points={{19,52},{24,52}}, color={255,0,255}, smooth=Smooth.None)); connect(Target_Current.y, PID.u_s) annotation (Line( points={{47,52},{54,52}}, color={0,0,127}, smooth=Smooth.None)); connect(PID.y, Go_Forward) annotation (Line( points={{77,52},{82,52},{82,74},{98,74}}, color={0,0,127}, smooth=Smooth.None)); connect(Input_Rack_Position, PID.u_m) annotation (Line( points={{-92,14},{-76,14},{-76,34},{66,34},{66,40}}, color={0,0,127}, smooth=Smooth.None)); annotation (Diagram(graphics)); end Determine_Output_Direction; November 1, 2011 53 54 HW3: Energy-Based Systems Modeling in Modelica BASIC CONTROLLER Below is the code for the basic controller sub-assembly. model Basic_Controller "Controller for motorized transection device" import Motors; Modelica.Blocks.Interfaces.RealOutput Forward_Duty_Cycle annotation (Placement(transformation(extent={{98,70},{118,90}}))); Modelica.Blocks.Interfaces.RealInput from_rack annotation (Placement(transformation(extent={{-116,68},{-92,92}}))); MainHW3.Controllers.Determine_Output_Direction_DC_Brushed_1 determine_Output_Direction annotation (Placement(transformation(extent={{-56,66},{-36,86}}))); Modelica.Blocks.Interfaces.RealOutput Reverse_Duty_Cycle annotation (Placement(transformation(extent={{98,-70},{118,-50}}))); Modelica.Blocks.Math.Product product annotation (Placement(transformation(extent={{6,30},{26,50}}))); Modelica.Blocks.Math.Product product1 annotation (Placement(transformation(extent={{4,-22},{24,-2}}))); Modelica.Blocks.Sources.Constant const(k=50) annotation (Placement(transformation(extent={{-60,24},{-40,44}}))); Modelica.Blocks.Sources.Constant const1(k=50) annotation (Placement(transformation(extent={{-60,-28},{-40,-8}}))); equation connect(from_rack, determine_Output_Direction.Input_Rack_Position) annotation (Line( points={{-104,80},{-68,80},{-68,77.4},{-55.2,77.4}}, color={0,0,127}, smooth=Smooth.None)); connect(determine_Output_Direction.Go_Forward, product.u1) annotation ( Line( points={{-36.2,83.4},{-17.1,83.4},{-17.1,46},{4,46}}, color={0,0,127}, smooth=Smooth.None)); connect(determine_Output_Direction.Go_Reverse, product1.u1) annotation ( Line( points={{-36.2,71.8},{-10,72},{-10,-6},{2,-6}}, color={0,0,127}, smooth=Smooth.None)); connect(product.y, Forward_Duty_Cycle) annotation (Line( points={{27,40},{52,40},{52,80},{108,80}}, color={0,0,127}, smooth=Smooth.None)); connect(product1.y, Reverse_Duty_Cycle) annotation (Line( points={{25,-12},{52,-12},{52,-60},{108,-60}}, color={0,0,127}, smooth=Smooth.None)); connect(const.y, product.u2) annotation (Line( points={{-39,34},{4,34}}, color={0,0,127}, smooth=Smooth.None)); connect(const1.y, product1.u2) annotation (Line( points={{-39,-18},{2,-18}}, color={0,0,127}, smooth=Smooth.None)); annotation ( Diagram(graphics={ Rectangle(extent={{-98,92},{-70,62}}, lineColor={0,127,0}), Text( extent={{-100,92},{-70,86}}, lineColor={0,127,0}, textString="Rack")})); end Basic_Controller; November 1, 2011 Appendices APPENDIX B – DETAILED TEST RESULTS PID CONTROLLER TESTING Table 7: PID Methodology Testing Results Target max_position = 200 mm (0.2 m) Tolerance = +0, -4 Tested methodology with early model components: Using strategy provided in Modelica documentation: yMax = infinity; yMin = 0. STEP 1: Adjust threshold Using threshold values of 0.2 m, we get overshoot: Threshold position (m) time (s) error (m) 0.197 0.2043 2.29 0.0043 0.196 0.20263 2.28 0.00263 0.195 0.20122 2.27 0.00122 0.194 0.20097 2.27 0.00097 0.193 0.19944 2.26 -0.00056 STEP 2: P-controller and adjust K K position (m) time (s) error (m) 1.00 0.272 1.36 0.072 0.50 0.233 1.35 0.033 0.40 0.225 1.38 0.025 0.10 0.2016 2.06 0.0016 0.09 0.19996 2.16 -4E-05 STEP 4: PD-controller and adjust Td Td position (m) time (s) 1.50 0.20469 1.34 1.00 0.2018 1.46 0.50 0.20065 1.69 0.30 0.199927 1.83 0.20 0.1996 1.9 0.10 0.199938 2.02 error (m) 0.00469 0.0018 0.00065 -7.3E-05 -0.0004 -6.2E-05 STEP 5: PID-controller and adjust threshold Using K=0.09, Ti = 1.4, Td = 0.3: Threshold position (m) time (s) error (m) 0.193 0.20468 1.695 0.00468 0.192 0.20401 1.69 0.00401 0.191 0.20251 1.68 0.00251 0.19 doesn't complete 0.1905 0.201904 1.68 0.001904 0.189 0.200328 1.67 0.000328 0.188 0.199818 1.67 -0.00018 STEP 3: PI-controller and adjust Ti Ti position (m) time (s) error (m) 0.01 doesn't complete 0.05 0.35 2.04 0.15 0.10 0.2715 1.71 0.0715 0.50 0.21956 1.78 0.01956 0.80 0.2125 1.84 0.0125 1.00 0.2102 1.87 0.0102 1.10 0.2097 1.89 0.0097 1.20 0.2086 1.9 0.0086 1.40 0.208 1.92 0.008 <== best result 1.50 0.2081 1.93 0.0081 1.60 doesn't complete **Adding the integral component speeds up the cycle, but accuracy is not within our tolerances. November 1, 2011 55 56 HW3: Energy-Based Systems Modeling in Modelica Table 8: DC Brushed Motor PID Detailed Testing Results Target max_position = 200 mm (0.2 m) Tolerance = +0, -4 Tested model parameters: Motor = DC Brushed Gear Ratio = 72.3 Using strategy provided in Modelica documentation: yMax = infinity; yMin = 0. STEP 1: Adjust Threshold (no controller effect) Threshold position (m) time max (s) error (m) time home (s) comments 0.2 0.20092 3.7115 0.00092 6.6326 0.199 0.19987 3.6955 -0.00013 6.6014 STEP 2: P-controller and adjust K K 0.5 1.00 1.50 2.00 2.30 2.40 2.50 2.50 position (m) time max (s) error (m) time home (s) comments 0.1867 9.1492 -0.0133 11.879 0.19987 3.6955 -0.00013 6.6014 From STEP 1. 0.1999 3.2205 -0.0001 6.1277 0.2000 3.039 0 5.9469 0.2000 2.977 0 5.8853 0.2000 2.9665 0 5.8743 0.2001 2.9615 1E-04 5.8698 Threshold adjusted = 0.1990 2.947 -0.001 5.8405 0.198 STEP 3: PI-controller and adjust Ti Ti position (m) time max (s) error (m) time home (s) comments 2.00 unstable 5.00 0.2000 3.0065 0 15.3026 10.00 0.1991 2.9515 -0.0009 8.62 20.00 0.1990 2.947 -0.001 6.31067 30.00 0.1990 2.947 -0.001 6.0259 40.00 0.1990 2.947 -0.001 5.9382 Increase in Ti only 50.00 0.1990 2.947 -0.001 5.9001 speeds return time November 1, 2011 Appendices STEP 4: PD-controller and adjust Td Td position (m) time max (s) error (m) time home (s) comments 1.00 0.1990 2.9625 -0.001 5.9601 0.10 0.1990 2.9475 -0.001 5.8416 0.01 0.1990 2.947 -0.001 5.8405 0.001 0.1990 2.947 -0.001 5.8405 STEP 5: PID-controller and adjust threshold Threshold position (m) time max (s) error (m) time home (s) comments 0.198 0.1990 2.947 -0.001 5.9024 November 1, 2011 57 58 HW3: Energy-Based Systems Modeling in Modelica Table 9: DC Brushless Motor PID Detailed Testing Results Target max_position = 200 mm (0.2 m) Tolerance = +0, -4 Tested model parameters: Motor = DC Brushless Gear Ratio = 72.3 Using strategy provided in Modelica documentation: yMax = infinity; yMin = 0. STEP 1: Adjust Threshold (no controller effect) Threshold position (m) time max (s) error (m) time home (s) comments 0.2 0.2019 1.704 0.0019 2.5615 0.199 0.2006 1.6965 0.0006 2.548 0.198 0.1994 1.6885 -0.0006 2.535 STEP 2: P-controller and adjust K K 0.5 1.00 1.50 2.00 2.30 2.40 2.50 2.50 2.50 position (m) time max (s) error (m) time home (s) comments 0.0165 0.2272 -0.1835 0.343 0.1994 1.6885 -0.0006 2.535 From STEP 1. 0.2004 1.075 0.0004 1.925 0.2010 0.907 0.001 1.761 0.2013 0.8665 0.0013 1.7213 0.2015 0.862 0.0015 1.717 0.2015 0.86 0.0015 1.716 Threshold adjusted = 0.2002 0.855 0.0002 1.705 0.197 Threshold adjusted = 0.1991 0.85 -0.0009 1.7 0.196 STEP 3: PI-controller and adjust Ti Ti position (m) time max (s) error (m) time home (s) comments 1.00 unstable 2.00 0.1995 0.8575 -0.0005 3.765 5.00 0.1991 0.85 -0.0009 1.92 10.00 0.1991 0.85 -0.0009 1.733 20.00 0.1991 0.85 -0.0009 1.701 Increase in Ti only 30.00 0.1991 0.85 -0.0009 1.7 speeds return time November 1, 2011 Appendices APPENDIX C – BRUSHLESS DC MOTOR MODEL booleanPulse .001 dC24_s? ground sensor? cW_3H? h_Bridg? inertia brushle? J=.002 November 1, 2011 59 60 HW3: Energy-Based Systems Modeling in Modelica Phase_1 Phase_2 resistor inductor R=.99 L=.0001 resistor1 inductor1 R=.99 L=.0001 resistor2 inductor2 R=.99 L=.0001 inertia J=.00000023 fixed Phase_3 November 1, 2011 flange_b Appendices Negativ? Positive? A_HIGH C_HIGH A_LOW C_LOW To_A To_B To_C November 1, 2011 61 62 HW3: Energy-Based Systems Modeling in Modelica >= 300 or1 Sensor_A or <= 60 Rotor_Angle gain >= correct? 120 k=57.296 and2 Sensor_B and <= 300 >= 0 <= 180 November 1, 2011 and3 Sensor_C and Appendices 50 inertia.w 45 40 35 30 25 20 15 10 5 0 -5 0.00 0.04 0.08 0.12 0.16 0.20 0.24 model CW_3HBRidge_Controller Modelica.Blocks.Interfaces.BooleanInput Sensor_A annotation (Placement(transformation(extent={{-126,40},{-86,80}}))); Modelica.Blocks.Interfaces.BooleanInput Sensor_B annotation (Placement(transformation(extent={{-126,-20},{-86,20}}))); Modelica.Blocks.Interfaces.BooleanInput Sensor_C annotation (Placement(transformation(extent={{-126,-80},{-86,-40}}))); Modelica.Blocks.Interfaces.BooleanOutput A_HIGH annotation (Placement(transformation(extent={{96,70},{116,90}}))); Modelica.Blocks.Interfaces.BooleanOutput A_LOW annotation (Placement(transformation(extent={{96,50},{116,70}}))); Modelica.Blocks.Interfaces.BooleanOutput B_HIGH annotation (Placement(transformation(extent={{96,10},{116,30}}))); Modelica.Blocks.Interfaces.BooleanOutput B_LOW annotation (Placement(transformation(extent={{96,-10},{116,10}}))); Modelica.Blocks.Interfaces.BooleanOutput C_HIGH annotation (Placement(transformation(extent={{96,-70},{116,-50}}))); Modelica.Blocks.Interfaces.BooleanOutput C_LOW annotation (Placement(transformation(extent={{96,-90},{116,-70}}))); Modelica.Blocks.Interfaces.BooleanInput PWM_input annotation (Placement( transformation( extent={{-20,-20},{20,20}}, rotation=270, origin={0,104}))); algorithm // if (Sensor_C) and ( Sensor_B) and (Sensor_A) then // C_HIGH = false; //Phase 1 November 1, 2011 63 64 HW3: Energy-Based Systems Modeling in Modelica when (Sensor_C) and ( not Sensor_B) and (Sensor_A) and (PWM_input) then C_HIGH :=false; C_LOW := false; B_HIGH := false; B_LOW := true; A_HIGH := true; A_LOW := false; end when; //Phase 2 when (Sensor_C) and ( not Sensor_B) and (not Sensor_A) and (PWM_input) then C_HIGH :=true; C_LOW := false; B_HIGH := false; B_LOW := true; A_HIGH := false; A_LOW := false; end when; //Phase 3 when (Sensor_C) and ( Sensor_B) and (not Sensor_A) and (PWM_input) then C_HIGH :=true; C_LOW := false; B_HIGH := false; B_LOW := false; A_HIGH := false; A_LOW := true; end when; //Phase 4 when (not Sensor_C) and ( Sensor_B) and (not Sensor_A) and (PWM_input) then C_HIGH :=false; C_LOW := false; B_HIGH := true; B_LOW := false; A_HIGH := false; A_LOW := true; end when; //Phase 5 when (not Sensor_C) and ( Sensor_B) and ( Sensor_A) and (PWM_input) then C_HIGH :=false; C_LOW := true; B_HIGH := false; B_LOW := true; A_HIGH := false; A_LOW := false; end when; //Phase 6 when (not Sensor_C) and (not Sensor_B) and ( Sensor_A) and (PWM_input) then C_HIGH :=false; C_LOW := true; B_HIGH := false; B_LOW := false; A_HIGH := true; A_LOW := false; end when; annotation (Diagram(graphics)); end CW_3HBRidge_Controller; model EMF_3 "Electromotoric force (electric/mechanic transformer)" parameter Modelica.SIunits.ElectricalTorqueConstant k(start=1) "Transformation coefficient"; //Modelica.SIunits.Voltage v "Voltage drop between the two pins"; //Modelica.SIunits.Current i "Current flowing from positive to negative pin"; // Modelica.SIunits.Angle phi // "Angle of shaft flange with respect to support (= flange.phi - support.phi)"; Modelica.SIunits.AngularVelocity w "Angular velocity of flange relative to support"; //changes by cjp; November 1, 2011 Appendices Real PI = Modelica.Constants.pi; Real vn; // cannot be forced to zero --> will result in zero if amplitude of currents are equal Real e0; Real e1; Real e2; Real kt; Real k0; Real k1; Real k2; Real p=1; //Real emf.i = 0; // Real emf.v = 0; // Real emf.phi = 0; // if useSupport Modelica.Electrical.Analog.Interfaces.PositivePin P0 annotation (Placement(transformation( origin={-70,99}, extent={{-10,-10},{10,10}}, rotation=90))); Modelica.Electrical.Analog.Interfaces.NegativePin P2 annotation (Placement(transformation( origin={85,98}, extent={{-10,-10},{10,10}}, rotation=90))); Modelica.Electrical.Analog.Interfaces.PositivePin P1 annotation (Placement(transformation( origin={10,101}, extent={{-10,-10},{10,10}}, rotation=90))); Modelica.Mechanics.Rotational.Interfaces.Support flange_a "Support/housing of emf shaft" annotation (Placement(transformation(extent={{-110,-12},{-90,8}}))); Modelica.Mechanics.Rotational.Interfaces.Flange_b flange_b annotation (Placement(transformation(extent={{-18,-111},{2,-91}},rotation=0))); equation //emf.i = 0; //emf.v = 0; //emf.phi = 0; // changes by cjp 0 = flange_a.tau + flange_b.tau; 0 = P0.i + P1.i + P2.i; 0 = vn + e0 - P0.v; 0 = vn + e1 - P1.v; 0 = vn + e2 - P2.v; kt = 2*k/3; k0 = kt*sin(p*flange_b.phi); k1 = kt*sin(p*flange_b.phi - 2/3*PI); k2 = kt*sin(p*flange_b.phi - 4/3*PI); e0 = k0*w; e1 = k1*w; e2 = k2*w; w = der(flange_b.phi); flange_b.tau = -(k0*P0.i + k1*P1.i + k2*P2.i) annotation ( defaultComponentName="emf", Icon( coordinateSystem( preserveAspectRatio=true, extent={{-100,-100},{100,100}}, grid={1,1}), graphics={ Rectangle( extent={{-85,10},{-36,-10}}, lineColor={0,0,0}, fillPattern=FillPattern.HorizontalCylinder, fillColor={192,192,192}), Line(points={{0,90},{0,40}}, color={0,0,255}), November 1, 2011 65 66 HW3: Energy-Based Systems Modeling in Modelica Rectangle( extent={{35,10},{100,-10}}, lineColor={0,0,0}, fillPattern=FillPattern.HorizontalCylinder, fillColor={192,192,192}), Ellipse( extent={{-40,40},{40,-40}}, fillColor={255,255,255}, fillPattern=FillPattern.Solid, lineColor={0,0,255}), Line(points={{0,-90},{0,-40}}, color={0,0,255}), Text( extent={{0,-50},{199,-90}}, textString="%name", lineColor={0,0,255}), Text( extent={{0,80},{189,46}}, lineColor={160,160,164}, textString="k=%k")}), Diagram(coordinateSystem( preserveAspectRatio=true, extent={{-100,-100},{100,100}}, grid={1,1}), graphics), Documentation(info="<html> <p>EMF transforms electrical energy into rotational mechanical energy. It is used as basic building block of an electrical motor. The me chanical connector flange can be connected to elements of the Modelica.Mechanics.Rotational library. flange.tau is the cuttorque, flange.phi is the angle at the rotational connection.</p> </html>", revisions="<html> <ul> <li><i> 1998 </i> by Martin Otter<br> initially implemented<br> </li> </ul> </html>")); annotation (Diagram(graphics)); end EMF_3; November 1, 2011 Bibliography BIBLIOGRAPHY 1. Portescap. Portescap. [Online] [Cited: October 28, 2011.] http://www.portescap.com. 2. Ogata, Katsuhiko. Modern Control Engineering. 2nd. Englewood Cliffs : Prentice-Hall, Inc., 1990. ISBN. 3. Dassault Systems. Dymola – Dynamic Modeling Laboratory, LimPID Information. Version 7.4 FD01 1992 - 2010. (Dymola documentation references: Astrom, K.J., and Hagglund, T., PID Controllers: Theory, Design, and Tuning. Instrument Society of America, 2nd edition, 1995, chapter 3.). November 1, 2011 67