VEX EDR Intro. Connect and program the Cortext controller to use the bumper switch Pro Preview

  • #362
  • 27 Apr 2017
  • 6:34

English

Let's connect the bumper switch to the cortex controller and implement a few programs to it. Where the first program will be moving forward until the robot hits something. Now it moves forward until I press the bumper switch.

The bumper switch has a cable and this cable must be connected to the digital input of the controller. Right here on the left side of the controller we have analog and digital inputs. And I'll connect the bumper switch to digital input 1. We just pull on this part and connect

in the following way. Now the bumper switch is connected to the cortex controller. We then implement the program and we're ready to start it. Let's go and see how we implement the program. In the software we have to configure the touch sensor and we go to 'Motor and Sensor Setup', then we have the motors in the motors tab configured and in the 'VEX Cortex Digital Sensors' on port 1 because we've connected it on port 1 we add a touch sensor. And for this touch sensor we give the name 'touchsensor'. 'OK'. In the program what we have done previously is just moving forward with these instructions. Motor on port 2 and port 3 just move forward. Now what we want to do is to execute these two lines while[sensor is touched] And if the sensor is not touched

then we just set motor on port 2 to equal power 0 and motor on port 3 to equal power 0. It is not actually possible to do this program in this way because the structure of the language is different but it's very very similar. And that's the main idea. While the sensor is touched execute these two lines, move forward. If the sensor is touched then execute these two lines. There's such a structure in the language called 'while loop'. And it basically works in the following way. While this condition is true these two lines will execute. If the condition is not true then the loop will end and line 14 will be executed. What we should check is: Is the sensor touched? So we have a function in the language called 'sensor value'. We're getting the value of the sensor, touch sensor. And if the value of the touch sensor is equal to 0 then we execute line 10 and 11. So, while sensor value is 0 this means while the sensor is not touched. Then we execute 10 and 11. Sensor value is a function, that's a function coming from the language and this function does the following thing. If the sensor is touched, it'll return something that is different from 0. If the sensor is not touched, then this function will return just 0. This here is the equal sign. This operator checks if this value is equal to 0. And that's the program. So, while the sensor value is 0 which means that the sensor is not touched we move forward. And if the sensor is touched, we finish the loop. This means it is touched and we just set the values for the two motors to 0, the power of the motors and they stop. That's basically the program. Again, we have a structure in the language called 'while loop'. This loop executes its body while this condition of the loop is true. And this condition of the loop is true in our case if the value of the sensor is 0. And the value of the sensor is 0 if the touch sensor is not pressed. When the touch sensor is pressed this whole condition is no longer true, it is false and this whole loop will end and when the loops end we have line 14 and line 15 executed. This is a very very standard struction in most programming languages. To do a 'while loop' in this way. When I now start the robot it will move forward while the sensor is not pressed.

Again.

And one more time.

Take this program, try to implement it, download it to the robot and experiment with your robot.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for VEX EDR introductory course
  • 43
  • 69:49
  • 0