Presentation is loading. Please wait.

Presentation is loading. Please wait.

Testbed: Exercises.

Similar presentations


Presentation on theme: "Testbed: Exercises."— Presentation transcript:

1 Testbed: Exercises

2 Be Mindful / Not Random! (be a thinker not a tinker)
There are a lot of variables when it comes to programming [ variables hinder troubleshooting ] If you are not mindful of what you do or don’t do, I cannot systematically help you eliminate variables. [ IDK, I think so = frustration for you ] If we can not limit the variables, I cannot help you solve your problem in a timely manner If I cannot solve your problem in a timely manner, I will need to move on to the next group

3 Safety Keep long hair clear of your testbed, especially your gears!
No plugging or unplugging of anything with the power on! – Turn-off the Cortex 1st!! You could get shocked and have to pay for anything you damage (intentional or not)

4 Check your Cortex - Properly inserted plugs?
Parallel to top and bottom edges White wire towards the middle

5 Are you ready to program your testbed?
If you followed your packet, your software should be set-up, now check your hardware: Hardware Checklist: properly inserted plugs into the cortex (white wire to the middle as shown on the last slide) two motors with motor controllers plugged into motor ports 2 & 3 (red to red & black to black as shown on the next slide) limit switch & bump switch in digital ports 1 & 2

6 Connecting the Motors Two-wire motors can be plugged directly into MOTOR ports 1 & 10 on the Cortex, and 2-9 using the Motor Controller 29 – red to red, black to black

7 FYI - VEX Motors 2 Types (labeled on motor):
2-wire motor 269 Newer 2-wire motor 393 Review All motors have the same values between 127 (full forward) and -127 (full reverse)

8 Practice Exercise Copy the code on the next slide into your RobotC file Trainer Notes: This slide is meant to be a class activity, for trainees to actually get some guided experience with the ROBOTC interface, ROBOTC Commands, Cortex system, ect. The steps should be: Open ROBOTC Verify the Platform Type is set to Cortex Natural Language Lilbary Create the Program Connect the Cortex to the Computer (via USB or VEXnet) Turn on the Cortex Go to Robot > Compile and Download Program Run the program – Observe the testbed Turn on Motor Port 3 in the program, after Motor Port 2 and before the wait command Compile and Download the Program Run the Program – observe the testbed Talk about the testbed design, how the motors are mirrored images of one another – even though you gave them the same motor power, they turn in opposite direction. This is something common on actual robots, where they mirror one another. In ROBOTC, us the Motors and Sensors Setup to reverse the appropriate Optional – rename the motors in the Motors and Sensors Setup Download and run the program – observe the motors spinning in the same direction.

9 Practice - Motor for 5 Seconds

10 Running a Program Choose Robot, compile and download, and start

11 How it works The next series of slides explain what is happening

12 Motor for 5 Seconds PRAGMA – generates from motors & sensors setup
Displays configuration changes from the Motors and Sensors Setup Defines the “main task” of the robot All commands belonging to task main must be in-between these curly braces

13 Motor for 5 Seconds Turns the port2 rightMotor on at half power forward

14 Motor for 5 Seconds Causes the robot to wait here in the program for 5.0 seconds

15 Motor for 5 Seconds End Result: rightMotor spins for 5.0 seconds.
Stops the port2 rightMotor. End Result: rightMotor spins for 5.0 seconds.

16 Modify the code from the practice activity so it works for the 1st programing exercise on the next slide.

17 Motor Exercises [1 of 6] Turn the rightMotor on forward at half speed for 5 seconds, then stop. Turn the leftMotor on in reverse at three-fourths speed for 2.5 seconds, then stop. Turn both motors on at full power, and spinning in the same direction, for 7.25 seconds, then stop. Trainer Notes: Recommend that trainees name their finished programs by the title of the slide, including the number and whether it was a group or individual activity. This will help them refer back to the code later. Teacher initial ____________

18 Basic Programming: Until Commands

19 Touch Sensors Touch Sensor Check How they work Two Types
Plugged into Digital 1 & 2 How they work Digital sensor - Pressed or Released 1 = pressed 0 = released Two Types Limit Switches Bumper Switches A very brief wait can be inserted after touch sensor related commands to reduce the bouncing effect: ( bumpSwitch ) ;

20 Use a combination of the practice code from earlier and the bumpswitch code on the last slide to complete the programing exercise on the next slide

21 Bump Switch Exercise [2 of 6]
Exercise: Program the rightMotor to turn on at half power, until the bump switch is pressed. The motor should then stop.

22 Use your limit switch to complete the exercise on the next slide
Instead of bumping the bumpSwitch, your are bumping the limitSwitch

23 Limit Switch Exercise [3 of 6]
Wait for the limit switch to be touched before the right motor turns on at half power for 5 seconds, then stops. Wait for the limit switch to be touched before both motors turn on at half power, until the sensor is bumped again. Both motors should then move in reverse at half power for 3.5 seconds. Discuss how the limit and bump switch would be used for Grandmas Chair, Toll booth, Sign, Tekrocks Bridge

24 VEX LED Plugged into DIGITAL Port 12 (with an extension see next slide) Set as “VEX LED” Red, Green, and Yellow colors available

25 VEX LED Connect the LED to the PWM Extension wire.
Turn-off the cortex! – no plugging or unplugging of anything with the power on! The outer terminal on the LED should be plugged in on the white wire. The center terminal on the LED should be plugged in on the red wire. The black wire should have nothing connected.

26 Decision Making: While Loops and Boolean Logic

27 While Loops A while loop is a structure within ROBOTC which allows a section of code to be repeated as long as a certain condition remains true. There are three main parts to every while loop.

28 1. The word “while” Every while loop begins with the keyword “while”.

29 2. The Condition The condition controls how long or how many times a while loop repeats. While the condition is true, the while loop repeats; when the condition is false, the while loop ends and the robot moves on in the program. The condition is checked every time the loop repeats, before the commands between the curly braces are run.

30 3. Commands to be Repeated
Commands placed between the curly braces will repeat while the (condition) is true when the program checks at the beginning of each pass through the loop.

31 The Truth About while() Loops

32 1. while() Loops do NOT Constantly Check their Conditions
while() loops check their conditions before running the body of code After the body of code is run, the while() loop checks the condition again The condition is NOT checked while the body of code is being run

33 2. while() Loops do NOT Keep Programs Running Forever
Exception: Infinite while() loops example “while (1 == 1)” or “while (true)” Once the while() loop’s condition is met/false, the robot moves past the while loop in the program and does not revisit it Students often assume that because there is a while() loop in the code, the program keeps on running

34 3. while() Loops are a Programming Structure, not a Command
They do not get a semicolon (;) after the condition Adding a semicolon will cause the while() loop to constantly check the condition, without running the body of code

35 4. All “until” commands in the NL are actually while() loops
All “until” commands are just a while() loop with a wait command, to hold the “Program Flow” at that spot in the code

36 Modify the code on the previous slides to complete the exercise on the next slide

37 While Loop Exercise 1 [4 of 6]
Example: Program the greenLED to repeatedly turn on for 2 seconds, then off for 2 seconds, while the limit switch isn’t pressed. So pressing the limit switch will stop the led from flashing Trainer Notes: Recommend that trainees name their finished programs by the title of the slide, including the number and whether it was a group or individual activity. This will help them refer back to the code later.

38 Timers More loop control please? Solution: Timers
Question: Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time? Answer: Nowhere! We need something else. Solution: Timers Can be thought of as internal stopwatches (4 available) Timers should be “cleared” anytime before they are used Watch where you clear them!

39 Timers In the program below, timer T1 is used as the condition for the while loop, which will run for 30 seconds: [bumpSwitch] == 1)

40 While Loop Exercise 2 [5 of 6]
Program the greenLED to repeatedly turn on for 0.5 seconds, then off for 0.5 seconds, while less than 5 seconds have elapsed. Trainer Notes: Recommend that trainees name their finished programs by the title of the slide, including the number and whether it was a group or individual activity. This will help them refer back to the code later.

41 If Statements When your robot reaches an if Statement in the program, it evaluates the condition contained between the parenthesis. If the condition is true, any commands between the braces are run. If the condition is false, those same commands are ignored. Very similar to how a while loop works, but does not repeat the code!

42 If-else statements The if-else Statement is an expansion of the basic if Statement. The “if” section still checks the condition and runs the appropriate commands when it evaluates to true Using the “else” allows for specific code to be run only when the condition is false. Either the “if” or the “else” branch is always run; no more, no less.

43 If-else if Exercise 1 [6 of 6]
Program the greenLED to turn on if the bumpswitch is pressed, and off if it’s released. Loop Forever. .


Download ppt "Testbed: Exercises."

Similar presentations


Ads by Google