Skip to content

programming

Kevin Wang edited this page Aug 22, 2015 · 4 revisions

Learning To Program

Getting Started

Creating Project:

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241894-creating-a-robot-project

Adding Commands and Subsystems:

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241895-adding-commands-and-subsystems-to-the-project

Using Speed Controllers:

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241859-driving-motors-with-speed-controller-objects-victors-talons-and-jaguars

Basically just:

  • Initialize controller, set to correct PWM
  • Call motorName.set(speed_you_want);

Safety with motors

Joysticks and OI:

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241881-joysticks

  • For X-box controllers, use getRawAxis and getRawButton instead
    • You can view the axes that are moving using DriverStation

Robot Drive:

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241857-getting-your-robot-to-drive-with-the-robotdrive-class

  • This class allows you to call commands after setting 4 motors to an object

You can also manually control motors

Arcade
  • Set motors to all move forward / reverse based on y-val
  • Set motors to all turn in one direction based on x-val
Tank
  • Set one side of motors based on input (y-val) of 1st joystick
  • Set other side based on input (y-val) of 2nd joystick
  • May need to invert one side - otherwise you go in circles
Mecanum

Commands

Default Commands (Useful for OI control)

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241907-default-commands

Command Groups

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241908-synchronizing-two-commands

  • Can either run one after the other or simultaneously

Scheduling (Adding) Commands

http://wpilib.screenstepslive.com/s/4485/m/13809/l/277232-scheduling-commands

We use Scheduler.getInstance().add(command_name);

  • Might also be able to use command_name.start(); Look at the “Requires” section too

Running Autonomous Commands

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241905-running-commands-during-the-autonomous-period

  • Can have one command that encapsulates multiple commands

Selecting From Multiple Autonomous Commands

http://wpilib.screenstepslive.com/s/4485/m/26401/l/255419-choosing-an-autonomous-program-from-smartdashboard

Preferences From Smart Dashboard

http://wpilib.screenstepslive.com/s/4485/m/26401/l/255423-setting-robot-preferences-from-smartdashboard

Sensors

http://wpilib.screenstepslive.com/s/4485/m/13809/c/88895

Limit Switches

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241867-switches-using-limit-switches-to-control-behavior

NOTE: There are certain ports on the roborio where

Gyros

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241871-gyros-measuring-rotation-and-controlling-robot-driving-direction

NOTE: Gyros currently only work when plugged into port 0 or 1 of Roborio

Encoders

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241875-encoders-measuring-rotation-of-a-wheel-or-other-shaft

PID

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241879-operating-the-robot-with-feedback-from-sensors-pid-control

Use small values to start; print output - if it’s only 1 or -1, it’s not really PID (but if it works, feel free to use it)

Pneumatics

Solenoids

http://wpilib.screenstepslive.com/s/4485/m/13809/l/241866-operating-pneumatic-cylinders-solenoids

Compressor

Optional for greater control over robot (otherwise runs automatically) Still need to have one though http://wpilib.screenstepslive.com/s/4485/m/13809/l/241865-operating-a-compressor-for-pneumatics

  • Justin Lin