Block Programming 2 Agenda 1 What is Block

Block Programming

2 Agenda 1. What is Block Programming 2. Getting Started 3. Pairing Android Phones 4. Connecting Your Laptop to Block Programming Mode Server 5. Block Programming Layout 6. Creating Your First Teleop 7. Adding Telemetry 8. Saving Our Op Mode 9. Creating Your First Autonomous 10. Block Programming Resources 11. Q & A 12. Extra

3 What is Block Programming

4 What is This? … 200 more lines

5 What is FTC Block Programming? ● ● The FTC Blocks Programming Tool is a user-friendly program that is operated by the Robot Controller phone. A user can create custom op modes, or programs, for their robot using the Block Tool and save these op modes directly onto the Robot Controller. Users drag and drop jigsaw-shaped programming blocks onto a “canvas” and arrange these blocks to create the program logic for their op modes. The FTC Blocks Programming Tool is powered by Google’s Blockly software and was developed with support from Google.

6 Getting Started

7 Getting Started (Modern Robotics System) ● ● You will need to have two FIRST-approved Android smartphones for the control system. One phone will be used as the Robot Controller, the other will be used as the Driver Station. Each phone must have a unique name. This will ensure that your phones will be communicating with each other rather than other teams’ phones at meets and tournaments. All phones are required by FTC to be changed in the Wi-Fi direct setting to be identifiable. ○ For example your team number is 1234 your Robot Controller phone should be named “ 1234 -RC”. The driver station phone should be named “ 1234 -DS”. Example of Wifi renaming screen.

8 Installing FTC Apps ● ● ● The FTC apps are available to download for free from the Google Play store. You will need to have both Android phones connected to a Wi-Fi network that has Internet access before you can access the Google Play store. You will need a Google account to be able to download the apps. Once you have made a Google Play Account in the search window of the Google Play app, type in the words “FTC Robot Controller” to find the Robot Controller or “FTC Driver Station” to find the appropriate FTC app for your phone. Install the appropriate app for each phone. Once installation is complete disconnect both phones from the Wi-Fi network.

9 Pairing Android Phones

10 Pairing Driver Station and Robot Controller ● ● Look for the Airplane mode icon and if the icon is not activated, touch the icon to put the phones into airplane mode. Placing the phone into airplane mode will turn off the Wifi connection. If the Wifi icon has a diagonal line through it, then the Wifi connection is disabled. You will need to touch the Wifi icon on the configuration screen to turn it on. Airplane Mode and Wifi are deactivated here Here our Wifi is enabled and so is our Airplane Mode.

11 Phone Pairing (Continued) ● ● ● Launch the Robot Controller phone and the Driver Station phone. ○ Verify that the Robot Controller app is running. The Robot Status field should read “running”. On the Driver Station phone tap the three vertical dots on the upper right hand corner of the main screen and select Settings. From the Settings screen, look for and select “Connect with Robot Controller”. Find the name of your Robot Controller from the list and select it. On the Driver Station phone return to the main screen. The first time you attempt to connect to the Robot Controller a prompt should appear on the Robot Controller screen. Click on the “ACCEPT” button to accept the connection request from the Driver Station.

12 Connecting Your Laptop to Block Programming Mode Server

13 Installation Requirements ● ● To be able to program using the blocks programming mode server, your laptop will need a Javascript-enabled browser. Google Chrome is highly recommended by FIRST as the Javascriptenabled browser for the FTC Blocks Programming Tool. Visit the Google Chrome website and follow onscreen instructions to download and install Chrome. ○ https: //www. google. com/chrome/browser/desktop/index. html

14 Connecting Your Laptop to the FTC Blocks Programming Mode Server ● ● You will need to put your Robot Controller smartphone into FTC Blocks Programming Mode. This allows the phone to become a Programming Mode server, and enables your laptop to connect to this server so that you can start creating your op modes. On the Robot Controller, touch the three dots in the upper right hand corner of the screen to launch the pop-up menu. Select “Programming Mode” to place the Robot Controller into Programming Mode main screen

15 Laptop to the FTC Blocks Programming Mode (Continued) ● ● The Programming Mode screen displays important information that you can use to connect your laptop to the FTC Blocks Programming Mode server. ○ Verify the network name and pass phrase for the Programming Mode’s wireless network. On your laptop look for the wireless network that matches the name displayed on the Robot Controller. Click on it to select it. When prompted, provide the network passphrase Information displayed on Programming mode screen to access server Connect your Laptop to the Block Programming Mode Server that matches the one displayed on the RC screen.

16 Launching The Block Programming Browser ● Launch the Javascript-enabled web browser on your laptop. Find the web address that is displayed on the Programming Mode screen of the Robot Controller. Type this web address into your browser to navigate to the Programming Mode web server. ○ Verify that your web browser is connected to the programming mode server. If it is connected to the programming mode server, the main FTC Blocks Development Tool project screen will be displayed. ● Press the “Create New Op Mode” button which should be visible towards the upper left hand corner of the browser window. When prompted, specify a name for the op mode and hit “OK” to continue.

17 Block Programming Layout

18 Block Programming Browser Layout ● ● ● On the left-hand side of your browser’s screen contains a list of categorized, color coded programming blocks. If you click on a category, the browser will display a list of available programming blocks related to the topic of that category. ○ For example clicking on the actuators drop down will open up options for DC Motors and Servo controls. The right-hand side of the screen is where you drag and arrange your programming blocks on the “canvas” to create the logic for your op mode.

19 Creating Your First Teleop

20 Creating Your First Teleop Op. Mode ● ● When you first create a new op mode, there should already be a set of programming blocks that are placed on the design canvas for your op mode. The main body of your op mode will defined by the outer purple bracket that has the words “my. First. Op. Mode” at the top. This name can be different depending on what is the name of your op mode program. All your teleop blocks will be placed inside of this. You can find this in the purple Functions tab.

21 ● ● Before you can start giving commands to the robot, you need to define how many motors you have and identify them with a name. We will identify four motors for this Op. Mode. ○ Since we have four motors facing in towards each other, we’ll need to identify in initialization that two motors will be reversed. You can find the blocks for this under the actuator-DCMotor tab. The blue block is our comment box. You can type anything in here to help you.

22 ● ● Once you have initialized and set your motor directions. Next, you’ll need to tell your program to “wait. For. Start”. You can find this command in the Linear. Op. Mode tab. This tells the program that it can not run the program any further until the play button on the Driver Station is pressed. Any programming blocks that are placed before “call My. First. Op. Mode. wait. For. Start” block will be executed when the op mode is first selected by a user at the Driver Station. Any code after the “call My. First. Op. Mode. wait. For. Start” block will get executed after the Start button has been pressed.

23 ● ● Once we have pressed play, we need to enter into a “while loop” to execute our teleop commands. Any blocks that are placed after “call My. First. Op. Mode. wait. For. Start” and before the green block labeled “repeat while call My. First. Op. Mode. op. Mode. Is. Active” will be executed sequentially by the Robot Controller after the Start button has been pressed. The green block labeled “repeat while call My. First. Op. Mode. op. Mode. Is. Active” can be found in the Linear. Op. Mode tab. Once the user presses the Stop button, the “call My. FIRSTOp. Mode. op. Mode. Is. Active” clause is no longer true and the “repeat while loop “ will stop repeating itself.

24 ● ● ● In our teleop we want to put all control blocks for driving in our “while loop”. Here we state which motors we want to control and with which gamepad controls. ○ In this example we’ll use the joysticks to control our motors. In a standard tank drive control we allow the left joystick to control the left motors and the right joystick to control the right motors. ○ Notice the gamepad values are set to negative. This is because joysticks have a range of -1 to 1 however pushing the joystick up produces a negative value. We want to use a negative value on the joystick to cancel out this negative.

25 Adding Telemetry

26 Adding Telemetry ● ● ● Your op mode is just about ready to run. You can chose to add a couple of telemetry statements that will send information from the Robot Controller to the Driver Station for display on the Driver Station user interface. This telemetry mechanism is a useful way to display status information from the robot on the Driver Station. Telemetry can be used to display sensor data, motor status, gamepad state, etc. from the Robot Controller to the Driver Station. The telemetry block can be found under the category Utilities. ○ For this example we want to keep track of how much power our back motors are receiving we chose “call telemetry. add. Data” block that has a key and number input. The key is the name of what will be displayed on the driver station. The number is what we are keeping track of.

27 ● ● Data that is added to the telemetry buffer will not be sent to the Driver Station until “telemetry. update” is called. Here we are keeping track of the power given to the two back motors.

28 Saving Our Op. Mode

29 Saving Our Op. Mode ● ● After you have modified your op mode, it is very important to save the op mode to the Robot Controller. Press the “Save Op Mode” button to save the op mode to the Robot Controller programming mode server. If your save was successful, you should see “Save completed successfully” in green letters next to the button. ● If you receive an error message indicating that the “Save project failed. Error code 0” you might not be connected to the blocks programming mode server. Ensure that your Robot Controller Phone is in Programming Mode.

30 Creating Your First Autonomous

31 Creating your First Autonomous Op. Mode ● ● Like teleop , our autonomous will be defined within the purple bracket that has the words “run. Op. Mode” at the top. This name can be different depending on what is the name of your Op. Mode program. We have to define that this is an autonomous program. Below our save Op. Mode selection we need to select autonomous.

32 ● Our next step is to define how many motors are in use, and identify them with a name. We will identify four motors for this Op. Mode. ○ We have to remember to reverse two of the motors when placing our blocks to be initialized.

33 Moving Forward with Encoders ● ● In this example of autonomous we will move forward using encoders. ○ Encoder are used to measure the movement of the motor. We set a target position for each motor to allow for more precise movements. This is the alternative to running under time which can be less accurate for many factors. Before we can give a target position to our motors we have to declare we are using encoders on our motors when initialized. Each motor has to be set onto “Run. Mode. RUN_TO_POSITION”. This tells the motors that they will be given a target position to run to.

34 ● ● For motors to run the most accurate under encoders you have to reset each motor count back to zero. This must be done during the initialized section of your Op. Mode. To do this we call “Run. Mode. STOP_AND_RESET_ENCODER”. Our initialized of our Op. Mode should declare the direction motors are moving, are they using encoders, and the resetting of encoders.

35 ● ● ● Once you have initialized your motors, next we tell the program to “wait. For. Start”. Under this block we can start giving commands to our motors. The first command we want to run is set target position blocks. This is were we tell our motors how far they will be running.

36 ● Now that we have defined a target position, we need to define the power those motors will be running at. Motors can have a power in the range of -1 to 1. ○ Setting motors to a power of 0 will stop the motors from running. ○ Setting motors to a power of 0. 5 will run the motors with half power. ○ Setting motors to a power of 1 will run the motors with full power.

37 ● ● When running with encoders, we don’t want the motors to stop running until they have reached their set target position. In this case we want the motors to keep looping until they have reached their positions. We will make a loop that will keep running until one front motors has reached its position and one back motor has reached its position.

38 ● We need to tell our motors to stop running once they have reached their positions. This command is simply executed by setting all motors to a power of 0. This command will not be executed until we have completed the requirements from our loop we previously created.

39 Full Autonomous (No Mechanisms) Full Teleop (No Mechanisms)

40 Block Programming Resources

41 Resources ● ● ● FTC SOCAL Website http: //www. firsttechsocal. org/ Brain Stormz 10298 Website https: //ftc 10298. wordpress. com/ or email ftc 10298@gmail. com FTC Block Documents: Blocks Programming Training Manual https: //www. firstinspires. org/sites/default/files/uploads/resource_library/ftc/2017 -2018/blocksprogramming-training-manual-mr. pdf FTC Blocks Programming Training Manual: REV Robotics Expansion Hub Edition https: //www. firstinspires. org/sites/default/files/uploads/resource_library/ftc/blocksprogrammingtrainingmanual. pdf#page 42 Blocks Programming One Page Description https: //www. firstinspires. org/sites/default/files/uploads/resource_library/ftc/2016 -2017 -season/blocksprogramming-tool-onepager. pdf Blocks Video Tutorials https: //www. youtube. com/playlist? list=PLEu. Gr. Yl 8 i. Bm 4 A 4 yr. Rcat. Gc. K 7 q 0 od 0 LYov

Q&A

43 Extra ● Op. Mode- A set of code containing instructions for a specific robot behavior. ● Teleop- The 2 minute time period where the robot is operated by the drive team. ● Telemetry- The automated communications process by which data is collected at remote points and transmitted to receiving equipment for monitoring. ● Autonomous- The 30 second time period where the robot is pre-programmed to operate on its own.
- Slides: 43