• No results found

Electricity in a 2D mechanicssimulator for education

N/A
N/A
Protected

Academic year: 2022

Share "Electricity in a 2D mechanicssimulator for education"

Copied!
66
0
0

Loading.... (view fulltext now)

Full text

(1)

Electricity in a 2D mechanics simulator for education

Emanuel Dahlberg

January 31, 2011

Master’s Thesis in Computing Science, 30 credits Supervisor at CS-UmU: Niclas B¨orlin

Examiner: Fredrik Georgsson

Ume˚a University

Department of Computing Science SE-901 87 UME˚A

SWEDEN

(2)
(3)

Abstract

Electricity can be a difficult topic to grasp since it is abstract, it is e.g. not possible to see the current and the voltage in a circuit. If electricity can be simulated and visualized, it can become less abstract and easier to understand. This thesis covers the process of simulating electricity in real-time together with a mechanics simulator, called Algodoo.

The process of analyzing electric circuits from a computers point of view is covered as well as different ways of simulating electric motors, generators and lasers. A large part of the thesis covers how to integrate the electricity and the mechanics simulators in a stable and accurate way. Furthermore, making the objects of the mechanics simulator able to conduct electricity is also covered.

The thesis shows that it is possible to simulate electricity in real-time, and that phys- ically correct conducting objects requires a lot of processing power, but can be simplified without losing too much correctness. The thesis also shows that the electrical and mechanics simulators preferably should be solved together to get a stable simulation.

Simulating electricity opens up an endless number of interactive scenarios, e.g. mechan- ical switches, potentiometers, relays and even logic gates. It can be a helpful aid as an introduction to electronics and since the simulators are integrated, it can also provide an introduction to mechanical work. The amount of energy required to perform different tasks can be compared and analyzed.

(4)

ii

(5)

Contents

1 Introduction 1

1.1 Background . . . . 1

1.2 Goals . . . . 1

1.3 Related work . . . . 2

1.4 Organization of this thesis . . . . 2

2 Algodoo 3 2.1 Rigid bodies . . . . 3

2.2 Hinges . . . . 3

2.3 Motors . . . . 3

2.4 Lasers . . . . 3

2.5 Springs . . . . 5

2.6 Fluids . . . . 5

3 User’s stories 9 3.1 Train . . . . 9

3.2 Car . . . . 9

3.3 Ohm’s law . . . . 10

3.4 Gear ratio . . . . 10

3.5 Hydroelectric power station . . . . 10

3.6 Electric ball pit . . . . 10

3.7 Logic gates . . . . 11

4 Simulating electricity 13 4.1 Electricity . . . . 13

4.1.1 The hydraulic analogy . . . . 13

4.1.2 Symbols . . . . 14

4.1.3 Circuits . . . . 16

4.1.4 Fundamental electric laws & theorems . . . . 17

4.1.5 Circuit analysis . . . . 19

4.1.6 Time-dependent vs. time-independent circuits . . . . 20

iii

(6)

iv CONTENTS

4.1.7 Active vs. passive circuits . . . 20

4.2 Battery . . . . 20

4.2.1 Ideal battery . . . . 21

4.2.2 Non-ideal battery . . . . 21

4.3 Node . . . 21

4.4 Wire . . . . 21

4.5 Resistor . . . 22

4.6 Potentiometer . . . . 23

4.7 Electric laser . . . . 23

4.8 Inductor . . . . 23

4.9 Capacitor . . . 23

4.10 Motor & generator . . . 24

4.10.1 Energy representation . . . . 24

4.10.2 Electrical representation . . . . 24

4.10.3 Incorporate the motor with the mechanics . . . . 25

4.11 Circuit simulation . . . 25

4.11.1 Differential equation method . . . 26

4.11.2 Steady state method . . . . 26

4.12 Conducting rigid bodies . . . 26

4.12.1 Finite element method . . . . 27

4.12.2 Distance method . . . . 27

4.13 Switch . . . . 29

4.14 Visualization . . . . 29

5 Design choices & experiments 31 5.1 Choice of simulation paradigm . . . . 31

5.2 Circuit simulation . . . . 31

5.3 Battery . . . . 36

5.4 Motor & generator . . . . 36

5.5 Switch & relay . . . . 38

5.6 Visualization . . . . 38

6 Results 41 6.1 Circuit simulation . . . . 41

6.2 Battery . . . . 41

6.3 Motor & generator . . . . 43

6.4 Switch & relay . . . . 47

6.5 Visualization . . . . 47

(7)

CONTENTS v

7 Discussion & conclusions 49

7.1 Circuit simulation . . . 49

7.2 Battery . . . . 49

7.3 Motor & generator . . . 49

7.4 Switch & relay . . . 50

7.5 Visualization . . . . 50

8 Summary 51 8.1 Goals . . . 51

8.2 Limitations . . . . 51

8.3 Future work . . . . 51

8.4 Personal reflections . . . 52

9 Acknowledgments 55

References 57

(8)

vi CONTENTS

(9)

Chapter 1

Introduction

Physics simulation is a young area of usage for personal computers. With the declining number of students that choose natural science in schools [Lavonen et al., 2005], more creative and practical physics software on computers in schools might increase the interest and help with the learning process.

1.1 Background

Algoryx Simulation AB is a company developing interactive multiphysics simulators located in Ume˚a, Sweden1. Their two main products are AgX Multiphysics, a 3D toolkit used in software that requires accurate and high performance real-time simulations, and a soft- ware called Algodoo2. Algoryx is a spin-off company from Ume˚a University and they have provided a lot of students with the resources to write a Master’s Thesis.

Algodoo is a 2D physics simulator with focus on learning and creativity. It is designed to be a software that the students can grow with, but at the same time the developers does not want to put any limitations on the possible usages [Algoryx Simulation AB, 2009]. It has the ability to simulate rigid bodies, fluids, hinges, springs, chains, gears and optics in the form of lasers, all with accurate values that the user can study. Algodoo is a further development of a software called Phun which is a result of Ernerfeldt [2011].

One field of physics that is missing from Algodoo is electricity. Electricity is quite abstract since it is impossible to watch the current that travels through a wire and the voltage over an electric component. With electricity simulators, current and voltage can be displayed and are therefore often an appreciated aid for students.

1.2 Goals

The goal of this thesis is to extend Algodoo with the ability to simulate electricity. Since Algodoo is an educational software the main focus will be to integrate the electricity into the mechanics and optics in a seamless way. This will provide an informative learning basis with room to explore without the risk of destroying any equipments or hurting any students.

Simulating electricity can provide students with tools to explore different electrical theories.

1www.algoryx.se

2www.algodoo.com

1

(10)

2 Chapter 1. Introduction

Scenarios that are hard to achieve in the real world can easily be studied and tested with simulators.

The mechanical simulation in Algodoo contain motors, which can be specified with a value of torque and a value of speed. By integrating electricity, the torque and speed of the motors could be controlled by the current and voltage across the motor. The rigid bodies should be able to conduct electricity, and therefore be used as wires and switches.

Rechargeable batteries as well as ideal batteries and electrical components such as resistors, should also be available. The electricity should be solved separated from the mechanics, i.e.

the mechanics is first solved and then the electricity is solved after.

Since the simulator will be used by students, it is important that accurate values are presented to the user. Furthermore, the simulator must be able to run in real-time with as low requirements on the computer as possible. Some considerations between speed and physically correct behavior must therefore be taken. There should however be some truth to the modeling of all components. Different methods to simulate and visualize electrical circuits should therefore be evaluated.

1.3 Related work

There exists many electric circuit simulators for analyzing circuits, e.g. SPICE (Simulation Program with Integrated Circuit Emphasis, Quarles et al. [1993]) and the Electric VLSI Design System [Rubin, 2010]. They are often designed to help engineers try out advanced circuits and assumes the user has knowledge in the area of electronics. This leads to com- plicated programs which might have a to step learning curve for students to manage.

Another related type of software that will be used for inspiration is Paul Falstad’s Circuit Simulator [Falstad, 2010]. It is more beginner friendly than most other circuit simulators and it has many advanced electronic components available. However, the mechanical aspect is missing from the simulator.

Logisim is a simulator that only handles logical circuits, but the focus is on learning [Burch, 2010]. It also requires some prior knowledge of electronics. If the goals of this thesis are reached, Algodoo will be able to simulate logical circuits as well.

1.4 Organization of this thesis

The rest of the thesis is organized as follows. Chapter 2 explains some of the features of Algodoo in more detail. Chapter 3 describes the user’s stories that the thesis is built on.

Chapter 4 covers the theory behind the simulation and the different ways to implement the simulator. Chapter 5 lists the design choices and experiments that were performed to find out what is stable and accurate, followed by the results of the experiments in Chapter 6.

Chapter 7 presents the conclusions that could be drawn from the results. Finally, Chapter 8 covers the achievements and limitations of the work. It also covers what was left out, but can be accomplished with more time.

(11)

Chapter 2

Algodoo

This chapter gives a brief introduction to some of the features of Algodoo.

2.1 Rigid bodies

Algodoo has the ability to simulate rigid bodies affected by gravity in 2D. Rigid bodies are physical objects that does not deform under any amount of pressure and the material of the bodies can be set to change the properties of the body. The forces and velocities that acts on a body can be displayed for the user to study.

The user can create rigid bodies with the help of the box tool, the circle tool or drawing by free hand. Bodies can also be merged together to create more complicated constructions.

A fixate can be set on a body to make it unable to move. Gravity will not affect the body and other bodies colliding with the fixated body will bounce off. See Figure 2.1 for some of the ways that rigid bodies can be used.

2.2 Hinges

A hinge joins two bodies together. The bodies can rotate freely around the hinge, making hinges perfect for creating the wheels of a car and the like. A body can also be attached to the world with a hinge, which means that a body, e.g. a gear, can be attach to the background and rotate freely without falling down, see Figure 2.2.

2.3 Motors

A hinge can be used as a motor where the user sets a target speed and a maximum applied torque, see Figure 2.3. The torque will be applied until the target speed is achieved, but if the body can not be turned with the applied torque, the target speed will not be achieved.

2.4 Lasers

Lasers follows the optical laws, i.e. the refractive index of a material will determine if a laser bounces of a body or goes through it. A white laser can be split into colors with a prism.

Even the speed of light can be set, see Figure 2.4.

3

(12)

4 Chapter 2. Algodoo

Figure 2.1: Rigid bodies with the forces displayed. The circular body to the right is made of the material steel, i.e. it is heavy. A fixated body has a circle on it with the letter X in the middle and can be seen to the left.

Figure 2.2: Hinges between two bodies and hinges between the world and a body. The bodies can rotate freely around the hinge.

(13)

2.5. Springs 5

2.5 Springs

A spring will create a force to keep its target length, see Figure 2.5. The strength as well as the damping can also be set on the spring.

2.6 Fluids

Water can be simulated with the correct density. Bodies made of different materials can be dropped into the water and the behavior can be studied. A body made of steel will sink, a body made of wood will float up in the water and a body made of helium will float up in the air, see Figure 2.6.

(14)

6 Chapter 2. Algodoo

Figure 2.3: A hinge can be made into a motor and a torque will then be applied to rotate the bodies attached to the hinge. A target speed and and max torque is set on the motor.

Figure 2.4: White and red lasers. The white laser can be split into colors. The speed of light can also be set on a laser, as with the laser to the right.

(15)

2.6. Fluids 7

Figure 2.5: Springs between bodies and the world. A spring provides a force to keep its target length.

Figure 2.6: Water can be used to illustrate density. The body to the left is made of wood, the body in the middle is made of steel and the body to the right is made of helium.

(16)

8 Chapter 2. Algodoo

(17)

Chapter 3

User’s stories

This chapter describes some user’s stories that the developers of Algodoo and the author put together to find out what components are needed and should be developed. The stories are just the first ideas that came to mind. There will be more possible scenarios to do if the goals are reached. The stories will be used when the design choices are to be made.

3.1 Train

A locomotive is connected together with a number of railroad cars and wires between the cars lights up the cars.

Components needed:

– Battery – Electric motors – Wires

– Lamps or something similar (a fan could also be used)

3.2 Car

Three different cars are built with two separate motors in the front and in the back. One car has the motors connected in series, another car has the motors connected in parallel and the last car has a connected car body with a more unpredictable circuit.

The car can later be used to finish a track. By changing the weight of the car or by not driving as fast, the car can finish the track with more energy left. The user can experiment with different sizes of the wheels, with different grip on the wheels and other small details that could change the amount of energy consumed.

Components needed:

– Battery – Electric motors – Wires

– Conducting bodies

9

(18)

10 Chapter 3. User’s stories

3.3 Ohm’s law

A more modern demonstration of Ohm’s electricity law. Two different cars with batteries and motors are connected with resistors of different resistance.

Components needed:

– Battery – Electric motors – Wires

– Resistors

3.4 Gear ratio

The gear ratio can be used to show how the same amount of work can be performed over a different time period. Gears can also be used to show how much more energy it takes to rotate a gear twice as large as another gear.

Components needed:

– Battery – Electric motors – Wires

3.5 Hydroelectric power station

Since Algodoo has the ability to simulate fluids, e.g. water, a power plant that charges a battery with the help of water could be made.

Components needed:

– Rechargeable battery – Electric generator – Wires

3.6 Electric ball pit

A ball pit with balls that can conduct electricity. Some balls can have unlimited resistivity to be non-conducting and others can have zero resistivity to be preferable by the electricity.

The battery connects to a laser with the balls in between, making it easy to see when a current is flowing.

Components needed:

– Battery – Laser

– Conducting bodies – Wires

(19)

3.7. Logic gates 11

3.7 Logic gates

All the logic gates can be created with relays. Lasers can be used to show when a input or output is true or false (on or off, one or zero).

Components needed:

– Battery – Lasers

– Relays in the form of electric motors and conducting bodies – Wires

(20)

12 Chapter 3. User’s stories

(21)

Chapter 4

Simulating electricity

This chapter explains some different ways of simulating electricity and the challenges that must be overcome. Section 4.1 can be skipped if the reader knows the basics about electricity.

Unless otherwise stated, this chapter follows Gates [2006].

4.1 Electricity

The three basic components of electricity is current, voltage and resistance. Current can be seen as the rate of flow of electric charge. The SI unit is ampere (A). Voltage is the electrical force that drives current. The SI unit is volt (V). Resistance of a component is the opposition of the flow of current. The SI unit is ohm (Ω). A closed loop is required for the electrical force to be applied, in other words, the resistance over air is very large. The amount of power (energy per second) used by a component is measured in watts (W) and is calculated as

P = I · V,

where P is the power used, I is the ampere through the component and V is the voltage over the component.

There are two basic sources of energy within electricity; voltage sources and current sources. Both have infinite energy in theory, but do not exists in the real world. The voltage source has a static voltage and the current changes depending on the resistance. A closed loop with no resistance would need infinite current and therefore infinite energy. The current sources has a static current and the voltage changes depending on the resistance.

An open loop would need infinite voltage and therefore infinite energy.

The directional flow of current through a circuit is by convention from the positive to the negative pole, even though it is most often negatively charged electrons that flow through a circuit. Used in this thesis is the conventional direction of flow.

4.1.1 The hydraulic analogy

Another way of looking at electricity is with the hydraulic analogy, which models electricity as a fluid flowing through pipes. The analogy can help with understanding the basics of electricity and the equivalents to electricity can be found in Table 4.1.

Electric wires can be seen as pipes that holds water. Voltage can be seen as a pressure difference that sets the water in motion. Current can be seen as the volume flow rate of

13

(22)

14 Chapter 4. Simulating electricity

Table 4.1: The hydraulic analogy to electricity.

Electricity Hydraulic

Wires Pipe

Voltage Pressure difference

Current Volume flow rate

Ideal voltage source Pump with constant pressure Ideal current source Pump with constant speed

Resistor A tighter pipe

Inductors A pipe with a wheel of paddles in the middle

the water in the pipes. A resistor can be seen as a tighter pipe, making the water flow at a slower rate.

An ideal voltage source can be seen as a pump that keeps a constant pressure, but with a changing volume flow rate. An ideal current source can be seen as a pump that keeps a constant volume flow rate, but with a changing pressure.

An inductor can be seen as a wheel of paddles placed in the middle of a pipe. The paddles will make a change in volume flow rate more difficult, which means that both picking up speed and slowing the water down will take some time.

The hydraulic analogy does however not cover every aspect of electricity and can be taken too far. If a hole is made to the pipes, water will leak, but electricity can not be pored out. For the same reason, water can flow without a closed pipe system, but electricity can not. The volume flow rate of water is much greater than that of electricity.

4.1.2 Symbols

A couple of symbols will be used to describe the different electrical components. The symbols used for voltage sources and current sources can be seen in Figure 4.1(a) and 4.1(b) respectively. Batteries are made up of one or more cells and are displayed with the symbol in Figure 4.1(c). Two lines of different length is used per cell and the longer line indicates the positive pole.

Resistors use different symbols in Europe and America, but both can be seen in Figure 4.2. The European symbol will be used in this thesis. A variable European resistor, called a potentiometer, can also be seen in Figure 4.2.

V

(a)

I

(b)

+

-

(c)

Figure 4.1: The symbols used for a voltage source (a), a current source (b) and a battery with two cells (c).

(23)

4.1. Electricity 15

Figure 4.2: The symbol for a resistor in a circuit. The European symbol is to the left, the American is in the middle and a variable European resistor (potentiometer) is to the right.

The symbol used for inductors and capacitors can be seen in Figure 4.3(a) and 4.3(b) respectively. A capacitor can be seen as a small rechargeable battery. A motor is displayed with the symbol in Figure 4.3(c) hiding the internal components. A lamp use the symbol shown in Figure 4.3(d). Finally, there are a number of different types of switches and some of them can be seen in Figure 4.4.

(a) (b)

M

(c) (d)

Figure 4.3: The symbols used for an inductor (a), a capacitor (b), a motors (c) and a lamp (d).

(24)

16 Chapter 4. Simulating electricity

(a) Single Pole, Single Throw (SPST).

(b) Single Pole, Double Throw (SPDT).

(c) Double Pole, Single Throw (DPST).

(d) Double Pole, Double Throw (DPDT).

Figure 4.4: Some of the symbols used for switches.

4.1.3 Circuits

A circuit is a connection of components with wires. For current to flow through a circuit, there must be a source of energy, e.g. a battery, and the circuit must be in a closed loop. In other words, there must be a potential difference (created by the battery) over a component, otherwise no current will flow. A battery connected with only one pole does not create a difference, both poles are required.

Circuits are often drawn as circuit diagrams with wires as line. Wires joined is displayed different from wires not joined (see Figure 4.5) so that they can be distinguished.

One simple example circuit diagram can be seen in Figure 4.6 and is made up of a battery and a motor. Figure 4.7 shows a more complicated circuit diagram.

(a) Some different wires. (b) Wires that are joined.

(c) Wires that are not joined.

Figure 4.5: Wires as seen in circuit diagrams.

(25)

4.1. Electricity 17

+

-

M

Figure 4.6: A simple circuit with a battery and a motor.

+-

+

-

Figure 4.7: A more complicated circuit with batteries and resistors.

4.1.4 Fundamental electric laws & theorems

A couple of laws and theorems are useful for analyzing electric circuits and they are described below.

Ohm’s law

Ohm’s law states that

V = R · I,

where V is the voltage, R is the resistance and I is the current. In other words the current through a component is the voltage over the component divided by its resistance. What this means is that the resistance blocks the rate at which the current is flowing, and can be compared to a smaller pipe that blocks the rate at which water is flowing, if the pressure (voltage) is constant. See figure 4.8.

V R

I

Figure 4.8: Ohm’s law can be used to determine the current that flows through a resistor.

(26)

18 Chapter 4. Simulating electricity

Kirchhoff ’s circuit laws

Kirchhoff ’s current law (KCL) states that for every node in a circuit, the current entering the node must equal to the current leaving the node. Kirchhoff ’s voltage law (KVL) on the other hand states that the sum of the voltage around any closed circuit must equal to zero.

Both Kirchhoff’s circuit laws are needed to analyze complicated circuits. See figure 4.9.

I1 I2 I3 I4 I5

(a) I1+ I2+ I3= I4+ I5

V1 V3 V2

V4

M

(b) V1− V2− V3− V4= 0

Figure 4.9: Kirchhoff’s circuit laws. The current law is to the left and the voltage law is to the right.

Th´evenin’s theorem & Mayer-Norton theorem

Th´evenin’s theorem states that any circuit with voltage sources, current sources and resistors can be replaced with a circuit with only a voltage source in series with a resistor. Mayer- Norton theorem states that any circuit with voltage sources, current sources and resistors can be replaced with a circuit with only a current source in parallel with a resistor. Both theorems are in some way each others opposite and are useful for confirming that large circuits are solved correctly. See figure 4.10.

Figure 4.10: The circuit is reduced using Th´evenin’s theorem on the top right and Mayer- Norton theorem on the bottom right.

(27)

4.1. Electricity 19

4.1.5 Circuit analysis

Analyzing a circuit is the process of determining the voltage over and the current through every component in the circuit. With simple circuits Ohm’s law is sufficient, but with more complicated circuits, Kirchhoff’s circuit laws are needed.

For instance, analyzing the Ohm’s law circuit (Figure 4.8) would be done by taking the voltage and dividing it by the resistance. If the voltage of the battery is 5 V and the resistance of the resistor is 100 Ω, the current is 5/100 = 0.05A (see Figure 4.11). As every component in the circuit has a known current and voltage, there is nothing more to analyze.

V=5V R=100Ω

I=0.05A

Figure 4.11: A simple circuit fully analyzed. The current through the resistor was unknown, but has been calculated.

The more complicated circuit in Figure 4.7 on page 17 can be analyzed with a method called Loop Current [DeCarlo and Lin, 2001], which uses KVL and Ohm’s law. The circuit has two loops and have the values found in Figure 4.12. The following two equations can be set up from KVL and Ohm’s law if the loops are followed clock-wise:

32 − i1· 2 − (i1− i2) · 8 = 0,

−20 − (i2− i1) · 8 − i2· 4 = 0.

Two equations and two unknowns are easily solved and the results of doing that is:

i1= 4, i2= 1.

The current through every resistor is then known and can be used to calculate the voltage over every resistor, which means that there is nothing more to analyze.

+

-

32V

i1 i2 20V

+

-

Figure 4.12: The loops and values of a more complicated circuit.

(28)

20 Chapter 4. Simulating electricity

4.1.6 Time-dependent vs. time-independent circuits

Time-dependent circuits are circuits that contains components that depend on time. Some components changes behavior over time and the scale of change can vary by orders of magnitude, from small capacitors that take microseconds to charge to large batteries that take hours to charge. A mechanics simulator, such as Algodoo, often runs in 100Hz, i.e.

with a cycle time of 0.01 seconds, but circuits often require a lot higher frequencies to avoid instability, depending on which time-dependent components that are used. Time- independent circuits does not change with time and are therefore easier to analyze.

4.1.7 Active vs. passive circuits

Active circuits are circuits that contains components that produce power or gain, called active components. They can be used to amplify a weak signal, i.e. a radio signal, and make it more usable, i.e. making speakers able to play music at a high volume. The operation of active components depend on the voltage over the component and must therefore be analyzed in multiple steps that makes them harder and more time consuming to analyze.

Passive circuits can be analyzed in one step and are therefore easier to analyze.

V

Internal resistance

Figure 4.13: The replacement circuit for a battery.

4.2 Battery

Batteries can be seen as a voltage source connected in series with a resistor, called the internal resistance, see Figure 4.13. The resistance is due to the chemical properties of the battery, but can nonetheless be seen as a resistor, which can help the user to understand how they work.

With an ideal battery the internal resistance is zero. Ideal batteries do not exist in the real world, but are valuable for understanding electrical theories, because they simplify the process of analysis circuits. With rechargeable batteries the electrochemical reactions are electrically reversible, which means that rechargeable batteries can be restored with energy if the current flows in the opposite direction.

Ideal, rechargeable and disposable batteries should be possible to simulate. Disposable batteries can be seen as a special case of rechargeable batteries that are not possible to recharge and are therefore easy to simulate if rechargeable batteries are implemented suc- cessfully.

(29)

4.3. Node 21

4.2.1 Ideal battery

An ideal battery can be simulated by replacing the battery with an voltage source. As described earlier, this implies that the battery has an unlimited amount of energy, and that the energy can be provided instantaneously.

4.2.2 Non-ideal battery

Simulation of a non-ideal battery is time-dependent, but on a relatively long time-scale.

The amount of energy stored is limited and will change over time. Stepping forward in time in a stable way can be done by a method called semi-implicit Euler [Erleben et al., 2005].

The capacity of a battery is often written in Ah (ampere hour) or W h (watt hour), but could also be written in J (joule). Most users are used to Ah and W h for batteries, but neither of them are SI-units.

The internal resistance and the output voltage can be changed to simulate a battery that is discharged and possibly charged. The internal resistance provides a battery with two important properties. It puts a cap on how much current that can be drawn from a battery in a period of time and it describes how discharged a battery is. A real battery is not completely out of energy when it stops being usable, but the voltage that the battery can provide is not enough for most devices [Klein et al., 2002].

The internal resistance alone could be used to lower the output voltage of a simulated battery. However, when the battery is completely empty, the resistance will be so large that it will be very difficult to recharge. To simulate the effect of a completely discharged battery, but keep the resistance at a low lever, the voltage can also be lowered when the battery is discharged.

There are therefore at least two different ways to simulate a battery. If only the resistance is changed the result will be a unusable battery that does not show 0% charged, but is realistic. If both the resistance and the voltage is changed the result will be a battery that shows exactly 0% charged when it is unusable, and will be easy to recharged at that level.

4.3 Node

A node is where two or more components connect. One method of analyzing a circuit is to determine the voltage at every single node.

4.4 Wire

There are two different types of wires that needs to be considered. Ideal wires with zero resistance and realistic wires where the resistance depends on the length, width and material of the wire [Giancoli, 1998]. Ideal wires only contribute to the connection graph of the circuit. The wires in them self are ignored and the nodes connected to an ideal wire could be combined into one.

Since the simulator will be used for educational purposes, the current should preferably be known everywhere in the circuit. This can be done by replacing the wire with a voltage source of zero voltage. It will create a larger circuit to analyze and with some circuits, like the one in Figure 4.14, there will not be a solution. The reason it is that a voltage source loop with no resistance would result in infinite energy usage (division by zero with Ohm’s law).

(30)

22 Chapter 4. Simulating electricity

+

-

+

-

Figure 4.14: A circuit without a solution, if the wires are replaced with voltage sources.

Another method of providing the users with a way of knowing the current and voltage everywhere in the circuit is to create a ammeter and a voltmeter. A voltmeter is used to measure voltage and can in a simulation be created with a very large resistor. A ammeter is used to measure ampere and can in a simulation be created with a voltage source with zero voltage (like the replacement wire).

4.5 Resistor

Ignoring temperature differences, resistors can be simulated with Ohm’s law and Kirchhoff’s circuit laws. They are the easiest component to simulate, and they are useful for controlling that the simulator is working as it should. This is because their behavior when connected in parallel and in series are simple to analyze.

The combined resistance of two resistors in series is R1+ R2= RT otal, if R1 is the first resistance, R2is the second resistance and RT otal is the combined resistance.

The combined resistance of two resistors in parallel is 1/R1+ 1/R2 = 1/RT otal. See Figure 4.15.

+

-

+

-

100Ω 100Ω 200Ω

+ -

100Ω

+ -

50Ω 100Ω

Figure 4.15: Reducing resistors in series can be seen above and reducing resistors in parallel can be seen below.

(31)

4.6. Potentiometer 23

4.6 Potentiometer

Potentiometers are resistors with a variable resistance that can be changed by the user.

They are often used for volume knobs and for similar applications.

4.7 Electric laser

Algodoo does not have a lamp, but it does have a laser pen where the laser fades away after a specified distance, called the fade distance. If the laser pen is seen as a lamp, the current that flows through it can represent the fade distance of the laser pen. A lamp is really just a resistor that emits light when heated up. However, the resistance of a lamp is depending on the temperature, which changes rather quickly when turned on. The temperature can therefore be ignored and the circuit only sees the laser as a static resistor.

4.8 Inductor

An inductor is time-varying and can be created with a wire that is looped a number of times. It stores energy in a magnetic field, which induces a voltage. The induces voltage can be calculated with the following equation:

v(t) = Ldi(t) dt ,

where v(t) is the time-varying voltage, L is the inductance of the inductor and i(t) is the time-varying current thats flowing through the inductor. Simulating an inductor completely therefore requires solving a differential equation.

The combined inductance of two inductors in series is L1+ L2= LT otal, if L1is the first inductance, L2 is the second inductance and LT otal is the total inductance.

The combined inductance of the two inductors in parallel is 1/L1+ 1/L2= 1/LT otal. In other words, the inductance of inductors in series and parallel works the same way as the resistance of resistors in series and parallel do (see Figure 4.15).

4.9 Capacitor

A capacitor is time-varying and can be created with two conductors separated by a non- conductive region. It is able to store energy in a static electric field. Charging a capacitor can be calculated with the following equation:

dW = q Cdq,

where dW is the work needed, C is the capacitance and q is the charge. Simulating a capacitor therefore also requires solving a differential equation.

The combined capacitance of two capacitors in series is 1/C1+ 1/C2 = 1/CT otal, if C1

is the first capacitance, C2 is the second capacitance and CT otal is the total capacitance.

The combined capacitance of the two capacitors in parallel is C1+ C2= CT otal. In other words, the capacitance of capacitors in series and parallel works the opposite way of the resistance of resistors in series and parallel (see Figure 4.15).

(32)

24 Chapter 4. Simulating electricity

4.10 Motor & generator

An electric motor can be simulated in a number of different ways because there are many different ways of constructing an electric motor.

4.10.1 Energy representation

One way of simulating an electric motor is by looking at it from a energy point of view. The energy used by a component can be calculated as

P = I · V,

where P is the (electrical) power used, I is the current and V is the voltage. The power produced by a motor can be calculated as

P = τ · ω,

where P is the (mechanical) power produced, τ is the torque and ω is the angular velocity.

Some way of controlling the energy used in the circuit is needed because the motor would otherwise never stop accelerating. This can be provided by replacing the motor with a resistor or by skipping the acceleration period and directly calculate the steady speed of the motor. The electrical motor can be seen as displayed in Figure 4.16.

+

-

M

+

-

Figure 4.16: The replacement circuit for an electric motor simulated with the energy repre- sentation.

There is however a problem with this model. The motor should be able to work as a generator, but it is difficult to know when the mechanical system is providing energy and when it is requiring energy. One solution is to let the user decide if the motor is a generator, which would make it less realistic.

The good thing about the model is that the system is energy balanced. No energy is added and that should result in a stable simulation.

4.10.2 Electrical representation

Another way of simulating an electric motor is by looking at its electrical characteristics.

From the circuits point of view the motor can be replaced with a resistance in series with an inductor and a voltage source [White, 1997], see Figure 4.17.

(33)

4.11. Circuit simulation 25

+

-

M

+

-

Figure 4.17: The replacement circuit for an electric motor simulated with the electrical representation.

The voltage, called the back EMF (electromotive force), is induced because the motor is spinning and it opposes the voltage over the whole motor. At low speed, the back EMF is small, and the current through the motor is high. With increasing speed, the back EMF will increase, and the current through the motor will decrease. The voltage over the whole motor will also decrease, making the acceleration decrease.

The model has the generator capabilities built in, and it is easy to change the charac- teristics of the motor. The motor will have a realistic acceleration curve, that corresponds well to basic real world motors. However, no obvious link between the electrical energy used and the mechanical energy produced exists.

4.10.3 Incorporate the motor with the mechanics

Whichever model is used, it must be incorporated with the mechanics. The mechanical motor in Algodoo is controlled with a speed and a torque. The motor tries to rotate the attached body at the specified speed, but only with the maximum torque specified. In other words, if the motor does not have enough torque to turn the body, the specified speed will not be achieved. There are therefore two different speeds that must be taken into account.

The target speed that the motor is trying to achieve and the real speed of the motor.

With the electrical motor model, the real speed of the motor controls the back EMF and the voltage over the whole motor is controlling the target speed that the motor is trying to achieve. With the energy motor model, the real speed of the motor times the torque should match the voltage over the whole motor times the current that goes through the motor.

4.11 Circuit simulation

The most common approach to simulate circuits is to first solve the circuit without any time-varying components, that is with voltage sources, current sources and resistors. This can be done with a method called Modified Nodal Analysis (MNA)[Litovski and Zwolinski, 1997], in which every node is calculated a voltage and every battery a opposite current. The method use KCL and Ohm’s law to set up a linear equation system that can easily be solved by a computer. A ground node must be chosen that is the reference point with voltage 0V . When the linear equations are solved the voltage at every node is known and can be used to calculate the voltage over and the current through every component. Figure 4.18 show what the method needs to analyze the circuit shown i Figure 4.7 on page 17. It also show the output of the method, i.e. the node voltages and the current through every battery.

(34)

26 Chapter 4. Simulating electricity

+-

R R R

V

V

Node 0 (groun

d) Node 1

Node 2

Node 3 I

+

-

I

Figure 4.18: The input and output when analyzing a circuit with MNA.

4.11.1 Differential equation method

To deal with time-varying components, one or more differential equations must be solved.

This is often done by stepping forward in time and approximating the derivative. The amount of time stepped forward is called the time-step and can be difficult to choose when simulating time-varying objects. A too large time-step might introduce instability and interesting parts of the simulation might be skipped. A too small time-step will make the simulator slow or require a lot of processing power. If the time-step has to be shared with the mechanical simulator, the size is even harder to choose. This is because mechanical simulators most often are stable with a different sized time-step than the circuit simulator.

4.11.2 Steady state method

Another approach to deal with time-varying components is to use a steady state approach.

What this mean is that the simulator calculates how the circuit would look after it is stable, instead of going forward with small time steps. In other words, the simulator jumps forward one very large time-step, but does so by exactly calculating how the simulated environment would look like after the time-step. Inductors can therefore be replaced with wires and capacitors can be replaced with open connections when using steady state.

The method makes it a lot easier to get a stable system, but the drawback is of course that inductors and capacitors works as if they are non existing. The state of rechargeable batteries could in theory be skipped until they are out of energy, but the time-scale are most often large enough to handle in 100Hz.

4.12 Conducting rigid bodies

To make rigid bodies able to conduct electricity, a couple of different methods can be used.

The main difference between the methods are how accurate they are. The more accurate, the more time it takes to calculate.

The resistance between two connection points on a body depends on a couple of things.

A larger distance will increase the resistance, but a larger cross-sectional area will decrease

(35)

4.12. Conducting rigid bodies 27

it. The ability of the material to oppose the flow of electric current, called the resistivity, as well as the temperature of the body also matters.

Some difficulties arise because Algodoo is in two dimensions, which makes the cross- sectional area undefined. Calculating the physically correct resistance over a body is non- trivial since the contact area must be known.

4.12.1 Finite element method

The most accurate method is to divide the body into small sections and for every section calculate the resistance [Humphries, 1998]. Important areas can be divided into smaller sections, which would give a better value. Overall it is a very expensive method which takes a lot of time to implement.

4.12.2 Distance method

A simpler method is to use the distance between contact points together with the resistivity of the material and add resistor between every two contact points. An example of this can be seen in Figure 4.19.

The size of every contact is assumed to be 0.5 mm and if the contact is wider it will be separated into two or more contacts, see Figure 4.20. This is not 100% physically correct, however, it may be accurate enough for the environment the bodies will be used in.

An artifact of the model will in some scenarios make the total resistance between two contacting bodies incorrectly change. If two bodies are in contact, a third body may add another contact which creates two more resistors and an alternative path for the current to travel, see Figure 4.21. This will create the incorrect scenario that the more contacts a body has from different bodies, the less resistance it has, since the total resistance is reduced with resistors in parallel.

A way to handle this artifact is by calculating a minimum spanning tree of the body’s resistors. Every node will therefore be connected, but no parallel resistors will be created, see Figure 4.22. This is still not physically correct, but behaves more logical and may be enough.

Figure 4.19: Two examples of resistor graphs of conducting rigid bodies in contact. The rectangular objects at the top and bottom of the figure have a very small resistivity and the circular objects between have a large enough resistivity to create resistors in the circuit diagram. The resistors inside the bodies indicate the resistance over the body between the contact points.

(36)

28 Chapter 4. Simulating electricity

Figure 4.20: The resistor graph of conducting rigid bodies in contact. The triangular object at the top has a wide contact area, but it is separated into two contacts instead.

A A

Figure 4.21: The resistor graph of three and four conducting rigid bodies in contact. The body A will change the resistance between the first three bodies.

A A

Figure 4.22: The resistor graph of conducting rigid bodies in contact. The body A does not change the resistance between the first three bodies if a minimum spanning tree is used.

(37)

4.13. Switch 29

4.13 Switch

Switches are used to open a closed circuit, i.e. stopping the flow of current, or changing the loops of a circuit. They open up an endless number of possible interactive scenarios.

Switches can be made as a separate electric component or with the already existing rigid bodies, that will be able to conduct electricity. Switches made with rigid bodies might provide a more realistic approach, but are more difficult to quickly put together. Algodoo does however provide small Phunlets, that works kind of like small scenes that can be imported into any other scene. If this works with rigid body switches, there might be no real down-side to them.

4.14 Visualization

One advantage of simulating electricity is that the current can be visualized, which can help users to understand what is really happening. Voltage can e.g. be shown with color and the current that travels through a wire can be displayed with the speed of yellow blobs or alternatively a shade of yellow. To get the actual values of the voltage and current through a wire, the user could be provided with ammeters and voltmeters. The values could be displayed directly, but might make the scene harder to work with and might not be as educational.

(38)

30 Chapter 4. Simulating electricity

(39)

Chapter 5

Design choices & experiments

This chapter describes the choices taken before the experiments and how the experiments was put together. The user’s stories was used as the basis for the decisions, but some considerations about features that might be useful in a future version of the simulator was also taken.

Whenever possible, the scripting language Python with the modules NymPy1and SciPy2 was used for the experiments. The modules add functions to Python, making it more like the numerical computing environment MATLAB3. Using a scripting language saves a lot of time when many experiments are to be done, but some experiments were also done in the final environment, i.e. Algodoo.

5.1 Choice of simulation paradigm

None of the user’s stories presented in Chapter 3 include any active nor time-varying com- ponents, apart from the battery. Making the simulator faster and more reliable by using the steady state approach and only passive circuits was therefore an easy choice. This means that no inductors, capacitors nor active components will be simulated. However, conducting bodies together with electric motors should be able to provide some of the functions active components provide.

As discussed in Section 4.12, creating a physically correct model of conducting bodies, has the potential to consume a lot of time and processing power without adding anything significant to the user experience. The simplified distance method for conducting bodies was therefore used as the basis for the experiment.

5.2 Circuit simulation

The following circuits were simulated. Circuit A (Figure 5.1) is a small circuit that can easily be analyzed by hand. Circuit B (Figure 5.2) is a simple, but larger circuit. Circuit C (Figure 5.3) is a circuit with a trivial solution, i.e. no source of power. Circuit D (Figure 5.4) has unconnected components. Circuit E (Figure 5.5) is a large open circuit. Finally,

1numpy.scipy.org

2scipy.org

3www.mathworks.com/products/matlab/

31

(40)

32 Chapter 5. Design choices & experiments

Table 5.1: A couple of circuits experimented with.

Circuit # comp # nodes

A 13 12

B 304 209

C 6 6

D 18 18

E 324 219

F 180 130

circuit F (Figure 5.6) has components with zero and unlimited resistance. The component and node counts are located in Table 5.1.

Two algorithms to set up the MNA linear equations were implemented. In Alg. 1, information about the connected nodes was stored on every component. In Alg. 2, two more items were stored in each node; the index into the MNA linear system of equations (4 bytes) and the set of components attached to the specific node (4n bytes). The memory overhead for a node is therefore 4+4n bytes, where n is the number of components connected to the node.

Two solvers were implemented to solve the MNA linear equations. One with single precision (float) and the other with double precision.

To verify that MNA analyzes circuits correctly, circuit A was simulated by Alg. 1 and 2 and solved by both solvers. The result was compared to the analysis presented in section 4.1.5 on page 19.

To compare memory usage and speed, circuits A and B were simulated by Alg. 1 and 2 and solved with double precision. The time was recorded by the Algodoo profiler as the average over 60 seconds. The simulation rate of Algodoo was reduced to 30 frames per second to reduces the possible interference from other programs running, by letting the processor usage stay below 100%.

Finally, to verify that some special cases are analyzed correctly, circuits C, D, E and F were simulated by Alg. 1 and 2 and solved by both solvers. For comparison, circuit E was solved by hand.

(41)

5.2. Circuit simulation 33

Figure 5.1: Circuit A. The blue and green boxes are batteries. The amount of energy left in a battery is showed with a green rectangle in the middle of the battery. The black rectangular boxes are resistors. The circles are connection nodes. The yellow blobs shows how the current travels through the wires. A green wire indicates positive voltage, a red wire indicates negative voltage, and a black wire indicates zero voltage. A voltage drop can be seen over the two horizontal resistors. This circuit contains twelve nodes, six of which are represented as black circles. Furthermore, each battery additionally contains two connection nodes and one invisible node for the internal resistor. The circuit contains 13 components, three of which are resistors and six of with are wires. Each battery additionally contains a resistor and a voltage source.

(42)

34 Chapter 5. Design choices & experiments

Figure 5.2: Circuit B. The pac-man-like circles are simulated as conducting bodies, creating a simple yet large circuit. The red rectangular box is simulating a laser. The laser is glowing since a current is running through it, i.e. the circuit is closed.

Figure 5.3: Circuit C. A trivial circuit without any power source.

(43)

5.2. Circuit simulation 35

Figure 5.4: Circuit D with unconnected components, i.e. two independent circuits.

Figure 5.5: Circuit E. The same circuit as Circuit B, except that the ball connected to the minus pole is not touching the other, i.e. the circuit is open.

References

Related documents

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

För att uppskatta den totala effekten av reformerna måste dock hänsyn tas till såväl samt- liga priseffekter som sammansättningseffekter, till följd av ökad försäljningsandel

Från den teoretiska modellen vet vi att när det finns två budgivare på marknaden, och marknadsandelen för månadens vara ökar, så leder detta till lägre

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

Av tabellen framgår att det behövs utförlig information om de projekt som genomförs vid instituten. Då Tillväxtanalys ska föreslå en metod som kan visa hur institutens verksamhet

Generella styrmedel kan ha varit mindre verksamma än man har trott De generella styrmedlen, till skillnad från de specifika styrmedlen, har kommit att användas i större

Parallellmarknader innebär dock inte en drivkraft för en grön omställning Ökad andel direktförsäljning räddar många lokala producenter och kan tyckas utgöra en drivkraft

Närmare 90 procent av de statliga medlen (intäkter och utgifter) för näringslivets klimatomställning går till generella styrmedel, det vill säga styrmedel som påverkar