1 / 34

What is RobotC?!?!

What is RobotC?!?!. Team 2425 Hydra. Overview. What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework Assigning values Variables What is logic? Sensors. What is RobotC. Computer programming language

cheryl
Download Presentation

What is RobotC?!?!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What is RobotC?!?! Team 2425 Hydra

  2. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework Assigning values Variables What is logic? Sensors

  3. What is RobotC Computer programming language A way for humans to easily tell machines what to do Converts understandable “words” into machine (or binary) code A text-based form of C specially crafted for use with robots

  4. What is RobotC Used For Tele-operated programs Autonomous programs Used for the FIRST Tech Challenge (along with LabView) Used for the Vex Robotics Competition (along with EasyC)

  5. What You Need to Program a Robot in RobotC Robot with a microcontroller that can be programmed in RobotC A computer A driver for your robot (allows your computer to talk to the robot) A way to connect your microcontroller to your computer (USB, Bluetooth, etc.) A RobotC compiler compatible with the type of microcontroller you are using

  6. What is a Compiler? Basic Concepts You “write” your RobotC as a text document Robots can only understand a file written in binary code Writing in binary is time consuming and difficult Writing in RobotC is easy because it lets you use words and symbols instead of 1’s and 0’s

  7. What is a Compiler? A compiler is what converts your RobotC text file into a binary executable file What you downloaded from RobotC.net is actually called and Integrated Development Environment (IDE) Allows you to write code Checks code for errors Converts code Downloads code

  8. How a Robot Program Works Line 1 Line 2 Line 3 Line 4 Line 5 Line 1 Line 2 Line 3 Line 4 Line 5 Follows a linear model (like a list of instructions) Code is written like a book Reads left to right Top to bottom Chronological order Every line of code represents a new instruction. The robot will do EXACTLY what each line of the code says when it reaches that point of the program

  9. Framework Pragma statements Void tasks Task main Initializations Logic Declarations Void tasks Pragma statements Tasks (task main) Initializations Logic Declarations Open “v1”

  10. Starting Your Program Plan out how you want your program to work Open the autonomous template file Write your pragma statements using the “Motor and Sensor Setup” button in the “Robot” tab Setup your “TETRIX Controllers” Setup your “Motors” Setup your “Sensors”

  11. Task Main First part of the code you write After the pragma statements are read, the microcontroller jumps to the “task main” First part of the code the microcontroller “executes” Usually the main part of your code Can be as simple as one declaration or as complex as a having numerous logic statements

  12. Assigning Values Objective: Make an NXT motor spin Steps: Create a new file called “helloworldv1” Set up the pragma statements with no Tetrix controllers and one NXT motor called “motorA” Create the task main by typing: task main() { }

  13. Assigning Values Steps: Go inside the “task main” Type (will be explained later): while(true) { } Assign a value to the motor inside the loop: motor[motorA] = 100; Select “Compile Program” from the “Robot” tab Test the code

  14. Assigning Values Now that we have a functional program, lets examine what we have written. Task main The phrase “task main” is specific name that tells the microcontroller that what is contained within its brackets is the main part of the code and where the microcontroller should start. It is followed by (). This specifies what information is imported into this task, which is not important since no information is imported to the main task () is followed by {}. These indicate what is contained in the task main.

  15. Assigning Values Assigning the value of the motor The phrase “motor[]” specifies that you are assigning a value to a motor. Since “motorA” is written inside the [], you are assigning a value to the motor named motorA. The “=“ tells the microcontroller that the whatever comes before the = will be set equal to what follows the =. Motor values can range between -100 and 100 with 0 meaning the motor is not moving. The line ends with a “;”. All lines end with a ; except for logic statements. (If you forget, the compiler will usually catch this error)

  16. Variables A variable is something within a program that can be assigned a value, have its value recalled, and have its value changed. Think of a variable like a bucket, what you put in stays there until you change it. Like in math, they can be single letters They can also be words Values for motors act like variables

  17. Types of Variables bool – boolean variable: a conditional variable which holds a numerical value of 0 or 1, with 0 for no and 1 for yes (1 byte) byte – byte variable: holds numerical values with no decimal place from 0 to 255 (or -127 to 127 if signed) (1 byte) short – short variable: holds numerical values (2 bytes) char – character variable: holds a sing;e character of text (2 bytes)

  18. Types of Variables int – integer variable: holds numerical values with no decimal place (4 bytes) double – 2 decimal point variable: holds numerical values with two decimal points (all doubles have two decimal places, even if they are .00) float – floating decimal point variables: holds numerical values with almost any number of decimal points string – string variable: holds a text value

  19. Using Variables Before a variable can be used, it must be initialized, or declared. This can be done form within the task main To declare a variable, write the type of variable, followed by the name of the variable Once declared, a variable can be assigned a value by typing the name of the variable, followed by an =, and then the value. You can also assign a value to a variable at the same time that you declare it by writing the type of variable, the variable name, an =, and the variable’s value.

  20. Using Variables Objective: Make an NXT motor spin based off of the value of a variable Steps: Create a new program called “hellloworldv2” Set up the pragma statements with no Tetrix controllers and one NXT motor called “motorA” Create the task main (everything from here will be done within the task main) Create an infinite while loop by typing: while (true) { }

  21. Using Variables Create an integer variable called “speed” outside the while loop: int speed; Assign “speed” a value of 50 inside the while loop : 50 = speed; Set motorA equal to “speed”: motor[motorA] = speed; Compile and test the program

  22. Using Variables Why didn’t this work? You wrote “50 = speed;” You cannot assign “50” a value of “speed”, you can only assign “speed” a value of “50” Note that the value of the motor can be easily assigned to an integer variable Now lets try using the “Variables” debugging window. It can be found under “Debugging Windows” under the “Robot” tab

  23. What is Logic? Logic is the way that your program makes decisions. Expressed in logic statements Controls the flow of the program Parts of a logic statement: Identifier (type of logic statement) Condition (the question asked that determines if the body of the logic statement is executed) Body code (the code executed if the conditional statement is found to be true)

  24. Logic Statements while – the program will constantly repeat the lines of code contained within this statement until the condition is no longer valid if – if the condition is satisfied, the program will execute the code contained within the “if” statement else if – if the “if” condition is not satisfied and the “else if” condition is, the program will execute the code contained within the “else if” statement else – if the “if” and “else if” conditions are not met, the program will execute the code contained in the “else” statement

  25. Conditions A condition is a test comparing one thing to another. There are several comparison operators used in conditions A == B – Is A equal to B? A > B – Is A greater than B? A >= B – Is A greater than or equal to B? A < B – Is A less than B? A <= B – Is A less than or equal to B? A != B – Is A not equal to B?

  26. Conditions You can also put multiple conditions in one logic statement using these operators: && - And || - Or You can use parenthesis just like you do in math to set the order in which things are conducted.

  27. Examples if (A == B) { hi } else if (A != B && A != 0) { good bye } else { ? }

  28. What is Logic? Objective: Make an NXT motor spin if a variable equals 4 or 5. Steps: Create a new program called “hellloworldv3” Set up the pragma statements with no Tetrix controllers and one NXT motor called “motorA” Create the task main (everything from here will be done within the task main) Create an infinite while loop by typing (everything from here is in the while loop: while (true) { }

  29. What is Logic? Create an integer variable called “x” with a value of 50 Create an if statement with a condition that checks if “x” is equal to 4 or 5: if (x == 4 || x == 5) { } Set motorA equal to 100 inside the if statement. Compile and test the program

  30. What is Logic? Why didn’t the motor stop spinning when the value was changed? We forgot the “else” statement Underneath the if statement, add: else { motor[motorA] = 0; } Try the program again

  31. Sensors Sensors find information about the robot’s surroundings Their values can be put into variables and used for logic statements In FTC, most of the sensors return a numerical value to the microcontroller Sensor values are updated many times per second, so remember that they will change quickly when a robot starts to move

  32. Sensors Objective: Make an NXT motor spin if a touch sensor is pressed. Touch sensors return two possible values, “0” for depressed and “1” for not depressed Steps: Create a new program called “hellloworldv4” Set up the pragma statements with no Tetrix controllers, one NXT motor called “motorA”, and one touch sensor called “touch”. Create the task main Create an infinite while loop by typing: while (true) { }

  33. Sensors Create an if statement with a condition that checks if “touch” is equal to 1: if (SensorValue[touch] == 1) { } Set motorA equal to 100 inside the if statement. Add an “else” statement which sets the motor value to 0. Compile and test the program

  34. That is everything you need to know to start writing RobotC programs! (I hope you aren’t too confused)

More Related