1 / 50

Introduction to Autonomous Programming

Introduction to Autonomous Programming. Team 7182, Mechanical Paradox Kieran Barvenik. This Class. This class is designed to be a hands-on workshop, where students can have the chance not only to learn the information provided, but also to apply it

libitha
Download Presentation

Introduction to Autonomous Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Autonomous Programming Team 7182, Mechanical Paradox Kieran Barvenik

  2. This Class • This class is designed to be a hands-on workshop, where students can have the chance not only to learn the information provided, but also to apply it • We hope that the workshop’s interactive medium will help people retain the information taught in the class more so than a normal lecture format would 2

  3. This Class • The class will be covering FTC specific Java programming and the essential building blocks for writing code for your robot • We will be creating a program that commands a standard pushbot to move forwards for 2.5 seconds, open, and close its claw 3

  4. Java and Android Studio • The FTC hardware system operates over an Android platform, which is written in Java • Android Studio is an IDE (Integrated Development Environment) specifically designed for Android programming • Interacting directly with the code is an extremely versatile way of writing programs that allows the writer to gain complete control over the program’s operation (in contrast to MIT App Developer, which is fairly limited) 4

  5. Looking at Android Studio A First look at the IDE 5

  6. The highlighted portion (in red) is the toolbar, where the user has access to the functions and shortcuts of the IDE 6

  7. The highlighted portion is the file explorer, where the user has access to the hierarchy of program files 7

  8. The highlighted portion is the program window, where viewing and editing of code occurs 8

  9. Android Studio Features • Android Studio includes a variety of other useful features for programming including, but not limited to: • Intelligent code editor (advanced code completion, analysis, and refactoring) • Automatic integration with version control and project management software such as GIT • Fast and expansive emulator 9

  10. What is an OpMode? • OpMode refers to a user generated operational mode, or a program run on the robot • The Term OpMode encompasses both Autonomous and Teleoperated modes • Autonomous OpModes are robot-controlled programs that are run during the first 30 seconds of a match • TeleoperatedOpModes are driver-controlled programs that are run during the last 2 minutes of a match 10

  11. Structure and Run Order • The run cycle of the program is its order of operations from the starting to the stopping of the program • OpModes contain multiple different prewritten methods (groups of code that perform an operation), each which plays during a different time during the run cycle of the program 11

  12. Structure and Run Order • Methods vary between 2 different types of OpModes: Normal and Linear • Normal OpMode: employs 4 main methods: init, start, loop, and stop • Linear OpMode: only uses one method, the runOpMode method, that runs once the program is initialized. • We will be creating a Linear OpMode, because the concepts we are demonstrating work better with the Linear setup 12

  13. Run Cycle Explanation In a Normal OpMode, pressing the stop button will stop the loop method, and proceed to run the stop method before exiting the program In a Normal OpMode, pressing the play button will immediately trigger the start method, followed by beginning the loop method In a Normal OpMode, pressing the init button will trigger the init method ; however, in a Linear OpMode, the init button will trigger the only method, runOpMode 13

  14. Creating the Program File • The first step in creating an FTC OpMode is to create a file to hold it • To do this, we need to navigate to the team code storage directory • Path: TeamCode/java/org.firstinspires.ftc.teamcode • OR: • FTCRobotController/java/com.qualcomm.ftcrobotcontroller/opmodes

  15. Creating the Program File • Right click the lowest directory in the hierarchy (for non-Beta users, the opmodes folder; for Beta users, org.firstinspires.ftc.teamcode)

  16. Creating the Program File • Select New, and Java Class • Enter the name of the program in the box (Note: although you can name the program virtually anything, it is best to name it something that relates to what it does such that you can recognize it easily)

  17. The Program File • The resulting file that pops up should look like this: • The statement at the top that begins with the keyword package simply declares where our program is located. The curly braces after the public class TestOp contain most of the OpMode’s code

  18. OpMode Creation (importing) • Before we start writing code that will actually move the robot, we need to import, or gain access to, the FTC SDK files. We need to add the following statements after the package statement but before public class …

  19. OpMode Creation (importing) • Import statements effectively are giving our program access to prewritten files in the package we specify in the statement • The above statement gives our program access to the LinearOpMode code located in the package com.qualcomm.robotcore.eventloop.opmode

  20. OpMode Creation (importing) • The program should now look like this:

  21. OpMode Creation (extension) • To begin creating the OpMode, we must first add the keywords extends LinearOpModebetween the public class TestOp and the opening curly brace 21

  22. Variable Declaration [flesh out] • First, we need to define variables to hold data that we will utilize and reference later in the program • We need to create 3 DcMotorvariables and 2 Servo variables • The lines we add to declare motors and servos are added inside the curly braces. The statements look like these: 22

  23. Variable Declaration • There are 3 motor variables to create: leftDrive, rightDrive, and arm • There are 2 servo variables to create: leftClaw and rightClaw 23

  24. OpMode Creation (runOpMode) • In the body of the program (between the curly braces and below our variable declarations), we now need to add the following block of code: This is the method in our program that will execute when the init button is pressed 24

  25. 25

  26. Initializing Hardware 1 • Next, we need to bind the variables we created earlier in the program to the robot’s hardware, such that the variables we interact with represent the motors and servos on the robot • The lines of code that we have to write to do this are placed inside the curly braces for the runOpModemethod 26

  27. Initializing Hardware 2 • The line to initialize a motor looks as follows: • The line to initialize a servo looks as follows: • The name inside the quotation marks is a name we give to the hardware device on the robot controller once the program is downloaded to the phone 27

  28. 28

  29. Wait for Start • After these lines of code, we have to add a waitForStart() method call. Because the runOpMode() method begins when the user presses the init button, the waitForStart() command tells the system not to continue until the play button is pressed on the phone 29

  30. 30

  31. Motor Movement • After the waitForStart() method call, is where the movement procedure is written • To make a motor move, the method [motorName].setPower(0.0) is called. The number put between the parenthesis is a decimal value that can range from -1.0 to 1.0, with -1.0 being full power in reverse and 1.0 being full power forwards. • To stop a motor’s movement, use 0 for the decimal number 31

  32. Servo Movement • To move a servo, the line [servoName].setPosition(0.0) is called in the runOpMode() method • The number inside the parenthesis is a decimal value that ranges from 0 to 1.0 • The decimal represents a position from 0 degrees to 180 degrees, so the decimal equivalent to the position in degrees can be found by dividing the number of degrees by 180 32

  33. Movement Code • To command the robot to drive forwards and open its claw, add the following code after the waitForStart();: 33

  34. 34

  35. Creating a Timer • To effectively write autonomous programs, a means of measuring distance must be utilized • The simplest way to accomplish this is by creating a timer, though encoders or sensors can also be utilized • The timer included in the FTC API is called ElapsedTime, a user controlled timer that can measure in units as small as milliseconds 35

  36. Creating a Timer • First, we need to create an instance of ElapsedTime by placing the following line of code after our movement code: 36

  37. Waiting • To tell our program to wait until a specific time has elapsed, we have to set up a loop that will continually check if our desired amount of time has passed (2.5 seconds, in our example) • To accomplish this, we add the following code after our movement code in the runOpMode() method (eTime.time() returns seconds, not milliseconds) 37

  38. 38

  39. Stopping Movement • After the time has elapsed, we want to command the robot to cease movement • To accomplish this, we will reuse the movement code we used earlier, but substituting 0 for the power value. The result is this: 39

  40. Stopping Movement • Additionally, we are going to close the claw by implementing this code: 40

  41. 41

  42. Waiting at the End • In order for the servos to fully close, we need the program to give them time to close; otherwise, the program will end and the servos will not move • We need to copy this code: And paste it at the end of the program to do that 42

  43. 43

  44. Registration of Your Program (non-Beta) • Even though the FTC OpMode is now complete, the program will not show up on the phone without registering it in the FTCOpModeRegister file • To do this, open the file and add a line of code like the following to the main body (with the other manager.register lines): 44

  45. Registration Select the FTCOpModeRegister Program in the FTCOpModeRegister->com.qualcomm.ftcrobotcontroller->opmodes->FTCOpModeRegisterdirectory 45

  46. Registration Add the following line next to the other similar lines: 46

  47. Registration (Beta Users) • Alternatively, if you are using the new beta version of the FTC SDK, registration of your program is far easier. Simply scroll to the top of your program file (the one the majority of code is written in) and insert the following line beneath the import statements:

  48. Registration • This line identifies the program to the FTC Robot Controller as an autonomous program (you can also use @Teleop for teleop programs). With the new version, the coding is all contained within one file rather than spread across multiple files, so the entire coding process is much more streamlined.

  49. Contact Information and Website Address • The PowerPoint used in this class will be uploaded to our team’s website for anyone interested in going over the material again • Our team’s website is: http://mechanicalparadox.org/ • If anyone from the class has questions about any of the topics covered, our team’s email is: mechanicalparadox7182@gmail.com 50

More Related