Learner

Exercise: Using an IR Seeker

Modern Robotics has a IR beacon sensor (called IR Seeker V3) designed for use with the Tetrix control system. This sensor can detect the IR beacons used for some FTC games and provide information about the location of the beacon relative to the robot. The FTC SDK has a sample program you can use to experiment with the IR Seeker. In AS, open the path FtcRobotController/java/[first package]/external.samples/SensorMRIrSeeker. You can enable this program and work with it but any changes you make will be overwritten at the next update of the SDK.

Exercise: Using a Color Sensor

Modern Robotics has a color sensor designed for use with the Tetrix control system. This sensor can read the color of a surface when the surface is within a few centimeters of the sensor. The FTC SDK has a sample program you can use to experiment with the color sensor. In AS, open the path FtcRobotController/java/[first package]/external.samples/SensorMRColor. You can enable this program and work with it but any changes you make will be overwritten at the next update of the SDK. You can copy the class to the teamcode area so any changes you make will be retained.

An Example of a RoboRio Robot Program

Here is a very simple Java program for RoboRio (FRC) robots. This is just to give you a preview of what we will be covering in the following lessons. We will show you what all of this means, where it comes from, how it works and examples of how this basic program is the basis of more complex programs that make robots move and respond to their environment.

An Example of an EV3 Robot Program

Here is a very simple Java program for EV3 (FLL) robots. This is just to give you a preview of what we will be covering in the following lessons. We will show you what all of this means, where it comes from, how it works and examples of how this basic program is the basis of more complex programs that make robots move and respond to their environment.

An Example of a Tetrix Robot Program

Here is a very simple Java program for Tetrix (FTC) robots. This is just to give you a preview of what we will be covering in the following lessons. We will show you what all of this means, where it comes from, how it works and examples of how this basic program is the basis of more complex programs that make robots move and respond to their environment. In the FTC environment, a robot program is called an OpMode.

Exercise: Drive in a Circle

Now lets look at an example that drives the robot in a circle. The key idea here is that if you drive the motors in the same direction but at different power levels (speeds) the robot will drive in an arc and if it runs long enough that arc becomes a circle.

Exercise: Drive in a Square Pattern

Now lets try something more difficult. Lets write a program to drive your robot in a square pattern. This requires 8 moves: drive straight for some amount of time, turn, drive straight, turn, drive straight, turn, drive strait, turn. Lets use the Java for loop to program only 2 moves, drive straight and turn but then repeat those two moves to get the total driving moves we need.

Select the package ev3.exercises. Right-click and create a Java class called DriveSquare then copy and paste the code below into that class:

Exercise: Drive Forward and Stop

Now its time write more interesting Java programs for the EV3. Start Eclipse on your PC. When Eclipse is ready, the EV3 Exercises project you created in the HelloWorld lesson should appear in the project explorer on the left side of the screen.

Exercise: Drive in a Circle

Now lets look at an example that drives the robot in a circle. The key idea here is that if you drive the motors in the same direction but at different power levels (speeds) the robot will drive in an arc and if it runs long enough that arc becomes a circle. Here is the code:

Exercise: Using Encoders

So far we have been controlling the distance the robot travels with elapsed time. A more accurate way to control movement is with encoders. Encoders attach to or are integrated into the drive motors and count the revolutions of the motor shaft either optically or magnetically. The DcMotor object has support for using encoder counts to control how long the motor will run when turned on. In the example code we will run forward for 5000 encoder counts and stop. Then we will run backwards to zero encoder counts to the starting point.

Pages