How to Program the VEX IQ Remote Control

This lesson will go over how to program the robot using the remote control

This version of the remote control program will show you how to create a program that uses the left joystick to control the drive for the left side of the robot, and the right joystick for the right side of the robot. This type of remote control drive system is called tank style.

First, set up your motors by clicking on the motor and sensor setup button.

First begin by going into your motor and sensor setup and name your motors, for this activity the motors will be “name1” for the left motor and it will be in port 1 the other motor will be “name2” and will be in port2. Once you set up the motors RobotC will generate your initial setup code.

Whenever you see two backslashes, // ,  this usually signifies a comment. When you are programming there are two types of comments you can create, they are single line and block commenting. Single line comments will look like the following

Make sure you comment your code so that anyone can look at your code and get an idea of what you are trying to do. It is also useful for leaving notes for yourself. In this example the comment is used to let you know what the names of the motor represent.

Next, inside of the task main create a “threshold” value. This value will represent the minimum value you have to move the joystick before it starts moving your robot. This exercise will use 15 as a threshold. Enter the following inside of task main.

Next, below the threshold, create a “while loop” with the test condition as “true” it should resemble the following

The “while loop” will allow any code, written within the braces: { }, to run whenever the specified test condition is met. In this case our test condition is true what this means is that we want it always running. This will tell the robot brain that we want the specified to run all the time. This is because we want the brain to ALWAYS receive information from the remote control. More information on loops can be found here.

Now, inside the “while loop” we will need to create an if statement and place it in the appropriate location. This will help tell the robot when it should move. We’ll show you the set up for the left motor, you will have to program the right motor on your own.

Now that we have the if statement set up, we will work on creating the condition in order for the if statement to work. This is done by using the function  getJoystickValue() .

 

getJoystickValue( )

getJoystickValue( Part of the Remote that you are trying to call on);

  • Entries for this function when using the Joysticks can be any of the following  ChA, ChB, ChC, ChD this will vary depending on which Joystick you are using.
    remote-control
    functionsfortheremote
  •  Joysticks can range from {-100 to +100}  this will be useful when you start to program.
  • Buttons can only be read as the following 0 for not being pressed and 1 for being pressed

Inside of the “condition” portion we will set some rules in order for the robot to move. For this we are only looking at the Joystick and ChannelA.

screen-shot-2016-09-21-at-2-49-02-pm

For the rule, we are setting the constraints we want to set up will be the following.

  1. Only use Channel A
  2. It has to overcome our “threshold” value of both +15 and -15 in order for it to work

These rules will translate into the following and should be placed inside the condition portion of your code

Enter this into your if statement and your code should look like the following

Inside of the if statement we will manipulate the motor to move based on the value given from the remote. We will also include a number to help scale the value based on the number provided. This number is 1.29 and it will hel the motor reach its maximum speed when receiving numbers from the Joystick. The following code should be entered in the if statement.

setMotorSpeed(name of motor you want to move, speed of the motor from -129 to 129);

in the else statement set the motor to be 0 when it does not follow the rule.

Activity

Complete the code for the right motor, as well as using ChD. (hint: create another “if” and “else” statement to control the other motor)

Final Code