Robotics History

Robotics History Activity

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.

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 a grouping 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 included in robot SDKs.

IF Statement Quiz 3 Answers



IF Statement Quiz 3 Answers



Exercise: Using a PID Controller

With the test robot used to develop this course, there is a problem with the previous examples of turning under gyro or IMU control. When turning at a constant power setting and setting the power to zero when the target angle is reached, depending on motor configuration, gear ratio, robot weight and the turn power, the robot will most likely not stop quick enough to be on the desired angle. This is called overshoot. On our test robot, a 90 degree turn would end up being 110-120 degrees. Fixing this can be tricky to do manually but there is an automated way to better control the turn.

Exercise: Using the REV IMU

The REV Expansion Hub has a built-in IMU, or Inertial Measurement Unit. This is a sensor that can measure acceleration (movement) in several axes. It can be used in place of an external gyro. The IMU is not used in quite the same way as the gyro but is similar. Note: you must configure the IMU on I2C channel 0, port 0. Here is the DriveAvoid example converted to use the IMU in place of the MR gyro.



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 RoboRio controller. 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.


1. An encoder measures the rotations of a motor shaft either optically or magnetically and makes a count of shaft movements available to your program on the DcMotor class. There are typically a number of counts per revolution of the motor shaft.


2. motor.setmode(DcMotor.RunMode.RUN_TO_POSITION);

Runs motor to the position (encoder count) you set with setTargetPosition() at the power level set with setPower() and stops the motor when the target position is reached.


Runs the motor at a constant speed set as a percentage of motor maximum speed with the setPower() method. Does not stop the motor based on the current target position.


Runs the motor without any automatic action based on encoder counts but does count and report encoder counts.


3. Using the number of encoder counts returned for one revolution of the motor shaft, set the target position to that number and run mode RUN_TO_POSITION. Apply power.


4. Set the run mode to RUN_WITH_ENCODER, set the speed to run with setPower(). Enter a wait for wait loop for wo seconds then set the power to zero.


5. The code sets the wrong run mode for using setTargetPosition(). The code does not set the power level of the motor to start movement.