Download presentation
Presentation is loading. Please wait.
Published byElaine Carter Modified over 9 years ago
1
Session 12 Sensors and Timers
2
3 Main Types of Robot Projects Command-Based Robot A more complicated project for more complicated robots Iterative Robot Much more simple, but functionality is more limited Sample Robot Just the raw basics. Used for testing small things, or for highly advanced control flow.
3
Robot Run Modes TeleOperated – a human controls the robot Autonomous – the robot does stuff itself Practice – a simulation of a real match Test – anything you want it to be
4
Basic Code Declare variables Initialize variables Manually set motor controllers Drive robot with Joystick
5
Terminology: Variable Declaration Class Name / Variable Type Variable Name Access Modifier
6
Terminology: Variable Initialization Makes a new object of that class Constructor for Talon class Arguments / Parameters Constructor for this class
7
Terminology: Variable Use Arguments / Parameters Variable that stores an object of the Talon class Calls set method of that object
8
Side note: Java’s Math class Java has a built in class called “Math” Contains static methods and constants that do math things Trig, logs, exponentiation, rounding, PI, etc. Math.abs(a) – returns the absolute value of “a” (takes int, double, float) Math.signum(a) – returns 1 if it’s positive, -1 if it’s negative, 0 if it’s 0
9
Joystick Class double getX() double getY() returns X/Y axis value double getRawAxis(int axis) returns the value of an axis boolean getRawButton(int button) returns whether or not a button is pressed
10
Timer Class void start() starts the timer object void stop() stops the timer object void reset() sets timer object to 0 void get() gets the current time (seconds) boolean hasPeriodPassed(double period) returns if that amount of time has passed (seconds) If it has, subtract the current timer’s value by that amount (avoids drift) static double getFPGATimestamp() returns the system clock time in seconds
11
Importing the Timer Class There are lots of “Timer” classes in Java Make sure you import the right one Eclipse might automatically import a wrong class Delete it and type it out import edu.wpi.first.wpilibj.Timer;
12
Using the Timer Class Declare/Initialize variables reset and start the timer autonomousInit() is called once as soon as autonomous is enabled Run a motor at 20% speed if less than 2 seconds have passed else, stop the motor motors will continue to run at the previous set speed forever
13
Sensors Sensors give the program information on the real world Used to automate processes and require less work of drivers Transmits information back via an electrical signal
14
Analog vs Digital Signals Analog Indiscrete Can take on countless values Rational number (double) AnalogInput class Digital Quantized Only takes on discrete values In most of our cases, 2 Boolean DigitalInput class
15
Limit Switch Digital Signal Either pressed, or not pressed constructor = DIO port on roboRIO
16
Analog Ultrasonic Rangefinder Uses sound to measure distance Value returned is not to any particular scale It is directly proportional to the distance, however
17
Accelerometer Measures lateral forces The roboRIO has a built in accelerometer BuiltInAccelerometer class Could be used to help prevent a robot from tipping over Can integrate to get rough velocity & position of robot
18
Gyro Measures rotational forces Can integrate to get angular velocity and position built into special Gyro class
19
IMU Inertial Measurement Unit (AKA a fancy gyro with accelerometers) We have the navX-MXP board (AKA “the goods”) Has its own API A very specific setup to use it I’ll cover this later when needed
20
Potentiometer Sends out an analog signal depending on how much it’s turned Usually linear, sometimes logarithmic scaling Usually only measures up to 1 rotation
21
Quadrature Encoders Measures angular position of a shaft or axle Counts number of rises/falls in a digital signal and adds them up We’ll be using these indirectly with CAN Talon SRXs (Friday)
22
Extra: Smart Dashboard An application that displays values sent from the robot Useful for debugging and finding out what things are
23
Coming Up This Friday (11/20) CAN, Talon SRXs, and PID controllers Next Week (11/25, 11/27) Nothing: Thanksgiving Break The Week After That (12/2, 12/4) Command-Based Robot
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.