Programming

ROBOTC


ROBOTC is the premiere robotics programming language for educational robotics and competitions. ROBOTC is a C-based programming language with an easy-to-use development environment. Use the Moving Forward sample program below to quickly get your robot moving!

Download software: http://www.robotc.net/download/cortex/

Cost: 30 day trial; licenses start at $49

Instructions to setup software: Getting Started ROBOTC Wiki Guide

Requirements: PC

Operating systems supported: Windows XP Professional or Home Edition with SP 2 or greater

Difficulty level: 3 out of 5


TRY IT!

1. Before downloading a program to a VEX Cortex, make sure to set up the Cortex using the ‘Getting Started with a VEX Cortex (Wired)’ guide on the ROBOTC wiki.

2. Open the ROBOTC program by clicking on its icon.

3. Navigate to the ‘File -> Open Sample Program’ file menu.

4. Double click on the ‘Basic Movement’ folder.

5. Double click on the ‘Moving Forward.c’ program to open it in ROBOTC.

6. With the Cortex connected to the computer, click on the ‘Robot -> Compile and Download’ menu option to download the program to the Cortex.

7. Finally, either click the ‘Start’ button on the program debugger window that appears or unplug the Cortex and power cycle it (turn it off, then turn it back on) to run the program. Your robot should wait for 2 seconds, then move forward for 3 seconds, then stop.


ABOUT THE PROGRAM — A WALK THROUGH

1. ROBOTC programs are read by the compiler from the top to the bottom, left to right (just like reading a book).

2. The first two lines tell ROBOTC that there are motors plugged into motor ports 2 and 3 on the Cortex, and it gives the motor on port 2 the name of ‘rightMotor’, and the motor on port 3 the name of ‘leftMotor’. We can then use these names in the program to tell ROBOTC which motor we want to control.

3. Lines 3 to 26 are comments and are simply notes that the programmer can use to let others know what each line or segment of code does. This helps readability and allows others to understand the code, even if they were not the original authors of the program. Note that the // can be used to comment a single line of text, allowing comments to be placed right next to other lines of code.

4. Line 27 contains the ‘task main()’ declaration that is needed in every ROBOTC program; this tells ROBOTC where to start ‘reading’ code.

5. Lines 28 and 35 are curly braces, which tells ROBOTC where the code starts (line 28, with the { ), and where the code stops (line 35, with the } ).

6. Line 29’s ‘wait1Msec’ command tells ROBOTC to ‘keep doing what you were doing for 2000 milliseconds’, which can be converted to 2 seconds (2000 ms = 2 s). Since ROBOTC isn’t doing anything before the ‘wait1Msec’ command, this line tells ROBOTC to ‘do nothing for 2 seconds’.

7. Line 32 turns on the right motor with a power level of +127 (full power forward) and Line 33 turns on the left motor with a power level of +127 (full power forward). Both of these commands happen one after another and essentially happen at the same time.

8. Line 34 is another ‘wait1Msec’ command, which tells ROBOTC to ‘keep doing what you were doing for 3000 milliseconds’ (3 seconds). Since both motors are turned on, this line tells ROBOTC to ‘keep both motors moving forward at power level +127 for 3 seconds’.

9. Line 35 is a closing curly brace ‘}’, which tells ROBOTC to turn off the motors and stop the program. It stops all of the code that is in between the opening curly brace ‘{’ on Line 28.


TRY THIS

1. Change the amount of time the robot waits at the start of the program from 2 seconds to 1.5 seconds. How will this affect how far the robot moves?

2. Make the robot move at half power instead of full power. How far does the robot move compared to full power?

3. What happens when you give the robot a zero power level? What about a negative power level?

4. How would you make the robot turn in place, instead of moving forward?

5. Can you make the robot move forward, stop, then back up to its original location?


LEARN MORE

VEX Cortex Video Trainer — A video walkthrough on setting up and programming a Cortex with ROBOTC.

ROBOTC wiki -– The official ROBOTC wiki, containing information on all things ROBOTC.

ROBOTC Forums — The place to discuss ROBOTC code with the knowledgeable ROBOTC community.

Write a comment about “ROBOTC”

Nickname:

Type your comment:

  • 1. Safety. Do the following:
      a. Show your counselor your current, up-to-date Cyber Chip.
      b. Discuss first aid and prevention for the types of injuries or illnesses that could occur during programming activities, including repetitive stress injuries and eyestrain.

    2. History. Do the following:
      a. Give a brief history of programming, including at least three milestones related to the advancement or development of programming.
      b. Describe the evolution of programming methods and how they have improved over time.

    3. General knowledge. Do the following:
      a. Create a list of 10 popular programming languages in use today and describe which industry or industries they are primarily used in and why.
      b. Describe three different programmed devices you rely on every day.

    4. Intellectual property. Do the following:
      a. Explain how software patents and copyrights protect a programmer.
      b. Describe the difference between licensing and owning software.
      c. Describe the differences between freeware, open source, and commercial software, and why it is important to respect the terms of use of each.

    5. Projects. Do the following:
      a. With your counselor’s approval, choose a sample program. Then, as a minimum, modify the code or add a function or subprogram to it. Debug and demonstrate the modified program to your counselor.
      b. With your counselor’s approval, choose a second programming language and development environment, different from those used for requirement 5a and in a different industry from 5a. Then write, debug, and demonstrate a functioning program to your counselor, using that language and environment.
      c. With your counselor’s approval, choose a third programming language and development environment, different from those used for requirements 5a and 5b and in a different industry from 5a or 5b. Then write, debug, and demonstrate a functioning program to your counselor, using that language and environment.
      d. Explain how the programs you wrote for requirements 5a, 5b, and 5c process inputs, how they make decisions based on those inputs, and how they provide outputs based on the decision making.

    6. Careers. Find out about three career opportunities in programming. Pick one and find out the education, training, and experience required. Discuss this with your counselor and explain why this career might be of interest to you.

  • Earning the Cyber Chip can help you learn how to stay safe while you are online and using social networks or the latest electronic gadgets.

    Topics include cell phone use, texting, blogging, gaming, cyberbullying, and identity theft. Find out more about the Cyber Chip at www.scouting.org/cyberchip.