Java

Overview: 
Learn how to use a regulated motor to act as a servo.
Objectives: 

Understand how to use a regulated motor to act as a servo.

Content: 

A servo is a motor where we control its movements in finer detail than just turn on or off. Typically we want to move the motor in a range less than one revolution. This allows us to use the servo (motor) to control things like arms (raise/lower) and grippers (open/close). A Regulated Motor allows us to move the motor to a specific angle or by a specific angle. This allows us to have finer control over the movement of the motor and that allows us to control more complex mechanisms than things that just rotate.

In the ev3.exercises package, create a new class called ServoDemo and copy the code below into that class:

This program assumes you have built the basic robot described in the Lego kit that has an arm on the front controlled by a Medium motor. The program will raise or lower the arm in response to the up/down buttons on the EV3, 10 degrees at a time until the angle of the arm is zero (all the way down) or 160 degrees (all the way up).

This example shows the use of the do-while loop and the Lcd library class to display the current arm angle on the LCD.

Note that the motor does not allow us to read the current angle of the motor so we have to keep track of that ourselves. When the motor object is created, it assumes it is at the zero position of travel. You have to put the arm in the position you define as zero before starting the program. Here we assume the arm is touching the ground at start. You have to run the program and determine what number of degrees represents the highest travel of the arm and then put that in the code as the upper limit.

 

Navigation:

Exercise: Using a Regulated Motor as a Servo

A servo is a motor where we control its movements in finer detail than just turn on or off. Typically we want to move the motor in a range less than one revolution. This allows us to use the servo (motor) to control things like arms (raise/lower) and grippers (open/close). A Regulated Motor allows us to move the motor to a specific angle or by a specific angle. This allows us to have finer control over the movement of the motor and that allows us to control more complex mechanisms than things that just rotate.

Overview: 
Discussion of how to proceed with the following units depending on which robot hardware platform you are using.
Objectives: 

Determine what Unit to proceed to next.

Content: 

If you are using the EV3 platform, it is simple enough that you have learned enough Java to do some actual programming. You can skip to Unit 9 and start working on some EV3 example programs. As you proceed in the examples you may see Java concepts and constructs that are covered in Unit 8. After doing some of the examples you should return to Unit 8 and complete it as it covers topics that, while not needed to get started, likely will be needed as you write more serious robot programs. After completing Unit 8 and doing the examples you should also study Units 12 and 13 to learn still more about Java, enabling you to do more sophisticated robot programming.

If you are using the Tetrix or RoboRio platforms, you could skip to those Units and start working with the examples. However, you will quickly encounter concepts and constructs covered in Unit 8. If you can't resist starting to program and skip Unit 8, try to return to it as soon as possible, so you will know more about what you will be seeing in the example programs you will be working with. Units 12 and 13 should also be completed to give you a more complete picture of what you will be seeing in the examples and what you are likely to see if you look at the FIRST samples or code from other teams.

Navigation:

What's Next

If you are using the EV3 platform, it is simple enough that you have learned enough Java to do some actual programming. You can skip to Unit 9 and start working on some EV3 example programs. As you proceed in the examples you may see Java concepts and constructs that are covered in Unit 8. After doing some of the examples you should return to Unit 8 and complete it as it covers topics that, while not needed to get started, likely will be needed as you write more serious robot programs.

Packages and Imports

Classes within a project or in a library are organized into packages. A package is simply an identifier specified at the top of a class with the package statement. In a project, all classes with the same package name are grouped together under that name. Packages are important when we want to use libraries of classes published by other programmers, such as the Java Class Library or one of the robot specific libraries.

Overview: 
Introduction to packages and the import statement.
Objectives: 

Gain a basic understanding of packages and the import statement.

Content: 

Classes within a project or in a library are organized into packages. A package is simply an identifier specified at the top of a class with the package statement. In a project, all classes with the same package name are grouped together under that name. Packages are important when we want to use libraries of classes published by other programmers, such as the Java Class Library or one of the robot specific libraries. Packages resolve naming conflicts between classes and help programmers to locate the classes they would like to make use of in their programs.

So how do we make use of packages? If we want to use one or more classes in a package in our program, we tell Java which package (or constituent class) we want to use with the import statement. Placed at the top of our program, one or more import statements make the imported classes act like they are part of our program and we can work with those classes in our code.

You will see various package and import statements in the examples. Packages and importing them are discussed in more detail in Unit 8.

Navigation:

Content: 

 

 

Line Number: x y z k
5 0 0 0 0
8 0 0 9 0
14 0 0 9 0
24 0 0 3 0
27 0 0 0 0
36 0 0 7 0
43 0 0 0 0
56 0 0 99 33
65 0 0 2 0
74 0 0 0 0
87 0 0 9 0

 

Navigation:

IF Statement Quiz 3 Answers

 

 

Customization Description: 
clone of robotics 102
Overview: 

This course is intended to introduce the Java programming language to students using the EV3 (FLL), Tetrix (FTC) and RoboRio (FRC) robotics platforms. For EV3, the course moves the student away from block based robot programming to using an advanced text based programming language. For Tetrix and RoboRio, the course will provide more instruction in Java itself, which is missing in existing materials. The course will teach a basic competency in Java with a focus on robotics applications. Robot construction will not be covered in any depth as it is assumed the student will have or acquire hardware building skills separately.

Get started using this course by clicking the first Unit and then the first Lesson. The Lesson content will be displayed and next/previous lesson buttons will appear at the bottom of each lesson making it easy to move between adjacent lessons.

Education Level: 

Pages