Vex Tutorial

This section provides a guide for wiring and programming your Vex based robot.

Wiring your Robot

The robot controller consists of a Raspberry Pi 3 which handles the high level Java program and an Arduino which handles the low level device control. The two devices communicate via serial ports.

TopShot

The Arduino provides 12 servo style PWM outputs, each of which can control one Vex motor or servo. The pins are numbered from 2 to 13 as shown below.

PinNumbering

Pins 2 through 9 support 7.2 volt motors such as the Vex motors. Pins 10 through 13 supply 5 volts an should be used for sensors or low voltage servos.

Let’s take a closer look at the connector:

Pinout

Here we can see that each port has 3 connections, one for ground, one for power and one for the PWM signal which controls the speed and direction of the motor. Notice that since the power connection is in the middle, plugging the motor in backwards will not cause any serious damage, although it will not work.

If we take a look at the connector on the motor, this is what we see:

MotorConnector

The black wire is ground, the red is power and the white is signal. They plug into the Arduino board like this:

PluggedIn

Here, the motor is plugged into port 2. Notice that the black wire is on the outside.

The default Vex program that you will be using is configured so the left drive motor is on port 2 and the right drive motor is on port 3. If you wish to use the program unchanged, you will need to plug your drive motors into these ports.

In addition, the default program supports two auxiliary motors which should be plugged into ports 4 and 5. Once you have all of your motors plugged in, it is advisable to zip tie them together to keep them in place:

Ziptie

 

Programming

You should receive a laptop with all the required software already installed. If you wish to install the software on your own laptop, you can find instructions here.

We will be using Eclipse to program our robots. Double click on the Eclipse shortcut on your desktop and the following window should open:

Eclipse

Also you will need to start the driver station by double clicking on the driver station icon on the desktop. This will open the following window:

DriverStation

If you are using a joystick, it must be connected before you start the driver station. The team uses Logitech joysticks, but other joysticks may work if they are recognized by Windows. If you don’t have a joystick connected, click the ‘Enable Virtual Joystick’ checkbox.

DriverStationExpanded

Now connect the power on your robot. The Raspberry Pi is configured as a WiFi hotspot and after a minute or two, the robot should show up as available on your PC. Each robot has a unique WiFi id and your will be Robotxx where xx is the number of your robot.

Connect your PC’s WiFi to your robot (remember that when connected to the robot, you will no longer have internet access). Once connected, click the “Launch Putty” button on your driver station console. This should bring up the following window:

Putty

This is a program which runs on the Raspberry Pi. It allows Eclipse to connect to the Pi and download and run the program you are working on. This program MUST be running in order for any of the following to work.

Now to run your program, switch back to your Eclipse window and click the run button shown below:

EclipseRun

This should start your program and the Eclipse ‘Console’ pane should show something like this:

Run

Now that the program is running, switch back to your Driver Station console and click the ‘Connect’ and then ‘Enable’ buttons:

Connect

You should now be able to drive your robot using the virtual joystick on the right. Simply click and drag the red dot.

Modifying the program

Depending on how you mounted your motors, you may find that the robot drives backwards instead of forwards. This is easy enough to fix. Simply open the ArcadeDrive.java file and change the following line:

    	y = y * y * y;

to

    	y = -y * y * y;

This changes the sign of the up/down motion of the joystick and will cause the robot to drive in the opposite direction.

After getting your robot to drive in the correct direction, you may also find that when you try and turn, it turns in the opposite way it is supposed to. This too can easily be fixed by changing the line:

    	x = 0.5 * x * x * x;

to

    	x = -0.5 * x * x * x;

Once again, this changes the sign of the left/right motion and will cause the robot to turn the opposite direction.

While we are here, you might notice that we are multiplying the x component of the joystick by 0.5. We do this to give you better control over the robot by making it turn slower. If you decide you would like it to turn faster (or slower), you can adjust this value to some other number between 0 and 1.

Adding additional motors / Servos

You may find that you need other motors or servos to control other actuators. The default program you are using already has two additional motors configured and one servo. The subsystems for these motors are Aux1Subsystem, Aux2Subsystem and ServoSubsystem, and the commands that use these subsystem are Aux1Command, Aux2Command and ServoCommand. You probably will not need to change these subsystems or commands, and the details of how to do this are beyond the scope of this tutorial.

What you will want to control, however is what buttons activate these two motors and the power you set. You do this by opening the OI.java file:

/*
 *	  Copyright (C) 2016  John H. Gaby
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, version 3 of the License.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *    
 *    Contact: robotics@gabysoft.com
 */

package robot;

import commands.Aux1Command;
import commands.Aux2Command;
import commands.ServoCommand;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import robotCore.Joystick;


/**
 * This class is the glue that binds the controls on the physical operator
 * interface to the commands and command groups that allow control of the robot.
 */
public class OI {
    //// CREATING BUTTONS
    // One type of button is a joystick button which is any button on a joystick.
    // You create one by telling it which joystick it's on and which button
    // number it is.
     Joystick m_stick = new Joystick(0);
     Button m_aux1Forward = new JoystickButton(m_stick, 1);
     Button m_aux1Reverse = new JoystickButton(m_stick, 2);
     Button m_aux2Forward = new JoystickButton(m_stick, 3);
     Button m_aux2Reverse = new JoystickButton(m_stick, 4);
     Button m_servoMax = new JoystickButton(m_stick, 5);
     Button m_servoMin = new JoystickButton(m_stick,6);
    
    // There are a few additional built in buttons you can use. Additionally,
    // by subclassing Button you can create custom triggers and bind those to
    // commands the same as any other Button.
    
    //// TRIGGERING COMMANDS WITH BUTTONS
    // Once you have a button, it's trivial to bind it to a button in one of
    // three ways:
    
    // Start the command when the button is pressed and let it run the command
    // until it is finished as determined by it's isFinished method.
    public OI()
    {
    	m_aux1Forward.whileHeld(new Aux1Command(0.5));
    	m_aux1Reverse.whileHeld(new Aux1Command(-0.5));
    	m_aux2Forward.whileHeld(new Aux2Command(0.5));
    	m_aux2Reverse.whileHeld(new Aux2Command(-0.5));
    	m_servoMax.whileHeld(new ServoCommand(180));
    	m_servoMin.whileHeld(new ServoCommand(0));
    }
}

It is here that we define which buttons we are going to use and what happens when you press them. For the two aux motors we are going to use buttons 1 through 4. Button 1 will make aux motor 1 rotate at half power in one direction and button 2 will make it rotate at half power in the opposite direction. The motors will stop when the button is released. Similarly buttons 3 and 4 will control aux motor 2. For the servo, we will use buttons 5 and 6 with button 5 moving the servo to the max position and button 6 moving it to the min position.

We define which buttons we are going to use with the following lines:

     Button m_aux1Forward = new JoystickButton(m_stick, 1);
     Button m_aux1Reverse = new JoystickButton(m_stick, 2);
     Button m_aux2Forward = new JoystickButton(m_stick, 3);
     Button m_aux2Reverse = new JoystickButton(m_stick, 4);
     Button m_servoMax = new JoystickButton(m_stick, 5);
     Button m_servoMin = new JoystickButton(m_stick,6);

Here we have declared the four buttons, 1 through 6.

Now we need to define what happens when we press these buttons and that is done with the following code:

    	m_aux1Forward.whileHeld(new Aux1Command(0.5));
    	m_aux1Reverse.whileHeld(new Aux1Command(-0.5));
    	m_aux2Forward.whileHeld(new Aux2Command(0.5));
    	m_aux2Reverse.whileHeld(new Aux2Command(-0.5));
    	m_servoMax.whileHeld(new ServoCommand(180));
    	m_servoMin.whileHeld(new ServoCommand(0));

For example, the first line specifies that while that button (button 1) is held down, the command Aux1Command should run with the motor set to half power. The command will end when the button is released stopping the motor. Similarly, the next line has the motor run in the opposite direction at half power. The values that the Aux1Command constructor can range from -1 to 1, with -1 full power one direction and 1 full power in the other.

For the servo, the ServoCommand constructor takes a position argument which can range from 0 to 180 degrees.

There are other options available for what happens when you press or click a button, but those are beyond the scope of this tutorial.

Additional Actuators

We have identified some additional actuators that might be of use.

The first is a servo. This works like a motor but the values you set control the position rather than the speed. Typically these can move through an angle from 0 to 180 degrees. We have tested this servo and found it to be suitable, they are about $5 each.

We have also found some continuous rotation servos which act like the Vex motors that you are using. We have a limited number Vex motors and because of the cost will probably no be purchasing more. However, we have tested this motor and it may be an inexpensive option if you need additional motors. These motors are fairly slow (~50 rpm) but are fairly strong so could probably be geared up. They cost about $8 each.

Both of these motors have the form factor for a MG995 motor and you can find cad designs for them online here.

Pierre Pierre, who replica handbag 185cm tall, gucci replica handbags the "Diamond King" in his hermes replica handbags . He has been selected as one of the handbag replica most beautiful 50 people in the "People" magazine. It is also known as replica handbags most elegant and quiet in the world. Unforgettable prince.