Lesson 6: Command-based (continued)

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Robot Code MVRT 2010 – 2011 Season. Robot code controls the robot Robot Main.vi –Calls all the smaller SubVis Rules of programming the robot –Be careful.
Java Workshop. Quick java review Goal: We want the application to tell us what the nth fibonacci number is. Components needed to achieve the goal: A Scanner.
The Basics of Java Programming and Command-Based Robot Projects TheRobettes.com.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Jeff Beltramo NHTI-Concord’s Community College FRC Team 1922.
Written by: Dr. JJ Shepherd
JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP.
Java Programming. Objectives Introduce Software Engineering Concepts Introduction to Object Oriented and Java Programming Provide Context for Software.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
FRC LabVIEW Software Overview Joe Hershberger Staff Software Engineer National Instruments.
Section 4.2: Functions that Test Conditions (continued)
Programming Part 1 Armond R. Smith Zhenying Wu. Overview of this Class ● Transition from FTC -> FRC ● Using Your Resources ● Java Keywords o Data Types.
Intro C++ Programming WINDSOR-ESSEX FIRST ROBOTICS
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Java for Robots How to program an NXT robot with a Java Brain Bert G. Wachsmuth Seton Hall University.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
FRC Java for Robotics Introduction Team 1279 ColdFusion January 8, 2011.
Java: Chapter 1 Computer Systems Computer Programming II.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
How to Control a Robot Kickoff Why, How, Where? Sense, think, act Robot, laptop, your brain GameRobot Human Game State Score External Sensors Internal.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Part III Robot Drive. Robot Main.vi The main body of your code: accesses all of the other programs in your project A big loop! Do not add any more loops.
Session 12 Sensors and Timers. 3 Main Types of Robot Projects Command-Based Robot A more complicated project for more complicated robots Iterative Robot.
Jon Cardwell Red Alert Robotics Team 1741 October 24, 2015.
CS100A, Fall 1998 Key Concepts 1 These notes contain short definitions of the basic entities that make up a Java program, along with a description of the.
Session 11 Intro to FRC API.
In the last lesson we discussed about: Casting Precedence The “=“ used as an assignment operator Made a calculate average program.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
While and If-Else Loops ROBOTC Software. While Loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain.
A: A: double “4” A: “34” 4.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Team 488 Java Architecture TESTABILITY!. Primary Goals Critical logic can be run without access to a cRIO or Robot ◦Multiple teams (Electrical, Mechanical,
Introduction to Programming with Java Presented by.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
INTRODUCTION TO JAVA PROGRAMMING FOR THE FIRST ROBOTICS COMPETITION JONATHAN DANIEL HEAD PROGRAMMER FERNBANK LINKS.
OpModes in FTC Eric Golde.
Pseudo-code 1 Running time of algorithm is O(n)
Lecture 14 Throwing Custom Exceptions
Advanced Software Concepts
Refactoring Methods: Kevin Murphy.
Chapter 3 Assignment Statement
Electrical Trainings MVRT
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים
Fe Maidens Programming
While Loops and If-Else Structures
null, true, and false are also reserved.
Lesson 4: Overall Review and Assessment
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Lesson 5: Review of Assessment and Introduction to Command Based Code
The Boolean (logical) data type boolean
Lesson 1: Fundamentals of Programming
Chapter 1: Computer Systems
Module 2: Understanding C# Language Fundamentals
searching Concept: Linear search Binary search
Training 11/11/16 Robot Code (WPILib).
Unit 3 - The while Loop - Extending the Vic class - Examples
JavaScript Reserved Words
Java Code Class Team 2992.
Simple Classes in Java CSCI 392 Classes – Part 1.
if-else Structures Principles of Engineering
Barb Ericson Georgia Institute of Technology Oct 2005
Introduction to java Part I By Shenglan Zhang.
Presentation transcript:

Lesson 6: Command-based (continued) Fe Maidens Programming 2017 - 2018 Spotlight: Drivetrain (Autonomous & Teleoperated) and Gears Stress that they need to be good at this because they will be writing the drive code for build season

DriveAuton code from last meeting (review + new concepts) import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2265.robot.subsystems.Drivetrain; package org.usfirst.frc.team2265.robot.commands; import org.usfirst.frc.team2265.robot.Robot; public class DriveAuton extends Command { private double left, right; public DriveAuton (double l, double r) { left = l; right = r; } protected void initialize() { protected void execute() { Robot.drivetrain.drive(left, right); protected boolean isFinished() { return false; protected void end() { Robot.drivetrain.drive(0,0); protected void interrupted(){ Can someone explain each part of the code (excluding these imports)? These methods are given to us by FRC. “protected” means that these methods are accessible to this class, the package, (commands) and other subclasses.

Drivetrain subsystem public class Drivetrain extends Subsystem { public static AnalogGyro gyro = new AnalogGyro(RobotMap.gyroPort); public static CANTalon frontLeft = new CANTalon(RobotMap.frontLeftPort); public static CANTalon rearLeft = new CANTalon(RobotMap.rearLeftPort); public static CANTalon frontRight = new CANTalon(RobotMap.frontRightPort); public static CANTalon rearRight = new CANTalon(RobotMap.rearRightPort); public static RobotDrive tankDrive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight); public static Encoder encoderLeft = new Encoder(RobotMap.encPort1, RobotMap.encPort2, true, Encoder.EncodingType.k1X); public static Encoder encoderRight = new Encoder(RobotMap.encPort3, RobotMap.encPort4, false, Encoder.EncodingType.k1X); public static double constant = 8.6; public Drivetrain() { encoderLeft.setMaxPeriod(2); encoderRight.setMaxPeriod(2); } // auton public void drive(double l, double r) { frontRight.set(-r); rearRight.set(-r); frontLeft.set(l); rearLeft.set(l); } } package org.usfirst.frc.team2265.robot.subsystems; import edu.wpi.first.wpilibj.command.Subsystem; import org.usfirst.frc.team2265.robot.commands.AutoAlign; import org.usfirst.frc.team2265.robot.commands.DriveTeleop; import org.usfirst.frc.team2265.robot.OI; import org.usfirst.frc.team2265.robot.Robot; import org.usfirst.frc.team2265.robot.RobotMap; import com.ctre.CANTalon; import edu.wpi.first.wpilibj.RobotDrive; import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Encoder; Drivetrain subsystem

package org. usfirst. frc. team2265. robot. commands; import edu. wpi package org.usfirst.frc.team2265.robot.commands; import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2265.robot.Robot; public class DriveTeleop extends Command { public DriveTeleop() { requires(Robot.drivetrain); } protected void initialize() { } protected void execute() { if (Robot.slow == false) { Robot.drivetrain.drive(); } else if (Robot.slow == true) { Robot.drivetrain.driveSlow(); } } protected boolean isFinished() { return false; /* Make this return true when this Command no longer needs to run execute() */ } // Called once after isFinished returns true protected void end() { } protected void interrupted() { } } DriveTeleop Command

Drivetrain Subsystem public class Drivetrain extends Subsystem { public static AnalogGyro gyro = new AnalogGyro(RobotMap.gyroPort); public static CANTalon frontLeft = new CANTalon(RobotMap.frontLeftPort); public static CANTalon rearLeft = new CANTalon(RobotMap.rearLeftPort); public static CANTalon frontRight = new CANTalon(RobotMap.frontRightPort); public static CANTalon rearRight = new CANTalon(RobotMap.rearRightPort); public static Joystick atkjoy = new Joystick(RobotMap.atkJoyPort); public static RobotDrive tankDrive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight); public static Encoder encoderLeft = new Encoder(RobotMap.encPort1, RobotMap.encPort2, true, Encoder.EncodingType.k1X); public static Encoder encoderRight = new Encoder(RobotMap.encPort3, RobotMap.encPort4, false, Encoder.EncodingType.k1X); public Drivetrain() { encoderLeft.setMaxPeriod(2); encoderRight.setMaxPeriod(2); } public void drive() { double leftVal = atkjoy.getRawAxis(5); double rightVal = atkjoy.getRawAxis(1); tankDrive.tankDrive(leftVal, rightVal); } Drivetrain Subsystem

Video of the robot scoring gears!!

Now let’s see it in a command group! package org.usfirst.frc.team2265.robot.commands; import org.usfirst.frc.team2265.robot.Robot; import edu.wpi.first.wpilibj.command.CommandGroup; public class CenterAuto extends CommandGroup { public static double d; public CenterAuto() { addSequential(new DriveDistance(65.0, 1.0)); addSequential(new ShiftChute(false)); addSequential(new DriveDistanceBack(-12.0, - 0.4)); } } //This is when the robot does scores from the center to the peg.