C++ Guide Written By 313
Uses Eclipse Cpp Mars as the IDE
Installing and setting up Eclipse for C++ (or JAVA) development
Base template to start from
Breakdown of Each Part
"#include "WPILib.h" This accesses a database, provided by FIRST, which has all of the methods and objects needed to program using FIRST materials like; talon code, piston code, etc.
"class Robot: public IterativeRobot" References a part of WPILibrary with the class name and tells the compiler that this is an iterative style as opposed to command base
"public:" Assigns the variables to be instantiated in this portion to be public or accessable from anywhere within the program or in other classes
"Robot()" Constructor for variables, area in which the device ID is assigned for the variables created in the previous section
"void RobotInit()" Whatever is in here executes on enabling any of the modes like TeloOp or Auton.
"void AutonomousInit()" Within here is what executes upon enabling autonomous in the driver station, while this is runnong the driver has no control over the robot.
"void TeleopPeriodic()" The code loops through this and runs it over 1000 times per second, this is where you put the controls for the TeleOp portion of on the field.
"void TankDrive(double left, double right)" This is referenced within TeleOp and is used to control the drive train and the two double variables are the speed of each side of the drive train.
Basic setup for tank drive with one piston.
"Joystick *driverController," This creates the variable driverController and assigns it to be a Joystick. The * marks the start of the name and the , is the ending of the name.
"driverController = new Joystick(0);" This assigns the driverController to a new Joystick, and assigns it to Joystick input (0). The input (0) is the port where it is plugged in at.
"armLift = new DoubleSolenoid(0,1);" This assigns armLift to be a new DoubleSolenoid connected to PCM slots 0 and 1.
"leftFront = new CANTalon(1);" This assigns variable leftFront as a can talon with ID of 1, the ID's can be set in the roboRIO configuration tool at adress roborio-****-frc.local/ with the **** being your team number. Since this tool uses Silverlight it is required to use Internet Explorer.
"conpressor->SetClosedLoopControl(true);" This enables the compressor on a controled loop for safety.
"TankDrive(driverController->GetRawAxis(1), driverController->GetRawAxis(5))" This sends the value of the vertical axis of the both sicks of the driver controller to the function TankDrive.
"if(operatorController->GetRawAxis(1) < -.25);" If the left sick of the operator controller is pushed forward greater than 25% push the piston up else if the left stick is pushed down greater than 25% then retract the piston.
"leftFront->Set(left);" sets the value of the frount left motor equal to the value sent to the function from the controller's left stick.
"rightFront->Set(-right);" sets the value of the right front motor equal to the opposite of the value sent to the function from the controller's left stick. One side has to be inverted because the gearbox shafts are facing different ways making them rotate in different directions when given the same command.
Very basic drive forward auton.This section only deals with the autonomous section.
"leftFront->Set(.5);" sets the left front motor to half power.
"Wait(3);" stops the program from progressign for three seconds, this leaves the motor set to go previously to continue.
"leftFront->Set(0);" stops the motor.
More advanced auton with multiple options: part 1
"void DisabledPeriodic()" this funcition repeats while the robot is turned on but not enabled.
"SmartDastboard::PutString("DB/String 7","");" This clears out the 6th line on the smart dashboard.
"if(operatorController->GetRawButton(6))" Conditional statement for when the right bumper on the operator controller is pressed.
"auton++;" Increments the auton variable by one.
"Wait(.2);" This is so that it dosent cycle multiple times off of one button press because of the speed that the code iterates.
"if(auton == autonMax + 1)" The two conditional statements are for if the auton number gets out of range of the amount of autonomus's made.
"else if(operatorController->GetRawButton(5))" This is the other bumper and the internal is to increment in the other direction.
This part is for labeling the different autons and the second half is where the autonomusus's go.
"auto str = std::to_string(auton + 1);" this parces the value of one greater than auton into a string so it can be printed into the smart dashboard.
"if(auton == 0)" This series of conditionals checks the number for auton and wirtes something to smart dastboard on line 7.
"if(auton == 0)" This refers to the conditionals within AutonomousInit, within the conditionals goes the commands to be executed during autonomous
Our mission is to provide students educational opportunities to learn and engage in science, technology, engineering, and mathematics (STEM)
through the FIRST Robotics program. We encourage and inspire students to follow a career path focusing on these subjects we find vital to their success in a
changing world. Over the years, we have received awards for our accomplishments and we aspire to become a major contender at the FRC International Competition.