Learner

Content: 
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.

 

Navigation:

Content: 

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%;
else
    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.

 

Navigation:

Content: 

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;
}
else
{
    b = 0;
}

if ( c > b)
{
    c = 100;
}

if (c == b)
{
    c = 0;
}

if (c < b)
{
    c = 5.4;
}

Click Next for the answers.

 

Navigation:

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

Exercise: Using Library Classes

Many times we write code that will be repeated in a single project or code that is repeated in different projects. An example of this is the code to read the touch sensor in the DriveCircle project. This code would be repeated in every project that uses a touch sensor. It can be useful to put utility code, that is code that be used in several places or several projects into separate classes that can be called upon whereever needed. Another benefit is if we need to change how we handle the touch sensor.

Exercise: Using Multiple Threads

If you have not read the lesson on multi-threading in the Advanced Topics unit, do so before continuing.

Exercise: Using Logging

We are now going to take a look at logging (also called tracing) as a tool to debug our robot programs. Logging is recording useful information from the robot program to a disk file on the controller device. You can then download that file to your PC and examine it. It can be very useful to record information while your robot is running during a match so you can look at it afterwards and see what took place. If you have not read the general lesson on Logging, you should do that now.

EV3 Control Center

The EV3 Control Center is installed with the leJOS SDK on your development PC. The Control Center is a powerful tool that allows you to view and control many aspects of the EV3 controller. With the EV3 connected to your PC, you can start the Control Center from the leJOS pull down menu on the Eclipse tool bar. You can also start Control Center by clicking on this file:

C:\Program Files\leJOS EV3\bin\ev3control.bat

You might want to create a desktop shortcut for that file as you will probably use Control Center often.

Pages