Learner

Exercise: Using a Touch Sensor

Lets look a using sensors by starting with the simple touch sensor. This is simply a button that can be used to signal your code that something has happened by pushing the button. We will add a REV Robotics Touch Sensor to the robot and plug it into digital port 0-1 on the Expansion Hub. We modify our controller phone configuration to identify digital port 1 as a  Rev Touch Sensor and name it touch_sensor. Why did we use port 1 instead of 0? It has to do with the way the ports are wired.

Exercise: Using Servos

Now lets look at using servos to control robot functions. The wheel motors we used in the previous exercises simply run at whatever power level they are set at. Servos are different in that they have a defined range of motion and you control them by setting the location in that range you want the servo to move to. Once in that position, servos resist movement. Servos are typically used for arms and grippers.

Exercise: Joystick Driving - Tank Mode

Now lets look at a teleop example. Here we will use the joysticks on one of the Xbox controllers to drive the robot. We will use tank style driving. In tank mode each joystick controls the motor on one side of the robot. Moving the joystick forward or backward will cause the motor on the corresponding side of the robot to turn in that direction and the power level will be determined by how much the joystick is moved off of center. In this mode, to drive straight you have to move each joystick the same amount.

Exercise: Joystick Driving - Arcade Mode

Lets look at another style of motor control (driving) called arcade. In arcade mode, a single joystick controls both forward/backward motion but also left and right. This allows the robot to be driven with one finger, typically the thumb.

Sample Robot in more Detail

Lets examine the Sample Robot project in more detail.

Looking at Robot.java the first thing we see is the package created for us by the WPILib plugin based on our team number.

Next we see some reference variables defined. These are for a RobotDrive object and a Joystick object. These objects are part of the WPILib API. The RobotDrive object gives you many ways to control the motors in a robot drive system.  The Joystick object gives you access to the inputs (deflection and buttons) available from a joystick.

Programming the RoboRio

RoboRio based robots can be programmed with one of three models or styles of program design. These are:

  • Iterative
  • Command
  • Sample

You can read a discussion of the three models here, but for our lessons we are going to use the Sample (also called Simple) model. It is our belief that this is the easiest model to start with.

Installing RoboRio Programming Tools

Before we get into installation of the software tools, we will go over some basics.

Exercise: Drive in a Square Pattern

Now lets expand on the previous example. This OpMode shows changing direction, use of a for loop and time delays to drive in a square pattern by programming only two of the moves needed (drive straight then turn).

Exercise: Drive in a Square Pattern

// simple autonomous program that drives bot in a square pattern then ends.
// this code assumes it will end before the period is over but if the period ended while
// still driving, this code would just stop.
 
package com.qualcomm.ftcrobotcontroller.local.opmodes;
 
import com.qualcomm.ftcrobotcontroller.local.lib.Logging;
import com.qualcomm.ftcrobotcontroller.local.lib.Util;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;

Exercise: Drive in a Square Pattern

// simple autonomous program that drives bot in a square pattern then ends.
// this code assumes it will end before the period is over but if the period ended while
// still driving, this code would just stop.
 
package com.qualcomm.ftcrobotcontroller.local.opmodes;
 
import com.qualcomm.ftcrobotcontroller.local.lib.Logging;
import com.qualcomm.ftcrobotcontroller.local.lib.Util;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;

Pages