- Windsor-Essex FIRST Robotics

advertisement
Intro C++ Programming
WINDSOR-ESSEX FIRST ROBOTICS
WWW.WINDSORESSEXFIRST.ORG
What will we cover today
•Understanding the sample code
•Understanding of basic C++ operations and data structures
•Resources for continued learning
Technical Resources
The FRC website has GREAT resources for this years new hardware.
◦ https://wpilib.screenstepslive.com/s/4485
◦ Covers Labview, C++, and Java
More Resources
Chief Delphi
http://www.chiefdelphi.com/forums/portal.php
Great resource – A forum with other FRC students, sharing and answering
questions
Sample C++ Code
Sample C++ Code
Variables
A variable is a container for data that needs to be used
for other steps.
Int, Float, Boolean are simple data variables
RobotDrive, Joystick are complex objects. These
objects store lots of data in a known structure.
Sample C++ Code
Functions
Contain code that can be easily called by other code
If a section of code will be reused in more than one
place, a function is an easy way to keep your code
organized, as well as easy to change in the future
Sample C++ Code
Loops
A code loop will loop until conditions are no longer
met.
In this case, we will loop through the tele operated
code until we are no longer Enabled or In Tele
Operated Mode.
Sample C++ Code
Object Structures - RobotDrive
RobotDrive is a data structure that contains both
variables and functions
In C++ these variables and functions can be accessed
using the “.” or “->” to refer to an objects structure.
Example myDrive.arcadeDrive(driveStick)
Sample C++ Code
Object Structures
Jaguar *exampleJaguar = new Jaguar(0);
exampleJaguar->Set(0.7);
gyro = new Gyro(1);
double angle = gyro.getAngle();
C++ Coding – Your Turn
#include <iostream>
using namespace std;
int main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
cout << " and its double is " << i*2 << ".\n";
return 0;
}
C++ Coding – Your Turn
#include <iostream>
int main ()
using namespace std;
{
int addition (int a, int b)
int z;
{
z = addition (5,3);
int r;
r=a+b;
return r;
}
cout << "The result is " << z;
}
C++ Coding – Get Some Class
#include <iostream>
width = x;
using namespace std;
height = y;
}
class Rectangle {
int width, height;
int main () {
public:
Rectangle rect;
void set_values (int,int);
rect.set_values (3,4);
int area() {return width*height;}
cout << "area: " << rect.area();
};
void Rectangle::set_values (int x, int y) {
return 0;
}
Setting Up a New Project
https://wpilib.screenstepslive.com/s/4485/m/13810/l/145319-creating-yourbenchtop-test-program
Download