Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jon Cardwell Red Alert Robotics Team 1741 October 24, 2015.

Similar presentations


Presentation on theme: "Jon Cardwell Red Alert Robotics Team 1741 October 24, 2015."— Presentation transcript:

1 Jon Cardwell Red Alert Robotics Team 1741 October 24, 2015

2 Agenda  C++ Overview  C++ for FRC http://wpilib.screenstepslive.com/s/4485 Resources http://www.usfirst.org/roboticsprograms/frc/te chnical-resources http://www.usfirst.org/roboticsprograms/frc/te chnical-resources

3

4 Why use C++?  C++ is powerful and flexible  C++ is object oriented (classes)  All source code is plain text  Programming only requires a text editor and a compiler For example: vi/notepad++ and g++/gcc WindRiver IDE is the best for FRC. Use Source-Code revision/repository (SVN/Git/…).

5 C++ Basics  The main() function Start and end for every program  Basic Data Types Integers, float, double Real numbers Characters 1,2,3… 2.71828, 3.14159… a,B,c…

6 Simplest C++ Program int main() { return 0; }

7 First Real Program (code) # include using namespace std; int main() { cout << “Hello Robot!” << endl; return 0; }

8 First Real Program (output)

9 C++ Datatypes int main() { // 32-bit integer int gear_teeth=16; // 32-bit real number float sensor_volts=11.6; // true/false bool target_acquired=true; … }

10 C++ Assignment gear_teeth = 32; gear_ratio = teeth1 / teeth2; num_rings += 4; should_deploy = false; count++;

11 C++ Decisions if (count == 13) { cout << “Count is 13”; } if (count == 14) { cout << “Count is 14”; } else { cout << “Count is NOT 14”; } if (current > 90) { cout << “Magic smoke may appear”; } else if (current > 60) { cout << “Motors are getting hot”; } else { cout << “Working as expected”; }

12 Tougher Decisions if (trigger == 1 && target == true) { cout << “FIRE!”; } if (fwd_limit == true || bkwd_limit == true) { cout << “Stop the motor!”; }

13 Relational Operators OperatorMeaning ==Equals (not the same as =) >Greater than >=Greater than or equal <Less than <=Less than or equal !=Not equal OperatorMeaning &&and (both must be true) ||or (either must be true)

14 Functions void drive_fwd() { drive_motor = 0.8; } float get_drive_cmd() { return joystick.GetY(); } float get_distance(float x, float y) { return sqrt( pow(targetX-x,2) + pow(targetY-y,2) ); }

15 Classes Kicker Drivetrain Arm

16

17 FRC Programming Process Drive the robot Determine something needs to change Change the C++ source code Compile the C++ source code Use the FIRST undeploy option to remove the old code Use the FIRST download option to download the new code Restart the robot

18 FRC C++ Architecture Core C++ Language C/C++ Standard Library WPILib (FIRST provided library) Individual team’s code

19 WPI Lib  WPI = Worchester Polytechnic Institute  WPILib = Helpful library that makes FRC programming much easier  WPILib Fully open and documented Rich set of classes to represent control of the robot

20 So How Do I Use the Joystick?  WPILib of course Class dedicated to the Joystick  Functions GetX() GetY() GetZ() GetTrigger() Many, many more

21 Robot Class Layout  Initialization Routines void RobotInit(void) { //Runs once and only once when the robot is initially turned on } void DisabledInit(void { //Runs when the robot enters disabled mode } void AutonomousInit(void) { //Runs when the robot enters autonomous mode } void TeleopInit(void) { //Runs when the robot enters teleoperated mode }

22 Robot Class Layout  Periodic Routines void DisabledPeriodic(void { //Runs in a loop while in disabled mode } void AutonomousPeriodic(void) { //Runs in a loop when in autonomous mode } void TeleopPeriodic(void) { //Runs in a loop when in teleoperated mode }

23

24 WPILib Documentation  http://first.wpi.edu/FRC/frcupdates.html http://first.wpi.edu/FRC/frcupdates.html  \docs\extensions\FRC\ Starting a new robot project ○ GettingStartedWithC.pdf WPI Overview ○ WPI Robotics Library User’s Guide.pdf Class Documentation and Functions ○ WPILib C++ Reference.chm (Bible for FRC)

25 Teaching New Students C++  “C++ for Everyone”, by Cay Horstmann, 2 nd Ed, 2010, Wiley. ISBN 978-0-470- 92713-7.  C++ Tutorial: http://www.tutorialspoint.com/cplusplus/i ndex.htm http://www.tutorialspoint.com/cplusplus/i ndex.htm  http://www.learncpp.com http://www.learncpp.com

26 Additional Questions  Email us:  Hugh Meyer hmeyer@meyermat.comhmeyer@meyermat.com  Jon Cardwell jondcardwell@gmail.comjondcardwell@gmail.com


Download ppt "Jon Cardwell Red Alert Robotics Team 1741 October 24, 2015."

Similar presentations


Ads by Google