

This is a perfect example of a simple drive code. For drive code, it is best to program using the channels. Our motors take in a speed value that can be any number from 127 to 127; this means that we could control one wheel or one side of a robot just using Channel 3 of our joystick controller. For example, vexRT(Btn7U) or vexRT(Btn8L) will return boolean values (true when pressed and false when not); vexRT(Ch3) will return a number from 127 to 127 when the left joystick is moved in the vertical direction. In ROBOTC, we can call on the values of these buttons and channels using vexRT(Channel # or Button label). The VEX controller below shows number labels for each channel (stick) or button.
ROBOTC JOYSTICK CODE
The simplest form of drive code is to have the drive motors receive a speed value from the VEX joystick controller. Drive code and any other code that involves you using the controller to make your robot do something belongs in this section.Īll motors work by taking in a number that corresponds to a speed value; that speed determines how quickly the motor rotates. Since you want to drive your robot, the drive code needs to be written in the usercontrol section. Now that our motors have been configured, you can write some drive code. You never know what will happen and ROBOTC does not save files after a crash. One important reminder when working on a computer is to save early and save often. Also, the motor controlling the left wheels of this robot has been reversed since it faces the motor that controls the right wheels.


Note that the sensor type for motors is almost always tmotorNormal. These #pragma lines should look similar to yours once your motors have been configured. Selecting the option for reversed will cause that motor to spin in the opposite direction which is necessary when you have to motors facing one another. Here you can name each of your motors according to their function and you can identify them as motors to ROBOTC (make sure that the port# indicated is the same as the one on your VEX cortex). You should see a new window open that looks similar to the one below. While you could type out a #pragma lines for every motor, it is much easier to go the Robot menu and select "Motors and Sensors Setup". A #pragma line typically looks like this: #pragma config(Sensor, Port#, Name, SensorType, openLoop). In ROBOTC, this is accomplished by using the #pragma lines at the very beginning of the document. Before we can even start writing drive code, we need to identify all of our motors and distinguish one from another. Motors are a very important part of any robot; they allow us to drive, intake, lift, etc. Once you have your blank Competition Template, you are ready to get started. We will look at each of these sections in detail later. As you can see in the image below, ROBOTC will automatically write #pragma and #include lines for you and then create three sections for pre_auton, autonomous, and usercontrol. The Competition Template is a template for how you must structure your code for participation in VEX competitions. When you click on File and look under New you will see an option for "Competition Template". The first thing you will want to do when you open ROBOTC is make a new document. This guide to ROBOTC focuses on version 3.05 of ROBOTC for Cortex and PIC and we use a VEX Cortex and a VEXnet Joystick controller.
ROBOTC JOYSTICK HOW TO
Knowing how to program in ROBOTC is essential for participating in VEX Robotics Competitions. ROBOTC is a Cbased programming language that is used to create and execute programs for VEX and Lego Mindstorms.
