Object-Oriented Programming In Mechatronic Systems
Summer School 2018
Module 1 – Introduction to Programming Aachen, Germany Cybernetics Lab IMA & IfU Faculty of Mechanical Engineering RWTH Aachen University
Object-Oriented Programming In Mechatronic Systems Summer School - - PowerPoint PPT Presentation
Object-Oriented Programming In Mechatronic Systems Summer School 2018 Module 1 Introduction to Programming Aachen, Germany Cybernetics Lab IMA & IfU Faculty of Mechanical Engineering RWTH Aachen University Organization 2
Object-Oriented Programming In Mechatronic Systems
Summer School 2018
Module 1 – Introduction to Programming Aachen, Germany Cybernetics Lab IMA & IfU Faculty of Mechanical Engineering RWTH Aachen University
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 2
Organization
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 3
Organization Topics Synopsis
Today’s mechanical engineering relies heavily on advanced software tools. Both industry and research expect you not only to use these tools but to design, develop and deploy them as well. During this course we teach you how.
Theory Practical Exercises
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 4
Alexander Paulus M.Sc. Researcher Cognitive Computing Dr.-Ing. Max Hoffmann Group Leader Industrial Big Data Dipl.-Inform. Daniel Lütticke Group Leader Production Technology Andreas Kirmse M.Sc. Researcher Industrial Big Data
Tobias Meisen Management Director
Organization
… at the Institute of Information Management in Mechanical Engineer (IMA)
Information Management for Mechanical Engineering
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 5
The Cybernetics Lab
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 6
Presentation – Cybernetics Lab IMA & IfU
Who are we?
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 7
Interdisciplinary at the Cybernetics Lab IMA & IfU
Univ.-Prof. Dr.-Ing. Christian Hopmann (IKV)
Acting Head of Institute
IT & Media Technology
Frank Hees
Vice Deputy Head of Institute
apl.-Prof. Dr. habil. Ingrid Isenhardt
Deputy Head of Institute
Associated Institute for Management Cybernetics
IfU
IMA
Jun.-Prof. Dr.-Ing. Tobias Meisen Managing Director
René Vossen Managing Director
Alexia Fenollar Solvay Mobility and Logistics Dipl.-Inform. Daniel Lütticke Production Technology Dipl.-Inform. Christian Kohlschein Cognitive Computing & eHealth
Stefan Schröder Innovation- & Work Science
Administration Public Relations
Kathrin Schönefeld Knowledge Engineering
Valerie Stehling Digital Learning Environments
Daniela Janßen Economic and Social Cybernetics
Pia Bresenitz Technical Cybernetics Dr.-Ing. Max Hoffmann M.B.A. Industrial Big Data
Max Haberstroh Managing Director Knowledge Management Information Management apl.-Prof.
nat. Sabina Jeschke
Klaus Henning Senior Advisor
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 8
What drives us
Research Domains
Robotics and Automation Artificial Intelligence Human- Machine Interaction Internet of Things Agile Development Knowledge Management Research Domains
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 9
Motivation
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 10
Motivation From Computer Aided Design (CAD) to Robotics …
Mechatronic Systems rely on Advanced Software Tools!
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 11
Motivation … to learning robots! (at our institute)
Mechatronic Systems rely on Advanced Software Tools!
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 12
Motivation … to self-optimizing production systems!
Mechatronic Systems rely on Advanced Software Tools!
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 13
Algorithms and Programming Languages
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 14
Algorithms and Programming Languages We need an interface between human and computer Both have different requirements:
Human:
knowledge
Computer
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 15
Algorithms and Programming Languages An algorithm is an unambiguous rule of action for solving a problem or a class of problems. Colloquially:
specific problems
but also everyday questions:
How do we formulate a problem for the computer?
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 16
Algorithms and Programming Languages Example of an algorithm: 1. Put a filter in the filter container 2. Fill the filter with coffee powder 3. Pour water into the tank provided for this purpose 4. Check whether empty coffee pot is ready 5. If yes: Go to step 7 6. If not: empty the coffee pot and place it under the filter 7. Press the start button 8. Wait until the coffee is ready (typically: machine "gurgles", steam rises)
Branch Termination Condition
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 17
Algorithms and Programming Languages Properties of algorithms: Finiteness:
Executability:
Uniqueness:
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 18
Algorithms and Programming Languages Interface between Human and Computer Still, both have different requirements:
Human:
Computer
Programming Language
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 19
Algorithms and Programming Languages
Learning programming languages comparable to "natural" foreign languages Syntax:
Semantics:
Syntactically correct, semantic nonsense: “A banana speculates purple the sunset.” Syntactically incorrect, semantically correct: “A banana is fruit yellow.” Syntactically correct, semantically correct: “A banana is a yellow fruit.”
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 20
Algorithms and Programming Languages
2. public static void main(String[] args){ 3. System.out.println("Hello World!"); 4. }
1.Program Hello 2.Print *, "Hello World!" 3.End Program Hello 1.class HelloWorld(object): 2. def __init__(self, args): 3. print(„Hello World!“)
Java Fortran Python Different syntax, identical semantics!
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 21
The Java Programming Language
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 22
The Java Programming Language Brief History
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 23
The Java Programming Language It’s widely spread!
TIOBE 2015 (Popularity Index) Industry use (to name a few)
Java C C++
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 24
Structure of a Java Program
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 25
Structure of a Java Program Structure of a Java Source File
public class Foo { } Class Definition public class Foo { void bar() { } } Methods public class Foo { void bar() { statement1; statement2; statement3; } } Statements
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 26
Structure of a Java Program Structure of a Java Source File public class HelloWorld { public static void main (String[] args) { System.out.println("Hello, World!"); } }
Class Definition Method Statement
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 27
Structure of a Java Program Structure of a Java Source File. A closer look at the class. public class HelloWorld { }
public access Opening Curly Brace Keyword class The name
Closing Curly Brace
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 28
Structure of a Java Program Structure of a Java Source File. A closer look at the method. public static void main (String[] args) { }
public access keyword static the name of the method return type arguments of the method Opening Curly Brace Closing Curly Brace
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 29
Structure of a Java Program Structure of a Java Source File. A closer look at the statement. System.out.println("Hello, World!");
print to standard
What to print in apostophes Statement must end in a semicolon!
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 30
Structure of a Java Program What are comments?
Examples
public class HelloWorld { // It‘s my first class! public static void main (String[] args) { /* I want to print on the command line */ System.out.println("Hello, World!"); } }
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 31
Variables
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 32
Variables What are variables?
Examples
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 33
Variables Two ways of “constructing” variables
Examples
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 34
Variables Four Primitive Data Types in Java
Data Type Example Keyword Logical value true, false boolean Single character a, b, … char Whole number 1, -3, 87, … byte, short, int, long Real number
float, double For details (e.g. max or min values) see: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 35
Variables Rules I
double temperature;
Rules II and Good Practice
https://en.wikipedia.org/wiki/List_of_Java_keywords
type name
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 36
Variables Three kinds of variables in Java
public class Cylinder { public double cylinderCap = 0; public static char vendor = 'A'; public double computeCylinderCapacity(int r, int h) { double rSquare = r*r; return rSquare * Math.PI * h; } } instance variables class/static variables local variables
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 37
Variables Defining Constants Variables
Examples (the bad and the good)
double circumf = 2 * 3.1415 * r; double area = r * r * 3.1415; final double PI = 3.1415; double circumf = 2 * PI * r; double area = r * r * PI;
yourself)
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 38
Variables Operators and Variables
Allocation and Arithmetic Operator Examples
int y = 7; int sum = x + y; int diff = 40 – y; double div = 30 / 4.3;
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 39
Variables Operators and Variables
Comparison, Unary and Logical Operator Examples
int one = 1; int two = 2; isSmaller = one < two;
int j = i++;
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 40
Variables Operators Priorities
int b = 7; int c = 2 a = a – b - c % (a * c++); // (a is –4)
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html Priority Operator 1 Unary, e.g. ++ 4 Additive, e.g. + 12 Logical OR e.g. || 14 Allocation, e.g. =
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 41
Variables Type Casts
“Upgrading”.
Target type has to be defined in “(“ and “)” brackets
Examples
double radius = i; // radius contains 70.0
int num = (int)d; // num contains 70
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 42
Variables Implicit type cast only one way
int variable double variable
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 43
Variables Type cast overview
byte short int long float double char
implicit type cast explicit type cast String boolean
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 44
Variables Output
Examples
System.out.print ("!"); // Output: Hello, World!
Object-Oriented Programming In Mechatronic Systems | Summer School 2018 | Aachen, Germany | Cybernetics Lab IMA & IfU 45
Practical Demonstration using Eclipse Getting started with Java
Listen up and exactly follow our instructions!!!
1. Open Eclipse 2. Create a new project 3. Create a new class 4. Implement a Main method 5. Implement a Variable inside the Main method 6. Implement a Variable outside the Main method 7. Print to console 8. Use the debugger
Thank you very much!