1. What is an encoder? How does it work?



2. There are three main settings for encoders. Briefly explain what each does (which is running at a set speed, which is running at a set power?)








3. Describe the process for setting a motor to turn one full rotation and then stop.



4. Describe the process for setting a motor to run at a consistent speed for two seconds and then stop.




5. This code is supposed to make the motor turn half a rotation. It never moves. There are two errors, what are they? (This is not a configuration problem)

        motor = hardwareMap.dcMotor.get("ml");


        startPosition = motor.getCurrentPosition();


        motor.setTargetPosition(startPosition + 500);

Here are the answers.



Unit 1 Review

1. Draw a picture/diagram showing the flow of steps from a programming idea all the way to running code.

2. What is the difference between source code and binary object code?

3. What does an API do for us?

4. What is the difference between an SDK and API?


1. We have not declared variable a. Line 1 would generate a compiler error.

1a. Declaration creates a variable with it's data type and allocates appropriate memory space based on the data type. A variable must be declared before it's first use. Initialization is assigning a starting value to a newly created variable.

2. Only a single variable can appear left of the assignment ( = ) operator.

3. a = 7, b = 9.

4. a = 7, b = 9, c = 63.

5. a = 7, b = 63, c= 63.

6. a = 63, b = 63, c = 63.

7. a = 63, b = 63, c = 5.

8. The student thinks the definition of c has been permanently changed by line 8 to be b * a. c is a simple integer variable and only contains the numeric value assigned to it. The result of line 8 is c = 63.

9. A compiler error due to the fact we are trying to assign a floating point number to an integer. The Java compiler can't convert the float to an integer without loss of accuracy.

10. The same compiler error for the same reason.




Given the following statements, answer the questions below:

1) a = 15;

2) int b;

3) b = 12;

4) a = a + 5;

5) b - 2 = 10;

6) int a = b - 5;

7) b = 9;

8) int c = b * a;

9) b = c;

10) a = b;

11) c = 5;

12) c = 3.2;

13) float f = 121.23;

14) c = f;

1. After the code up to line 4 has run, b will indeed be equal to 12, but a will NOT be equal to 20. There actually is an error. What is wrong with what we have done with a up to line 4?

1a. What is the difference between declaration and initialization? (When do you need to say the type of variable, like int)

2. Line 5 also will make java unhappy and won’t do anything (and will actually prevent us from compiling). Why?

3. After line 7, what will the variables a and b have stored in them?

4. After line 8, what will the values of a, b and c be?

5. After line 9, what will the values of a, b and c be?

6. After line 10, what will the values of a, b and c be?

7. After line 11, what will the values of a, b and c be?

8. A student thinks that at the end of line 10, a= 63, b = 63, and c = 3969 (which is 63*63). What mistake are they making?

9. What is the result of line 12?

10. What is the result of line 14.

The answers are on the next page.


1) a > b; 
15.4 greater-than 5.6?   True.

2) c > a; 
9.8 greater-than 15.4?   False.

3) A == a; 
Error, variable A not defined.

4) (a > b) || (b < c); 
(15.4 greater-than 5.6) or (5.6 less-than 9.8)
          true          or        true        ?      True.

5) b = 5.1; 
Error, not a comparision.

6) b == 5.6; 
5.6 equal to 5.6?     True.

7) !(c < a) 
   not (9.8 greater-than 15.4)
   not          true          ?  False.

8) (c < a) && (b > a); 
(9.8 less-than 15.4) and (5.6 greater-than 15.4)
        true         and         false          ?  False.

9) !(b != b)
 not(5.6 not equal 5.6)
 not(      false      )?        True.




Example of if statement misuse.

Lets say I have a robot that has a servo that I want to control using two buttons on a controller, and I want the following rules to be followed:

-If button A is pressed, the servo extends all the way

-if button B is pressed, the servo extends halfway

-if no button is pressed the servo retracts

Here is a pseudocode implementation of these rules:

if A.isPressed()
    servo extends 100%;

if B.isPressed()
    servo extends 50%;
    servo extends 0%;

Consider the case when button A is pressed, but B is not. What will the behavior of this code result in? Fix the code using appropriate changes to the conditionals.

Click Next for the answers.




Given the code below, the desired result is for c to end up as 100 if it’s bigger than b, 0 if it is equal to b, and 5.4 if it is less than b.

1) What does b end up being equal to?

2) According to the rules I wrote in words above, what should c be equal to at the end of this code?

3) Does this code do this?

4) Fix the code to have the desired behavior.

float a = 20;
float b = 5;
float c = 10;

if (a > b)
    b = 2 * b;
    b = 0;

if ( c > b)
    c = 100;

if (c == b)
    c = 0;

if (c < b)
    c = 5.4;

Click Next for the answers.



Advanced Core Device Interface Module

The Modern Robotics Core Device Interface Module is used to connect devices, typically sensors, to the robot control system. There are several different connection protocol options available: digital, analog and I2C. A number of the Modern Robotics sensors use I2C and typically, if you only have one sensor of a specific type, you can ignore the I2C details and let the FTC SDK object for the sensor communication using default parameters.

Singleton Design Pattern

In a previous lesson, we discussed static variables and methods. Static variables and methods are available without an instance of their containing object and are shared with all other object instances that exist in your program. This is used for global variables and utility methods that don't really have the aspect of multiple instances that many objects do. We also said that Java does not support static classes. Lets explore the idea of static classes in more detail.

Intro to the Robot Control System

A robot consists of motors, actuators, sensors and other components that provide it's functionality. Your program gets input from and sends commands to those components to operate the robot. Sitting between your code and the hardware components is the Robot Control System