OpenLLM-France/wikimedia huggingface dataset:
# Non-Programmer's Tutorial for Python 3/Recursion
## Recursion

In Python, a recursive function is a function which calls itself.

### Introduction to recursion

So far, in Python, we have seen functions which call other functions. However, it is possible for a function to call itself. Let's look at a simple example.
If you were to run this program in IDLE, it would run forever. The only way to stop the loop would be to interrupt the execution by pressing Ctrl + C on your keyboard. This is an example of an infinite recursion. (Some users have reported a glitch in the current IDLE system causing the exception raised by Ctrl + C to start looping as well. If this happens, press Ctrl + F6, and the IDLE shell should restart.)
It is arguable that recursion is just another way to accomplish the same thing as a while loop. In some cases, this is absolutely correct. Though, there are other uses for Recursion that are very valid, where while loops or for loops may not be optimal.
Recursion can be controlled, just like loops. Lets look at an example of a controlled loop.
The above uses arguments/parameters to control the number of recursions. Simply use what you already know about functions and follow the flow of the program. It is simple to figure out. If you are having trouble, please refer back to Non-Programmer's Tutorial for Python 3/Advanced Functions Example.

## Practical Applications of Recursion

Often, recursion is studied at an advanced computer science level. Recursion is usually used to solve complex problems that can be broken down into smaller, identical problems. Recursion isn't required to solve a problem. Problems that can be solved with recursion, most likely can be solved with loops. Also, a loop may be more efficient than a recursive function. Recursive functions require more memory, and resources than loops, making them less efficient in a lot of cases. This usage requirement is sometimes referred to as overhead. You might be thinking, "Well why bother with recursion. I'll just use a loop. I already know how to loop and this is a lot more work." This thought is understandable, but not entirely ideal. When solving complex problems, a recursive function is sometimes easier, faster, and simpler to build and code.
Think of these two "rules":
* If I can solve the problem now, without recursion, the function simply returns a value.
* If I cannot solve the problem now without recursion, the function reduces the problem to something smaller and similar, and calls itself to solve the problem.
Let's apply this using a common mathematical concept, factorials. If you are unfamiliar with factorials in mathematics, please refer to the following reading. Factorials
The factorial of a number n, is denoted as n!.
Here are some basic rules of factorials.
If n = 0 then n! = 1 If n > 0 then n! = 1 x 2 x 3 x ... x n
For example, let's look at the factorial of the number 9.
9! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9
Let's look at a program which calculates the factorial of any number entered by the user, by method of recursion.
# Non-Programmer's Tutorial for Python 3/The End

So here we are at the end, or maybe the beginning. This tutorial is on Wikibooks, so feel free to make improvements to it. If you want to learn more about Python, The Python Tutorial by Guido van Rossum has more topics that you can learn about. If you have been following this tutorial, you should be able to understand a fair amount of it. The Python Programming wikibook can be worth looking at, too.
Hopefully this book covers everything you have needed to get started programming. Thanks to everyone who has sent me emails about it. I enjoyed reading them, even when I have not always been the best replier.
Happy programming, may it change your life and the world.

### External Resources

Here are few other books which cover Python 3:
* A Byte of Python by Swaroop C H
* DataCamp Interactive Python 3 Tutorial - Online
* Hands-on Python Tutorial by Dr. Andrew N. Harrington
* Introduction to Object Oriented Programming in Python by Dr. Francesco Lelli
* Subject:Python programming language lists other Wikibooks related to Python.
# Programming Fundamentals/Loop Examples
## References

* Wikiversity: Computer Programming
# Programming Fundamentals/Introduction Examples Java
## Overview

Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers “write once, run anywhere” (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java was originally developed by James Gosling at Sun Microsystems and released in 1995.
Java is one of the most popular current programming languages and is often used in computer science courses.

## Example
### Discussion

Each code element represents:Programming Fundamentals/Hello World
* // begins a comment
* class Main begins the Hello World program
* { begins a block of code
* public static void main(String args) begins the main function
* System.out.println calls the standard output print line function
* "Hello world!" is the literal string to be displayed
* ; ends each line of Java code
* } ends a block of code

## Java IDEs

There are many free cloud-based and local IDEs available to begin coding in Java. Check with your instructor or do your own research for recommendations.

### Cloud-Based IDEs

* CodeChef
* GDB Online
* Ideone
* paiza.IO
* PythonTutor
* repl.it
* TutorialsPoint

### Local IDEs

* Wikipedia: BlueJ
* Wikipedia: jEdit
* Wikipedia: jGRASP

## References

* Wikiversity: Computer Programming
* ↑ Wikipedia: Java (programming language)
* ↑ TIOBE: Index
# Programming Fundamentals/Iteration Control Structures
## Overview

In iteration control structures, a statement or block is executed until the program reaches a certain state, or operations have been applied to every element of a collection. This is usually expressed with keywords such as while, repeat, for, or do..until.

## Discussion

The basic attribute of an iteration control structure is to be able to repeat some lines of code. The visual display of iteration creates a circular loop pattern when flowcharted, thus the word “loop” is associated with iteration control structures. Iteration can be accomplished with "test before" loops, "test after" loops, and counting loops. A question using Boolean concepts usually controls how often the loop will execute.

### Pseudocode: Iteration (Repetition) Control Structures

While Loop
Do-While Loop
Repeat-Until Loop
For Loop

## References

* cnx.org: Programming Fundamentals – A Modular Structured Approach using C++
* ↑ Wikipedia: Structured programming
# Programming Fundamentals/Introduction Examples JavaScript
## Overview

JavaScript, often abbreviated as JS, is a high-level, interpreted programming language. Alongside HTML and CSS, JavaScript is one of the three core technologies of the World Wide Web. JavaScript enables interactive web pages and therefore is an essential part of web applications. The vast majority of websites use it, and all major web browsers have a dedicated JavaScript engine to execute it.
JavaScript is one of the most popular current programming languages, and is the primary programming language for front-end web development. JavaScript files have a .js file extension. JavaScript has been implemented in multiple platforms with different I/O commands. Several examples follow.

## Example
### Discussion

Each code element represents:
* // begins a comment
* console.log writes to the JavaScript console output log
* "Hello world!" is the literal string to be displayed

### Discussion

Each code element represents:
* // begins a comment
* alert calls the window alert function to display a message
* "Hello world!" is the literal string to be displayed

### Discussion

Each code element represents:
* // begins a comment
* document.write writes output to the current document
* "Hello world!" is the literal string to be displayed

## JavaScript IDEs

There are many free cloud-based and local IDEs available to begin coding in JavaScript. Check with your instructor or do your own research for recommendations.

### Cloud-Based IDEs

* Chapman.edu: Online JavaScript Interpreter
* CodeChef
* GDB Online
* Ideone
* paiza.IO
* PythonTutor
* repl.it

### Local IDEs

* Wikipedia: Brackets (text editor)
* Wikipedia: Visual Studio Code

## References

* Wikiversity: Computer Programming
* ↑ Wikipedia: JavaScript
* ↑ TIOBE: Index
# Programming Fundamentals/Introduction Examples Python
## Overview

Python is an interpreted high-level programming language for general-purpose programming. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales.
Python is one of the most popular current programming languages, is frequently recommended as a first programming language, and often used in information systems and data science courses.

## Example
### Discussion

Each code element represents:Programming Fundamentals/Hello World
* # begins a comment
* print calls the print function
* "Hello world!" is the literal string to be displayed

## Python IDEs

There are many free cloud-based and local IDEs available to begin coding in Python. Check with your instructor or do your own research for recommendations.

### Cloud-Based IDEs

* CodeChef
* GDB Online
* Ideone
* paiza.IO
* Python Fiddle
* PythonTutor
* repl.it
* TutorialsPoint

### Local IDEs

* Wikipedia: IDLE
* Wikipedia: Thonny

## References

* Wikiversity: Computer Programming
* ↑ Wikipedia: Python (programming language)
* ↑ TIOBE: Index
# Programming Fundamentals/Introduction Examples Swift
## Overview

Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, macOS, watchOS, tvOS, and Linux. Apple intended Swift to support many core concepts associated with Objective-C, but in a “safer” way, making it easier to catch software bugs. Swift was introduced in 2014.
Swift is a popular programming language for the Apple platforms it supports, but it lacks support for Microsoft Windows environments.TIOBE: Index.

## Example
### Discussion

Each code element represents:Programming Fundamentals/Hello World
* // begins a comment
* print calls the print function
* "Hello world!" is the literal string to be displayed

## Swift IDEs

There are several free cloud-based and local IDEs available to begin coding in Swift. Check with your instructor or do your own research for recommendations.

### Cloud-Based IDEs

* GDB Online
* IBM Swift Sandbox
* Ideone
* iSwift
* paiza.IO
* repl.it

### Local IDEs

* Wikipedia: AppCode
* Wikipedia: Atom (text editor)
* Wikipedia: Xcode

## References

* Wikiversity: Computer Programming
* ↑ Wikipedia: Swift (programming language)
# Programming Fundamentals/Introduction to Programming
## Overview

This chapter introduces programming, the software development process, tools and methods used to develop and test programs. These include integrated development environments (IDEs), version control, input and output, and a Hello World program in pseudocode and flowchart format. The programming languages C++, C#, Java, JavaScript, Python, and Swift are introduced with example code.

## Chapter Outline

* Why Learn Programming?
* Systems Development Life Cycle
* Program Design
* Program Quality
* Pseudocode
* Flowcharts
* Software Testing
* Integrated Development Environment
* Version Control
* Input and Output
* Hello World
* Code Examples
** C++
** C#
** Java
** JavaScript
** Python
** Swift
* Practice: Introduction to Programming

## Learning Objectives

* Understand key terms and definitions.
* Create pseudocode for a programming problem.
* Create a flowchart for a programming problem.
* Perform software testing for a programming problem.
* List the four categories and give examples of errors that may be encountered when using an Integrated Development Environment (IDE).
* Test an Integrated Development Environment using a Hello World program.
* Modify an existing program to meet given requirements.
# Programming Fundamentals/Loading an Array from a Text File
## Overview

Loading an array from a text file requires several steps, including: opening the file, reading the records, parsing (splitting) the records into fields, adding the fields to an array, and closing the file. The file may be read all at once and then parsed or processed line by line. The array must be as large as the number of records in the file or must be generated dynamically.

## Discussion

Loading an array from a file presents an interesting dilemma. The problem revolves around how many elements you should plan for in the array. Let’s say 100, but what if the file has fewer or more than 100 values. How can the program handle it correctly?
Either:
* Read the file and count the number of records.
* Create a static array of that size.
* Read the file again and add each record to the array.
Or:
* Read the file and dynamically add the records to the array.

### Processing Records

There are two options for file processing:
* Read the entire file into memory, split the records and then process each record.
* Read the file line by line and process one record at a time.
Which of these approaches is better will depend on the size of the file and the types of file and string processing supported by your programming language. Reading the entire file at once may be faster for small files. Very large files must be processed line by line.

### Processing Fields

Processing fields require splitting records based on the given file format. For example, a comma-separated-values file might be formatted as:
The first line contains field names separated by commas. The following lines contain a value for each of the fields and are separated by commas. Note that all text file input is strings. Each line must be split on the field separator (comma) and then numeric fields must be converted to an integer or floating-point values for processing.

## Key Terms
### dynamic memory

    Stack created memory associated with local scope.

### parsing

    Splitting

### static memory

    Data area memory associated with global scope.

## References

* cnx.org: Programming Fundamentals – A Modular Structured Approach using C++
# Programming Fundamentals/Loop Examples C++
## References

* Wikiversity: Computer Programming
# Robotics/Components/Actuation Devices/Miniature internal combustion engines

These are the small internal combustion engines used in model cars and planes.
# Robotics/Components/Actuation Devices

Actuation devices are the components of the robot that make it move (excluding your feet). Best known actuators are electric motors, servos and stepper motors and also pneumatic or hydraulic cylinders. Today there are new alternatives, some which wouldn't be out of place in a good SF-movie. One of the new types of actuators are Shape Memory Alloys (SMA). These are metal alloys that shrink or enlarge depending on how warm they are. Another new technique is the use of air-muscles.
* Motors
* Shape Memory Alloys
* Air muscle
* Linear Electromagnetic
* Piezoelectric Actuators
* Pneumatics/Hydraulics
* Miniature internal combustion engines
# Robotics/Components/Actuation Devices/Motors

There are several different types of motors. Each motor type has several advantages as well as disadvantages depending on a particular robots design. See this Wikipedia article for basic information about the different electro motors.

### AC-motors

There are several different types of AC-motors, but their use is limited to high power stationary industrial robots. They are harder to use than DC-motors.

### DC-motors

DC-motors are very easy to use, but like most other motors their usefulness for robotics is very dependent on the gearing available. DC-motors are made much more effective if they have an efficient gear ratio for a particular task. If your priority is to have a fast spinning motor and torque is of little concern a low gearing or even no gearing may be what you need; however, most motors used in robots need torque over top speed so a motor with a high gear ratio could be more useful.
The control of a DC motor can be split into two parts: speed and direction.

#### Direction

Changing direction in which a DC-motor turns is very easy: simply reverse the polarity.
Both pairs of switches ( (S1A,S1B) and (S2A, S2B) )-see the picture on the right- will always switch together. This circuit is called an H-bridge. In a real design the switches can be several different components (Relays, transistors, FETs) or the whole circuit (without the motor) could be an IC (integrated circuit). use sugarcan relays

#### Speed

Speed is a little bit more complicated. Many beginners would try to slow down a motor by reducing its voltage with a variable resistor or other ways. This does not work well, because it will not only reduce the motor's speed, it will also reduce a motor's strength, while also consuming a lot of electricity as large amounts of heat are generated by the resistor.
A far better way is to use a PWM (Pulse-width modulation) device.

### Servo

What is a servo?
Servos are used in robotics for different purposes: e.g. to move a sensor around or to move the legs of a robot. Some users modify the servo so that they can use it as a DC-motor with a gearbox.
Controlling a servo is done with Pulse-width modulation. The length of the pulse is relative to the position the servo will turn to. The length of this pulses is usually between 1ms and 2ms, if so 1.5ms would be the center position. This pulse needs to be repeated with small intervals (otherwise the servo might turn to a "save" position or it might simply stay at its current position. This depends on the type of servo used).

### Stepper motor

We cover stepper motors in more detail in the next chapter, Robotics/Stepper Motors.
(The category-box overlaps some of the text here. This line added to keep the real content on the screen)
# Robotics/Components/Actuation Devices/Pneumatics Hydraulics

Pneumatic and hydraulic systems are actuators which provide linear movement. Hydraulic systems, especially, can produce extremely high forces.

### Pneumatic system

The Pneumatic Actuator is sometimes called a Pneumatic Ram. The basic Pnuematic Ram consists of 3 main parts. These 3 parts are the Cylinder, Piston and Rod.
The Cylinder, which is black in the diagram, is where the process takes place. Most of the cylinders in use for hobby robotics are constructed of stainless steel and depending on the type of ram it will either feature one or two ports for compressed air.
The Piston, marked in green, is similar to one that you would find in a car engine. It essentially provides a surface for the compressed gas to act upon.
The Ram , marked in blue, is connected to the piston and transfers the force from the piston to the mechanism that needs moving.
There are several different types of cylinders:
* Single acting cylinder: This cylinder has one input and has a spring. If the pressure is released from the cylinder the spring pushes the piston rod back to its starting position.
* Double acting cylinder. This type of cylinder is moved by pressurizing one side at a time of the piston. (see images below).

#### Applications

Pneumatics are useful for generating linear motion.
* Movement of a lever in a walker robot design.
* Closing a gripper

#### Design Considerations

The use of Pnuematics requires a supply of compressed gas. For a stationary robot on a production line a compressor could be set up nearby to supply it however this isn't possible for a robot that is on the move. The solution is to have a container that holds compressed air. If lots of compressed air is required the addition of a compressor into the design may be required however bear in mind that a compressor will consume a large amount of power.

#### Calculating Output Force

The force a cylinder can be expressed as
    $F=\ {pA_{Piston}}\,\!$
* F: Force in Newtons
* p: Air pressure in cylinder in Pascals. Pressure can be obtained through use of a Pressure Gauge in the air circuit before the Ram.
* A: Surface area of the piston in square meters. This can be obtained from the manufacturers specifications.

##### Notes

* ^ Note: the surface area of the rod side of the piston is smaller than the other side.
# Robotics/Communication Sensors
## Data transmission channels

Being able to send data to and from your robot can be a very handy addition. There are 2 commonly used methods for wireless data transmission: IR (InfraRed) and RF (Radio Frequency). Both methods have their own advantages and disadvantages. Which to use depends on several factors.

### IR

IR data transmission best known example is the TVs remote control. Using IR on a robot is quite easy and very cheap. The disadvantage of IR is that it's limited to line-of-sight transmission.Line-of-sight or the distance of operating can be increased by use of microwaves (transmission-receiver) systems

### RF

RF are well known in radio controlled cars. RF is more expensive than IR, but doesn't have the line-of-sight limitation. These days there are complete RF "modems" available which can be connected to a robot without much (or even any) extra components. Although possible building your own RF communication modules isn't advisable. There are strict laws about which frequencies you can use and with how much power you can transmit.

## Using IR

IR is not much more than modulated lightflashes. Since IR falls outside of the visual spectrum humans can't see these flashes without e.g. a digital camera (the CMOS image chip can see IR, on the screen those IR flashes appear bright white).

### Remote Control

The great thing about IR remote controls is that you can use many of these directly to control your robot. Although there are several (very) differend IR remote control standards, there is one standard that is used by multiple manufacturers. This standard, called RC5, is very easy to use as many programming languages for microcontrollers have build in RC5 support. The hardware is limited to an integrated receiver module (e.g. TSOP1736), a capacitor and a resistor.

## Further reading

* ↑ De Vleeschauwer David. "Phillips RC5 infrared remote protocol page". Detailed information on how to encode and decode RC5 bits.
* ↑ Michiel Niemeijer & Eric Toonen. "The RC5 code" and "Survey remote control transmitters CTV sets". A list of standard RC5 command codes. (was: http: //web .archive.org/web/20060226134827/http: //193.23.168 .87/Mikrocontroller/Kohlert/rc5_codes.html "The RC5 code").
* Very often RF communications are "noisy", and require a higher-level protocol to tolerate the noise. Serial Programming/Forming Data Packets describes some of the details.