User Tools

Site Tools


marvin:ecp2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
marvin:ecp2 [2009/01/29 10:33] riepermarvin:ecp2 [2009/01/29 11:02] (current) rieper
Line 24: Line 24:
 ====Our Angle of Approach Towards Control Theory==== ====Our Angle of Approach Towards Control Theory====
  
-Basically there are three approaches to our control problem, which we will describe briefly in an increasing order of complexity.  The first method requires no more than an intuitive understanding of the tuning parameters in a given control loop as we consider the control plant as a black box. We simply implement a control loop by following the directions of the control loop as indicated in the following section Introducing the PID Controller. In this case we make no attempts to precalculate the stability issues e.g. using bode plots to observe phase margin as a function of our bandwidth. Instead we use a trial and error principle based on our intuitive understanding of the tuning parameters. The problem with this approach is that lack of knowledge about the dynamics of the control plant (the robot) if we do not succeed. We have no theoretical foundation.\\ +Basically there are three approaches to our control problem, which we will describe briefly in an increasing order of complexity.  The first method requires no more than an intuitive understanding of the tuning parameters in a given control loop as we consider the control plant as a black box. We simply implement a control loop by following the directions of the control loop as indicated in the following section [[#Introducing the PID Controller|Introducing the PID Controller]]. In this case we make no attempts to precalculate the stability issues e.g. using bode plots to observe phase margin as a function of our bandwidth. Instead we use a trial and error principle based on our intuitive understanding of the tuning parameters. The problem with this approach is that lack of knowledge about the dynamics of the control plant (the robot) if we do not succeed. We have no theoretical foundation.\\ 
-The second approach is again to consider the control plant as a black box, but here we wish to estimate the characteristic transfer function of the plant. Recall that if we give an impulse to a filter we are given the filter characteristic by means of the impulse response. The analogy to control theory is to apply a step function and observe the transient response, which is illustrated on the figures in the following section [[#Introducing the PID Controller|Introducing the PID Controller]]“Introducing the PID Controller”. Depending on the order of the system we may need to apply a ramp or a parabola, but the principle is the same. By observing the rise time and settling time we may be able to estimate the transfer function and thereby to create a more solid foundation as to why the system is unstable and how large bandwidth we can obtain. This method is more complex since we need to be able to measure the transient response, which often requires expensive and precise equipment.\\ +The second approach is again to consider the control plant as a black box, but here we wish to estimate the characteristic transfer function of the plant. Recall that if we give an impulse to a filter we are given the filter characteristic by means of the impulse response. The analogy to control theory is to apply a step function and observe the transient response, which is illustrated on the figures in the following section [[#Introducing the PID Controller|Introducing the PID Controller]]. Depending on the order of the system we may need to apply a ramp or a parabola, but the principle is the same. By observing the rise time and settling time we may be able to estimate the transfer function and thereby to create a more solid foundation as to why the system is unstable and how large bandwidth we can obtain. This method is more complex since we need to be able to measure the transient response, which often requires expensive and precise equipment.\\ 
-The third method is to derive a mathematical model of the dynamics of the control plant and this can be somewhat complex. In the case of a balancing robot it is helpful to look at the mathematical modelling of an inverted pendulum and there next to add the physical dimensions of the balancing robot. When working with modelling we end up with non linear equations, which is a problem as our controllers are linear. One common method is to use the state space representation and then to make a linearization around the steady state point or the equilibrium. If our mathematical model is precise and close to the true physical model we obtain a great theoretical foundation for creating a stable system. This is exactly what Yorihisa Yamamoto(([[http://www.mathworks.com/matlabcentral/fileexchange/19147| Yorihisa Yamamoto's]])) has done and the result is outstanding. In our case however, the modelling is too comprehensive and we have seen several examples that prove a stable balancing robot. We therefore rely on our intuitive understanding and use method one to implement our solution. We have decided to use the PID controller as we have already obtained some practical/intuitive understanding of the tuning parameters during LAB4(([[http://wiki.aasimon.org/?id=marvin:lab4|Lab 4]])).+The third method is to derive a mathematical model of the dynamics of the control plant and this can be somewhat complex. In the case of a balancing robot it is helpful to look at the mathematical modelling of an inverted pendulum and there next to add the physical dimensions of the balancing robot. When working with modelling we end up with non linear equations, which is a problem as our controllers are linear. One common method is to use the state space representation and then to make a linearisation around the steady state point or the equilibrium. If our mathematical model is precise and close to the true physical model we obtain a great theoretical foundation for creating a stable system. This is exactly what Yorihisa Yamamoto(([[http://www.mathworks.com/matlabcentral/fileexchange/19147| Yorihisa Yamamoto's]])) has done and the result is outstanding. For this relatively short project however, the modelling is too comprehensive and we have seen several examples that the balancing can be achieved using the first method. We therefore rely on our intuitive understanding and use method one to implement our solution. We have decided to use the PID controller as we have already obtained some practical/intuitive understanding of the tuning parameters during LAB4(([[http://wiki.aasimon.org/?id=marvin:lab4|Lab 4]])).
  
  
Line 112: Line 112:
 The above pictures are from (([[http://en.wikipedia.org/wiki/PID controller| PID Controller]])) \\ The above pictures are from (([[http://en.wikipedia.org/wiki/PID controller| PID Controller]])) \\
    
-By inspection we summarize the following. An increase in the proportional gain will create a larger overshoot, but reduce the steady state error and rise time. An increase in the integral controller also increase the overshoot, while eliminating the steady state error. If we increase the differential controller, we decrease the overshoot with no affect on the steady state error, but the bandwith of the system will be reduced. The default parameters in the program caused Marvin to oscillate to much, so based on the observed behaviour of Marvin, we decided to increase the differential controller in proportion to the other controllers, thereby reducing the overshoot and hence the oscillation. In the following we have used the above guidelines and observations in an iteratively trial and error based estimation of the parameters.+By inspection we summarize the following. An increase in the proportional gain will create a larger overshoot, but reduce the steady state error and rise time. An increase in the integral controller also increase the overshoot, while eliminating the steady state error. If we increase the differential controller, we decrease the overshoot with no affect on the steady state error, but the bandwidth of the system will be reduced. 
  
  
Line 130: Line 130:
  </code>  </code>
  
-Further readings and inspiration are found at "Sensors and Sensing"(([[http://www.cs.brown.edu/people/tld/courses/cs148/02/sensors.html|Sensors and Sensing]])), which was presented in week 3 of the course.+Further readings and inspiration are found at this homepage(([[http://www.cs.brown.edu/people/tld/courses/cs148/02/sensors.html|Sensors and Sensing]])), which was presented in week 3 of the course.
  
 ==== Defining the States in the Control Loop ==== ==== Defining the States in the Control Loop ====
Line 143: Line 143:
 {{ :marvin:p_lab2_marvin.png?200 |Side View Plane Of Inverted Pendulum}} {{ :marvin:p_lab2_marvin.png?200 |Side View Plane Of Inverted Pendulum}}
  
-This makes perfectly sense, since we need to drive the wheels in a direction that keeps the upper body of the robot in equilibrium. We therefore need sensor readings regarding the position of the wheels and the upper body in order to keep the wheels under the robot’s center of gravity. It is easy to argument for the first order derivatives as well. From a mathematical point of view, the control point is a linearization of second order nonlinear equations (differential equations of the inverted pendulum) and therefore a descent approximation would include the first order terms to indicate the curvature as well. From a practical point of view, the curvature/velocity indicates how fast we are moving from the steady state point and these terms are very relevant in order for the error signal to rise relative to oscillations during balancing. We may also refer to this as feature extraction as we are selecting sufficient features to define the motion and position of this “inverted pendulum”.  We sum up the states in the following diagram.\\+This makes perfectly sense, since we need to drive the wheels in a direction that keeps the upper body of the robot in equilibrium. We therefore need sensor readings regarding the position of the wheels and the upper body in order to keep the wheels under the robot’s centre of gravity. It is easy to argument for the first order derivatives as well. From a mathematical point of view, the control point is a linearisation of second order non-linear equations (differential equations of the inverted pendulum) and therefore a descent approximation would include the first order terms to indicate the curvature as well. From a practical point of view, the curvature/velocity indicates how fast we are moving from the steady state point and these terms are very relevant in order for the error signal to rise relative to oscillations during balancing. We may also refer to this as feature extraction as we are selecting sufficient features to define the motion and position of this “inverted pendulum”.  We sum up the states in the following diagram.\\
  
 {{ :marvin:p_lab2_pid2.png?300 |The Closed Loop Including PID Controller}} {{ :marvin:p_lab2_pid2.png?300 |The Closed Loop Including PID Controller}}
Line 150: Line 150:
  
 ==== Parameters and Stability ==== ==== Parameters and Stability ====
-The calculation of the right PID control parameters is essential to secure a stable system. This is called loop tuning. If loop tuning is not done according to the task at hand, the control system will become unstable i.e. the output will diverge. Oscillation might occur in this case. The only thing that will prevent divergens or oscillation is saturation or mechanical breakage. This may happen a lot when trying to produce a balancing robot and is generally not a problem due the great structural integrity, however if the controller is to control something else that might not be as rigid as our construction oscillation is always something to avoid in the first place. \\+The calculation of the right PID control parameters is essential to secure a stable system. This is called loop tuning. If loop tuning is not done according to the task at hand, the control system will become unstable i.e. the output will diverge. Oscillation might occur in this case. The only thing that will prevent divergence or oscillation is saturation or mechanical breakage. This may happen a lot when trying to produce a balancing robot and is generally not a problem due the great structural integrity, however if the controller is to control something else that might not be as rigid as our construction oscillation is always something to avoid in the first place. \\
 Loop tuning could be defined as adjusting the control loop parameters (Proportional gain(P), Integral gain (I) and Derivative gain(D)) to the optimum value for a desired control response. The z-transform for the controller should, in order to be stable obey the rules for a stable system, that is poles of the system should be located inside the unity circle, see diagram below. Loop tuning could be defined as adjusting the control loop parameters (Proportional gain(P), Integral gain (I) and Derivative gain(D)) to the optimum value for a desired control response. The z-transform for the controller should, in order to be stable obey the rules for a stable system, that is poles of the system should be located inside the unity circle, see diagram below.
  
Line 158: Line 158:
  
 There are a number of different approaches when tuning PID parameters of which three will be described below. There are a number of different approaches when tuning PID parameters of which three will be described below.
-The methods that can be used range from no knowledge of the system to a full simulation of the system that can be used to calculate stability and set the exact parameters of the PID controller for optimum performance. One thing to note before talking about parameter tuning is the difference between online tuning and offline tuning. Online tuning means tuning when the system is running. That means one adjust parameters while the system is running. Offline tuning means take the control out of the plant, adjust the parameters and then re-engage the system. It is the later method we have used. The robot have been stopped, the parameters have en adjusted in the software, and lastly new firmware have been uploaded. Online tuning could have been used with a bluetooth link between the robot and a PC wherefrom new parameters could be uploaded on the fly.+The methods that can be used range from no knowledge of the system to a full simulation of the system that can be used to calculate stability and set the exact parameters of the PID controller for optimum performance. One thing to note before talking about parameter tuning is the difference between online tuning and offline tuning. Online tuning means tuning when the system is running. That means one adjust parameters while the system is running. Offline tuning means take the control out of the plant, adjust the parameters and then re-engage the system. It is the later method we have used. The robot have been stopped, the parameters have en adjusted in the software, and lastly new firmware have been uploaded. Online tuning could have been used with a Bluetooth link between the robot and a PC from where new parameters could be uploaded on the fly.
  
-=== Manual tuning ===+=== Manual Tuning ===
  This is a trial and error approach. You do not need to have any idea about the plant. The procedure is as follows:   This is a trial and error approach. You do not need to have any idea about the plant. The procedure is as follows: 
   * Set I and D values to zero   * Set I and D values to zero
Line 187: Line 187:
 There exist different kinds of tuning software. One of these could be (([[http://www.mathworks.com|MatLab]])). These software based solutions require a mathematical approach. In order to do this it is necessary to have a mathematical model of the plant to be controlled. The procedure induces an impulse into the system and then uses the controlled systems frequency response to design the PID parameters. There exist different kinds of tuning software. One of these could be (([[http://www.mathworks.com|MatLab]])). These software based solutions require a mathematical approach. In order to do this it is necessary to have a mathematical model of the plant to be controlled. The procedure induces an impulse into the system and then uses the controlled systems frequency response to design the PID parameters.
  
-=== Summarize of approaches ===+=== Summarize of Approaches ===
 The three different approaches can be seen from the table below. In that table the advantages an disadvantages can me seen together with what knowledge is required.  The three different approaches can be seen from the table below. In that table the advantages an disadvantages can me seen together with what knowledge is required. 
 ^ Method ^ Advantages ^ Disadvantage ^ Requirements ^ ^ Method ^ Advantages ^ Disadvantage ^ Requirements ^
 ^ Manual Tuning | No math required (Online*) | Inaccurate  | Some skill level | ^ Manual Tuning | No math required (Online*) | Inaccurate  | Some skill level |
-^ Ziegler-Nichols | Proven method (Online*)| Trial and error, pretty agressive tuning | Ability to measure starting parameters such as <latex>$P_c$</latex><texit>$P_c$</texit> and <latex>$K_c$</latex><texit>$K_c$</texit> |+^ Ziegler-Nichols | Proven method (Online*)| Trial and error, pretty aggressive tuning | Ability to measure starting parameters such as <latex>$P_c$</latex><texit>$P_c$</texit> and <latex>$K_c$</latex><texit>$K_c$</texit> |
 ^ Software Tools | Consistent tuning, Online or offline tuning, Allow for simulation beforehand | Expensive, knowledge about plant and development tools are required | Mathematical model | ^ Software Tools | Consistent tuning, Online or offline tuning, Allow for simulation beforehand | Expensive, knowledge about plant and development tools are required | Mathematical model |
 * Online can in some cases be a disadvantage, e.g. a very long settling time. The time to try small adjustments may take days. * Online can in some cases be a disadvantage, e.g. a very long settling time. The time to try small adjustments may take days.
Line 206: Line 206:
 This class contains all the PID magic happening that makes Marvin keep its balance. This class contains all the PID magic happening that makes Marvin keep its balance.
  
-The balancing module reads the angles and the angle velocities from the gyro and motors, and uses these values (weighted) to feed to the PID control calculation which again produces the new power to apply to the motors.+The balancing module reads the angles and the angle velocities from the gyroscope and motors, and uses these values (weighted) to feed to the PID control calculation which again produces the new power to apply to the motors.
  
 These are the constants used as weights in PID control, and the error calculation: These are the constants used as weights in PID control, and the error calculation:
Line 223: Line 223:
 velocities) <latex>$\dot{\Psi}$</latex><texit>$\dot{\Psi}$</texit> and <latex>$\dot{\Phi}$</latex><texit>$\dot{\Phi}$</texit>, thus making <latex>$K_\Psi$</latex><texit>$K_\Psi$</texit> the weight of the <latex>$\Psi$</latex><texit>$\Psi$</texit> value in the error calculation, <latex>$K_\dot{\Psi}$</latex><texit>$K_{\dot{\Psi}}$</texit> then weight for the <latex>$\dot{\Psi}$</latex><texit>$\dot{\Psi}$</texit> and so on...\\ velocities) <latex>$\dot{\Psi}$</latex><texit>$\dot{\Psi}$</texit> and <latex>$\dot{\Phi}$</latex><texit>$\dot{\Phi}$</texit>, thus making <latex>$K_\Psi$</latex><texit>$K_\Psi$</texit> the weight of the <latex>$\Psi$</latex><texit>$\Psi$</texit> value in the error calculation, <latex>$K_\dot{\Psi}$</latex><texit>$K_{\dot{\Psi}}$</texit> then weight for the <latex>$\dot{\Psi}$</latex><texit>$\dot{\Psi}$</texit> and so on...\\
  
-The sleep call at the end of the loop, reflects the max sample speed of the Gyroscope, which should be is 300 times per second, 3.33msec between calls, but since the code itself takes up some time, the actual sleep value of 3msec seem to work appropriately.+The sleep call at the end of the loop, reflects the max sample speed of the gyroscope, which should be is 300 times per second, 3.33msec between calls, but since the code itself takes up some time, the actual sleep value of 3msec seem to work appropriately.
  
  
 The controls are added, in two places: The controls are added, in two places:
-  * To make Marvin move forward and backwards we add the tilt offset to the gyro angle (at the ''gyro.getAngle()'' call).+  * To make Marvin move forward and backwards we add the tilt offset to the gyroscope angle (at the ''gyro.getAngle()'' call).
  
   * To make Marvin rotate wee add the left and right motor offsets directly to the right and left motor power (at the ''motors.setPower(...)'' call).   * To make Marvin rotate wee add the left and right motor offsets directly to the right and left motor power (at the ''motors.setPower(...)'' call).
Line 240: Line 240:
  
   public void run()   public void run()
 +
   {   {
     MotorControl motors = new MotorControl(Motor.C, Motor.B);     MotorControl motors = new MotorControl(Motor.C, Motor.B);
marvin/ecp2.1233221600.txt.gz · Last modified: 2009/01/29 10:33 by rieper