Prerequisites: [wiki:SoftwareOverviewControl Control Systems Overview] = Lesson 1: Getting Started = If you want to tell a computer to do something, you have to communicate with the computer in a programming ''language''. When we say language, we mean it. A language has words and grammar and everything else, just like French. Computers, despite what you may think, are dumb. They do only exactly what you tell them to, and don't guess or interpret. If say to your Mom or Dad "Hey, can you bring me that thing?", there's a (slim) chance they may bring you the right "thing". A computer wont. Ever. Just a cold, unfeeling "'''ERROR'''". A programming language is very precise, and to tell a computer what you want, you have to be precise too. In this training session, we'll introduce programming to you, and make some things work. You know, those ''things''. Hang on, it gets harder from here. (A quick note...If you know all this already and are getting bored...CONGRATULATIONS! Here's a '''[https://www.youtube.com/watch?v=x94yTpv0T1k link]''' to some cute corgi puppy videos as your reward. Then, come back and dive into a later section. This is all self-paced.) We'll be starting with a programming language called [https://www.python.org/ Python], specifically Python 3. There are a lot of programming languages. Some are created because they're better for solving certain problems, others because people are bored and want to try something new. Python has been around for a while, and its pretty popular because its easy to use. The team uses Java to control the robot but that language is a little trickier. We'll get to that one later once you get a handle on the basics. Python, like every programming language, has a structure. Here are the big parts: * ''Variables'': Things you assign to and read from. Like in Algebra. A="Dump Truck" sets the variable A to the string "Dump Truck". They're basically the nouns. * ''Functions'': These do things. They take nouns as arguments, do something, and can return nouns. In redCar = paintCarRed(blueCar), paintCarRed is a function. They're the verbs, they do things, and they take variables and return variables. * ''Control Structures'': These are instructions like IF this is true THEN do that…. These are like grammar rules, like use active voice, or use punctuation. * ''Libraries'': A lot of other people have written functions to do things. A lot of things. When these things are bundled together they're called libraries. You can tell a computer to use a library and save your self a lot of typing. Much like in English, you blend all of these together to create stories, or programs. Both have a beginning middle and end. So lets write the first programming story that all programmers start with: "Hello World" {{{ a="Hello World" print(a) }}} This tells the computer to print, you guessed it, "Hello World" on the screen. Now you try it: Go [https://www.tutorialspoint.com/execute_python3_online.php here]. Its our code editor for this training exercise. You can enter code in the center area of the page, click execute, and see the results below. I recommend you bookmark that site, its pretty cool. Now on that site, highlight all the text in the central area and hit back space (this we'll clear out all the sample code. We'll call this "clear out the test code" from now on. Then highlight the code above, and click copy, and paste the two lines above into that editor. Then click "Execute". (We'll call this series of actions "run the code" from now on. After a bit, you'll be rewarded with the message in the bottom window: {{{ Hello World! }}} And, boom, now you're a programmer. The rest is just more details. This is the end of Lesson 1. = Lesson 2: More Things To Do = Now "Hello World" is not too exciting if you want to program robots, but its important. It is a program, albeit a short one. We showed you how to run a function (or verb) print, which does something with its argument A, where A is assigned the value "Hello World". If you want to do more, we need to introduce control structures. Take the program below. Location = 'HERE' IF (location == 'HERE') THEN Print "We're here! Come on in' ELSE Print "Go away, we're out eating tacos" ELSEIF Cut and paste this program here, then run it (Press Execute). It should print "We're here! Come on in!". If it doesn't ask for help. Spacing matters in Python. Now, change line one to Location='Poughkeepsie, NY'. It should print "Go away, we're out eating tacos". If I was in Poughkeepsie, I'd be out eating tacos too. Ummm, tacos. This control struction evaluates a *expression* (location=='HERE') and if its true, then do the THEN part, otherwise do the ELSE part. This is called the IF-THEN-ELSE structure, and it’s the most basic control structure. Here's a couple other control structures that you should know For Loop: This one repeats over a variable. It's good for counting try running this one:; For (Potato While: The more charming cousin of the for loop, this one repeats [[[wiki:ProgrammingReserve Programming]Archive | Programming Archive]] [[Image(https://qph.ec.quoracdn.net/main-qimg-cf520202236c0a99986988706131aafb-c,right,30%,margin=20)]] FRC robots are controlled by their on-board roboRIO computer. The computer runs software (programs) that are written by Control Systems students using a programming language. Programming languages are very compact, precise ways of telling the robot what to do. Programming languages are very different from spoken languages (English, Spanish, Chinese, etc.) and often consist of as few as [https://www.programiz.com/c-programming/list-all-keywords-c-language 32 words]! What's really cool about programming languages is that using that tiny set of words, you can write programs of amazing sophistication. FRC supports many different programming languages, but Team 2537 uses [https://en.wikipedia.org/wiki/Java_(programming_language) Java]. Java is the primary language taught by most high schools and colleges because the [http://media.collegeboard.com/digitalServices/pdf/ap/ap-course-overviews/ap-computer-science-a-course-overview.pdf AP Computer Science exam] requires Java. Although it is not an ideal language for robotics, using Java allows participation in robotics to help reinforce material learned through the school curriculum. Java is also among the [https://spectrum.ieee.org/computing/software/the-2017-top-programming-languages most popular programming languages] so it is well worth learning. Java is part of the family of programming languages that includes C, C++, and C# which collectively have dominated computer programming for the last several decades. The small set of Java words includes verbs (words that invoke an action like '[https://www.tutorialspoint.com/java/java_do_while_loop.htm do]'), conditionals like '[https://www.javatpoint.com/java-if-else if]', and you can introduce nouns that are the subjects or objects that other words can act on. Let's examine the simple turtle-graphics exercise of drawing a square and see how it might look written in Java: {{{#!th rowspan=3 align=justify || English || Turtle || Java || {{{#!td 1. Draw with a Black pen 1. Do this Four Times: 1. Move Forward 10 Paces, Drawing 1. Turn Right 90 Degrees }}} {{{#!td COLOR BLACK [[BR]] REPEAT 4[[BR]] DRAW 10 [[BR]] RIGHT 90 [[BR]] NEXT }}} {{{#!td setColor(Color.Black); [[BR]] int edge = 0; [[BR]] while (edge < 4) { edge = edge + 1; [[BR]] moveAndDraw(10); [[BR]] turn(90); [[BR]] } }}} }}} Like all languages, Java has specific rules of syntax (grammar, spelling, etc.) that dictate how the language is used. Learning the key words and syntax are the first challenges when learning Java. Notice that: * Each Java command ends with a semi-colon * Groups (''blocks'') of commands are enclosed in curly-braces. * Details provided to a command (''parameters'') such as the color to set are placed in parentheses These are all examples of Java syntax. Like all programming languages, Java allows you to combine groups of commands into a single unit that forms an abstraction. For example, the words shown above that draw a square could be combined into a single new word that can be used to replace the individual words. This allows programs to be built with increasing abstraction so high level concepts such as 'put the ring on the peg' can be expressed clearly and concisely. Assignment Conditionals Looping Libraries Rio.