1 / 37

VEX and Robot C: Natural Language Programming

An introduction to natural language programming in Robot C for VEX robots, which simplifies coding and makes programming tasks easier. Learn about basic output programming, behavior-based programming, VEX motion subsystem, programming with sensor feedback, while loops, if statements, and if-else statements.

jwitcher
Download Presentation

VEX and Robot C: Natural Language Programming

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. VEX and Robot C Presented by Chris Patterson Modified by J. Andazola

  2. Robot C and Natural Language

  3. Natural Language In short, Natural Language is a form of C based programming that cuts down on coding and makes things a bit simpler.

  4. Natural Language Example 1 • For Example, • What do you think startMotor(rightMotor, 127); does?

  5. Natural Language - Until Example 2 • For example, what might you expect the following to do? untilTouch(bumpSwitch); startMotor(leftMotor, 63);

  6. EXAMPLE 3

  7. Example 3 • A motor turns on once the bump switch is touched and then turns off once the limit switch is touched.

  8. Basic Output Programming EXAMPLE 4 • Let’s turn on the rightMotor for 4 seconds and then off for 4 seconds. Repeat this operation twice.

  9. Basic Output Programming – Example 4

  10. Basic Output Programming

  11. Basic Output Programming – Example 5 • Turn on a motor and then wait 5 seconds. Set servo to position 127 for 3 seconds and then position 96 for 4 seconds.

  12. EXAMPLE 5 • A motor turns on clockwise at full power when the potentiometer is greater than 3000 and turns counterclockwise at full power when the potentiometer is less than 2000.

  13. Example 5

  14. Example 6 - What will this program do?

  15. Basic Output Programming – Example

  16. Natural Language - Until • The program will wait at the “Until” line of code. Once the condition for that sensor is true, the program continues.

  17. Behavior-Based Programming • A behavior is anything your robot does • Turning on a single motoror servo • Three main types of behaviors • Complex behaviors – Robot performs a complex task (automated fan control) • Simple behaviors – Simple task performed by the robot (fan stops when sensor activated) • Basic behaviors – Single commands to the robot (turn on a motor) • Complex behaviors can always be broken down into simple behaviors, which are then broken down into basic behaviors

  18. VEX Motion Subsystem – Servos • Similar in appearance to the 3-wire motor • Very different in operation • Rotates between 0 and 120 degrees • Motor is set to a “power value” • Servo is set to a “position value” • -127 = 0 degrees, 0 = 60 degrees, 127 = 120 degrees, etc. • Natural Language command • setServo()

  19. Programming with Sensor Feedback

  20. VEX Sensors Subsystem • Digital Sensors: -Bumper Switch -Limit Switch -Optical Shaft Encoder -Ultrasonic Range Finder • Analog Sensors: -Light Sensor -Potentiometer -Line follower

  21. While and If-Else Loops

  22. While Loops • While loop is a structure within ROBOTC • Allows a section of code to be repeated as long as a certain condition remains true • Three main parts to every while loop • The word “while” • The condition • Commands to be repeated

  23. The Condition • Condition controls how long or how many times a while loop repeats • When condition is true, the while loop repeats • When condition is false, the while loop ends and the remainder of the program executes • Condition is checked once every time loop repeats before commands between curly braces are run

  24. Revisit Example 1 EXAMPLE 1 • Let’s turn on the rightMotor for 4 seconds and then off for 4 seconds. Repeat this operation twice. • Instead of running it twice, let’s loop it continuously. (running it twice would require a variable, and we aren’t there quite yet)

  25. While Loops – Example 1 Revisited

  26. While Loops • The while loop has a true condition so it will always run. If the condition is always true, you cannot leave the while loop. • While loops can be based on a sensor condition as well. For example:

  27. While Loops – Using a sensor condition

  28. While Loops – Using Multiple Conditions

  29. While Loop – Timers as Conditions Timer T1 is used as the condition for the while loop, which will run for 30 seconds

  30. If Statements • If statement in the program is evaluated by condition contained in parentheses • If condition is true, commands between braces are run • If condition is false, those commands are ignored • Very similar to how a while loop works, but does not repeat the code

  31. If-Else Statements • If-else statement is an expansion of if statement • If checks condition and runs appropriate commands when it evaluates to true • Elseallows code to run when condition is false • Either ifor elsebranch is always run once

  32. If Statements Example

  33. Let’s revisit Example 4 • A motor turns on clockwise at full power when the potentiometer is greater than 3000 and turns counterclockwise at full power when the potentiometer is less than 2000

  34. Example 4 – While loop and If-Else Statements

  35. This is just the beginning… • You have been given enough tools to go out and EXPLORE on your own time. • Use the lessons in the PLTW curriculums to try out some of the activities and projects.

  36. Questions?

More Related