• No results found

Virtual Prototyping and Physical Validation of an Inverted Pendulum: "Sea-Calf Bot"

N/A
N/A
Protected

Academic year: 2022

Share "Virtual Prototyping and Physical Validation of an Inverted Pendulum: "Sea-Calf Bot""

Copied!
110
0
0

Loading.... (view fulltext now)

Full text

(1)

BA CHELOR THESIS

Computer System Engineering, Mechatronic Engineering, 180 credits

Virtual Prototyping and Physical Validation of an Inverted Pendulum

"Sea-Calf Bot"

Martin Gustavsson, Viktor Frimodig

Cyber-Physical System, 15 credits

Halmstad, February 5, 2015

(2)
(3)

Virtual Prototyping and Physical Validation of an Inverted Pendulum

”Sea-Calf Bot”

Bachelor thesis 15 credits Computer System Engineering

Mechatronic Engineering

February 5, 2015

Authors Viktor Frimodig Martin Gustavsson

Supervisor: Walid Taha Examiner: Bj¨ orn ˚ Astrand

Halmstad University

(4)

iv

(5)

Acknowledgments

We would like to thank Thomas Lith´en and Tommy Salomonsson for their knowledge and help about hardware. Xu Fei for help with Acumen. Duc Vinh La, Rami Raad Ishac, Adam Davidsson, Fredrik Lindblom and Shivanand Narayandas for perusal and feedback. Our supervisor and customer Walid Taha for a lot of ideas, leadership and for providing us with this project. Bj¨orn

˚Astrand our examiner for valuable feedback and the grades we pray for.

Sincerely Viktor Frimodig Martin Gustavsson

Halmstad February 5, 2015

v

(6)

vi

(7)

Link to the project homepage http://sea-calf-bot.webnode.se/ in QR- code. Made in MS Paint Adventures.

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

vii

(8)

viii

(9)

Abstrakt

Arbetet motiveras av m˚alet att knyta samman verklighet och modell, samt att se om det finns m¨ojlighet att utveckla ett billigt utbildningsverktyg f¨or utbildning i cyberfysiska system.

Detta projekt har unders¨okt m¨ojligheter att bygga en billig inverterad pendel med regulator samt koppla samman denna med modelleringsspr˚aket Acumen. I Acumen skapa en modell av systemet och j¨amf¨ora den med en fysisk prototyp.

F¨or att l¨osa dessa problem har en 3D skrivare anv¨ants f¨or att skapa h˚ardvara.

Arduino UNO f¨or styrning och Raspberry Pi f¨or att m¨ojlig¨ora kommunikation med Acumen ¨over WLAN.

Resultatet blev en billig inverterad pendel, som kan byggas f¨or en kostnad runt 750 kr. Grafer fr˚an Acumen, och fr˚an data samlad fr˚an sensorer kan analyseras.

Med en modell av en inverterad pendel visar resultaten att Acumen kan anv¨andas i utveckling av cyberfysiska system. Skillnader finns mellan modell och verklighet men ¨aven likheter.

Nyckelord - Reglerteknik, Cyberfysiska System, Inverterad Pendel, Lagranges Ekvationer, PD-Regulator.

ix

(10)

x

(11)

Abstract

The work is motivated by the goal of linking reality and model, and to see if there is an opportunity to develop an inexpensive educational tool for training in cyber-physical systems.

This project has investigated the possibilities to build a cheap inverted pen- dulum with controller and connect this with the modeling language Acumen.

Acumen models is used for comparison with the actual prototype.

To solve these problems has a 3D printer been used to create hardware, Arduino UNO for control and Raspberry Pi for enable communication with Acumen over WLAN.

The result was a cheap inverted pendulum, which can be built for a cost around 750 SEK. Graphs created in Acumen and from data collected from sensors can be analyzed.

With a model of the inverted pendulum system, the results show that Acu- men can be used in the development of cyber-physical systems. There are differences between model and reality but also similarities.

Keywords - Automatic Control, Cyber-Physical Systems, Inverted Pendulum, Lagrangian Mechanics, PD-Controller.

xi

(12)

xii

(13)

Contents

1 Introduction 1

1.1 Goals and Objectives . . . 1

1.2 Limitations . . . 4

2 Background 5 2.1 Acumen . . . 5

2.2 Cyber-Physical Systems . . . 5

2.3 Inverted pendulum . . . 6

2.4 State-of-the-Art . . . 6

2.4.1 Similar projects and products . . . 7

2.5 Conclusion background . . . 8

3 Theory 9 3.1 Modeling of Dynamic Systems . . . 9

3.1.1 Model of a Pendulum . . . 9

3.1.2 Euler-Lagrange’s equation . . . 10

3.2 Control theory . . . 12

3.2.1 Balance control . . . 12

3.2.2 Energy based Swing-Up control . . . 15

3.2.3 Hybrid control . . . 16

3.3 Sensor . . . 17

3.3.1 Encoder . . . 17

3.3.2 Potentiometer . . . 18

3.3.3 Accelerometer and Gyro . . . 18

3.4 Actuator . . . 19

3.4.1 DC motor . . . 19

3.4.2 Servo . . . 21

3.5 Computer Networking . . . 22

3.5.1 TCP . . . 22

3.5.2 UDP . . . 23

4 Method 25 4.1 Approach . . . 25

4.2 Modeling in Acumen . . . 25

4.2.1 Visual model . . . 27

4.2.2 Modeled characteristics of the real system . . . 27

4.3 Communication . . . 28

4.4 Construction of prototype . . . 28

xiii

(14)

4.4.1 Design . . . 29

4.5 Actuation . . . 29

4.6 Automatic Control . . . 30

4.7 Microcontrollers . . . 31

4.7.1 SAM3U4E . . . 31

4.7.2 Arduino UNO . . . 32

4.7.3 Raspberry Pi . . . 33

4.8 Measuring technology . . . 33

4.8.1 Gyro and accelerometer . . . 34

4.8.2 Hengstler rotary encoder . . . 34

4.8.3 Bourns potentiometer . . . 34

4.9 Testing . . . 36

4.9.1 Quality tests . . . 36

4.10 Experiment and analysis of data . . . 37

4.10.1 Network latency . . . 37

4.10.2 Noise level . . . 37

4.10.3 Disturbance rejection . . . 37

4.10.4 Simulation of control program . . . 38

4.10.5 Validation of Acumen models . . . 38

5 Results 41 5.1 Model . . . 41

5.2 Prototype . . . 45

5.2.1 Power requirements and Noise . . . 47

5.2.2 Control system . . . 48

5.2.3 BOM . . . 48

5.3 Communication . . . 49

5.3.1 Network Latency . . . 49

5.4 Simulations . . . 52

5.4.1 Increased task period . . . 52

5.4.2 Increased resolution of the ADC . . . 54

5.4.3 Increased friction . . . 56

5.5 Control system sturdiness . . . 57

6 Discussion 59 6.1 Summary of goals . . . 59

6.1.1 Theory . . . 59

6.2 Analysis and Interpretation . . . 59

6.2.1 Virtual models . . . 59

6.2.2 Network latency . . . 60

6.2.3 Noise level . . . 60

6.2.4 Disturbance . . . 60

6.2.5 Prototype . . . 61

6.3 What would be done differently today . . . 61

7 Conclusion 63 7.1 Experiences . . . 63

7.2 Future work . . . 64

7.2.1 Certification . . . 64

xiv

(15)

Bibliography 67

A Requirement specification 73

B Virtual models in Acumen 77

C Wiring 83

D Control program 85

xv

(16)

xvi

(17)

List of Figures

1.1 Ping pong game in Acumen. . . 1

1.2 Virtual prototype. . . 2

1.3 Typical control system. . . 3

1.4 Control system and Acumen. . . 3

1.5 Control system and Acumen controller. . . 4

2.1 Issues in a Cyber-Physical System (CPS) [5]. . . 5

2.2 Law enforcement Segway. . . 7

2.3 Similar projects and products. . . 8

3.1 Diagram of pendulums. . . 10

3.2 Inverted pendulum. . . 10

3.3 Poles unstable system. . . 13

3.4 Closed loop negative feedback control system. . . 13

3.5 Diagram of a P- and D-controller poles. . . 14

3.6 Diagram of a PD controller’s poles. . . 15

3.7 Hybrid control. . . 16

3.8 Principle of an optical encoder. . . 17

3.9 Principle of an optical absolute encoder. . . 18

3.10 Block diagram of a complementary filter. . . 19

3.11 Basic knowledge about a brushed DC motor. . . 20

3.12 Diagram of a DC motor used for derive motor equations [32]. . . 20

3.13 Block diagram over a servo motor . . . 21

3.14 Difference between TCP and UDP [49]. . . 22

4.1 Visualization in Acumen. . . 27

4.2 Feautures added to Acumen. . . 28

4.3 Design, prototype. . . 29

4.4 Hitec HS-422, DC-servo [56]. . . 30

4.5 SAM3U-EK [60]. . . 31

4.6 Arduino UNO [62]. . . 32

4.7 Raspberry Pi Model B+ [64]. . . 33

4.8 Rotary Encoder, Hengstler RI32-O/1000ER.11KB. . . 34

4.9 Potentiometer, Bourns 3590S-6-103L [69]. . . 35

5.1 Set-up of Acumen simulation. . . 41

5.2 Visual representation of RIP. . . 45

5.3 3D-printed parts. . . 46

xvii

(18)

5.4 Prototype. . . 46

5.5 PWM-signal. . . 47

5.6 Measured angle from potentiometer. . . 47

5.7 Network latency. . . 50

5.8 Latency, sending larger data. . . 51

5.9 Packets got buffered. . . 52

5.10 Simulation of increased period. . . 54

5.11 Simulation increased resolution. . . 55

5.12 Simulation increased friction. . . 56

5.13 Graphs showing the system’s robustness. . . 57

7.1 TOPIO 3.0, a ping pong playing robot [74]. . . 64

xviii

(19)

List of Tables

3.1 Definitions [32] of variables from Fig. 3.12. . . 21

5.1 BOM, all prices in Swedish kronor. . . 49

5.2 Initial condition for simulation. Resolution from the prototype. . 53

5.3 Increased instability. . . 53

5.4 Initial condition for simulation, resolution. . . 55

5.5 Simulation, increased resolution. . . 55

5.6 Initial condition for simulation, friction. . . 56

5.7 Simulation, friction. Change in overshoot and amplitude. . . 56

xix

(20)

xx

(21)

Nomenclature

Abbreviations

ADC Analog to Digital Converter BOM Bill of materials

CAD Computer-Aided Design MCU Microcontroller

PC Personal Computer

PWM Pulse-width modulation RIP Rotary Inverted Pendulum SPI Serial Peripheral Interface SSI Server Side Includes

TCP Transmission Control Protocol UDP User Datagram Protocol USB Universal Serial Bus

WLAN Wireless Local Area Network

Pendulum

Symbol Meaning Unit

α The angle between the horizontal axis and the arm

[rad]

g Gravitational constant [m/s2]

Ja Moment of inertia for the arm [kg ∗ m2] Jp Moment of inertia for the pendulum [kg ∗ m2]

la Length of the arm [m]

lp Length of the pendulum [m]

ma Mass of the arm [kg]

mp Mass of the pendulum [kg]

ra The distance between the arm pivot point and the center of mass

[m]

rp The distance between the pendulum pivot point and the center of mass

[m]

θ The angle between the vertical axis and the pendulum

[rad]

T Kinetic energy [J ]

xxi

(22)

u The linear acceleration of the pivot point

[m/s2]

V Potential energy [J ]

Actuator

Symbol Meaning Unit

β Actuator angle [rad]

βm Motor angle [rad]

Bm Motor, viscous friction [N ms]

ia Current, motor winding [A]

Kb Motor back-emf, constant [V /rad/sec]

Kt Motor torque, constant [N m/A]

La Inductance, motor winding [H]

n Gearbox ratio [n : 1]

Ra Resistance, motor winding [ω]

τ Torque, actuator [N m]

τm Torque, motor [N m]

vm Supply voltage [V ]

xxii

(23)

1 Introduction

This chapter introduces a definition of the problem and objectives of the project.

Although limitations will be described.

Halmstad University has a model of a ping pong game with competing agents in Acumen, shown in Fig. 1.1. This model is used as the term project for the Masters (and Senior Bachelors) level course in cyber-physical systems. The general problem question for the university are how to go from the model in Acumen to a real ping pong playing robot, and to do this in a manner that can allow them to demonstrate this important connection to students taking advanced courses.

Figure 1.1: Ping Pong game in Acumen. Used at Halmstad university as an educational tool.

To achieve this many key critical step has to be taken toward that goal, and this project will be about the first step which will be constructing both virtual and physical models of an inverted pendulum with a controller, and establishing the tight connection between them. Ultimately, the aim is to build working prototypes and then improve and validate the model.

1.1 Goals and Objectives

The needs that the project should satisfy is that the university wants to show students how the real world is connected to the virtual. It will also benefit the global research project Acumen since it should demonstrate that it is possible to use Acumen to make a tangible prototype.

1

(24)

CHAPTER 1. INTRODUCTION 2

To do this a virtual model of the pendulum and its controller will be made in Acumen. And for validating of the simulated model a physical model of an inverted pendulum, including the control system, will be constructed. To test the strong connection between the virtual and physical models, the plan is to set up the virtual and physical systems so that it is possible to have Acumen control the pendulum directly. With this functionality, if there is a difference between the virtual and physical models, there is a chance to improve both to get them to be reasonably consistent.

The work is based on the assumption that by using an inverted pendulum it is possible to experimentally investigate enable virtual prototyping and de- velopment of much more sophisticated robots. By virtual prototyping, it will become feasible to visually observe improvements in the controlling software.

An intriguing ability that will make software contributes more to people’s phys- ical life and well being.

Some requirements for the project from the full requirement specification in Appendix A.

• Develop an accurate mathematical model and visualize it in Acumen.

• Develop an inverted pendulum controller in Acumen.

• Construct inverted pendulum system with controller that communicates with Acumen by WLAN.

• Use data from the sensor in Acumen.

• It shall be possible to build more inverted pendulums to a low cost.

• The pendulum should be able to swing up from an non-inverted position.

Following figures visualize parts of the project that will be implemented to reach the goals that were presented above. One part will be to develop models of the control system in Acumen. Fig. 1.2 shows a block diagram of different parts of a control system modeled in Acumen.

Figure 1.2: Virtual Prototype: Several models interact with each other to create a virtual model that can be observed.

(25)

CHAPTER 1. INTRODUCTION 3

Figure 1.3: Graph of a typical control system. This system will be modeled in Acumen and implemented in a MCU.

In Fig. 1.3 is a graph presented which shows a typical control system. It closely resembles the diagram showed in Fig. 1.2 which representing an Acumen model.

The controller in this system is typically implemented on a microcontroller (MCU) and this control system will also be implemented and running on a MCU as a test to demonstrate closed loop control for the prototype.

Figure 1.4: Control system and Acumen. By connecting the model in Acumen with a real physical prototype can verification be made.

If Fig. 1.3 presents a real system controlling a plant and Fig. 1.2 present a simulation of the same system it is interesting to show how much these two system differs. One step will be to create a connection between these two systems and allow comparison between them. Fig. 1.4 show this link between the control system and the modeling language.

This link can be implemented by using WLAN with a server and a client.

The values can be used to make the models in Acumen to move. These values can also be utilized to provide graphs to make comparisons with the graphs Acumen presents.

(26)

CHAPTER 1. INTRODUCTION 4

Figure 1.5: Control system and Acumen controller. By enabling Acumen to send actuation signals in real time, difference between model and reality can be further examined.

One goal of the project is to make Acumen to be a part of the control loop as showed in Fig. 1.5. This would make it possible to use and verify the con- troller in Acumen directly by enabling it to send actuation signals to actuators.

By switching from the MCU controller and Acumen controller their behavior can be compared. This enables the engineer to work more on models and con- trollers in the modeling language and verify the function in the real world before implementing the control on a MCU.

1.2 Limitations

In this project, an inverted pendulum with a movement in two degrees of freedom is considered.

Control

The control system should only keep the pendulum upright. This implies that the arm the pendulum is mounted on is allowed to move in order to keep the pendulum from falling but no or small effort is made to control the arm position.

Control of multiple variables like arm position and angle of the pendulum is possible but requires more complex control system.

Budget

The project has a budget of 6000 SEK that should not be exceeded. To achieve this equipment provided from the university should be used when necessary.

One prototype should cost around 100 dollars to reproduce. This is because it should be possible to sell the prototype to schools in developing countries.

Even if the final prototype should cost around 100 dollars so can more sensors for validation be used.

(27)

2 Background

This chapter provides a description of the work done related to this project.

Research and similar projects will be presented. A description of Acumen and the inverted pendulum will also be given here.

2.1 Acumen

Acumen is a program currently developed by Prof. Walid Taha and the rest of the Effective Modeling research group [1]. It is used for modeling and simulation of dynamic systems that have both continuous and discrete behaviors, so called hybrid systems [2].

This is important in applications like real-time software, robotics and mecha- tronics. In recent years, methods for modeling of hybrid systems has been de- veloped and Acumen is one of the applications were it is possible to perform modeling in. Another modeling language which have likeness to Acumen is Modelica. Modelica is used in industry by many companies [3]. This concludes that there is a need for research and improvements in modeling languages to meet the industry today and in the future.

2.2 Cyber-Physical Systems

A cyber-physical systems [4] deals, Fig. 2.1, with the interaction between soft- ware and a physical process. Embedded computers that wireless monitor phys- ical processes, through feedback, which affects computations is a typical cyber- physical system.

Figure 2.1: Issues in a Cyber-Physical System (CPS) [5].

5

(28)

CHAPTER 2. BACKGROUND 6

Economic and social conditions is greater than realized and great efforts are be- ing made to develop the technology. Significant challenges exist because physical components differs from object-oriented software components through quality and safety.

2.3 Inverted pendulum

An inverted pendulum is a pendulum upside down with it pivot point placed under its center of mass. This form an inherent unstable system. While the inverted pendulum can stand up as described before, inverted position, any small disturbances will cause the pendulum to fall. An inverted pendulum controller’s job is to keep the pendulums center of mass above its pivot point even when disturbances occur [6].

2.4 State-of-the-Art

The inverted pendulum problem is not uncommon in the field of control engineering. The uniqueness and wide application of tech- nology derived from this unstable system has drawn interest from many researches and robotics enthusiasts around the world. In re- cent years, researchers have applied the idea of a mobile inverted pendulum model to various problems like designing walking gaits for humanoid robots, robotic wheelchairs and personal transport systems. ([7], p.2).

As Rich Chi Ooi [7] writes in its thesis so has much work been done to build robots based on the inverted pendulum principle. Work on both how to build the robot, but also how to explain its behavior mathematically.

For example a demonstration of how Lagrange’s method can be used for a simple inverted pendulum on a cart [8], and how Lagrange’s method can be used to describe the pendulum physical properties [9, 10]. Thesis projects which discusses how to build a two-wheeled robot that can self-balance only by reading and understand data provided from the sensors and act on the two wheels according to the inverted pendulum model [7, 11–15].

Research papers that describes the use of the inverted pendulum princi- ple and how it gives an effective application. The papers addresses control of under-actuated systems like the inverted pendulum on a cart, mobile inverted pendulum which can be a Segway, like the one in Fig. 2.2, and gait pattern generation for humanoid robots [16, 17]. A research paper from Swiss Federal Institute of Technology Lausanne that presents JOE, which is a mobile inverted pendulum and a revolutionary prototype of a balancing robot [18]. Books and tutorials which describe the control theory for the inverted pendulum problem and the mathematics necessary for the calculation of the pendulums physical properties [6, 19, 20].

(29)

CHAPTER 2. BACKGROUND 7

Figure 2.2: Law enforcement Segway, offers added mobility in an urban envi- ronment [21]. This is an product based on the inverted pendulum principle.

Experiments have been done with all kind of hardware, for example, a tutorial of how to build a rotary inverted pendulum [22], a robot balancing an inverted pendulum have been done with Lego [23] and a couple of videos showing a pendulum on a cart standing up straight [24–27].

It is currently important in the development of control systems to make unstable systems safer. So when testing control system it is common to use the classic nonlinear problem of the inverted pendulum which without control system will become very unstable [28].

Acumen can run in real time and interact with the real world. In the work of Xu Fei, he shows that it is possible to get position readings from an smart-phone to control a racket in Acumen. This is done over WLAN. This capability could be used to interact with the inverted pendulum prototype directly [29, 30].

2.4.1 Similar projects and products

A product developed for academic teaching is an Rotary Inverted Pendulum Trainer on a NI ELVIS platform with LABVIEW™ software from National In- struments [31], shown in Fig. 2.3a. Unit price for a NI ELVIS platform with Rotary Inverted Pendulum plug-in module and LabVIEW™ software will cost at least 120 000 SEK where only the pendulum module costs around 20 000 SEK.

(30)

CHAPTER 2. BACKGROUND 8

(a) RIP on NI ELVIS platform [31]. This product is commercially available, but very expensive.

(b) RIP on a servo motor [32].

Figure 2.3: Similar projects and products.

A project has been made with cheap hardware and self-manufactured parts [33]

and describe how to proceed to build and analyze an inverted pendulum on a cart. No results are presented on whether the person succeeded to get the pendulum to balance or not.

In [22] a guide is presented on how to build an Rotary Inverted Pendulum (RIP) with controller for approximately 2000 SEK.

An RIP on a servo motor, Fig. 2.3b, to demonstrate model-based design of a cyber-physical system. The system is modeled using Simulink and Modelica [32]. Something similar would be possible to construct and model with Acumen.

2.5 Conclusion background

An inverted pendulum is a popular problem in control theory and much work has been done in this subject both by amateurs and professionals. By examine the material provided on the net further and with sufficient hardware it should be possible to create an inverted pendulum with a controller.

The basic math on how to describe the physics of this kind of system is also available and can be used to derive the equations needed for modeling in Acumen.

(31)

3 Theory

This chapter provides a description of the theory needed to model an inverted pendulum in Acumen. Theory of different sensors and actuators which is the basis for component selection. As the project includes transfer of data is theory for network communication also given here.

3.1 Modeling of Dynamic Systems

Dynamic systems are often used as a part of the modeling of mechatronic sys- tems. A dynamic system’s behavior depends on how it affected at an earlier time. To analyze a dynamic system will an mathematical model be required.

The model can be linear or nonlinear, and both continuous and discrete [34].

3.1.1 Model of a Pendulum

In the Free body diagram of a pendulum, Fig. 3.1a, is it possible to see the pendulum pivot point being accelerated u in one direction, that will give the pendulum an acceleration that will cause the pendulum to swinging upward to an inverted position.

When it has reached its inverted position, it needs a controller that can keep it balanced, an application which requires this is the RIP in Fig. 3.1b.

In order to calculate the moment of inertia Jp of the pendulum can the general expression (3.1) be used.

Jp= Z

r2dm (3.1)

were r is the distance from the pivot point. For a simple pendulum can the sum of all elemental point masses dm multiplied by the square of the length be generalized to

Jp= mplp2. (3.2)

The resulting nonlinear equation of motion of the pendulum in Fig. 3.1a is given by

Jpα(t) = m¨ pg rpsin α(t) + mpu rpcos α(t) (3.3) which will later be used to create an energy controller that can swing up the pendulum [35].

9

(32)

CHAPTER 3. THEORY 10

(a) Free body diagram of a regular pendu- lum.

(b) Rotary Inverted Pendulum - RIP.

Figure 3.1: Diagram of pendulums.

Differential equations is commonly used to describe dynamic systems. One method to find a fitting equation for a system is by Lagrangian mechanics. By using the Lagrangian it is possible to set up the equation of motion by using the equation of kinetic energy together with the equation of potential energy.

This form an equation over the dynamic system behavior and will later be used to create a balance control that can balance the pendulum.

3.1.2 Euler-Lagrange’s equation

Figure 3.2: Inverted pendulum. By using Euler-Lagrange’s equation so can this system be described mathematically.

The Lagrangian L definition [36] in Equation 3.4 will be used to derive the equation of motion for an inverted pendulum.

L = T − V

= 1

2m v2− m g h. (3.4)

In Equation 3.4 are T and V replaced with their respective definition of kinetic and potential energy. Were v stands for velocity, m mass and h displacement in

(33)

CHAPTER 3. THEORY 11

height. The potential energy of the pendulum, which is in its inverted position, shown in Fig. 3.2 is

V = mpg lp cos α. (3.5)

The pendulums velocity can be divided into a vector v representing the change in position. The pendulums position from Fig. 3.2 is presented in Equation 3.6.

x = lpsin α, y = lpcos α. (3.6) In Equation 3.4 can v2be rewritten to l2pα˙2by using Pythagorean trigonometric identity.

v2= ˙x2+ ˙y2

= (lpα cos α)˙ 2+ ( − lpα sin α)˙ 2

= l2pα˙2(sin2α + cos2α)

= l2pα˙2.

(3.7)

The Lagrangian (3.4) becomes then L = 1

2mpl2pα˙2(sin2α + cos2α) − mpg lp cos α

= 1

2mp(l2pα˙2) − mpg lp cos α.

(3.8)

The Euler-Lagrange equation is defined as d dt

∂L

∂ ˙α =∂L

∂α (3.9)

and the Lagrangian (3.8) can be substituted into Euler-Lagrange’s equation (3.9) by taking the time derivative and partial derivatives with respect to α and

˙ α.

∂L

∂α = mpg lpsin α, d dt

∂L

∂ ˙α = mpl2pα¨ mplp2α = m¨ pg lp sin α ⇒ α =¨ g

lp sin α.

(3.10)

The same method can be used for an inverted pendulum on a cart.

x = p + lpsin α, y = lpcos α,

˙

x = ˙p + lpα cos α,˙ y = −l˙ pα sin α.˙ (3.11) Equation 3.11 differ from Equation 3.6 because it has a variable p which repre- senting a cart position. Using Equation 3.4 to get the kinetic energy T of the system gives

T =1

2mp( ˙p2+ 2 lpp ˙˙α cos α + l2pα˙2). (3.12) Use the Lagrangian definition (3.4) with T and V (3.5) to get the Lagrangian

L = T − V = 1

2mp( ˙p2+ 2 lpp ˙˙α cos α + l2pα˙2) − mpg lp cos α. (3.13)

(34)

CHAPTER 3. THEORY 12

Using Equation 3.9 to take the time derivative and partial derivatives as in Equation 3.10 gives then

mplp2α + m¨ plpp cos α = m¨ pg lpsin α ⇒ ¨α = g sin α − ¨p cos α lp

. (3.14) The conclusion of this is that a longer pendulum will accelerate slower and it is therefore possible to have a slower actuator. This result will be used when the balance control system will be designed, see Section 3.2.1.

3.2 Control theory

Control theory about a PD-controller that can balance the pendulum, the energy controller to swing it up and the hybrid control to create a system of both functions is provided in this section.

3.2.1 Balance control

Alan V. Oppenheim, Professor of Engineering at MIT’s Department of Electrical Engineering and Computer Science [20], have an open lecture about control theory and feedback. This section sum up some of the points he gives. The motion of an inverted pendulum was described in Section 3.1.2 and by using Equation 3.14 which can be written as

lpα(t) = g sin α(t) − u(t) cos α(t).¨ (3.15) This system is not linear. By assuming that α(t) is close to zero a linear system can be achieved since

sin α(t) ' α(t), cos α(t) ' 1

⇒ lpα(t) − gα(t) = −u(t).¨ (3.16) Using the Laplace transform (α(t) ∼ A(s)) on Equation 3.16 gives

A(s) = 1

lps2− g (−U (s)) (3.17)

where U (s) is the input to the system and 1

lps2− g = H(s) (3.18)

which is the plants transfer function. The poles in the s-plane are s = ±

rg

lp (3.19)

which gives an unstable system due to poles in the right plane, see Fig. 3.3.

(35)

CHAPTER 3. THEORY 13

Figure 3.3: Poles in the s-plane. Since one pole is on the right half plane the system is unstable.

PD-Controller

Figure 3.4: Closed loop negative feedback control system.

To achieve a stable system can Proportional (P) plus Derivative (D) feedback be used. The carts acceleration u(t) is proportional to the pendulums angle α with a constant K1 and to the derivative of the pendulums angle ˙α with a constant K2.

u(t) = K1 α(t) + K2 ˙α(t). (3.20) By choosing reasonable values of K1 and K2 a PD-controller can be imple- mented. The system function G(s) is given by the Laplace transform on u(t)

G(s) = U (s) = K1 + K2 s. (3.21)

The closed loop system function A(s) of the system shown in Fig. 3.4 is described by

A(s) = H(s)

1 + G(s) H(s) (3.22)

and inserting Equation 3.18 and 3.21 in 3.22 gives the closed loop system func- tion

(36)

CHAPTER 3. THEORY 14

A(s) =

1 lps2−g

1 + (k1 + k2 s)l 1

ps2−g

= 1

lps2− g + k1 + k2 s.

(3.23)

The system poles for Equation 3.23 can then be calculated to be

0 = s2+ s (K2/lp) − g/lp+ K1/lp

⇒ s = −K2 2 lp

± s

(K2 2 lp

)2−K1 − g lp

. (3.24)

With a positive K2 so that K2 2 lp

>

s (K2

2 lp

)2−K1 − g lp

(3.25)

and poles in the left plane is achieved which implies a stable system. Now, Equation 3.15 is attributed to

lpα(t) = g sin (α(t)) − (K1 α(t) + K2 ˙¨ α(t)) cos (α(t)). (3.26) In Fig. 3.5a is it presented how the poles move with increasing K1, Fig. 3.5b shows how the poles change with increasing K2. Figures are made in MATLAB.

(a) P-control. When increasing the P-part of the controller the poles moves along the imaginary axis.

(b) D-control. With only D-control the pole in the right never cross the imaginary axis. The system do not become stable.

Figure 3.5: Diagram of a P- and D-controller poles.

With only proportional control, a stable critical system can be achieved. When increasing the P-part of the controller poles move along the imaginary axis.

This means the system will oscillate and never settle. With only D-control the system cannot become stable. By using the P and D together can be a stable system be achieved, according to Fig. 3.6.

(37)

CHAPTER 3. THEORY 15

Figure 3.6: PD-control: Used together the poles ends up in the left-half plane and a stable system is achieved.

If external disturbances is added to the system, Equation 3.22 will then become A(s) = H(s)

1 + G(s) H(s)lpQ(s) (3.27) which don’t change the poles of the system. Equation 3.26 becomes then with disturbances

¨

α(t) = g sin (α(t)) + lpq(t) − (K1 α(t) + K2 ˙α(t)) cos (α(t)). (3.28)

3.2.2 Energy based Swing-Up control

Katsuhisa Furuta and Karl J. ˚Astr¨om [37] has a simple algorithm for swinging up a pendulum by assuming that the pendulum begins with zero velocity in its non inverted position. And if the pivot point is accelerated in one direction, the pendulum begins to swing upward toward an inverted position as described in Section 3.1.1. By letting the pendulum swing symmetrical about its pivot point, this will pump sufficient energy to the pendulum so that it can swing up to an inverted position. An introduction of how to perform an energy control was given in [35]. The energy equations of the pendulum is given in Equation 3.29 and 3.30 with the assumption that the pendulum starts in its non inverted position as in Fig. 3.1a. The potential energy

V = mpg rp(1 − cos α) (3.29) and the kinetic energy

T =1

2Jpα˙2. (3.30)

The total energy E of the pendulum become then E = mpg rp(1 − cos α) + 1

2Jpα˙2 (3.31) and differentiating gives the differential equation

(38)

CHAPTER 3. THEORY 16

E = ˙˙ α Jpα¨2 + mpg rpsin α (3.32) substituting Equation 3.3 into 3.32 to get the pendulums acceleration

E = m˙ pu rpα sin α.˙ (3.33) By assuming that the arm acceleration is proportional to the motor drive cur- rent and voltage will it be easier to control the energy of the pendulum. The proportional control law will increase the energy E towards the reference energy Er

u = (Er− E) ˙α cos α. (3.34) This equation is nonlinear and depend on the pendulums angle. It is this linear acceleration u that will be controlled in order to swing up the pendulum.

To use the energy control to swing up the pendulum, Equation 3.34 has to be modified because the control signal have to be large in order to change the energy fast and the control signal have to be saturated at the maximum acceleration for the arm.

u = sat(µ(Er− E) ˙α cos α) (3.35) where sat will saturate the control signal and µ will gain the control signal.

3.2.3 Hybrid control

In order to both balance the pendulum and swing it up so can the swing-up control be combined with the balance control according to Fig. 3.7.

Figure 3.7: Hybrid control. Two controllers run in parallel, the switch choose which one to use. The switch is done at some discrete event. For an inverted pendulum system can this discrete event happen when the error is within a certain value.

Hybrid system is both continuous and discrete. The both closed loop controller is continuous while the switching part is discrete. The switching part choose which controller to use. The balance controller is used in the interval where the angle is close to 0. When the pendulum is outside that range the system switch to the swing-up controller [35].

(39)

CHAPTER 3. THEORY 17

3.3 Sensor

One part of a control system is a sensor that gives feedback to the controller. In this case a sensor that can measure the angle of the pendulum is needed. Some techniques to measure rotary applications is going to be described.

3.3.1 Encoder

Incremental encoder

A common encoder is the optical encoder, which consist of a circular disk with opaque lines and patterns that creates a coded track mounted on a rotating shaft, a light source and a photo detector (light sensor), see Fig. 3.8. When the disc rotates, the photo sensor will detect the segments in the disc and usually generate a square pulse signal output that can be used in a counter. The resolution on the encoder depends of the number of segments per revolution [38].

Figure 3.8: Principle of an optical encoder [39]. A LED send light through a disc with holes. When the disk spin, signals is generated, in form of square waves. This signal can be used to sense speed.

A measure of the direction of rotation is not possible with only one kind of pulse.

To do that two code tracks is used which is called quadrature outputs, because they are 90 out of phase with each other, and the direction is determined by the phase relationship between the two channels. The position is calculated by adding up the number of pulses in a counter.

A disadvantage with incremental encoder are that they loses the count when power is turned off. When it should start over, the equipment must begin in a home location to initialize the counter.

Absolute encoder

In applications were absolute position information is needed this type of encoder are used. The principle of an absolute encoder is similar to the incremental en- coder, the difference is how the segments are placed [40]. Absolute means that each position is unique. It is composed by some channels that are combined binary, the number of channels will determine how high resolution it is possible to get. The encoder will emit a combination of signals that together will deter- mine the actual position. Unlike the incremental encoder the absolute encoder

(40)

CHAPTER 3. THEORY 18

is not needed to start in a fixed reference point because as soon as the voltage is turned on it will notify the control system the exact position.

Figure 3.9: Principle of an optical absolute encoder [41]. With several LED and several different signals generated, position and speed can be sensed.

As shown by Fig. 3.9, the disc consists of several channels that determine the position. The upper first channel determines which half of the disc, the second quarter, and the third eighth and so on. The segments are arranged so that the binary code that is provided is a Gray code. It uses Gray code, because every change is changing only one bit at a time and know exactly where it is, even if it is between two different segments.

3.3.2 Potentiometer

The potentiometer is a form of controllable resistor, it has a shaft which ro- tates a slide connector along a resistive path. A potentiometer functioning as a voltage divider where the voltage gained from the potentiometer can be used to determine the absolute position. There are single and multi-turn potentiometer and the difference between them is that the multi-turn has greater precision [42].

To use that analog signal in a MCU, there is first a need to convert the analog signal to a digital signal and it is made with an Analog to Digital Converter (ADC). Sending in an electrical analog signal on the ADC and it outputs a binary value. The value that comes out is the rounded value of the original sample as the number of bits is not unlimited [43].

3.3.3 Accelerometer and Gyro

By using these two components together, it is possible to measure the angle along a single axis [44]. Earth’s gravity has a constant acceleration and when an accelerometer is parallel to gravity so will the measured acceleration be 1G and when it is perpendicular to gravity 0G. And by using Equation 3.36 where A is the measured acceleration and g is the gravity of Earth the tilt angle α can be calculated.

α = arcsinA

g. (3.36)

(41)

CHAPTER 3. THEORY 19

There can be incorrect measurements of the angle if the accelerometer is used on an object that is affected by other accelerations. To avoid that it is possible to use a low pass filter to filter out high-frequency acceleration. By using a low pass filter the measurement will take even longer time.

A gyroscope measures the angular velocity and by integrating the velocity it is possible to get the angle. When a gyro is in a stationary position, it will not delivering a constant offset. This phenomenon is called drift. Upon integration the smallest offset can cause data to grow to infinity.

By using a complementary filter it will be possible to use the gyro data for a short time and use the accelerometer to correct drift over time. This way is one solution to rapidly provide an angle and a drift-free system.

Figure 3.10: Block diagram of a complementary filter. This is needed because the sensed angle from the gyro can drift over time. While the accelerometer is noisy. By using them together they can complement each other.

Fig. 3.10 shows a block diagram of a complementary filter, it will combine the best part from the two sensor signals. Inputs to this complementary filter is an angle from the accelerometer and an angular velocity from the gyro. The angle from the accelerometer is low pass filtered to reduce influence from short duration signals. The gyro data is integrated to give an angle and high pass filtered to remove long-term drift. These two filtered signals are then summed up together to give a single estimated angle [45].

3.4 Actuator

An actuator is a device used to control a mechanical system. The actuator is controlled by a signal and converts the signal into mechanical motion. In order to balance the pendulum it will require some form of actuators that can perform the work to balance the pendulum.

3.4.1 DC motor

A basic DC motor [46], Fig. 3.11a, consists of an axle, armature, stator and commutator. Brushed DC motors have also brushes. The stator contains of the motor case and coils or permanent magnets depending on type of motor. The principle of a DC motor is to convert electrical energy to mechanical motion.

A brushed DC motor allows an electric current to flow through an armature, which is also called the rotor, placed in a magnetic field to produce a force which

(42)

CHAPTER 3. THEORY 20

causes the rotor to rotate.

Fleming’s left hand rule can be used to determine in which direction the motor will rotate. Hold the left hand as Fig. 3.11b shows, let the index finger go in the magnetic field direction and the middle finger in the direction of the current so will the motor rotate in the direction of the thumb.

To create a magnetic field can either electromagnets or permanent magnets be used. The split ring commutator has two segments which closes the armature circuit, and the main task of the commutator is to reverse current so that the rotor can continue to rotate in the same direction. The brushes drag against the commutator and feed it with electrical power. The most common DC mo- tor brushes is made of graphite, but in the past brass and copper was used.

Nowadays, engineers work to make metal brushes more effective than graphite brushes.

(a) Picture shows how a brushed DC motor is constructed [46].

(b) Fleming’s left hand rule [47].

Figure 3.11: Basic knowledge required to understand how a brushed DC motor works and is built.

A brushless DC motor works the same way as the brushed. The difference is that they are differently constructed. In a brushed DC motor is the rotor composed of coils and the stator consists of magnets. In a brushless DC motor is this the opposite.

Figure 3.12: Diagram of a DC motor used for derive motor equations [32].

(43)

CHAPTER 3. THEORY 21

La Inductance, motor winding Bm Motor, viscous friction Ra Resistance, motor winding τ Torque, actuator ia Current, motor winding τm Torque, motor

vm Supply voltage n Gearbox ratio

Kb Motor back-emf β Actuator angle

Kt Motor torque βm Motor angle

Table 3.1: Definitions [32] of variables from Fig. 3.12.

Based on Fig. 3.12 so is the motor dynamics [32] set in Equation 3.37, definitions can be seen in Table 3.1.

La˙ia+ Raia= vm− Kbβ˙m

τm= Ktia− Bmβ˙m. (3.37)

3.4.2 Servo

Figure 3.13: Block diagram over a servo motor. A feedback loop with P-control is implemented inside the servo. The goal is to control the position of the servo.

Setpoint is given by PWM.

A servo is a motor which does not usually rotating full turns, instead it will move into a position. To do this it will need a feedback loop with a sensor for measuring the position of the shaft and something that can take decisions based on the feedback. A small servo, Fig. 3.13, usually consists of an amplifier (K), a sensor, a DC motor (M) and a gearbox (G) to reduce the speed and increase the torque.

In cheap servos is potentiometer the most common sensor used to measure the position of the shaft. It also have an error signal generator that compares the set point with the actual value and move the servo until the error is eliminated.

A servo is controlled by the width of the pulse sent to the servo, that means the servo is controlled by PWM [48]. As can be seen in Fig. 3.13 the amplifier

(44)

CHAPTER 3. THEORY 22

(K) works as a P-controller. By adding a gearbox to the model of a DC motor, Equation 3.37, can a linear model [32] of a servo be obtained.

τ = τmn

β = βm/n. (3.38)

This equation can be used to model the dynamic behavior of the actuator.

3.5 Computer Networking

As stated in Section 1.1 the prototype should communicate over WLAN. In order to send and receive data over WLAN between a server and a client a socket is needed. There are two types of sockets, TCP and UDP, see Fig. 3.14.

They differ in reliability, package delivery order, connection and method of transmission.

Figure 3.14: Difference between TCP and UDP [49].

3.5.1 TCP

TCP is a connection-oriented protocol where a connection between two applica- tion programs is established and maintained until all segments have been sent and/or received. TCP explains how to break down the application data into segments, how to send and receive data, flow control, retransmission of lost or damaged segments and confirmation that the segment arrived.

TCP guarantees that all segments will arrive because it sends back to the sender an acknowledgment that it has received a segment, it will also ask the sender to resend the segment if it didn’t arrive. If any segments gets lost, TCP sorts the received segments so they end up in the order the segments were transmitted in. Retransmission and that TCP have to sort segments after they arrived can cause latency in TCP transmission [50].

(45)

CHAPTER 3. THEORY 23

3.5.2 UDP

UDP is an alternative to TCP. Unlike TCP which sends data in segments, UDP sends single packets. Because UDP is a connection less protocol it does not create a connection between sender and receiver before a packet is transmitted.

Therefore, the receiver cannot know if all packets were received or if they came in the right order. If the receiver receives a fragmented packet it’s discarded and the receiver does not request the sender to resend the package. UDP assumes that the application program takes care of delayed and lost packets [51].

(46)

CHAPTER 3. THEORY 24

(47)

4 Method

This chapter will describe the approach and how the components was selected.

Various components pros and cons will be critically analyzed against each other.

Methods for testing against requirements will also be described.

With the background material as a base, a requirement specification has been developed. The requirement specification describes the requirements of each subsystem, in order to have the goal deemed to be fulfilled. The requirements are written so that they can’t be interpreted in several different ways. With a requirement specification, see Appendix A, it is possible to start working on a prototype. The prototype will be tested against the specifications.

4.1 Approach

The project will attempt to keep an idealized design process which is an itera- tive process. It has four steps that are repeated until a finished product [52].

The 4 steps of an iterative process.

• Modeling continuous systems (eg inverted pendulum).

• Simulating models in a modeling program (eg Acumen).

• Build a prototype.

• Comparing the model against the prototype.

4.2 Modeling in Acumen

Modeling makes it possible to find out new ideas and implementations before they become prototypes. This is desirable since prototypes can be expensive, especially if they contain errors.

Acumen is a program for modeling of dynamic systems, but there are several other programs that can do that, for example, MATLAB, Mathematica and Modelica. Since this project will favor the development of Acumen will then all modeling be done in this program.

At Acumen will an RIP be modeled and it should be as similar to the real prototype as possible. To begin with, only the real and the virtual model will be compared visually. It is only when the model is as close to the real, and it’s

25

(48)

CHAPTER 4. METHOD 26

hard to tell the difference between them, it will be essential to collect sensor data to Acumen and compare them with data Acumen generate.

The Euler-Lagrange method can be used to model the dynamics of the sys- tem. These methods is presented in Section 3.1.2. Equation that are derived will be rewritten to fit Acumen.

lpα(t) = g sin α(t) − u(t) cos α(t).¨ (4.1) Equation 4.1 is the same as Equation 3.15 which was presented in Section 3.2.1 and can be rewritten into Acumen, as in Program 1.

Program 1 Equation 4.1 rewritten to Acumen language.

angle’’ = (g * sin(angle) - pos’’ * cos(angle)) / len;

Acumen supports object-oriented modeling. Models can be encapsulated to make more readable models. It is also possible to write Acumen simulations without this object-oriented manner. The choice to make Acumen simulations that consist with several models that interact with each other is motivated by the need for further development. Changes or additions to the model will be made and without an clear understandable setup this becomes difficult. In Fig. 1.2 and Fig. 1.3 in Section 1.1 the idea how these models should interact is presented. More details in how to model in Acumen is presented in tutorials by Walid Taha [53, 54]. In Program 2, basic set up for object-oriented modeling is shown.

Program 2 Modeling, Counter class example.

// Model of a counter class Counter()

// Differential equation

// t’ = 1, with the initial condition t(0) = 0 private

t := 0; t’ := 1;

end end

// Create the counter and waits until the simulation is done.

class Main(simulator) private

mode := "init";

end

switch mode case "init"

create Counter();

mode := "wait";

case "wait"

end end

(49)

CHAPTER 4. METHOD 27

4.2.1 Visual model

Models in Acumen can be presented visually as stated in Section 1.1. This is done by connecting variables from models with graphical presented objects.

Program 3 is a visualization of a pendulum. A picture of the pendulum can be seen in Fig. 4.1.

Program 3 Visualization of a pendulum.

_3D =

[["Cylinder",

[0, pos + sin(angle), cos(angle)], // Center point

[0.05, 2], // Thickness, length

yellow, // Color

[-angle + pi/2, 0, 0]]]; // Tilt angle

Figure 4.1: Visualization of the pendulum in Acumen.

Depending on how the variables angle & pos change so will this cause the visual model to move.

4.2.2 Modeled characteristics of the real system

The model of the inverted pendulum will have certain characteristics in order to mimic the reality. The characteristics are

• Quantization - Some sensors can’t detect small changes.

• Discretization - Control algorithms is often implemented as task running at a predefined period [55]. This can be modeled in Acumen using a variable as timer.

Quantization is modeled as an if-statement.

if x > x_sample + sensitivity_of_sensor

x_sample := x_sample + sensitivity_of_sensor

(50)

CHAPTER 4. METHOD 28

While discretization is modeled with timers.

if timer_value >= task_period timer_value := 0 // Reset timer // Do periodic task

4.3 Communication

A controller shall be developed in Acumen, and it should send control signals to the prototype and the model, as presented in Fig. 1.5 and Fig. 4.2. Efforts are going to be made to add functionality to Acumen that enable communication with the real world. This will be implemented with programming in Scala and or Java, using sockets and WLAN. Scala is the language Acumen is designed and programmed in, but it is possible to use Java classes in Scala.

The communication will be implemented as a server added to Acumen and it will communicate with a client on the prototype, Fig. 4.2. A client will be implemented on a Raspberry Pi and it will communicate with the server in Acumen through WLAN.

Figure 4.2: Server should be added to Acumen. Efforts is going to be made in order to control of the prototype from Acumen.

According to Section 3.5, UDP is the best choice for real streaming of sensor data. But since no connection at the protocol level is created between the PC and the prototype, the server can not know who is sending the data. A desirable feature is that it should be possible to see if there is a connection between the server and client, and then TCP is the best choice because UDP does not connect directly to the receiver like TCP does. The biggest reason that TCP will be selected is that the idea that in the future, be able to communicate with multiple clients. With UDP, it is not possible to know who sent the data for anyone can send to the recipient’s UDP port. To be able to see who sent the data, TCP, has been prioritized before the higher transmission rate of UDP.

4.4 Construction of prototype

A study was made between the inverted pendulum on a cart and a RIP. The pro- totype that was chosen to be built is the RIP, because it consists of a minimum number of mechanical parts. Generally, fewer parts that are used, the cheaper prototype. This makes it also easier to meet the requirement of an inexpensive prototype. The prototype will mainly consist of a servo, a potentiometer (to measure the pendulums angle) and a MCU. Justification for the choice of these components will be made later in this chapter.

(51)

CHAPTER 4. METHOD 29

These components will be assembled to a prototype and to assemble these parts, a 3D printer will be used to create mechanical parts. A 3D printer will be used since it can produce parts for prototypes quickly and easily to a low cost. To print these parts, the first thing is to design them in a CAD program. Knowledge is available in the CAD program SolidWorks and will therefore be used.

Figure 4.3: Design, A MCU interact with a potentiometer and servo in order to keep the pendulum upright. Sensor data is sent over WLAN.

Fig. 4.3 shows how the prototype is supposed to work. The servo should keep the pendulum upright and the potentiometer measures the pendulum’s angle. The measured angle is sent to the MCU and out of the MCU comes control signals to the servo. The MCU will also handle the communication with Acumen.

4.4.1 Design

All parts will be mounted on a plate that it is possible to drill in. The MCU comes with pre-drilled screw holes, so it will only be to drill the holes in the plate and screw it on. A servo bracket is a part that will be made in a 3D printer. A bracket is needed since there is a risk that the servo creates large forces that it will loosen. The servo brackets job is to ensure that the servo is fasten properly.

In order for the servo to be able to keep the pendulum upright will one arm out from the servo be printed out by the 3D printer. At the tip of the arm will a potentiometer be mounted. The arm will be designed to be mounted on the servo and have a potentiometer mounted at the front. A bracket to mount the pendulum on the potentiometer shaft will also be printed. The pendulum will be a rounded rod.

4.5 Actuation

There are essentially two types of actuators that have been studied in detail.

A DC motor and a servo motor. The two factors that have determined the choice are the speed and torque. The speed is needed for the system to rapidly compensate the pendulum tilt angle. The torque is required for the motor to be capable of moving the arm where the pendulum is mounted on. Both types

(52)

CHAPTER 4. METHOD 30

of motors can cope with the job because there are projects that have used them successfully, see Chapter 2.

A DC motor with gear can hold both high speed and have a high torque, but then requires higher power. A DC motor also requires additional electronics in the form of an H-bridge to change the direction.

Figure 4.4: Hitec HS-422, DC-servo [56].

Servos consists of a DC motor with gearbox and has built-in electronics, accord- ing to Section 3.4.2. A servo has the limitation that it has a limited operating range. It will therefore be a risk that the servo can reach its end position be- cause no control of arm position is made. The pendulum will fall when the servo reaches its end position.

One crucial factor is the cost, a servo is cheaper than a DC motor with gearbox and associated electronics. A servo was selected with the justification that the pendulum should not raise so large excursions so that the servo reaches its end position. The selected servo is Hitec HS-422, Fig. 4.4.

4.6 Automatic Control

Different method to implement an closed-loop controller exist. One common controller is the PD (Proportional & Derivative) controller. It has its back- ground in analog control but is often used in digital systems, together with ADC. To make the algorithms work well the computer system must sample the continuous signal measured from the plant accurate so a discrete representation of the continuous signal can be obtained. The sampling is an drawback for the PD controller implemented in a computer. To recreate the signal in a computer must the sampling be done at a frequency that is at least twice so big as the signals, according to Nyquist–Shannon sampling theorem [57].

Some other control methods that came up during the background investigation.

• Fuzzy logic control.

• P-, PI-, PD- and PID-control.

• Energy based control.

• Hybrid control.

(53)

CHAPTER 4. METHOD 31

• Sliding mode control.

• Feedforward control.

• LQR.

Since the project group already have experience about PD control and the survey of the field, Section 2.4 and Chapter 3, shows that this method have been used successfully before. It was chosen to get implemented. Energy based control and hybrid control was also chosen to be implemented in order to swing-up the pendulum and combine swing-up with balance control. Because they are the most common methods, according to Chapter 2.

4.7 Microcontrollers

A MCU will be needed to read the sensor data, send control signals to the actuator and manage communication with a server that will be available on a PC. Comparisons between different MCU will be done here, and ends with an explanation of why Raspberry Pi was selected.

4.7.1 SAM3U4E

SAM3U4E, Fig. 4.5, is a chip which contains of an ARM cortex-M3 reduced instruction set computing processor. Maximum speed of operation is 96 MHz for the Cortex-M3. The chip also includes peripherals such as timer counters, real-time timer, PWM, 12-bits ADC. The timer counters are equipped with quadrature decoder logic. SAM3U is very well suited or USB applications [58].

Platforms with the SAM3U4E microprocessor is the SAM3U-EK and Arduino DUE [59].

Figure 4.5: SAM3U-EK [60].

Benefits

• Many I/O.

• Good real time capabilities.

• Quadrature decoder logic.

• High resolution on the ADC.

(54)

CHAPTER 4. METHOD 32

Disadvantages

• No WLAN module is included.

• Expensive.

4.7.2 Arduino UNO

Arduino UNO, Fig. 4.6, is a development platform with an 8 bit ATmega328 processor. It has 14 digital I/O pins (of which 6 are PWM outputs), 6 analog inputs with an ADC of 10 bits. It has a clock speed of 16 MHz. Arduino UNO also supports SPI communication. Programming can be done in the Arduino software IDE (Integrated Development Environment) but also in other third party programs like Visual Studio. The programming is done in C/C++ [61].

Figure 4.6: Arduino UNO [62].

Benefits

• Cheap.

• Good real time capabilities.

• Easy to connect hardware.

• Big community with a lot of material on the web.

• Several different libraries is provided for program development.

Disadvantages

• No WLAN shield is included.

• Low resolution on the ADC.

(55)

CHAPTER 4. METHOD 33

4.7.3 Raspberry Pi

Raspberry Pi, Fig. 4.7, is a mini computer with Broadcom BCM2835, a System- on-Chip, which consists of a ARM1176JZFS processor running at 700MHz and it has 512 MB RAM. It runs on the operating system Raspbian which is a version of Linux. The newest model Raspberry Pi Model B+ has 4 USB ports and 40 GPIO pins that can be programmed to become an input or output. GPIO pins are the physical link between the real world and the Raspberry Pi. Raspberry Pi is provided with a SPI bus for communication with peripherals. To write programs on a Raspberry Pi is Python used as the programming language [63].

Figure 4.7: Raspberry Pi Model B+ [64].

Benefits

• Cheap.

• Several different libraries is provided for program development.

Disadvantages

• No WLAN module is included.

• No built-in ADC.

• Lot of different features were some of them will not be relevant to this project.

From this survey wanted the customer that the Raspberry Pi should be used because, together with the WLAN module, was the cheapest.

4.8 Measuring technology

A sensor is needed to measure the angle of the pendulum according to the vertical axis. Bourns 3590S-6-103L potentiometer was chosen to be the sensor that detect the pendulums angle α. It can turn 3600 and have a relative low friction in comparison with other potentiometers. Here is options presented and weighed against each other.

(56)

CHAPTER 4. METHOD 34

4.8.1 Gyro and accelerometer

Something that has been taken in mind when selecting materials has been how to reduce the amount of materials, how to optimize production and how to get so long component life as possible. The fact that accelerometer and gyro were not selected is because it would entail more components. It can also be difficult to mount these two sensors, they suit better in a self-balancing robot than on a pendulum. An encoder or potentiometer with axle is desirable because then there is something to attach a pendulum on.

4.8.2 Hengstler rotary encoder

RI32-O/1000ER.11KB from Hengstler is an incremental encoder with a resolu- tion of 1000 pulses per revolution [65] provided from the university. Hengstler RI32-O/1000ER.11KB is presented in Fig. 4.8.

The reason why not an encoder, rotary or absolute was chosen is because of their high price. A typically absolute encoder cost a lot while a decent rotary encoder cost more than 1000 Swedish kronor. A cost that don’t fit in the budget.

Figure 4.8: Hengstler RI32-O/1000ER.11KB. Rotary encoder, that generate pulses on 3 channels.

Quadrature decoder logic

A preferred feature that the development board should have if using incremental encoder is quadrature decoder logic for decoding the pulses from the encoder.

The quadrature decoder will take the incoming pulses and count them and store the value in a register in the MCU [66]. This register will automatically count up when the encoder is moved in one direction and count down when moves in the other. Details of how this technology is implemented is presented on the web [67].

4.8.3 Bourns potentiometer

The sensor that was finally chosen was a potentiometer. Encoders in the same price as the chosen one has more torque than the potentiometer. The chosen potentiometer 3590S-6-103L from Bourns can turn 3600 which is 10 full turns [68]. The sensor is shown in Fig. 4.9. It has a torque on 1.1 Ncm [68] compared

(57)

CHAPTER 4. METHOD 35

to the Hengstler encoder which has ≤ 0.05 Ncm [65]. Since the potentiometer is a mechanical construction where the shaft slides along a resistive path, it will eventually wear out, and the potentiometer must be replaced.

Figure 4.9: Bourns 3590S-6-103L [69]. Potentiometer with 10 turns and rela- tively low friction.

ADC for selected potentiometer

To use the analog signal from the potentiometer, which is used as a sensor to detect the pendulum’s angle, in a MCU an ADC has to be done to get a digital signal that can be used by the MCU.

Following equations will give how many degrees the potentiometer shaft must turn for the ADC to detect a change by one. To control the pendulums angle is a hypothesis made that the need for an ADC with around 1 resolution to be able to measure the angle of the pendulum is enough. If the hypothesis was wrong, an ADC with higher resolution will be chosen. Equation 4.2 gives how many volts it goes to 1.

5

3600 = 1, 388889 mV /deg. (4.2) According to Equation 4.3 will a 10 bits ADC detect the interval 0 to 3,5 as 0 and 3,5 to 7 as 1. This will not be enough to control the pendulum.

5 V

1024 = 4, 882813 mV /step, 3600

1024 = 3, 515625 deg/step. (4.3) In order to improve the resolution have an ADC with a resolution on 12-16 bits (4096-65536 different values) been considered.

5 V

4096 = 1, 220703 mV /step, 3600

4096 = 0, 87890625 deg/step. (4.4)

5 V

65536 = 76, 293945 µV /step, 3600

65536 = 0, 054931 deg/step. (4.5) With a better ADC, it will be possible to detect smaller changes on the pen- dulum’s angle. The ADC that was selected is ADS1286 [70], because according to Equation 4.4 can this have sufficiently high resolution, and it may sample at a frequency of 20kHz. To use it with a MCU so supports this ADC SPI and

References

Related documents

As a result of the virtual water trade (import only) Iraq saved 46,672,673 m 3 of water as a national water-saving (NWS), but there is no global water saving (GWS) because

The work followed two approaches: (a) a systematic exploration of the influence of control parameters (bow force, bow velocity, and bow-bridge distance) on the output of a

46 Konkreta exempel skulle kunna vara främjandeinsatser för affärsänglar/affärsängelnätverk, skapa arenor där aktörer från utbuds- och efterfrågesidan kan mötas eller

The increasing availability of data and attention to services has increased the understanding of the contribution of services to innovation and productivity in

For assembly lines, such design refinements exist as the mappings from abstract product features (Prod- uct::ProductFeature) to process tasks (Process::Task ), as well as from

The EU exports of waste abroad have negative environmental and public health consequences in the countries of destination, while resources for the circular economy.. domestically

In these information systems, the entities represented in the virtual layer are passive and acted upon by the active entities in the real world.. If one takes the viewpoint described

Anchoring is the process of creating and maintaining associations between descriptions and perceptual information corresponding to the same physical objects.. To illustrate, imagine