Walid M. Taha · Abd-Elhamid M. Taha Johan Thunberg

# Cyber-Physical Systems: A Model-Based Approach

Cyber-Physical Systems: A Model-Based Approach

Walid M. Taha • Abd-Elhamid M. Taha Johan Thunberg

# Cyber-Physical Systems: A Model-Based Approach

Walid M. Taha School of Information Technology Halmstad University Halmstad Hallands La¨n, Sweden

Abd-Elhamid M. Taha Alfaisal University Riyadh, Saudi Arabia

Johan Thunberg Halmstad University Halmstad Hallands La¨n, Sweden

ISBN 978-3-030-36070-2 ISBN 978-3-030-36071-9 (eBook) https://doi.org/10.1007/978-3-030-36071-9

© The Editor(s) (if applicable) and The Author(s) 2021. This book is an open access publication. **Open Access** This book is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.

The images or other third party material in this book are included in the book's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the book's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.

The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.

The publisher, the authors, and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Cover Image Credit: © N.R. Fuller, National Science Foundation

This Springer imprint is published by the registered company Springer Nature Switzerland AG The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland

*To the future*

# **Preface**

This book is aimed at anyone who would like to be an inventor or an innovator of cyber-physical systems, that is, machines, manufactured products, methods, or combinations of such things. The goal of such invention or innovation is to fill concrete needs in society. Modern examples of such creations include autonomous and electric vehicles, quadcopters, smartphones, and robots. More than ever before, it is useful to describe such systems as *cyber-physical* because they combine aspects that have previously been confined within the realm of relatively separate disciplines, and in particular, within computer science and within physical sciences. We believe that, increasingly, a more holistic and unified view of such systems is needed. This book achieves this goal by taking a model-based approach, which allows the reader to develop her mathematical modeling skills in a manner that allows her to combine her knowledge from a diverse range of technical disciplines into the same model. At the same time, we are guided by the fact that different types of activities go into the process of creating and developing such systems, including three that this book is concerned with: learning, teamwork, and design. We start by considering these three points in more detail.

## **Learning**

Learning is a lifelong activity that has become more important than ever in today's knowledge economy. Today, there is much more to learn. The very computing and communication technologies that inspire this book are themselves accelerating science and technology, and the pace with which we accumulate new knowledge. To manage this changing learning landscape, you need to work smart. This book aims to help you do that by starting from a high-level, systems perspective and working down into key, representative subtopics. This way you are able to focus on key concepts that are broadly applicable to almost all modern inventions. An important tool that this book provides to help you with learning in the long term is the model-based approach, and especially the hybrid-systems modeling formalism, which is introduced early in the book and used throughout to provide practice.

This book is also intended to encourage you to ask questions. To set an example, the book itself motivates many topics and ideas by asking questions. Asking questions is one of the most important skills for lifelong learning—it is an activity that involves taking stock of what we know and identifying the gaps that we need to fill to achieve a certain goal. The book is not about what you *should* do with these concepts, but rather, what you *could* do. It is up to you and your understanding of the world and its needs to put these concepts to work. We challenge *you* to show us how new systems can be designed.

## **Teamwork**

Teamwork and collaboration are essential because many modern inventions require bringing together ideas from a wide range of disciplines, and to bring in knowledge from a vast number of areas. As a skill, teamwork is at the top of what employers tell us they need. Of course, teamwork and collaboration can be a tricky subject to learn about from a book—we only experience collaboration when we work with others. This book will help you do that in three ways. First, it introduces key concepts from several areas that are often implicated in new inventions, including those that are related to computing and some related to more physical science and engineering disciplines. To talk about these concepts, some basic vocabulary is introduced. Both the concepts and the vocabulary help us appreciate the type of expertise that experts in different subjects have, and to build the beginnings of the vocabulary needed to work with these experts.

Second, the book gently introduces the reader to three powerful mathematical notions that formalize the similarities between a wide range of seemingly different concepts. Seeing the similarities allows us to compress our knowledge and to be able to think quickly of alternatives. The focus is less on the mathematical origin and nature of these concepts and more on how to use them in modeling and simulation, which is where their effects are more animated, and where you will need them the most. These concepts can be seen as an example of a core mathematical formalism that give us tremendous expressivity to express ideas and to animate them through simulations. These concepts are:

3. **Rate change laws**: These are laws that relate to the rate of change of one or more quantities. Examples are laws such as "the speed of the vehicle is 25 miles per hour" or "the rate of change of speed is equal to −9*.*8 meters per second squared."

These concepts will be used to model all the different types of phenomena covered in the book. The point of this minimalism is to make it easier for you to see the similarity between concepts that arise in different settings. It also means that you only need to learn a small number of concepts and you will have a lot of opportunities to practice them well. When you have mastered them and their use in modeling, they will become a powerful communication tool for you both when collaborating with others and when you are working on inventions of your own. Incidentally, if you are surprised that we will be doing so much with these three seemingly simple concepts, you are in good company. They are only intuitive and simple individually. When combined, their expressive power and usefulness multiply.

Third, the first part of the book includes study problems, labs, and a project that are intended to be carried out in collaboration with at least one partner. Study problems help you check your understanding of the material covered in the chapter, labs offer more hands on experience, and the project helps you connect the learnings from different chapters together. In a classroom setting, the instructor will typically organize project teams. If you are reading this book independently, we encourage you to work on the labs, study problems, and project with a partner.

## **Design**

Design is a process that involves creativity and experimentation, two things which are closely intertwined—trying out things is an essential part of a process of developing something new and establishing that it achieves the intended purpose. To help you experiment and explore ideas efficiently, this book makes use of a modeling and simulation environment called Acumen. Acumen was built specifically around the three key mathematical notions mentioned above, and to make it easier for both learners and researchers to study models that use these concepts. It has several features that can support you in developing your core creativity skills:

seen to imply different notions of time, one discrete and the other continuous. Acumen has a notion of time that unifies both.

Modeling is a critical skill for the upcoming generations of inventors, engineers, and scientists, as it allows us to clearly formalize, reflect on, and communicate ideas. For this reason, modeling is a central theme and tool in this book.

## **Using This book**

This book is designed as the textbook for an introductory graduate or undergraduate course to the subject. It can also be used independently. When used for a course, it is typical that Part I is covered sequentially and then one or two topics from Part II are covered. Part I (Core Concepts) contains the material expected to be covered by most university-level courses on the subject and is intended to be covered in sequence. Part II (Selected Topics) contains additional topics that have limited interdependence among them. Thus, a course can include any one or more of them once the materials in Part I (at least up to Chapter 5) have been covered.

When this book is used as the textbook material for a course that takes up 50% of a student's work week, one chapter can be covered each week. This is the case, for example, in the Swedish higher education quarter system, where students take two courses per quarter. In a US quarter system where one course is roughly a 30% of a student's work week, or in a UK semester system where it is closer to 20% of a student's work week, the pace should be adjusted accordingly.

At the end of each chapter in Part I, there are three different types of tasks; they are referred to as Study Problems, Labs, and Projects and are numbered in accordance with the chapters. Study problems are suitable as classwork or home assignments done by students individually or in groups and are submitted to the teacher weekly. These are, in comparison with the labs and projects, of a more theoretical nature and train the students to understand the boundaries of what simulation can deliver. Furthermore, the theory helps us appreciate how simulations can answer questions not possible to answer by mathematical derivations.

#### Preface xi

The labs are tasks done in Acumen; typically in a classroom or in lab environment under the supervision of a lab assistant. There is no recommendation to assess (grade) the labs. They can be seen as an opportunity for students to become familiar with Acumen and the specific concepts discussed in the chapter that the lab illustrates.

Each chapter's project is a sub-project of a larger project that runs as a common thread throughout the Part I. The end goal is to develop a model of a table tennis (ping pong) playing robot. To succeed, we break down the task into sub-goals manifested through project's activities. The final model is based on incremental additions made in the respective chapter's project activity. Then the content of those ranges from modeling of mechanical and physical phenomena, through hybrid phenomena such as bouncing balls, modeling of sensors and actuators subject to discretization and quantization, to control theoretic aspects such as the control of a robotic arm and coordinate representations thereof. As a proposal for a final project, the different models for the ping pong playing robots can compete against each other one by one in a round-robin format in the simulation environment Acumen.

The three different tasks, namely, study problems, labs and projects, work in symbiosis where study problems provide a theoretical understanding of the material, the project provides a practical understanding of modeling and simulation, and the labs act as a bridge between these two parts.

## **Summary of Content**

Chapter 1 introduces the field of Cyber-Physical Systems (CPS), places it in the broad context, and explains the importance of this interdisciplinary subject in today's connected society. Chapter 2 addresses modeling of mechanical and electric systems. This includes conservation laws, statics, and dynamics. We model such systems mathematically using linear equations and Ordinary Differential Equations. The physical models addressed capture phenomena that evolve in continuous space and time. In Chapter 3, the key question raised is how we model phenomena that may contain not only continuous part but also discrete ones. The answer we provide is to model these phenomena as hybrid systems. We illustrate this by modeling a bouncing ball as a hybrid automaton and furthermore provide examples of physical systems with computational parts that are both discrete and continuous. In Chapter 4, we introduce basic concepts about control theory. This includes static control and dynamic control including Proportional Integral Derivative (PID) control. Chapter 5 can be seen as a continuation of Chapter 4, where we consider the effects of digital controllers, actuators, and sensors. Such devices give rise to effects such as quantization and discretization. The continuous evolution of a CPS device in the physical world subject to control and sensory discretization and quantization effects can be modeled as a hybrid system. Chapter 6 addresses coordinate transformations, which is key to control are essential for the design of a CPS. As examples we consider robotic arm manipulation and conversion between Euclidean and Polar coordinates. Chapter 7 sheds light on challenges arising in multi-agent systems where agents may have different, possibly conflicting, objectives. It provides understanding as well as bridges the gap to systems involving multiple devices that, for example, compete or collaborate for resources. Chapter 8 introduces Communication from a point of view that is suitable for the needs of the CPS context, and Chapter 9 does the same for basics of Sensing and Actuation. Appendix A includes a slightly revised edition of the user manual for the Acumen language, as used in this book.

## **Expected Background**

Our goal is to make the book as accessible as possible and to inspire the reader to explore further in a wide range of technical topics far beyond those covered within the book itself. That said, to make the best use of the book, it will greatly help that the reader is familiar with—and not necessarily mastery of—the following:

It is our intent that the book provides a gentle environment to further develop the student's familiarity with these topics. Thus, to the extent that it is possible, the book is self-contained for any university freshman in a Science, Technology, Engineering, or Mathematics (STEM) program.

## **After This Book**

Invention, innovation, computing, physical systems, modeling, and simulation are all vast topics that are impossible to cover in any single textbook. They are also all evolving subjects that are a living part of our world. Even the overarching notion of Cyber-Physical Systems (CPS) that you will learn about in this book is also far too broad for one book. The goal of this book is to give you a sense of what is out there, to help you get started, and—if we succeed—to inspire you. To do that, we must repeatedly press the brakes in each chapter to avoid getting too deep and technical, which is the role of the books and research papers that you will choose to read when you decide that you wish to learn more about these specific topics. Our philosophy in this respect seems to be well-aligned with the following thought articulated by Benjamin Bloom in *Evaluation to Improve learning*, 1981:

In each subject field there are some basic ideas which summarize much of what scholars have learned over the long history of the field. These ideas give meaning to much that has been learned, and they provide the basic ideas for dealing with many new problems as they are encountered by people who have learned what the field has to offer. We believe that it is a primary obligation of the scholars as well as teachers of the subject to search constantly for these abstractions, to find ways of helping students learn them, and especially to help students learn how to use them in a great variety of problem situations. To learn such principles and generalizations adequately is to become a very different human being. Through them one comes to appreciate the beauty and orderliness of the universe. Through them one learns to appreciate the great power of the human mind. To learn to use such principles is to possess a powerful way of dealing with the world. (p. 235)

To pursue this ideal, we have limited the scope of the book in several respects, which are addressed by more specialized textbooks and courses that the reader can easily find through an online search or by asking advisors in a university setting. Thus, a natural step after this book is to pursue more specialization. Understanding how a broad range of areas of science and engineering connect is a different matter from understanding the specific areas or their specialties. The former type of knowledge is called breadth, and that is what this book addresses thoroughly. To do this, we have to leave out a lot of material that is covered in programs that focus on specific subjects, including most aspects of modeling electrical circuits (linear systems, electronics, power electronics), physical systems (statics, dynamics, basic physics, classical mechanics), computer systems (digital logic, computer architecture), communications (communication theory, information theory, networks, wireless networks, real-time networks), control (linear systems, digital control, nonlinear control). Specific directions that are natural to seek deeper specialization in this area are:

1. **Embedded Systems**. A deeper understanding of specific methodologies and technologies is often needed to build actual physical systems. For example, we do not address specific architectures, microprocessors, or popular embedded technologies such as the Arduino or the Raspberry Pi. We also do not talk about common values for resistors capacitors or other devices, nor do we talk about device numbers (such as popular chips delivering transistors or operational amplifiers). A notable textbook with a modern approach to design methodology is:

Edward A. Lee and Sanjit A. Seshia. *Introduction to Embedded Systems, A Cyber-Physical Systems Approach*. MIT Press, 2011. Available online at http://LeeSeshia.org.

Another focusing specifically on managing complexity in design is:

Hermann Kopetz. *Simplicity is Complex - Foundations of Cyber-Physical System Design*. Springer, 2019.

A now classic textbook with an engineering focus is:

Peter Marwedel. *Embedded System Design: Embedded Systems Foundations of Cyber-Physical Systems*. Second Edition. Springer, 2011.

André Platzer. *Logical Foundations of Cyber-Physical Systems*. Springer, 2018. Lecture videos available online at http://video.lfcps.org/.

and

Rajeev Alur. *Principles of Cyber-Physical Systems*. MIT Press, 2015.

4. **Mathematical Foundations**. Our focus is on mathematics as a language for expressing ideas clearly, for analyzing ideas using mechanized tools such as computer simulation, and for communication between individuals. We put little emphasis on proof in general and on foundations (differential equations, calculus, linear systems, topology, real analysis).

Thus, the purpose of this book is not to cover all these areas, but rather to give you enough knowledge to appreciate the nature and significance of these different areas, and to enable you to peruse the ones you choose to learn more about.

## **Our Experience Teaching with the Book**

The lecture notes that served as the basis for this book have been used as the basis for courses taught at Halmstad University for several years by Walid Taha and by Johan Thunberg, at Rice University by Robert "Corky" Cartwright and by Mike Fagan, and at Alfaisal University by Abd-Elhamid M. Taha. At Halmstad University, the material was developed in the form of lecture notes starting in 2012. These lecture notes were made available online at bit.ly/LNCS-*yyyy* where *yyyy* is any year between 2012 and 2018, inclusive.

#### Preface xv

Experience with teaching this course at Halmstad University was reported in the following publications:

Walid Taha, Robert Cartwright, Roland Philippsen, and Yingfu Zeng. "A first course on cyber physical systems." In *Workshop on Cyber-Physical Systems Education (CPS-Ed)*. 2013.

Walid Taha, Yingfu Zeng, Adam Duracz, Xu Fei, Kevin Atkinson, Paul Brauner, Robert Cartwright, and Roland Philippsen. "Developing a first course on cyber-physical systems." *ACM SIGBED Review* 14, no. 1 (2017): 44–52.

Walid Taha, Lars-Göran Hedstrom, Fei Xu, Adam Duracz, Ferenc A. Bartha, Yingfu Zeng, Jennifer David, and Gaurav Gunjan. "Flipping a first course on cyber-physical systems: an experience report." In *Proceedings of the 2016 Workshop on Embedded and Cyber-Physical Systems Education*, p. 8. ACM, 2016.

This course focused on Part I (Core Concepts) and typically covered material from one chapter from Part II (Selected Topics). The course was initially an elective (optional) course for senior undergraduates and Masters students and was then later converted into a required introductory course for Masters students. The material was also used as a basis for an introductory doctoral student course. At Rice University, it was offered as an elective undergraduate course. At Alfaisal University, it was offered as an elective undergraduate course.

## **Let Us Hear from You!**

We would be very interested to hear from both students and teachers about their experience with this book, both on positive experiences and on areas where the book or Acumen can be improved. To contact us, please write us at cps–<EMAIL_ADDRESS>
Seattle, Washington Walid M. Taha Riyadh, Saudi Arabia Abd-Elhamid M. Taha Halmstad, Sweden Johan Thunberg

# **Acknowledgments**

There are several people without whom this book would have not been possible.

The area of cyber-physical systems, which is the subject of the book, would have not materialized if it were not for the efforts of many individuals that believed strongly in the need for it. We are indebted to the whole community, especially the core group of visionaries that include Helen Gill, Edward A. Lee, and Janos Sztipanovits, who played a key role both in shaping the community and in supporting the efforts that resulted in this book.

In recognizing the importance of cyber-physical systems and of modeling formalisms, we are greatly influenced by Paul Hudak and his work on both Functional Reactive Programming and Domain-Specific Languages. We see Acumen as a continuation of this work. Paul's interests spanned programming languages and building RoboCup robots and gave us confidence that a project such as this book would be possible.

Acumen itself would have never been possible without the enthusiasm, excitement, and hard work of its core team of developers, including Adam Duracz, Paul Brauner, Jan Duracz, Kevin Atkinson, Yingfu Zeng, and Xu Fei. The design of Acumen was also influenced by discussions with several other colleagues, especially Aaron Ames, Robert Cartwright, Michal Konečný, Eugenio Moggi, Marcia O'Malley, Roland Philippsen, and André Platzer.

We thank the students and colleagues that took a course based on early versions of this book with Walid at Halmstad University in Spring of 2012: Tantai Along, Maytheewat Aramrattana, Amirfarzad Azidhak, Chen Da, Carlos de Cea Domínguez, Adam Duracz, Carlos Fuentes, Pablo Herrero García, Veronica Gaspes, Nicolina Månsson, Diego Leonardo Urban, Viktor Vasilev, Rui Wang, Fan Yuantao, Yingfu Zeng, and Hequn Zhang. Their interest and enthusiasm provided critical support for continued development of the lecture notes into the 2013 edition as well as several editions that continue now in the form of this book. On the way, numerous other students have contributed to its development.

The book would have not been possible if it were not for support from the National Science Foundation, which funded a project that was initially managed by Helen Gill and later by Ralph Wachter and David Coreman. The project description included a course outline that very closely matches the contents of this textbook.

The book would have also not been possible without the support of the Head of Education at the School of Information Technology, Halmstad University, Jörgen Carlsson, and the program coordinator for the Embedded and Intelligent Systems (EIS) Master's program at Halmstad University, Stefan Byttner, both of whom encouraged the introduction of the course and provided the academic environment that enabled its development to full fruition.

The chapter on sensing and actuation benefited greatly from discussions and feedback from Per-Erik Andreasson, Emil Nilsson, and Ross Friel.

Earlier versions of several chapters benefited from editing by Mark Stephens. Staffan Skobgy kindly read a draft of the book and provided us with valuable feedback. Several colleagues gave us valuable suggestions, including Maytheewat Aramrattana, Jörgen Carlsson, John Garvin, Mohammad Reza Mousavi, Perdita Stevens, Sotiris Tzamaras, and Kazunori Ueda.

The Acumen manual was at various points edited by Mark Stephens. Valuable input relating to the core language and its intricacies was provided by Kevin Atkinson, Adam Duracz, Veronica Gaspes, Viktor Vasilev, Fei Xu, and Yingfu Zeng. Roland Philippsen and Jawad Masood suggested several suggestions from the point of view of actual users with expertise in analytical dynamics.

Support for the development of Acumen and this textbook was provided by the US National Science Foundation (NSF) Cyber-Physical Systems (CPS) project #1136099, by the Swedish Knowledge Foundation (KK), by the ELLIIT Strategic Network, and by Halmstad University. The development of Acumen was also supported by several corporate and institutional sponsors, including National Instruments, Schlumberger, Volvo Technology Group, and SP (now RISE).

We are enormously grateful to Roslyn Lindquist for developing the beautiful illustrations for this book and for gracefully putting up with our last minute requests for modifications, changes, and more illustrations.

Last, but not least, we would like to acknowledge at least part of the debt we owe towards our parents, including a mother who painstakingly worked to ensure that we know the difference between how the digits for 2 and 3 are written and a father for answering endless questions. We are forever grateful.

# **Contents**

#### **Part I Core Concepts**

#### Contents xxi

#### **Part II Selected Topics**

# **Part I Core Concepts**

# **Chapter 1 What is a Cyber-Physical System?**

Our starting point is to reflect on our world today and to consider examples and characteristics of what has come to be known as Cyber-Physical Systems (CPSs). We then look at the innovation process and the associated workforce challenge. Next, we explain how the field of CPS brings together several previously distinct fields such as Embedded Systems, Control Theory, and Mechatronics. We conclude with an overview of what you can expect to learn from this book.

## **1.1 Our Planet. Our Knowledge. Our Destiny**

We live in a world that is changing at a much faster pace than ever before. More than at any other time in our history, there is a pressing need for new ways of looking at science, technology, and social phenomena—ways that can help us understand our planet, ourselves, and how we can take control of our collective destiny. Our population and our consumption of the Earth's resources are soaring. Estimates put the world's population near eight billion<sup>1</sup> and annual per capita energy consumption at about <sup>20</sup> MWh/year, that is about 2 tonnes of oil equivalent per year.<sup>2</sup>

Fortunately, with the development and availability of powerful communication infrastructure, our awareness of the state of the world and our ability to influence it are also improving. For example, it is remarkable that the number of smartphone users on the planet has already topped three billion,<sup>3</sup> which is close to half of the world population. This means that our collective ability to share information and cooperate has already reached a remarkable level.

© The Author(s) 2021

<sup>1</sup>United Nations' World Population Prospects 2019.

<sup>2</sup> The International Energy Agency (IEA)'s statistics reports about 2 Tonnes of Oil Equivalent (TOE) for Total Primary Energy Supply (TPES) per capita. This amounts to 22 Mega-Watt hours (MWh) for the conversion rate of 11 MWh per TOE.

<sup>3</sup>Statista reports 3.3 billion smartphone users worldwide.

W. M. Taha et al., *Cyber-Physical Systems: A Model-Based Approach*, https://doi.org/10.1007/978-3-030-36071-9\_1

Without a doubt, our knowledge in the areas of science, technology, and social sciences has played a key role in shaping the modern world. Of particular importance is knowledge in the areas of computing and communication. These are areas that have recently witnessed exceptionally rapid development due to advances in digital computing and communication. In the history of human knowledge, these are relatively recent developments that are currently treated as separate disciplines. In research and in education, topics relating to digital computing and communication have been viewed as distinct areas of specialization.

The workforce marketplace has long prized specialized expertise. But in today's knowledge economy<sup>4</sup> specialization also poses new challenges: The process of innovation that leads to new breakthroughs relies critically on interdisciplinary collaboration and insight. This is especially the case for digital products that have a physical presence. While many successful Internet-based products benefit from the relative ease of innovation in "pure information technology," such ease is not currently present for systems that sense the physical world or can interact with it. The reasons for this problem are multifaceted. To develop a system with a physical presence or "embodiment" requires diverse expertise from many areas (e.g. Mechanical Engineers, Computer Scientists, Electrical Engineers, Computer Architects), and experts in these areas may not have a common language. What is more, in many cases addressing this problem requires finding commonalities in the foundations of these disciplines as well as ways to reflect them in the education of the experts in these different domains.

We are not alone in holding this view. Given the extent to which digital technologies pervade modern life, a growing community of researchers and educators believe that closer integration with many other disciplines will be needed in the future.<sup>5</sup> The development of numerous innovative products in the home, health, and entertainment sectors all require close collaboration between several innovators with different advanced training (such as Masters or Ph.D. degrees). The current organization of disciplines at university level appears to hamper the cross-disciplinary communication needed to realize such collaboration. The organization of scientific knowledge and its educational delivery may seem like distant problems, but they have concrete implications for the workforce and, as a result, affect our collective ability to contribute to the world we live in.

## **1.2 Observe. Understand. Innovate**

One of the goals of this book is to help you learn skills that can make you become a better observer of the world around us as well as new products and technologies. This is one of the reasons that the book covers physical modeling. Doing so has a secondary purpose of increasing your awareness of the mathematics that can be

<sup>4</sup>See for example Powell and Snellman, the Knowledge Economy, 2004.

<sup>5</sup> See for example Stankovic, Sturges, and Eisenberg, A 21st Century Cyber-Physical Systems Education, 2017.

used to model our world, and creates opportunities for showing how this type of mathematics can provide insights into this world. Mathematics gives us a way to test our understanding of different phenomena, and as such provides us with a means to improve this understanding. Our understanding of problems that need to be addressed and components that can be used to fill these needs are prerequisites for successful innovation.

## *1.2.1 Cyber-Physical Systems and Hybrid Systems*

While several definitions are used in the literature, an early definition is simple and intuitive enough: According to Lee and Seshia, the term Cyber-Physical Systems (CPSs) was coined by Helen Gill around 2006, at the National Science Foundation (NSF) in the U.S., to refer to the integration of computation with physical processes.<sup>6</sup> Often, it also has a communicating or networked aspect.

If we consider this description from the point of view of the mathematics needed to model them, we can begin to see some technical requirements: Computational components give rise to a need for discrete modeling; physical components give rise to a need for continuous modeling; and a communications/networking aspect gives rise to a need for probabilistic and possibly also a game theoretic modeling. Many fields of mathematical modeling will use either continuous or discrete mathematics, and not mix them. And, in fact, combining these two can lead to some fundamental technical problems. Adding probabilities on top requires an additional level of care. But at a more practical level, simply expressing models that combine both discrete and continuous components requires a modeling formalism that can express both. That is precisely what hybrid (continuous/discrete) systems provide. In this book we will make extensive use of continuous systems, discrete systems, and hybrid systems, for modeling CPSs, and will make modest use of probabilities in introduction to basic concepts in the treatment of game theory, communication, and sensing and actuation.

## *1.2.2 Examples*

Many examples of CPSs surround us in everyday life. In the home we have cleaning robots, smart lighting systems, and smart heating, ventilation, and air-conditioning (or HVAC) systems.

For transportation we have cars, planes, motorized scooters, Segways, and electric bicycles. Existing systems like these are representative of the areas where we can expect to see significant innovation and development in the future. For instance,

<sup>6</sup> Page xii of Edward A. Lee and Sanjit A. Seshia, Introduction to Embedded Systems, A Cyber– Physical Systems Approach, http://LeeSeshia.org, ISBN 978-0-557-70857-4, 2011.

while cars have been around for almost 350 years,<sup>7</sup> new features like Lane Departure Warning Systems (LDWS) are now available in vehicle product lines.

Medical solutions include pacemakers, insulin pumps, personal assistance robots, and smart prosthetics. Many of these technologies did not exist until recently, and have the potential both to save lives and to significantly improve health and wellbeing. Wearable fitness and health-monitoring systems promise to have a hugely positive impact on users, whether or not they are healthy or have a physical or a cognitive disability. Health monitoring systems are just one example of the whole area of sensor networks, which includes those made of tiny sensors used to observe large land, marine, or aerial spaces.

Finally, examples from the energy sector include windmills, smart grids, and various energy harvesting technologies. In fact, it is no exaggeration to think of our entire planet as a single, massive CPS.

While the skills you will acquire in this book are centered primarily around systems that you can construct, these same skills will also help you better understand existing systems.

When we survey such examples we notice that some are more futuristic or more spectacular than others. For example, the Segway may seem more critically dependent on having a "cyber" (or computational) component than a car. A car can exist and function without a computational part. But a Segway has just two wheels, and it is not at all obvious whether it can even exist or function without the computational component that keeps it upright.

Mechanically, the Segway is an unstable system that we can prove mathematically ought to fall if the computational component that keeps it upright is switched off. The Segway uses a *real-time* control system that runs on a dedicated, embedded computer. Whereas, traditionally, many systems have been designed to be stable in the absence of active control, the Segway and many generations of jet fighters (such as the Saab JAS 39 Gripen) have designs whose stability depends critically on active control.<sup>8</sup> The idea in all of these cases is that pursuing this path leads to more efficient designs that can realize functionality that would be impossible without the active control. For a variety of technical reasons, the control itself would not be possible without a computational component. One of the goals of this book is to help you understand what makes a system more challenging to realize—this is often exactly the same thing that makes it seem futuristic and spectacular.<sup>9</sup>

While powerful airborne vehicles can be very impressive, in the grand scheme of things their applications are relatively limited, and their impact on daily life can be minimal. In contrast, smart home technologies may have a bigger and more direct impact. For example, significant energy is expended in heating and cooling buildings, washing and drying clothes, and transporting people and commodities to

<sup>7</sup>History of The Automobile provides an example that could be as old as 1672.

<sup>8</sup>Aircraft functions of this type are sometimes referred to as supermaneuverability.

<sup>9</sup> Clarke's third law states that "Any sufficiently advanced technology is indistinguishable from magic." In a sense, we are saying here that what appears magical is often also what is at the edge of our knowledge, and is therefore where we need to push further to increase our understanding of the world.

and from homes. This means that the optimization of HVAC systems can have a significant impact on global energy consumption. Similarly, computation can enable sophisticated hydroponic gardening right in the home to provide us with a local supply of fresh nutrition. Combining the two may also enable more advanced management of various parameters of comfort in the home (air moisture levels, CO2 levels) and improve health and living conditions.

## *1.2.3 Computational vs. Physical Systems*

It is common when we first hear the definition of Cyber-Physical Systems to assume the computational and physical subsystems are distinct. Often this will be the case, but not always. The key point is that when we use these designations we are making an abstraction. Every physical system that we can think of, by definition, will have physical components. At the same time, computation is an abstract notion that we can identify when we recognize the presence of a mathematical function or relation. Today, we often assume that computation is performed digitally. But this is not always the case: Analog computers have long existed, and quantum computers are already being built. Even when we limit ourselves to digital computation, the distinction is still not clear: A modern microprocessor has aspects that simultaneously touch upon essentially all computational and physical aspects discussed in this book. Especially to microprocessor designers, it is simultaneously physical and computational in a very real way, and both its physical and computational characteristics affect each other directly.

## *1.2.4 Biological and Intelligent Systems*

While the focus of much CPS research and education is on systems that we can construct and develop into products, it is also instructive to reflect on one class of systems that has many characteristics of CPSs—namely, living creatures including ourselves. While we often view living creatures as purely biological systems, living systems clearly have physical manifestations. These manifestations simultaneously exhibit a range of physical phenomena, including mechanical, chemical, electromagnetic, and optical. At the same time, they often seem perfectly capable of computation and communicate on a regular basis. Living systems can be a great source of inspiration for the design of new CPSs and, similarly, advances in CPSs could provide us with better tools to improve understanding of life and ourselves. For example, living systems are the inspiration for the field of Artificial Intelligence, which aims to develop computational methods for solving problems that are important in the real world, but for which we may not even have a clear notion of what an acceptable solution should be.

No part of this book is dedicated to such systems, but the principles covered are still applicable.

## **1.3 Developing New Products**

To collaborate on developing new products, it is useful to have a shared concept of product development. Different organizations, and even different individuals, have different approaches. For this reason, it is important to consider features common to all processes, and to use them as a starting point. We can at minimum distinguish four artifacts in the process of product development: idea, model, prototype, and product. This is by no means an exhaustive list, but is sufficient to allow us to describe key aspects of any such process.

An **idea** is a mental notion of an object, function, or design. Ideas are the colorful realm of inspiration. Good ideas are usually created in an environment where we have a good understanding of the problem that needs to be solved, the context in which the solution will be applied, and the space of feasible solutions. Generating good ideas, therefore, requires awareness of the real needs as well as what science, technology, and society makes possible.

A **model** is a formal description. In this context, the word formal means having form, such as syntactic or geometric manifestation. Thus, a textual or graphical description can be seen as formal. Mathematical descriptions are also excellent examples of formal models. Moving from an idea to a model makes it possible to apply conceptual and computational tools to analyze the new function or design. Obviously, mathematical descriptions have the advantage of being amenable to mathematical analysis and reasoning, but other formal models can also enjoy similar properties. Models written in plain language and including possibly a few drawings, as is common in patents, can be more accessible to a general audience than mathematical models. Models can also be realized as computational codes, which can be used for efficient early testing and design space exploration.

A **prototype** is a physical, operational instance of the model. This enables more early testing, which allows qualitatively different validation than what can be achieved analytically or computationally. Prototypes can be used to evaluate the safety as well as the response of users to first-hand experience with the product concept. Today, additive manufacturing technologies such as 3D printing are proving to be a powerful tool for enabling the rapid construction of prototypes with minimal delays and costs.

A **product** is a manufactured commodity that can be sold commercially to end users. While the public often identifies new technology with new products, building products involves much more than technical innovation. Creating products involves systematic analysis of the market, finding financing, recruitment, management, production planning, logistics, marketing, sales, billing, customer support, and other business operational activities. Even though this book does not cover these aspects, it is important to be aware that these are significant parts of the effort to deliver a finished product.

**Fig. 1.1** A typical process for developing a new product

Figure 1.1 depicts the typical relation between such artifacts, and the basic iterative cycle for moving from one to the next. As a rule of thumb, it is often the case that moving from one stage of development to the next involves at least one order of magnitude (that is, at least ten times) more effort than the previous stage. This compounding of effort in moving from one stage to the next, combined with the fact that the process often involves significant iteration and refinement, means that maximizing the quality of the intermediate product *before* we move to the next stage can significantly reduce the final cost. The high cost of iterating back from a late stage in this pipeline is a big motivation for modeling and simulation. In the worst case, such high costs can include production defects such as Boeing's problems with the 737 Max model, Toyota's brake system problem, and the Intel Pentium bug.

These examples illustrate that the better equipped we are to produce better ideas, models, and prototypes, the more successful we can be as innovators. This observation highlights the importance of techniques such as virtual prototyping (using rigorous modeling and computational simulation), testing (of both computational and physical components), formal verification (of discrete, continuous, and hybrid systems), and model-based production and manufacturing.

## **1.4 Is the Field of Cyber-Physical Systems New?**

While the term cyber-physical systems is relatively new, we should consider whether the field or *idea* behind this way of studying systems also new. It is important that inventors, innovators, leaders in a discipline reflect on and understand the nature and the reasons for the existence of the field. When we do this for CPS, we must consider a wide range of related disciplines and reflect on how they are connected. In the following we consider several relevant concepts and discuss their relationships to CPS.

A **hybrid system** is a mathematical model that features both continuous and discrete behaviors (related areas are **switching systems** and **impulsive differential equations**). While many CPSs can be modeled mathematically as hybrid systems, it is important that we distinguish between the concept of the actual, physical system and its mathematical models and the techniques used to study such.

The mathematical models are there to capture observed behavior, but as new observations occur that cannot be explained by the model it has to be modified or even replaced. It is a common mistake to think of models of physical systems as continuous and models of computational systems as discrete. Models of physical systems can be continuous, discrete, or a combination of both. For example, Bohr's model introduced in 1913 put forth the notion that electrons can only exist in discretely different orbits around the nucleus of an atom, planting the seed for quantum mechanical models. In this book, we study hybrid models of a simple bouncing ball (flying is a continuous behavior, bouncing is a discrete event). Furthermore, at the quantum level, many important phenomena cannot simply be viewed as continuous or discrete systems; rather, as probabilistic systems. Computational systems cannot always be viewed as purely discrete systems. Digital computers are generally implemented as continuous electronic circuits designed to operate reliably only when viewed as discrete systems. Also, there are systems known as analog computers that are continuous systems. Some examples of such systems can be realized perfectly using digital computers. Finally, quantum computing is an active research area that relies on probabilistic models. CPSs are real-world objects, whereas hybrid systems are a mathematical abstraction.

An **embedded system** is a computational system embedded in a physical system. Any CPS contains an embedded system. The main distinction is that the term "embedded system" reflects a primary focus on the computational component (that is *embedded* in a larger, physical system). Traditionally, research on embedded systems focused on problems such as formal verification of discrete systems (automata), hardware design, minimization of energy consumption and production cost, as well as embedded software development. The CPS view emphasizes the importance of taking into account the physical context of the computational system which is often necessary to design, test, and verify the functionality that we are developing.

A **real-time system** is one which must respond to external changes within certain timing constraints. Many, but not all, real-time systems are embedded systems. For example, an automated trading agent would not normally be viewed as an embedded system, even though it must operate under strict timing constraints if it is to function usefully in response to rapidly changing market conditions. Traditionally, research in real-time systems has focused on scheduling or real-time tasks in systems that have periodic or aperiodic request patterns, multiple (interchangeable) computational resources, tasks of varying priorities, and real-time communication. Naturally, research in this area often focuses on worst case run time requirements. A CPS may or may not be a real-time system: The control system in a car has real-time constraints, but the sound system does not necessarily have such.

**Reliability** is the ability of a system to continue to perform its function despite the failure of some of its components. Reliability can be achieved in several ways, starting from building components from stronger materials to adding redundancy and error-checking to detect and try to compensate for errors and failures. In many domains, including computational systems, probabilistic methods have been used effectively to increase reliability, while keeping costs manageable.<sup>10</sup> Probabilistic methods, however, are only one tool for designing and constructing reliable systems. Mastery of other more fundamental concepts in systems design allows us to become more effective users of probabilistic methods. Different CPSs have differing reliability demands, and reliability need not feature prominently in the develop-

<sup>10</sup> For some examples of how probabilities are used as a model of reliability, refer to Johan Rhodin's Wolfram Technology Conference talk.

ment of all individual CPSs. However, in general, as connectivity between different CPSs increases, there is also an increasing need to consider system-wide reliability implications for each type of individual cyber-physical subsystems.

**Dependability** is a more holistic notion that can encompass several related attributes, such as availability, reliability, durability, safety, security, integrity, and maintainability. In the context of the interdisciplinary field of **systems engineering**, it is viewed as a measure of these combined attributes. Systems engineering is often viewed as a field of both engineering and engineering management, reflecting its unique point of view between what is traditionally engineering and traditionally management. We see both systems engineering and dependability as of great importance for inventors and innovators, and that the content covered in this book will give the reader a solid foundation to pursue further studies in these disciplines.

<sup>A</sup> **multi-agent system** is a mathematical model consisting of interactive objects.<sup>11</sup> It is often associated with the mathematical discipline of **game theory**. Multi-agent systems and game theory provide useful techniques for modeling and reasoning about concepts such as *belief*, *knowledge*, *intent*, *competitiveness,* and *cooperation*. Notions of intelligence are often considered in relation to multi-agent systems and mathematical models of both discrete and hybrid (continuous/discrete) games exist. In contrast to the study of hybrid systems, the multi-agent systems and game theory focus on the behavior of collections of agents rather than individual agents.

Finally, CPS is closely related to the disciplines of **mechatronics**, **control theory, robotics**, and the **Internet of Things (IoT)**. A common feature of these disciplines is that they are highly interdisciplinary. CPS can be viewed as an attempt to take an even more all-encompassing approach than the first three disciplines, and being quite comparable to the last one (IoT). Texts on mechatronics may not necessarily dedicate a large part to communications and networking, or to hybrid systems foundations. Textbooks in control theory covering issues such as hybrid systems are still considered relatively advanced and specialized. Robots<sup>12</sup> are obviously great examples of CPSs, illustrating many of the challenges involved in designing innovative CPS products. We will use a ping pong (table tennis) playing robot as a running case study in a project that we will develop incrementally in different chapters. Both CPS and IoT take the view that the world is becoming highly connected and computational, and it is possible that the two approaches will converge. Historically, CPS is seen by some as having emerged from the Control Theory community, whereas IoT as having emerged from the Communications community.

<sup>11</sup> The definition we use is inspired in part by the one used in the article Multi-agent Systems. More information on the subject can be found in the online text of Shoham and Leyton-Brown.

<sup>12</sup> The definition we use is more specific than the one used in the article Robot. We exclude usage of the word when referring to purely computational ("virtual") systems, which we view as metaphorical use of the term.

## **1.5 What You Will Learn from This Book, and How**

The specific goals of this book include:

The book involves a simulation-based project. Simulation has many valuable uses, including:

As mentioned earlier, the project will focus on studying a robotics problem, namely, how to design a robot that can play ping pong. There are several reasons why robotics is a useful example of a CPS domain, including:

Designing robots gives rise to:

#### 1.6 A Writing Tip 13

Through these experiences, we can develop a sense of how designing systems becomes more challenging as certain characteristics/parameters of the system increase, such as:

	- Increasing the degrees of freedom (in models of physical systems).
	- Increasing the size of state space (in models of computational systems).
	- Reducing what can be sensed or actuated (in the control system view).
	- Reducing the dependability of the components (across all aspects).
	- Linear to non-linear Ordinary Differential Equations (ODE)s.
	- ODEs to Partial Differential Equations (PDE)s.
	- ODEs to Integral/Differential Equations (IDE)s.
	- Boolean circuits to automata to Turing machines.
	- Systems that are either discrete only or continuous only to systems that involve both types of behavior (hybrid systems).

Complex systems are challenging for engineers developing state-of-the-art tools, as well as for researchers conducting basic research. Developing a sense of what today's analytical and computational tools can handle will enable you to be a more effective innovator by focusing on designs that are feasible to analyze and design. It will also enable you to be a more effective researcher by understanding where the frontiers of knowledge lie, which is knowledge that is prerequisite to making fundamental research advances.

Congratulations on completing this introduction! Before we continue and summarize the chapter, we suggest readers that are using this book as course material for a course on CPSs to consult the Acumen manual, see Appendix A. Acumen will be used as the simulation and modeling environment in the project.

## **1.6 A Writing Tip**

We have noticed over the last 10 years significant confusion about how to use the abbreviation CPS as a short hand for the term Cyber-Physical Systems in the plural case in particular. This point is worth raising because abbreviation practice makes reading easier and can help avoid confusion. The main tricky bit seems to be that the abbreviation CPS is used both as the name of an area that studies a type of system and a plural for a group of systems. In particular, if we want to abbreviate "The area of Cyber-Physical Systems is new" we would replace the term by CPS. In contrast, if we say "Both cars and robots are Cyber-Physical Systems" we would replace the term by CPSs. When in doubt, think of the term Operating Systems (OS). If we want to abbreviate "The area of Operating Systems is new" we would replace the term by OS. In contrast, if we say "Both Linux and BSD are Operating Systems" we would replace the term by OSs.

## **1.7 Chapter Highlights**

	- (a) Examples: autonomous vehicles, the smart grid, smart homes, smart cities.
	- (b) A smart planet.
	- (c) The challenges for mankind: innovation, safety, privacy, security, regulation, and ethics.
	- (a) Relation to other fields.
	- (b) Workforce and educational challenge.
	- (a) Distinct and easily recognizable stages: Idea, Model, Prototype, Product.
	- (b) Order of magnitude increase in cost with each transition between stages.
	- (c) The highly iterative nature of the process.
	- (d) The cost of failure. How "late" discovery of flaws can be exponentially costly.
	- (e) The role of virtual prototyping and verification.
	- (a) The goal is to introduce you to the field, so that you know where to look for knowledge when you need it.
	- (b) Emphasis on modeling and simulation, which help you understand the math, accelerates your ability to experiment and innovate, and is fun!
	- (a) Recognizing the sources of technical complexity through learning about hybrid systems, control, communication, and game theory. This includes understanding the nature of the system dynamics (linear, non-linear, ODEs, etc.) and the size of the systems studied (in the discrete and the continuous domains).
	- (b) Experience through an in-depth case study (the project)

## **1.8 Study Problems**

## **1.9 Lab: Warm Up Exercises**

The purpose of the lab activities is to bridge between the theory discussed in the chapter and the more experimental activities of the project. The labs and the project will use Acumen. Acumen is an open source modeling and simulation environment specifically aimed at CPS design. The Appendix found at the end of this book contains a manual for Acumen. The distribution contains a set of examples that will be used in the Labs.

The purpose of this first lab is to connect to practical experience with modeling and simulation. The activities of the lab are to:

	- Download the 2016/8/30 Acumen distribution
	- Uncompress it or unzip it
	- Run the Jar file that you will find in the uncompressed folder
	- If this does not work right away, then go to Java.com, download and install Java 8, and restart your machine, run the Jar file again.
	- Geometry (in 3D, like our real world, and what we need to understand in order to talk about robot arms)
	- Dynamics, the basic differential equations needed for things like *f* = *ma*

The examples are in three folders in the 01\_Introduction examples folder. The first sequence (00–09) are examples of static 3D forms; the second sequence (10–19) are examples of dynamic behaviors and their plots; the third sequence of examples (20–29) are dynamic 3D forms.

Go through all the examples in the three sequences, one by one. For each example, read the text model, read the model itself, write down how you expect the model to behave, run the model, and then compare your expectations to what you saw when you ran the model. Next, make small changes to the model to test your understanding of how it work. You will notice that each example contains questions and challenges to help you make sure that you fully understand each model. Going through all three sequences is a really good way to brush up on the mathematical concepts that will be used in the coming few chapters.

Feel free to play and experiment and come up with whatever shapes you would like! The material introduced in these examples is enough to let you create a lot of really interesting 3D shapes.

The third sequence of example will be particularly helpful preparation for the coming chapters, as it introduces several basic concepts that illustrate how differential equations are used to model dynamics. Here is a brief summary of these concepts: Simple dense-time models are introduced with the equation *x* = 1*.* Definite integration of constants and polynomials arises naturally in discussing such equations, but such integrations are needed only when we calculate solutions by hand. A simulation environment that solves these differential equations (like Acumen) can also calculate numerical solutions automatically. Higher derivatives are illustrated by the equation *x* = 1. Exponential functions are introduced by the equations *x* = *x* and *x* = −*x*. Complex exponential functions (trigonometric functions) in the solution forms are introduced by the equation *x* = −*x*. These systems also exemplify linear differential equations. Physical systems that can be modeled by these types of equations (falling ball, electric flows, AC current, etc.) are briefly touched upon. The pendulum equation *x* = − sin(*x*) is given as an example of the non-linearity that arises naturally in mechanical models.

## **1.10 Project**

The goal of the project is to provide you with a concrete case study for applying what you learn in each chapter and to provide you with an opportunity for first-hand experience of the challenges and rewards of designing CPSs. To achieve this goal, the project will focus on an example of a CPS design task—namely, building a machine that can play ping pong. While building a robot can often require significant time, space, and financial resources, we can use model-based design and simulation techniques to produce a comprehensive blueprint and significantly sharpen our knowledge and skills with much less cost.

The first project activity will give you a sense of the overall way you will work with models in the project. The Cannon Beach game is intended to help you apply your knowledge of physics, control, differential equations, and other areas to solve a challenging design problem. Your knowledge will be deeper in some areas than in others. This variability in expertise is normal, and is typical in real-world situations. It is an important engineering skill to be able to find ways to solve difficult problems with the experience you already have, and to continue to develop your skills while working on new challenges.

The picture above shows what the game visualization looks like. From left to right you have a pile of cannonballs, the cannon, and the target. When the game is being played, the target (bullseye) appears at different locations. When the cannonball is fired, it travels with a given speed and the angle where the cannon is pointing. The angle is measured from the ground to the cannon. The bullet is subject to the effect of gravity and air resistance. You probably already know a lot about the effects of gravity for this problem, but not so much about air resistance. This problem is a chance for you to learn a bit about how air resistance is modeled, and how it affects solving problems.

Your task is to design a player (or "controller") that sets the direction of the cannon so that you hit the target. The more accurately you hit the target, the more points you get.

This controller takes the target position as input, and must compute a value for the angle. You can assume for now the velocity is given (see model) and leave it as it is. In terms of specific technical details, you can assume that gravity *g* = 10 m*/*s<sup>2</sup> and air resistance coefficient *k* = 0*.*01 m*/*s<sup>2</sup>*.* The target can appear at any point between positions −6 and 6. You will need to read the model of the game to learn the full details.

What you need to submit for this assignment is a modified version of the following template. In this template, the model parameters *position*, *target*, *velocity* represent the cannon's position, the target's position, and the bullet's velocity, respectively. The angle output should between 0 and *π*.

```
model ResponseExample( position ,target , velocity) =
initially
  angle = 0, distance = 0
always
  distance = target - position ,
  angle = pi/4
```
## **1.11 To Probe Further**

At the end of each chapter you will find a collection of pointers for further exploration. Some will be more technical, others will be lighthearted. The idea is to help you explore further beyond the material presented in the chapter.

	- Chris Hadfield's website
	- Economist article about Copyright in Space

**Open Access** This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence and indicate if changes were made.

The images or other third party material in this chapter are included in the chapter's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.

# **Chapter 2 Modeling Physical Systems**

How can we use math to predict the behavior of physical systems? In this chapter we cover principles for modeling physical systems; differential equations, with a focus on Ordinary Differential Equations (ODEs); systems of equations; vector calculus; one-, two- and three-dimensional mechanical systems (statics and dynamics); and resistive and linear electric circuits.

## **2.1 Reconnecting with the Physical World**

In Chapter 1 we explained how CPSs are ubiquitous in modern society. The systems are closely coupled with the physical world. To understand these systems and to build the skills required to develop new innovations we need to have some experience with modeling physical systems. Often, it is the physical nature of the problem that will either drive the solution or affect the extent to which a new product solves the given problem.

The physical phenomena that are useful to model depend on the problem. For different problems, we may wish to model physical, chemical, biological, economic, or even social phenomena. While working on our solution, it can be very helpful to consult specialized textbooks or research papers about modeling any particular phenomena that seem to have a significant effect on the behavior of our system.

Physics has a particularly important role in the design of CPSs. It encompasses mechanics, electromagnetics, optics, and thermodynamics, all of which are often present even in the realization of the cyber (computational) components of a CPS. Fortunately, understanding the basic principles for such systems can help us both in analyzing real-world problems and in developing the "mathematical muscles" that can help us to learn more about modeling on our own when required.

## **2.2 Conservation Laws**

A theme in physical modeling is the presence of conservation laws. These laws are the workhorse of the process of mathematical modeling, so, it is very useful to keep an eye out for them. Examples from mechanical systems include:

The main example from electrical systems is:

• Conservation of current.

Deeper principles in physics allow us to connect some of the principles mentioned. For example, the famous equation *E* = *mc*<sup>2</sup> allows to connect energy and mass. For us here, the importance of these principles stems from their utility in allowing us to model and analyze physical systems.

## **2.3 Elements in Mechanical Systems**

In addition to conservation laws, mechanical and physical systems will have standard elements. Examples in a mechanical system include:

**Mass** The basic rule for a mass is *F* = *ma*, where *F* is force, *m* is mass, and *a* is acceleration. Note that this is a second order differential equation, since *a* is really *x* (the second derivative of *x*), where *x* is the position. Note also that this equation holds when we are in one, two, or three dimensions. In all cases, *F* and *a* are both *n*-dimensional vectors where *n* is the dimension of the space we are working in, but *m* always remains a scalar (single-dimensional) value.

**Force (Including Gravity)** Force is an element that can represent the basic mechanical interaction between two objects. It is also involved in the basic rule *F* = *ma*. For our purpose it can be through physical contact or the effect of gravity.

**Lever** This is an element that consists of a long rod balanced on a pivot, which has two forces applied to it that would individually cause it to rotate in opposite directions. The lever is in equilibrium if the torques around the pivot are equal. In the case of the example shown in Figure 2.1, this means that

$$m\_1ga = m\_2gb.\tag{2.1}$$

Interestingly, we can see gravity appears as a multiplier on both sides. This means two things. First, in the rare situation where there is no gravity, and so, *g* = 0, the equation holds for any masses and lengths. More practically, in non-zero gravity we can divide both sides of the equation by *g* to get

$$m\_1 a = m\_2 b.\tag{2.2}$$

**Fig. 2.1** Two masses *m*<sup>1</sup> and *m*<sup>2</sup> are placed on a rod balanced on a pivot. The distances to the pivot, *a* and *b*, can be chosen so that the system is in equilibrium and does not move

**Friction** is a phenomena that generates a force that opposes the direction of (potential) movement, and is usually proportional to a normal force that is normal to the direction of the movement (often a surface along which another object is moving). In the case of the example shown in Figure 2.2, the normal force would be pointing upward.

**Fig. 2.2** A box is pushed with a force FApplied to the right. A force Ffriction is acting in the opposite direction. The gravitational force is negated by a normal force that points in the opposite direction

**Spring** The spring is a component that is modeled by Hooke's law, which is usually represented by the equation

$$F = -kx,\tag{2.3}$$

where *F* is a force, *x* is a displacement relative to a neutral (natural) position for the spring, and *k* is a (scalar) coefficient that relates these two values. Figure 2.3 illustrates this behavior by presenting three instances of the same spring in equilibrium. In the first case there is no mass attached; in the second, there is a single mass attached; in the third, there is a double-mass attached, leading to double the extension seen in the middle example. It is important to note again that both the *F* and *x* quantities can be n-dimensional, and that the *k* parameter is always a scalar.

**Fig. 2.3** Illustration of Hooke's law. If an object with mass 2*m* is attached to a spring, its length increases twice as compared to when an object with mass *m* is attached to the spring

**Damper** A damper is a device that creates a force against the direction of movement, and in proportion to the speed of the movement (compare this to friction mentioned above). The rule for a damper therefore has the form

$$F = -kv,\tag{2.4}$$

where *F* is a force, *k* is a constant, and *v* is a velocity. We use *k* for constants. Thus, this is not the same constant as the one used in Hooke's law, i.e., Equation (2.3). The example shown in Figure 2.4 presents a combined example involving a mass, a damper, a spring, and an external force. This example is one dimensional.

**Fig. 2.4** A system with both a damper and a spring. Dynamical behaviors of such systems will attenuate over time and the system converges to a static configuration

**Air Resistance** This is a force created by air and applied to any object moving through it. At slow speeds (much less than the speed of sound), we can view this force as being proportional to the square of the speed. Thus, the formula can be expressed in the one-dimensional case as

$$F = -kv \cdot \mathbf{abs}(v). \tag{2.5}$$

We use the absolute value function abs in this manner to make sure that the resulting value gives the force the right sign. Now, in the more general 3D-setting, the equation would be expressed as follows:

$$F = -kv||v||,\tag{2.6}$$

where *v* is the Euclidean norm of *v*. The reader can verify that (2.6) reduces to (2.5) in the one-dimensional case.

Using these rules, we can model complex systems by writing the equations for all of the individual components and solving (or simulating) them as a system of equations.

A **statics** problem is one where the system components are not moving, and nothing internal to the system can cause them to move. As an example, consider the system shown in Figure 2.5. If we are told that this system is at rest, then we can write an equation that relates *m, g, k, x*, and *Fk*. Given any three of these parameters, we can determine the fourth. Also, given a relation between two of these parameters, we can determine a relation between the other two.

The same system can become a **dynamic** system if we are told that at least one part may be moving. For example, the mass *m* (at position *x*) may be moving, in which case it would have speed *x* and acceleration *x*. The possibility of a non-zero acceleration must now be factored into the equation, and it would involve *g, k, x, x* , and *F*. We will also generally need to know the position at some given time, such as the position *x*(0) at time 0, in order to be able to solve the resulting equation.

A more involved example is the following configuration in Figure 2.6. For this example, we can write a system of ODEs involving *x*<sup>1</sup> and for *x*2, their derivatives

**Fig. 2.5** An object with mass *m* is attached to a spring. The gravitational force is acting on the object but no air resistance is assumed

**Fig. 2.6** A one-dimensional system involving two objects with masses *m*<sup>1</sup> and *m*2, respectively. The objects are connected via springs and dampers

and their second order derivatives. This system of equations provides a model which we can analyze and simulate.

## **2.4 Working in 2D and 3D**

For many physical systems, it is useful to reason about the mechanics in 3D. But occasionally the problem can help us keep things simple, and we can work in 2D or even 1D. When we need to work in 2D or 3D, the key insight required is how to factor a single force or speed into multiple forces that are relevant to the equations for the components. In general, for such a factorization, basic trigonometric identities will be very helpful. Consider the example in Figure 2.7. In this example, the normal

**Fig. 2.7** A box with mass *m* is placed on a slope. A friction force given as a function of the normal force is stopping the box from sliding down. However, when the inclination, given by the angle *α*, is large, the friction force is not large enough to stop the box from sliding

force Fnormal is a determined by the gravitational force *mg* and would have to be computed using the angle *α*. The value of Ffriction, in turn, would be determined by the friction laws. A good source of examples of this type of analysis can be found at physicsclassroom.com.

## **2.5 Elements in Electrical Systems**

Standard elements in electrical systems include:

**Resistor** This is one of the most basic elements of an electric circuit. The current *I* passing through this element has a direct relation to the voltage *V* across the resistor. This relation is known as Ohm's law, and is expressed mathematically as

$$V = IR,\tag{2.7}$$

where *R* is the resistance. The diagram in Figure 2.8 illustrates schematically a situation where this relation should hold.

**Fig. 2.8** The current *I* is passing through a resistor with resistance R

**Capacitor** This is an element where the voltage across is proportional to the integral of the current going through the element. The diagram in Figure 2.9 includes the schematic symbol for this kind of device in a circuit diagram. Alternatively, we can say that the current is proportional to the rate of change of the voltage across it, that is, *V* = *dV* (*t*)*/dt*. Mathematically, this means that

$$I = CV',\tag{2.8}$$

where the ratio *C* is called the capacitance. The higher the capacitance, the greater the current needed to correspond to a small change in voltage.

**Inductor** This is an element where the rate of change in current, that is, *I* = *dI*(*t*)*/dt*, is proportional to the voltage across it. That is

$$V = LI',\tag{2.9}$$

where the ratio *L* is called the inductance. The higher the inductance, the higher the voltage we need to get the same rate of change in current. Figure 2.10 illustrates a circuit involving an inductor.

**Voltage Source** A voltage source simply provides a voltage that is either fixed (a direct current or DC source) or variable, in which case it may be an alternating current (AC) source.

**Current Source** Like a voltage source, a current source provides a current that may be fixed or variable, depending on the type of source.

As can be seen from the remarks above, each of these elements comes with a set of equations that describes its effect on the system that it is used in. To analyze a

**Fig. 2.9** Circuit with a capacitor

**Fig. 2.10** Circuit with an inductor

given circuit, these rules are applied, along with one or more instances of the basic conservations laws for circuits, which are that:

Several examples of this kind of analysis can be found online at this page by Erik Cheevers (see also To Probe Further below).

## **2.6 The Absence or Presence of Time in a Model**

In many important systems, it is possible to remove time out of the modeling process. The study of mechanical systems where time is not involved is called "statics." Electrical systems that can be analyzed without need to consider time include circuits made purely out of resistors and a constant source of voltage or current. Whether or not we need to model time depends on

For example, a mechanical system made of a lever, e.g., a teeter-totter, that is in balance does not need a notion of time to be analyzed. Similarly, an electric circuit made of resistors, capacitors, and inductors, and where all currents and voltages are constant, can also be analyzed without reference to time. However, if the mechanical system is not in balance or the circuit has a voltage changing over time, then time needs to be taken into account.

## **2.7 Arithmetic Equations, and Linear and Non-linear Systems of Equations**

When we consider problems where there is no notion of time, we generally build equations using arithmetic operations including addition, subtraction, multiplication, and division. Equations that use only addition and subtraction (or multiplication/division by a constant) are called "linear equations," and are generally relatively easy to solve by hand when the number of variables involved is small.

**Example 2.1** Consider the following set of equations:

*x* + *y* = 3 *x* − 3*y* = −1 Solve this equation for *x* and *y*.

**Solution 2.1** This is a linear system of equation. A basic strategy for solving such a system of equations is to convert one of the equations into a form where only one of the variables appears on the left-hand side of the equal sign. Then substitute that variable with the expression on the left-hand side in the remaining equation. The first equation can be rewritten as *x* = 3−*y* when we subtract y from both sides. When we substitute the right-hand side into the next equation we get (3−*y*)−3*y* = −1, which simplifies to 3 − 4*y* = −1. By subtracting 3 from both sides we get −4*y* = −4. Dividing both sides by −4 we get *y* = 1. Substituting that into *x* = 3 − *y* we get *x* = 3 − 1=2.

If we have equations where we multiply two different variables, or if we use functions like exponentiation, logarithms, roots, or trigonometric functions for variables or values that depend on variables, then these equations are no longer linear. Sometimes, it is possible to use a method similar to the one above to solve such equations. In general, however, it is not possible. As a result, it is often necessary to resort to iterative approximation methods to solve such equations, which can be more computationally expensive (even when done by a computer).

## **2.8 Where Different Numbers Come from**

It is helpful to note that the kinds of operations that we use in the equations actually give rise to different classes of numbers. For example, the N (natural numbers), Z (integer numbers), Q (rational numbers), A (algebraic numbers), and R (real numbers) are the numbers that can express solutions to different kinds of problems. In the order they were presented, these sets are larger and larger, and incorporate more points. The set <sup>N</sup> <sup>=</sup> {1*,* <sup>2</sup>*,* <sup>3</sup>*,...*} is also referred to as the counting numbers. The set <sup>Z</sup> contains <sup>N</sup> but also all numbers in <sup>N</sup> constructed by multiplied by <sup>−</sup><sup>1</sup> or 0, that is, besides N. The rational numbers are all numbers that can be written as *<sup>a</sup> b* , where *<sup>a</sup>* <sup>∈</sup> <sup>Z</sup> and *<sup>b</sup>* <sup>∈</sup> <sup>N</sup>.

The algebraic numbers in the set A are solutions to equations like

$$x^m = n \tag{2.10}$$

and they require having inverse options like root(*m, x<sup>m</sup>*) = root(*m, n*) implies *x* = root(*m, n*). The value computed by such a function is not in the set of natural numbers N nor in the set of rational numbers Q, but is in a "new" set A.

## **2.9 Time-Dependent and Differential Equations**

Because many components have time-dependent behavior, we will often need ordinary (as opposed to partial) differential equations to describe them. Ordinary Differential Equations (ODEs) can be classified in several ways. One of the most important classifications is the distinction between linear and non-linear equations. In the case of linear ODEs, the equations are linear in the variables and the derivatives thereof. Linear ODEs usually have solutions only involving exponential or complex exponential functions. By complex exponential functions we mean exponential functions where the exponent has a complex number coefficient. According to Euler's identity, exponentials that have purely imaginary coefficients correspond to sine and cosine functions. They are commonly used in connection with electrical circuits and mechanical systems. It is very important to note that sine, cosine, and other functions occur in the *solutions* but not in the equations themselves.

Non-linear ODEs may have solutions that do not have a closed form (analytical) representation. In such cases one usually has to rely on simulation and numerical solutions, which is commonly done for mechanical systems and electronics circuits. One could point out in this context that even though the solution is not expressible in closed form, certain aspects of it could sometimes be deduced analytically. For example one could prove that the solution will converge to a specific point as time progresses (but not exactly how without simulation). This is something that goes beyond the scope of this book.

Other types of differential equations exist apart from ODEs, such as Partial Differential Equations (PDEs) and Integral Differential Equations (IDEs), but those will also not be covered in this book. Our focus here is on ODEs with respect to time and rigid body systems, with no flexible elements.

We will always use *t* as the variable for time, and we differentiate with respect to time. We identify time with the real numbers R. For derivatives with respect to time, we often see the notation *dx/dt* or *dy/dt*. Depending on the situation, we may write the same equation as:

$$dx(t)/dt = 1 \quad \text{or} \quad \frac{dx(t)}{dt} = 1. \tag{2.11}$$

Or more concisely as:

$$dx/dt = 1 \quad \text{or} \quad \frac{dx}{dt} = 1. \tag{2.12}$$

Or even more concisely as:

$$x'=1.\tag{2.13}$$

The notation in the last equation is the same as that in Acumen. Acumen is a small modeling language and it is designed to be this way to let us learn a lot about cyber-physical systems in this book.

## **2.10 Prototypes of Equations (That Will Recur Throughout the Book)**

The Acumen examples from Lab 1 are *prototypes* that represent important classes of subproblems that can be used to solve a bigger problem. We will see examples of these equations throughout the book.

In what follows, we discuss how these prototypes can be solved.

$$\bullet \quad x' = 1,\\
x(0) = x\_0.$$

Solved by taking definite integral from 0 to *t* to both sides: : *t* <sup>0</sup> *x ds* = *t* <sup>0</sup> 1*ds* and this implies *x*(*t*) + *k*<sup>1</sup> = *t* + *k*<sup>2</sup> which in turn implies *x*(*t*) = *t* + *k*<sup>2</sup> − *k*1. Now we can use this equation and our initial assumption that *x*(0) = *x*<sup>0</sup> to deduce that *k*<sup>2</sup> − *k*<sup>1</sup> = *x*(0). Thus *x*(*t*) = *t* + *x*0.

• *x* = 1, *x* (0) = *v*0, *x*(0) = *x*0.

Solved by applying the same procedure as the previous equation twice. In particular this is used in Newton's law *f* = *ma* where *a* is the second derivative of *x*. We assume that *f* is constant and consider the equation:

$$\frac{f}{m} = x'',$$

where *<sup>f</sup> <sup>m</sup>* is chosen to be equal to 1 for simplicity. *t* <sup>0</sup> *xds* = *t* <sup>0</sup> 1*ds* and so *x* = *t* + *v*0. We can now do the same trick to solve it: *t* <sup>0</sup> *x ds* = *t* <sup>0</sup> (*t* + *v*0)*ds*, which gives us *x* = *t* <sup>2</sup>*/*2 + *v*0*t* + *x*0. As an exercise, use this method to solve a variation of this problem where *x* = −9*.*8.

• *x* = *x*.

If we apply the same trick as in the previous examples and integrate both sides: *t* <sup>0</sup> *x ds* = *t* <sup>0</sup> *xds*, that is *x*(*t*)−*x*(0) = *t* <sup>0</sup> *xds* we cannot move forward because we need to know *x* to be able to integrate it. The solution, if *x*(0) = 1, is the exponential function *x*(*t*) = *e<sup>t</sup>* , since its derivative is the function itself. The function *e<sup>t</sup>* describes exponential growth, present in applications such as bank interest growth or bacteria population growth. The function *e*−*<sup>t</sup>* models exponential decay, for example, radioactive isotope decay or capacity charge decay.

• *x* = −*x*.

A solution, when *x*(0) = 0, is sin(*t*) (recall: sin (*t*) = cos(*t*) and cos (*t*) = − sin(*t*)). Note that sin(*t*) is an exponential function with a complex coefficient. An example modeled by this equation is a spring mass. Please see Harmonic oscillator for a description. The equation arises from the description of the force exercised by the spring: Remember that the force created by a spring is −*kx* where *x* is the distance from the equilibrium part. The equation above would arise if there is a mass *m* = 1 and a spring coefficient *k* = 1.

$$\bullet \quad x'' = -\sin(x).$$

sin(*x*) is a non-linear function, so this is an example of a non-linear ODE, where we usually resort to simulation for evaluation of system behavior. This particular equation is used to describe a pendulum pendulum.

Key point from these examples is that *x* = 1 and *x* = 1 have polynomial solutions, whereas *x* = *x* and *x* = −*x* have (real or complex) exponential solutions.

**Example 2.2** Prove that the solution of *x* = *x* is NOT a polynomial of finite order. Proof sketch: Assume that the solution is a polynomial of finite order, and the highest nominal has power *n*. Derive a contradiction.

**Exercise 2.2** Prove that the solution to *x* = sin(*x*)is not an exponential function.

## **2.11 Remarks on the Basic Machinery for Solving Differential Equations**

In many cases we know how to solve a differential equation because we know what function has that derivative. For example, consider the monomial *t <sup>n</sup>*+1. This is a function of *t* that has the following derivative: *d*(*t* (*n*+1))*/dt* = (*n* + 1)*t n*.

**Example 2.3** *d*(*t* <sup>2</sup>)*/dt* = 2*t* and *d*(*t* <sup>14</sup>)*/dt* = 14*t* 13.

The linear property of differentiation states that if *a* and *b* are functions of time, then *d*(*a* + *b*)*/dt* = *d*(*a*)*/dt* + *d*(*b*)*/dt*.

**Example 2.4** The properties described above help us to compute derivatives by hand. For example, we can use it to compute that *d*(*t* <sup>101</sup> + *t* <sup>52</sup>)*/dt* = *dt*101*/dt* + *dt*52*/dt* = 101*t* <sup>100</sup> + 52*t* 51.

**Fundamental Theorem of Calculus** - *B <sup>A</sup> f*(*t*)*dt* = *F*(*B*) − *F*(*A*) where *dF/dt* is *f*, (see Fundamental theorem of calculus).

**Why Is the Fundamental Theorem of Calculus so Important for Us?** There is a common pattern in mathematics that is worth keeping in mind as we look at solving differential equations. This pattern highlights the importance of inverse functions in helping us solve equations. For example, if we are asked to solve for *x* in the equation *x* + *m* = *n*, what do we do? Firstly we isolate *x* by applying the inverse of +*m*, which is −*m*, to both sides of the equation. This means that we convert the first equation to a new one: *x* + *m* − *m* = *n* − *m*. Then, we simplify it to get *x* = *n* − *m*, and this last equation gives us the solution to this problem. A similar thing happens with differential equations. Intuitively, the Fundamental Theorem of Calculus is important because it tells us that there is a way in which integration is essentially an inverse of differentiation. This means that it is often very useful to use integration when solving differential equations.

**Note on the Exponential Function** Not only does it hold that (*e<sup>t</sup>* ) = *e<sup>t</sup>* , but also *d*(*ke<sup>t</sup>* )*/dt* = *kd*(*e<sup>t</sup>* )*/dt* = *ke<sup>t</sup>* .

A generalization of *x* = *x* or *x* = −*x* is *x* = *kx*. This corresponds to the generalization of the exponential function to *ekt*, for which we have *d*(*ekt*)*/dt* = *kekt*.

## **2.12 Chapter Highlights**

	- (a) Basic physical phenomena
		- Physics
		- Chemical process
		- Biological processes
	- (b) Characteristics of models' physical phenomena
		- Quantities are often real-valued
		- Change is often continuous
		- Usually enjoy conservation laws that are the key to modeling them!
		- The equations we get will be:
			- Either linear or non-linear
			- Either without time (statics) or involving time (dynamics)
	- (a) Conservation laws: Force, Energy, Momentum
	- (b) Components: Mass, gravity, surface, friction, spring, pulleys
	- (c) Static Examples:
		- A single mass with gravity
		- A single mass with gravity, friction, and a lateral force
		- A pile of masses
		- A lever (teeter-totter)
	- (d) Laws for different components (like springs and pulleys)
	- (e) Conservation of force generalizes naturally in 1, 2, 3 dimensions
	- (a) Conservation laws: Current, Voltage
	- (b) Components: Resistors, capacitors, and inductances

## **2.13 Study Problems**

#### 34 2 Modeling Physical Systems

**Fig. 2.11** An object with mass *m* is attached to a spring, which, in turn, is attached to the ceiling

Assume that all objects are sufficiently far from each other. In other words, you do not have to worry about impacts.

Assume that there is a gravitational force *g* pulling the mass down, and that the normal length for the spring is *l*0.

$$\text{force} = k(\text{length} - l\_0)^3.$$

Write the equations for *x* and *z* for the system above.

(d) Assume that air resistance has an effect on the masses *m* as a result of its movement. Assume coefficient *r* for the effect of air resistance on this mass. Instead of the usual air resistance law, use the following modified law:

$$\text{force} = r \text{(speed)}^3 \dots$$

Write a modified version of the equations you wrote above to reflect this effect.

3. Consider the following simple system shown in Figure 2.12.

**Fig. 2.12** An object with mass *m* is attached to two springs, which, in turn, is attached to the ceiling

The diagram depicts an 8 kg mass that is hanging from two springs. The mass is subject to the effect of gravity. Assume g = 10 m/s<sup>2</sup>. The mass has no other support than the springs (if they are removed, it falls). The springs are attached to the ceiling. The distance between the box and the ceiling is 1 m. We denote by *k<sup>A</sup>* and *kB*, the spring constants for spring *A* and spring *B*, respectively. The system is *static*, meaning, it is stable and there is no movement. This means that the springs are *stretched*, or extended so that they are each exerting a force.

	- (a) Assume that the ping pong ball is a point mass with position *p* = (*x, y, z*). Assume that the floor has infinite mass, and is horizontal. Assume further a coefficient of restitution of 0*.*8, meaning that the outgoing vertical speed is 0*.*8 of the incoming vertical speed. Write down an expression of *p* after the impact in terms of *p* before the impact.
	- (b) Now assume that the floor can have any orientation, and that the normal unit vector to the floor is *N* = (*nx, ny, nz*) that is orthogonal to the surface of this floor. Note that a unit vector *N* has the property that -*N*- = 1. Write down an expression for *p* after the impact in terms of *p* before impact.
	- (c) Now assume further that the floor has mass 5 kg and the ball has mass 2 kg, and that the floor is not moving before impact. What is the speed *p* after impact?

5. Consider the following mechanism in Figure 2.13.

**Fig. 2.13** A one-dimensional mechanism involving two objects and three springs

Let the normal (unstretched) length for the springs be zero. Let *u*<sup>1</sup> and *u*<sup>2</sup> be input forces on each mass. Let *x*<sup>1</sup> and *x*<sup>2</sup> be the positions of the two masses labeled *m*<sup>1</sup> and *m*<sup>2</sup> as measured from the left wall. Let the right wall be at position *L* from the left wall. Assume the width of each mass is negligible (zero). Let *k*1, *k*2, and *k*<sup>3</sup> be the coefficients for the three springs. Assume that all objects remain sufficiently far from each other and the two walls at all times (do not worry about impacts).

## **2.14 Lab: Spring Bouncing and Object Creation**

The purpose of this lab is to introduce us to some key modeling challenges and concepts that arise when we want to integrate both continuous and discrete dynamics. This is a good preparation for the project work and for the coming chapter.

A simple way to model a bouncing ball is that when it is away from the ground it is in free fall, and when it is touching the ground it experiences a force that we can view as the force of a spring with a high coefficient. We can call this the spring bouncing model. The following idea can be expressed as follows:

```
model Main ( simulator) =
initially
x = 10, x' = 0, x'' = 0
always
if (x > 0)
then x'' = -9.8
else x'' = -9.8 - 100 * x
```
Begin this lab by sketching out the expected plots for the variables x, x', and x''. Then, run this simulation and compare it to the sketch that you had made.

An important Acumen construct used in the ping pong model is object creation. Model definitions allow us to define a type of objects. For example, we can take out parts of a model that relate to a ball from the model Main, which is a special model representing the entire world that we are simulating, to a separate model. This would lead to a model such as the following:

```
model ball (x0) =
initially
x = x0 , x' = 0, x'' = 0
always
if (x > 0)
then x'' = -9.8
else x'' = -9.8 - 100 * x
```
Now, we can easily create a world in which there are two different balls that start at different heights as soon as the world that we are simulating starts. This is done as follows:

```
model Main ( simulator) =
initially
ball1 = create ball (10),
ball2 = create ball(20)
```
For this lab, explore how to modify and test such a definition to: (1) how to model the presence of a damping force during the process of bouncing (this is a force that simply acts against the direction of movement), and (2) how we can introduce the effect of air resistance to a model of a moving ball.

## **2.15 Project: Mascot and Ping Pong Game**

There are two parts to this chapter's project activities: Creating a mascot for your ping pong player and familiarizing yourself with the ping pong model.

**Part 1** Design a mascot for your player using Acumen. You should be able to do this after you have finished going through all the examples in the 01\_Introduction directory of the Acumen distribution, and carrying out the exercises there. The mascot should consist only of a Main class and should include a \_3D statement that creates the 3D form of your mascot. Once you have a good design you can consider animating the mascot or making it act in a short animation (maximum 10 s). Some examples of mascots and animations produced by past students can be found in the following online video.

**Part 2** The Acumen distribution comes with a default ping pong model that can be used for the project. If you are using the book in the context of a course, your instructor may provide a custom made version of that model. The ping pong model is designed to illustrate:

If you are not already familiar with the game of ping pong, browse through the article Table Tennis (ping pong) to familiarize yourself with it.

A good description of the model we will use for the project can be found in Section 6.2 of Xu Fei's Master's Thesis. Characteristics of this model include:

	- (a) Ball\_Sensor processes Ball data going into Player
	- (b) Ball\_Actuator processes signals going from Player to Bat

3. To learn the most from the physical modeling part of this model, it helps to do some derivation yourself starting from a 1D model of a bouncing ball to build up to a 3D. It is instructive to go over that model in detail to learn how vector and vector calculus operations are supported in Acumen.

In the flying case, the aerodynamics part motivates the discussion of unit and norm of vectors, and some identities between them (such as what is the value of unit(p)\*norm(p), for example).

4. Going over the Ball\_Sensor model helps in understanding sampling and how it can be modeled.

The initial model for ping pong that is used for the project can be found in the following directory:

examples/01\_CPS\_Course/99\_Ping\_Pong/Tournament1

in the Acumen distribution. Read and make sure that you understand all the files in this directory. The distribution also comes with default models for different stages of the project (called tournaments in the implementation). If you are using this textbook for a course, your instructor may also provide you with special editions of these models more closely matching the goals of the course you are following. Figure 2.14 depicts the way the ping pong model typically appears in Acumen. Numbers associated with each players are scores, and the bars on the side indicate remaining energy for the player. The white sphere is the ball itself, while the red and cyan dots are values predictions/estimates made by each player about where the ball will be at certain times. By modifying the default models provided you will both develop the design of the robot player and control how different aspects of the design are visualized in simulations.

**Fig. 2.14** A typical view of ping pong model in Acumen

## **2.16 To Probe Further**

**Open Access** This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence and indicate if changes were made.

The images or other third party material in this chapter are included in the chapter's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.

# **Chapter 3 Hybrid Systems**

What if our models are neither continuous nor discrete? In this chapter we cover hybrid automata. Starting from a continuous setting, we introduce discrete events and look at the issues that arise in making such a transition. We analyze the issues of zero crossing and decidability; mode switching and its effect on derivatives; discrete transitions; and Zeno behavior.

## **3.1 Introduction**

We begin by considering a classic example that builds on concepts that we are familiar with from modeling physical systems. Consider a ball that leaves the ground with a certain speed and at a certain angle, and determine where it lands. In all such high school and college physics questions, every story stops as soon as the ball hits its target. But what happens to the ball *after* it hits the ground?

A bouncing ball is a system that can be described by two different modes of behavior: falling; and bouncing or resting on the floor. How can we model a system that includes such different modes of behavior?

When the ball is **falling** we have only the effect of gravity, which has a constant *g* = 9*.*8 N/kg. In that case, the ball is governed by the Newtonian law of *F* = *ma* (force equals mass times acceleration). We should keep in mind that the net or "total" force on any object is the sum of all the forces applied on the object. This summation applies whether we are working in a one, two, or three dimensions. Since we have

$$\mathbf{F}\_{\text{gravity}} = ma,\tag{3.1}$$

then if the only force acting on a mass is gravity, then we also know that

$$gm = ma.\tag{3.2}$$

© The Author(s) 2021

41

W. M. Taha et al., *Cyber-Physical Systems: A Model-Based Approach*, https://doi.org/10.1007/978-3-030-36071-9\_3

By dividing both sides by *m* we obtain *a* = *g*. By substituting 9.8 for the value of *g*, we get (in the dimensionless setting, where "m/s2" is ignored) that *a* = 9*.*8.

The position vector *x* is usually defined as the vector going from the floor level to the position of the ball. In this setting the acceleration goes in the opposite direction. Finally, as a differential equation in relation to the position *x*, the above equation simply means

$$x'' = -9.8.\tag{3.3}$$

Now let us turn to modeling the process of **bouncing**. One solution could be to imagine that, once the ball is in contact with the floor, it experiences another force that we will model as a spring force arising from contact with the ground. The higher the spring coefficient, the faster the bounce. To model this effect, we must return to our original equation and consider the entire situation. The total force on the object must still, as always, be equal to the mass times the acceleration. But the forces acting on the ball are now slightly different:

$$\mathbf{F}\_{\text{gravity}} + \mathbf{F}\_{\text{flocc}} = ma.\tag{3.4}$$

The gravity force and the acceleration are the same as above; but Ffloor will be determined by Hooke's law, generating a force −*kx* where we can take *k* to be a large coefficient. Thus, Equation (3.4) can be expressed as

$$-gm + k(-x) = am.$$

Now, when solving for *a* we get

$$a = (-gm - kx)/m.$$

Now we notice that we need to specify the coefficient *k*. Interestingly, at this point we may also need to specify the mass (why did we not need to worry about the precise mass of the ball before?). However, we can avoid the need to specify both separately, because the equation can be further simplified to

$$a = -gm/m - (k/m)x$$

which is can be written as

$$a = \ -g - (k/m)x.$$

We can simply consider a situation where the ratio between *k* and *m* is high (such as 100); then we have all the information that we need for a model of a ball that can undergo simple elastic bouncing when it hits the floor. With this, we can replace the acceleration *a* with with *x*, and *k/m* with 100, to get the differential equation:

$$x'' = -9.8 - 100x.$$

We can use Hooke's law to model Ffloor, i.e., to model the floor as a spring.

Now all that remains is the question of how to specify the switch between being in flight and being in the bouncing state. This can be described as follows:

$$\text{if } (x>0) \, x'' = -9.8 \text{ else } x'' = -9.8 - 100x.$$

Once we introduce if-statements into our models we are no longer working with simple differential equations. Rather, we have moved into a world where our models are describing different behaviors when the system is under different *modes*. We can think of a mode as the domain of validity of certain conditions (such as *x* ≥ 0 or *x* ≤ 0 in the above example). More generally, we can choose to define the notion of a mode as an explicitly named state (such as "Falling" or "Bouncing"), which we treat as an explicit part of our model.

**Exercise 3.1** Use Acumen to find out the effect of increasing the ratio *k/m*. For example, try out the simulation with different values for the spring coefficient to validate the model. What happens when you use 1000, 10,000, or 15,000 instead 100? What happens when you use 25,000 or 50,000?

## **3.2 Hybrid Automata**

Hybrid systems are systems of mathematical equations that combine both continuous and discrete dynamics. Often, they are formalized as a kind of extension to finite state machines called hybrid automata. For our purposes in this book it suffices to have an intuitive understanding of these notions. To get started, to remind ourselves of finite state machines (or finite automata), let us take the example of a simple traffic light.

**Example 3.1** Mathematically speaking, we may want to model a traffic light as being, at any point in time, in one of the three states. We can think of a state as simply one of the three constants in the set {Red, Green, Yellow}. Further, we may want to model the *behavior* of the traffic light machine by a set of rules that determine the allowable ways in which the state of the traffic light can change from one instance to another. Rules in the case of a finite state machine are simply pairs of states written as "*s*1 ⇒ *s*2." The first state is the one we are in and the second state is the one we can go to next. So, a typical traffic light can be modeled with the following rules:

This is a purely *discrete* model. In a synchronous model of finite state machines, we can require that transitions only happen at previously determined "clock ticks."

The notion of a *trace* of a finite state machine is simply a sequence of allowable state transitions that a finite state machine can undergo. For example, the following sequences are valid traces for the machine we described above: Red ⇒ Green ⇒ Yellow, as well as the trace Green ⇒ Yellow ⇒ Red ⇒ Green. However, the sequence Green ⇒ Yellow ⇒ Green is not a valid trace because we have no rule that allows the transition Yellow ⇒ Green. Similarly, it should also be noted that in this system there are no transitions from one state to itself. So, Red ⇒ Green ⇒ Green is not a valid trace either.

Now let us consider another example.

**Example 3.2** Consider another finite state machine that represents whether an air-conditioning system is either cooling or on standby. In this case, we can have two simple states {Cool, Wait}. As you know, an air-conditioning system cools the room for a while, then switches back to the waiting state, then reverts to cooling, and so on. So, the rules for the possible transitions in such a system are quite simple:

During the cooling process, the system pumps heat out of a room at a constant rate, and the temperature goes down. In addition to the standard finite state machine model of this system, we may also want to build more details into our model. In particular, we might want to specify something about the temperature of the room explicitly; we might also want to specify the rate at which the room is gaining heat from the outside environment, and the rate at which the air-conditioning system is removing this heat when it is in the cooling state. Such information cannot be included in a traditional finite state machine model. However, we can extend the basic model and arrive at what is known as a *hybrid automaton*. This is where we can add information to each state about some continuous variables that can evolve according to certain rules over time (which itself is modeled as a dense time). For this example, all we have to do is the following: introduce a real-valued variable *T* to describe the current temperature of the room, and then add the following two rules about what happens to this variable when the system is in each of the two states.

In each of the two states there is a dynamical equation describing the rate of change of the temperature. Such equations can be much more involved than the ones considered here, and could, for example, be non-linear. However, what is important here is that this model specifies clearly what happens to the temperature in the room (in terms of the rate at which it changes) when it is in each of these two states. In addition, we may want to go back to our rules and specify how the *thermostat* (the controller for the air-conditioning unit) determines when it should change from one state to another. We can do this by creating an extended set of transition rules as follows:

Note that we use different temperatures to switch, to avoid alternating too quickly and potentially damaging our air-conditioning system.

**Exercise 3.2** Use Acumen's strings and case-statements to express the example system above as an Acumen model. Simulate the system with a starting value for Temperature as 23◦.

## **3.3 Reset Maps**

Now we return to our bouncing ball example. In addition to specifying rules for how continuous variables can evolve inside a state, we can also perform a discrete change to a variable as we transition from one state to another. This allows us to perform instantaneous changes in direction without having to use, for example, a spring with a high stiffness coefficient. However it requires a further refinement to our notion of hybrid automata, namely, the introduction of *reset maps*. This extension simply allows us to specify that, as a transition occurs, we want to reset certain variables in our system to new values that are better suited to model the state of our system. Now we can model our bouncing ball example as follows:

Note that in this system we only have a single state, "Flying." The second bullet specifies the dynamics while in this state, namely, falling with a constant, negative acceleration. For this system, one state is actually enough because the work needed to model bouncing can be done in the transition from this state to itself, and in particular, in the reset map applied in the transition from this state to itself. The reset map is what is described by the part that says *x* ⇐ −0*.*9*x* , and it means that we want the *x* value (which is the speed of the bouncing ball) to be reset to a new value after the transition. That value will be the result of multiplying the value of *x* before the transition by 0.9. Furthermore, we will switch the sign of the speed, thus changing its direction, so that the ball that was falling down before the transition will be going upwards after the transition. Note that, as a result of the sudden change to the speed that occurs at that transition point, the acceleration will not be a well-defined notion at that instance.<sup>1</sup>

**Exercise 3.3** Write out such a model in Acumen, and simulate the system starting from a height of 10 and an initial speed of 0. How well does your model work? Make a note of any unexpected behavior that your simulation might exhibit.

A finite state machine or an automata is *deterministic* if its behavior is always uniquely defined when it is in any given state. If this is not the case, then the system is said to be *non-deterministic*. Most simulation tools only simulate deterministic systems.

<sup>1</sup> In situations like this it may be possible to use more advanced mathematical notions such as impulse functions (or Dirac delta function), but this discussion is outside the scope of this book.

## **3.4 Zero-Crossing**

Using precise tests (such as *x* = 0) for transitioning from one state to another is generally quite challenging for simulation tools built on traditional numerical methods. This is because real numbers are generally represented in computers as floating points, and functions that change over time are represented as a sequence of floating point values defined at specific points in time, represented also by floating point values. For our purposes in this book, and to keep things simple, we will try to always express our models with more robust conditions such as *x* ≤ 0 even though we really do not intend to model the possibility of *x* being less than 0.

## **3.5 Zeno Behavior**

Zeno's paradox is a phenomenon that can happen in a hybrid system (a system that exhibits both continuous and discrete dynamic behavior). The hybrid automaton model of the bouncing ball exhibits this phenomenon. In particular, the consecutive bounces form a geometric series that can be shown to end in a finite time (which we call the Zeno point), even if the number of bounces that takes place beyond that point is unbounded.

To understand what is going on here for yourself, consider the situation where the ball is at height zero but is moving up. Calculate the time (based on the initial upward speed) until it hits the ground again. What is that ratio between the speed and the time it takes to hit the ground? Now note that there is a well-defined ratio between the upward speed at the start of this problem, and the upward speed of the ball after the bounce. Convince yourself that this ratio also determines a ratio between the current jump and the next jump. Convince yourself further that this ratio will be the same between any two consecutive jumps. Write out the formula for the time at which the ball will stop jumping, giving some initial parameters.

## **3.6 Modeling Elastic Collision**

*Note: While this topic is discussed here only briefly, it is an important example of discontinuity in physical models (and therefore an example of why we need hybrid systems to model physical systems). Also, it is important for understanding the ping pong model.*

Collisions in basic mechanics are a simple class of problems involving time. Their characteristic is that there is a discontinuity in one of the derivatives. Consider the situation in Figure 3.1, where we have two co-linear masses that experience a collision where energy and momentum are conserved. How do we determine the speeds after the collision?

 Conservation of momentum means that

$$m\_1u\_1 + m\_2u\_2 = m\_1v\_1 + m\_2v\_2,\tag{3.5}$$

whereas conservation of energy means that

$$\frac{m\_1 u\_1^2}{2} + \frac{m\_2 u\_2^2}{2} = \frac{m\_1 v\_1^2}{2} + \frac{m\_2 v\_2^2}{2}.\tag{3.6}$$

By using (3.5) and (3.6) together we can solve for *v*<sup>1</sup> and *v*<sup>2</sup> in terms of *u*<sup>1</sup> and *u*2. The solution is

$$\begin{aligned} v\_1 &= \frac{(m\_1 - m\_2)u\_1 + 2m\_2u\_2}{m\_1 + m\_2}, \\ v\_2 &= \frac{(m\_2 - m\_1)u\_2 + 2m\_1u\_1}{m\_1 + m\_2}. \end{aligned}$$

This tells us the speeds for both objects after the collision. When kinetic energy is conserved, we says that the collision is *elastic*, and *inelastic* when it is not conserved. The speed of each particle after an inelastic collision can be determined in the same way as above, but with the energy equation modified appropriately. Often, energy loss is specified in terms of a *coefficient of restitution*, which is the ratio between relative speeds before and after the collision.

The *relative speed* between two objects is the speed of the first measured from the second and vice versa. If two cars travel in the same direction at 100 and 120 km/h, respectively, the relative speed will be 20 km/h; if the two cars travel at the same speeds but at opposite directions, the relative speed will be 220 km/h.

## **3.7 Chapter Highlights**

	- (a) Mix continuous and discrete systems
		- Area of much of the research in formal analysis and verification of CPS today
	- (b) Provide a natural model of cyber-physical system
	- (c) Are also a more natural model of purely physical systems
		- Impacts and discontinuities are naturally modeled as discrete events
	- (d) Cyber systems have not only discrete but also continuous aspects
		- Time, energy, time-to-failure, radiation, relativistic effects
	- (a) Traffic light
	- (b) States: Red, Green, and Yellow
	- (c) Transitions
		- Untimed
		- Adding a timer and a reset map
	- (a) States: Heating, Cooling
	- (b) Equations: Heat equations
	- (c) Guards: Leave a gap in between
	- (a) States: Falling, and Bouncing?
	- (b) Equation: Falling
	- (c) Guards: Hitting Zero (with refinement)
	- (d) Zeno-behavior?
	- (a) Equation for flight
	- (b) Time in flight
	- (c) Flight in terms of max height
	- (d) Time in terms of coefficient
	- (e) The limit of a series

## **3.8 Avoid Common Mistakes**

These are remarks intended to help you avoid some common points of confusion:

## **3.9 Study Problems**

	- (a) Represent each move by an output of the name of the color ("Red," "Orange," "Blue," or "Green"). Draw a state machine that shows the number of states needed for a traffic light that outputs a signal that carries **red**, then **orange**, then **red**, and then goes to **blue,** then **red**, and repeats this process.
	- (b) Assume that the light stays in the **red** and **green** states for 60 s, and in all the other states only for 10 s. Write an Acumen object class My\_Light that models this functionality. The only required field in this object is a signal my\_choice which can be "R," "O," "B," or "G" depending on the first letter of the color. Make sure that the object is self-contained and do not assume any inputs from the outside.
	- (a) Represent each move by an output of the first letter ("P," "R," or "S"). Draw a state machine that shows the number of states needed for a simple player that repeatedly outputs a signal that carries **paper**, then **rock**, then **paper**, then **scissors**, and then repeats this sequence.
	- (b) Assume that the machine must output each move for 0.75 s. Write an Acumen object class My\_PRS that models this functionality. The only required field in this object is a signal my\_choice which can be "P," "R," or "S." Make sure the object is self-contained, and do not assume any inputs from the outside.

**Fig. 3.2** Two cars about to collide

**Fig. 3.3** Two cars, before and after collision (Source: scienceblogs.com)

	- (a) Calculate the coefficient of restitution *c* in this collision.
	- (b) Write down the conservation of momentum equation relating "before" and "after" speeds.
	- (c) What speed must *v*<sup>1</sup> be in order to have *v* equal to 1000?
	- (d) Assume that *m* = 1000. What is the energy lost in the collision of part c?

**Fig. 3.4** Two spheres, before and after an inelastic collision (Source: scienceblogs.com)

**Fig. 3.5** A finite state machine with two states, and initiated at state 1

## **3.10 Lab: Discrete Bouncing**

The purpose of this lab is to introduce you to hybrid-systems modeling constructs and to connect the ideas discussed in this chapter to project activities.

Taking as a starting point the models you developed for the previous lab, compare and relate those models to the following model sketch:

```
model ball (x0) =
initially
x = x0 , x' = 0, x'' = 0
always
if (x > 0)
then x'' = -9.8
 // - 0.1 * x' * abs(x') // Drag
else if (x' < 0)
then x'' = -9.8 - 100 * x + 10
 // Another state split to enable damping
 // during bounce
else x'' = -9.8 - 100 * x - 10
model Main ( simulator) =
initially
ball1 = create ball (10),
ball2 = create ball(20)
```
Next, note that bouncing in the original model worked by pretending there is a spring that gets activated when the ball is below ground level. Consider the possibility of creating a model where the bounce occurs instantaneously. Build and test a model that works in this way.

Once you are done with this exercise, compare your model to the following one.

```
model BB()= // Basic bouncing ball
initially
x = 5, x' = 0, x'' = 0
always
if (x <= 0) && (x' < 0)
then x'+ = - 0.5 * x'
else x'' = -9.8
```

```
model Main( simulator)=
initially
b = create BB()
```
The model above has a curious feature. After the ball "reaches zero height," it starts to slip down below level zero. That is because we are actually allowing gravity to be in effect in the case that x< = 0 and x' > 0. This creates a cycle of small computational steps where the ball starts below the ground with a positive speed but is subjected to gravity, at the end of the cycle it has a small negative speed and has lost height, and impact condition is detected and the speed is set to positive half again, and the process repeats, but the ball is still losing height.

A better model is the following one, where we ensure that when the ball is below the ground but is on the rise it maintains this speed and is not subject to any additional forces:

```
model BB()= // Basic bouncing ball
initially
x = 5, x' = 0, x'' = 0
always
if (x > 0) then x'' = -9.8
else if x'<0
then x'+ = -0.5 * x'
else x'' = 0
model Main( simulator)=
initially
b = create BB ()
```
Compare your model to this one as well, and make note of the points that you found required extra care to be able to model instantaneous bouncing when you tried to build it yourself. While arriving at a simple and clear model of an instantaneously bouncing ball is challenging, it is representative of the frequently occurring situations where a dynamic within a continuous domain reaches a well-defined boundary that it is being pushed against, and where the dynamic of the boundary is to push back the object into the domain.

## **3.11 Project: Speed-Based Player for Ping Pong Robot**

This chapter's project activity is to develop a ping pong player that can outperform the other player, and at the very least, the default player. In this activity, your model controls the player by sending a speed signal to move the bat. Be careful, because the larger the speed you use, the faster you will run out of energy! Basically, the default player works by computing a bat speed and predicting two key points on the future trajectory of the ball. The first point (p1) is where the ball will hit the table. This is calculated by using the velocity of the ball. The second point (p2) is the highest point in the air that the ball will reach after it bounces on the table. This is calculated from the predicted speed after bouncing. Then, the bat moves to hit the ball at the highest point (pH) of the ball after it has bounced. It is important to note that the bat loses energy (maxE) whenever it moves and hits the ball, and that each player starts with a fixed energy level. Your modified player must consume less energy than the default player and also predict the second point better than the default player. You will need to develop your own strategy to make the bat move less or improve the velocity of the bat.

If you are using this textbook as part of a course, be sure to check with your instructor about whether there is a special edition of the model you are expected to use.

An important skill that good scientists and engineers need in order to complete projects faster and better is debugging. In essence, you need this skill to determine how to go from a system that is not quite doing what you want to one that is. The key to successful debugging is to work systematically to isolate and localize problems. Scientists and engineers that solve real problems seem to apply this skill extensively. Check out this article on this topic.

Designing any interesting system also involves accumulation of a lot of knowledge. Our memory is only one way of collecting knowledge, and it often does not work as well as we think it does. Documenting the result of each of your project activities is a good way to organize the knowledge that you accumulate. Therefore, think of them not only as something you write for the instructor, but also for yourself, and review them constantly during the process. Another very powerful way of accumulating knowledge is test cases. Build your own test cases and use them to automatically test your player as you are developing it. You can develop test cases by making alternative players that play with different strategies.

In future project activities, make sure that your player avoids each of the pitfalls that you discovered during this activity. We recommend that you share the players that you have developed among yourselves, as this will help you improve player development for the next activity, and increase your chances of winning at the finals.

## **3.12 To Probe Further**

**Open Access** This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence and indicate if changes were made.