Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming FTC Robots with Android Studio

Similar presentations


Presentation on theme: "Programming FTC Robots with Android Studio"— Presentation transcript:

1 Programming FTC Robots with Android Studio
Eagle Robotics Team 7373

2 Disclaimer This is only an overview
We cannot cover every aspect of Android Studio If you have questions, contact us using the information provided in your handout or check out our code library: eaglerobotics.net/code

3 System.out.println(“Welcome!”);
What tools will you need to code in Android Studio? JDK 8 Android Studio 2.1 The latest version of the ftc_app from GitHub Links to all is on web page Install JDK BEFORE As. ftc_app can be either downloaded or forked off GitHub

4 Android Studio Interface
Project Window Program Editor This is the stock view of Android Studio… Project Window – This is where you navigate the projects file tree Program Editor- This is where source code is edited Tool Windows- This can serve many different purposes depending on how you configure you Android Studio Tool Windows

5 Android Studio Interface
This is my custom view of Android Studio. You can customize it to look however you want.

6 Navigating Projects Package Classes
This is that is inside the project windows All work will be done in this directory FtcRobotController / java / com.qualcomm.ftcrobotcontroller / opmodes C is a class Folder is a package These 2 classes are very important Register- This is where you assign what op modes actually show up on the phone NullOp- This is a barebones structure for any program Classes

7 Editing Opmodes Double click class to open it here
This is where the source code is edited. Classes being edited are listed in tabs on the top Do not leave too many open at once or you will get confused

8 Registering Opmodes In order to use an opmode, it must be enabled
In order to do this you only need to comment out one line of code above the class header You can also change the labels that describe your opmode to keep things more organized They can be organized by Autonomous/Teleop, Group, and Name @Autonomous(name = "Concept: NullOp", group = "Concept") public class ConceptNullOp extends OpMode {

9 Uploading the Project Plug in Android Robot Controller
Press Play Button in Menu Select Android Device to Deploy to Press OK The App Should Now be on your Android Robot Controller Put the app on your home screen for easy quick access This is basics of using Android studio… onto basic Java syntax

10 Basic Java Syntax Almost All Statements will end with a ;
i.e. System.out.println(“Hello World”); Every method or class will be surrounded by braces i.e. public void method () { //Code goes here… } Java is very particular so be patient Java is case sensetive

11 Basic Java Syntax Comments can be written using //
These are ignored by the compiler but help to document and organize code i.e. //set drive motor power to 1 driveMotor.setPower(1); These can also be quite helpful for testing small sections of the code at a time Comments can span multiple lines if the following from is used /* * put an asterisk on every line * then you can comment * on multiple lines */ Helps for testing by commenting out troublesome portions of code or code that is known to work Be careful to end the multiple lines comment or it will comment all code

12 Java Variable Types Double, float, and int boolean Enumerated types
These are the most commonly used number type in programming FTC robots boolean This is a value that stores TRUE or FALSE This is used for logic statements such as While, For, If, etc. Enumerated types These are a specific type of variable that can hold explicit values like Go, Stop, Start… This is not the same as a string Float is a number with decimals, int is a whole number Motor and servo are propriotery (only use for robots)

13 Java Logic Opertators && - And || - Or ! - Note == - Equals
> - Greater Than < - Less Than >= - Greater Than or Equal To <= Less Than or Equal To != - Does Not Equal

14 Java Iterative and Logic Statements
while(conditions) { … } for(int i = 0; I <= 100; 1++) { … } if(condition) { … } else { … } switch(case){ case 1: … break; case 2: … break; default: … break;

15 opModeIsActive() method
Returns a Boolean This method is very important to be able to stop your robot at any time even when you are running a loop while( opModeIsActive() ) { … }

16 Basic Form of a Program There are 2 basic forms any robot program will take Iterative Init/start Method Starts when init button is hit in driver station Runs code once then waits for start to move to run the start and then loop method loop Method Runs repeatedly until stopped by the driver station Linear runOpMode Method Runs through only once until stop button is pressed or timer runs out waitForStart method is used to separate the initialization of the robot from the start of the program Iterative is good for Teleop Linear is good for Autonomous But you can use both for either type of opmode and oftentimes there are advantages… I tend to work with Linear opmodes for flexibility

17 Initializing the Robot
Create objects Servo and Motor i.e. Motor leftdrive; Servo arm; Reference the variable to the hardware map leftdrive = hardwareMap.dcMotor.get(“motor name”); arm = hardwareMap.servo.get(“servo name”); Fill in motor name or servo name for the name used on the robot controller hardware map Keep these names simple and consistent yet descriptive Best practice is to keep an excel spreadsheet will all hardware map data, wiring information, and any serial numbers or labeling information for each controller and motor/servo

18 Running the Robot Use either object gamepad1 or gamepad2 to get input
Fill in * for direction, Left, Right gamepad1. Output Range *_bumper Boolean True or False *_trigger Float [0,1] *_stick_y or *_stick_x [-1,1] dpad_* a, b, x, y A note for all axis on joysticks… the values they return is – up and + down… If button is pressed, it will return true

19 Running the Robot: Motors
Running a motor motor.setPower(float); Fill in your motor variable for motor name and drive power value for float This drive power can be from -1 to 1 If a value outside the bounds is sent, a null pointer error will be returned To prevent this clip the range of the input into the motor power = Range.clip(power, -1, 1); Use the gamepad joystick to control your power variable float power = gamepad1.left_joystick_y; power = Range.clip(power, -1, 1); motor.setPower(power); Range.clip has 3 arguments, number to clip, lower bound , and upper bound It will return the closest bound if it exceeds either bound

20 Running the Robot: servos
Running a servo servo.setPosition(float) Fill in servo variable name for servo and position value for float The position can be from 0 to 1 The same range clipping technique can be used for servos position = Range.clip(position, 0, 1); Running a servo… if(gamepad1.dpad_up) { servo.setPosition(1); } else { servo.setPosition(0); } Or any value for that matter…

21 A Basic Teleop public void init() { Servo arm; Motor leftDrive; Motor rightDrive; arm = hardwareMap.servo.get(“arm”); leftdrive = hardwareMap.motor.get(“leftdrive”); rightDrive = hardwareMap.motor.get(“rightdrive”); } Now that we have the knowledge to write a basic teleop program lets walk through one init

22 A Basic Teleop public void loop() { //get boolean values from dpad and change position of servo if(gamepad1.dpad_up) { servo.setPosition(1); } else if(gamepad1.dpad_down){ servo.setPosition(0); } //get power from left joystick and run motor float leftPower = gamepad1.left_joystick_y; power = Range.clip(leftPower, -1, 1); leftDrive.setPower(leftPower); float rightPower = gamepad1.right_joystick_y; power = Range.clip(leftPower, -1, 1); rightDrive.setPower(rightPower); } Now that we have the knowledge to write a basic teleop program lets walk through one init

23 Questions? www.eaglerobotics.net/code
us at or We hope you enjoyed… Prepared for programming robots…

24


Download ppt "Programming FTC Robots with Android Studio"

Similar presentations


Ads by Google