Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Software Concepts

Similar presentations


Presentation on theme: "Advanced Software Concepts"— Presentation transcript:

1 Advanced Software Concepts
Rockwell Automation FTC Kickoff

2 Copyright © 2016 FTC Team TBD
Introductions To Be Determined – TBD 6th Year FTC Team from Aurora, OH Res-Q World Champions and World Control Award Winner Around-the-Room Team Name/Number Hometown What Do You Want to Learn Today? PUBLIC Copyright © 2016 FTC Team TBD Slide 2

3 Copyright © 2016 FTC Team TBD
Classes and Packages A class is a collection of objects of a similar type. Once a class is defined, any number of objects can be created which belong to that class. An object is an instance of a class. A package allows a developer to group related classes (and interfaces) together. PUBLIC Copyright © 2016 FTC Team TBD Slide 3

4 Copyright © 2016 FTC Team TBD
Access Modifiers By Default: Visible to the package. Private: Visible to the class only. Protected: Visible to the package and all subclasses. Subclass is “extending” another class. Example: MyTeleopCode extends OpMode Public: Visible to the world. Static: One instance shared by all instances of class. Final: Cannot later be changed Static and Final Together to Define a Constant int ourTeamNumber = 6022; private int ourTeamNumber = 6022; protected int ourTeamNumber = 6022; public int ourTeamNumber = 6022; Modifier Class Package Subclass World public Y protected N No Modifier private final public int ourTeamNumber = 6022; static public int ourTeamNumber = 6022; static final public int CONSTANT = 1234; PUBLIC Copyright © 2016 FTC Team TBD Slide 4

5 Object-Oriented Programming
Object-oriented programming is based on the concept of “objects”. Objects contain data in the form of fields/attributes. Objects contain code in the form of procedures/methods. An object's methods can access and often modify the attributes of the object. Programs are designed by making objects that interact with one another. A big advantage of object-oriented programming is that it enables programmers to create modules that do not need to be changed when a new type of object is added. A programmer can simply create a new object that inherits many of its features from existing objects. This makes object-oriented programs easier to modify. PUBLIC Copyright © 2016 FTC Team TBD Slide 5

6 Object-Oriented Programming
Abstraction Implementation of an object that contains the same essential properties and actions we can find in the original object we are representing. public class ResQMountain { public static enum MountainStatus { ON_MTN, OFF_MTN; private MountainStatus() { } } public static enum MountainZone { LOW_ZONE, MID_ZONE, HIGH_ZONE; private MountainZone() { } } } PUBLIC Copyright © 2016 FTC Team TBD Slide 6

7 Object-Oriented Programming
Encapsulation Internal representation of an object is generally hidden from view outside of the object’s definition. public class ExampleRobotDrivetrain { private DcMotor trackLeft; private DcMotor trackRight; private DcMotorController trackController; public ExampleRobotDrivetrain (DcMotor aLeftTrack, DcMotor aRightTrack, DcMotorController aController) { trackLeft = aLeftTrack; trackRight = aRightTrack; trackController = aController; trackRight.setDirection(DcMotor.Direction.REVERSE); } public int getDriveEncoder() { return Math.abs(trackRight.getCurrentPosition()); } public void resetDriveEncoders() { trackLeft.setMode(DcMotorController.RunMode.RESET_ENCODERS); trackRight.setMode(DcMotorController.RunMode.RESET_ENCODERS); } public void setPower(double aLeftPower, double aRightPower) { trackLeft.setPower(aLeftPower); trackRight.setPower(aRightPower); } } PUBLIC Copyright © 2016 FTC Team TBD Slide 7

8 Object-Oriented Programming
Inheritance Classes can inherit attributes and behavior from pre-existing classes called base classes, also known as superclasses. public class TrackCleaning extends OpMode { private RobotTracks robotTracks; @Override public void init() { robotTracks = new RobotTracks(hardwareMap.dcMotor.get("trackLeft"), hardwareMap.dcMotor.get("trackRight"), hardwareMap.dcMotorController.get("drivetrainController")); } @Override public void loop() { robotTracks.setPower(0.5, 0.5); } @Override public void stop() { robotTracks.stop(); } } public abstract class OpMode { public Gamepad gamepad1 = null; public Gamepad gamepad2 = null; public Telemetry telemetry = new Telemetry(); public HardwareMap hardwareMap = null; public double time = 0.0D; private long a = 0L; public OpMode() { this.a = System.nanoTime(); } public abstract void init(); public void init_loop() { } public void start() { } public abstract void loop(); public void stop() { } } PUBLIC Copyright © 2016 FTC Team TBD Slide 8

9 Object-Oriented Programming
Polymorphism Ability of an object to take on many forms. Class can have multiple inheritance. Deer d = new Deer(); Animal a = d; Vegetarian v = d; Object o = d; //All the reference variables d, a, v, o refer to the same Deer object in the heap. //Example from because I haven’t really used polymorphism in robotics code. PUBLIC Copyright © 2016 FTC Team TBD Slide 9

10 Copyright © 2016 FTC Team TBD
State Machines Not a physical machine!  Can be implemented in an opmode through a switch. In only one state at a time (known as the current state). Changes from one state to another when initiated by a triggering event or condition. Allows for autonomous programs to be programmed using the standard opmode (rather than the often buggy linear opmode). public void loop() { switch(stateMachineFlow) { case 0: //Initial expand and servo delay robotOrientation.zAxisRotationZero(); robotCaster.positionDeployed(); robotTracks.resetDriveEncoders(); runtime.reset(); stateMachineFlow++; break; case 1: //Half of lowering track guards robotTrackFlaps.positionUp(); robotOrientation.zAxisRotationZero(); if(runtime.time() >= 0.25) stateMachineFlow++; //Time to ensure that flaps drop break; //Skipping over steps just to keep this presentation consolidated case 10: //Climb the mountain robotTracks.runWithoutEncoderPWM(); robotTracks.setPower(-1, -1); robotMtnLock.updateChurroCount(runtime.time()); if(robotTracks.isStalling()) stateMachineFlow = -1; if(robotMtnLock.getChurroCount() >= mtnChurrosToClimb) stateMachineFlow++; break; default: //Autonomous complete! #YEET robotTracks.stop(); robotSweeper.stop(); robotWinch.stop(); break; } } PUBLIC Copyright © 2016 FTC Team TBD Slide 10

11 Copyright © 2016 FTC Team TBD
Using Motor Encoders Measures how far a motor has turned. Useful for autonomous programming. More reliable than timing. Can be positive or negative. someMotor.getCurrentPosition(); Two motors on the same controller can also take advantage of PWM control. Keeps motors running in sync with each other. someMotor.setMode(DcMotorController.RunMode.RUN_WITH_ENCODERS); Can also be used to code a stall detection system. PUBLIC Copyright © 2016 FTC Team TBD Slide 11

12 Copyright © 2016 FTC Team TBD
Using Gyroscopes Measures rate of rotation. Through integration, can be used to measure how big of an angle the robot has turned. More accurate turns. Modern Robotics sensor and Moto-G2 have 3-axis gyroscopes. Modern robotics has built-in integration, which allows for greater accuracy and easier implementation. PUBLIC Copyright © 2016 FTC Team TBD Slide 12

13 Copyright © 2016 FTC Team TBD
Using Touch Sensors Can be used as limit switches. Prevents movement of a motor in one direction if a touch sensor is pressed so that a mechanism is not damaged and/or motion does not continue. PUBLIC Copyright © 2016 FTC Team TBD Slide 13

14 Copyright © 2016 FTC Team TBD
Using Other Sensors In general, using sensors is a good thing! Sensors give more data to robot, which leads to more accurate decisions. JavaDocs are a great source of help for interfacing with sensors. Don’t be afraid to try new sensor systems. Last season, we used magnetic, light, color, accelerometer, etc… PUBLIC Copyright © 2016 FTC Team TBD Slide 14

15 Copyright © 2016 FTC Team TBD
Documenting Code Show structure using UML diagrams. Show algorithms and routines through flowcharts. Describe what code does and how it improves performance. For engineering notebook examples and resources that help with UML and flowcharts, visit PUBLIC Copyright © 2016 FTC Team TBD Slide 15

16 Any Questions? Thank You and Good Luck!

17 Programming Exercises/Challenges
Feel Free to Collaborate and Ask for Help


Download ppt "Advanced Software Concepts"

Similar presentations


Ads by Google