0% found this document useful (0 votes)
192 views

Generic RobotC Programming Book

A book I did as a ticket to get a test retake. Turns out I did wwwaaaaaaayyyyyyyy more work than needed.

Uploaded by

Downald Troump
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views

Generic RobotC Programming Book

A book I did as a ticket to get a test retake. Turns out I did wwwaaaaaaayyyyyyyy more work than needed.

Uploaded by

Downald Troump
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Generic

RobotC
Programming
Book
A collection of random programs
and ramblings concerning RobotC.

Anonymous
Generic
RobotC
Programming
Book
There is no copyright for this work so I will put some placeholder text so
it looks like a normal book with a block of copyright stuffs.. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Ut lobortis gravida sem vel
fermentum. Duis ac nunc justo. Donec gravida mollis velit, eu lobortis
odio imperdiet ac. Donec magna odio, congue quis ullamcorper vel,
lobortis id diam. Etiam tempor massa ac sagittis suscipit. Duis vel nunc
vestibulum, feugiat nisl eget, gravida quam. Cras ullamcorper elit elit, et
volutpat nisl consequat sit amet. Donec molestie, orci sed pulvinar
egestas, ante neque feugiat magna, at faucibus nisl. Images in this book
are probably copyrighted in some way but I am too lazy to cite.
Contents
Introduction
Things You Should Know .............................................................. 7
The “Killswitch” Task ....................................................................... 8
Braces .................................................................................................... 9
Pseudocode ........................................................................................ 9
Semicolons .......................................................................................... 9
Creation of New Tasks ................................................................... 9
While loops ....................................................................................... 10
Errors ................................................................................................... 11
Motor and Sensor Setup ............................................................. 12
Program Examples
Program 1.......................................................................................... 14
Program 2.......................................................................................... 16
Program 3.......................................................................................... 18
Program 4.......................................................................................... 20
Program 5.......................................................................................... 22
Program 6.......................................................................................... 24
Conclusion ............................................................................................. 26
Introduction
Things You Should Know
Welcome to the world of in-school robotics, where
you get to build random contraptions with people you don’t
know and write code that contains lots of errors in a
language you have never heard of. The language here being
the “Natural Language PLTW” variant of RobotC. Here is a
picture of the logo in case you haven’t seen it yet.

Well someone obviously spent lots of time on the logo.


Anyway, you have to manually type in random words that are
vaguely understandable by anyone that is somewhat fluent
in English into this amazing IDE called “ROBOTC for VEX
Robotics 4.x” which totally isn’t an over-glorified text editor.
You can go ahead and download it at
http://www.robotc.net/release/vexrobotics in case you want
to experience the quality of the proprietary RobotC
Integrated Development Environment in the comfort of your
very home.

7
The “Killswitch” Task
When programming, you must remember to always
insert the following code into the beginning of your
program:

This bit of code, known as the Killswitch task, stops all


running tasks when a limit switch that’s assigned to the
name is pressed. This is useful if you run a
program containing erroneous code that could destroy any
of the various overpriced VEX EDR parts. For example, if your
program attempts to drive a $14.99 “2-Wire Motor 393” in a
situation where the “2-Wire Motor 393” cannot turn, a motor
strain will occur in which the motor makes a high-pitched
whirring sound and slowly kills itself. While on the subject of
destruction, you should also know that you should treat your
“VEX ARM® Cortex®-based Microcontroller” with lots of
care as damage to this underpowered and poorly designed
device will set you back $249.99, meaning you won’t be
getting that new gaming console anytime soon. Additionally,
not including this task may or may not cause a sudden grade
drop of 30% depending on your instructor.

8
Braces
You should remember to have the same amount of
closing braces and opening braces.

Without these braces, you may encounter errors.

Pseudocode
You may have noticed the text from the image above
contains text in the same line of the command that begins
with two back slashes. This is known as pseudocode, and it
explains what each command does. Simply press tab a few
times after the command, add two backslashes, and you can
type text that will be ignored by the “VEX ARM® Cortex®-
based Microcontroller”. You are recommended to add
pseudocode to any program you create as it makes it easier
to diagnose and evaluate by others.

Semicolons
Semicolons at the end of each command separate the
statements in your code. You do not use them when defining
tasks or creating while loops.

Creation of New Tasks


To create a new task, start a new line and type ,
add a space, your task name, and then end with without

9
adding a space. Here is an example of what it should look
like:

While loops
While loops are used when you want a certain bit of
code to run in a loop only when a certain condition is met.
Here is an example of a while loop.

This will continuously command to run at a speed of


50 as long as 1 equals 1, which it always will until you change
it to something else, like:

Once this condition is broken, or in the above case, the value


for fails to equal 0, the loop will stop looping
and the program will start executing the code defined after
the while loop, or if there is no code, stop. And, if you
noticed, you need two equal signs, as well as spaces
seperating the values and the equal signs.

10
Errors
In the event that there are errors in your code and you
are trying to compile it, details concerning your errors
appear in the error log. They look like this:

The “Compiler Errors” pane of the window shows where the


file was compiled, the date it was compiled, and the errors.
Here, I forgot to define some sensors in line 7 and 12. If this
happens, you can click on the “Motor and Sensor Setup” to
tell the program where you plugged in your motors and
sensors and assign names to them.

11
Motor and Sensor Setup
To clarify how to use the Motor and Sensor Setup, I
will provide a screenshot.

Here, you can set what type of motor is connected to each


motor port, and give it names. The same goes for the “VEX
2.0 Analog Sensors 1-8” and the “VEX Cortex Digital Sensors
1-12” tab. After closing out of the program, it will add a
couple of lines of code beginning with , and then

You should not edit this code, as it could cause errors.


Consult your instructor if you don’t know what to do or can’t
figure out the difference between analog and digital sensors.

12
13
Program Examples
Program 1
Write a program that will start the right and left motors at a
speed of 50 and run them for 2 seconds, then stop the
motors and reverse them both at a speed of 50 for 3 seconds
and then stop both.

14
The start of this program causes the Killswitch task to
run and causes the left and right motor of a typical VEX
testbed to start turning at a speed of 50 (see lines 15-17).
After 2 seconds, both motors stop and 0.5 seconds are
allowed for the motors to come to a complete stop (see lines
18-21). The motors start up again running backwards at a
speed of 50, and then stop again after 3 seconds (see lines
22-26). The program then ends.

15
Program 2
Write a program that will do nothing until the bump switch is
pushed and then both motors will run at a speed of 120.

16
Pressing the bump switch starts the Killswitch task and
then starts both left and right motors at a speed of 120 (lines
16-20). The motors will continue running until either the
battery runs out, the Killswitch task is triggered, the “VEX
ARM® Cortex®-based Microcontroller” is shut off, or the
program is manually stopped on the computer where the
“ROBOTC for VEX Robotics 4.x” IDE is running.

17
Program 3
Write a program that will start the left motor at a speed of 75
if the limit switch is pushed.

18
Upon pressing the limit switch, the Killswitch task is
started and the left motor will start running at a speed of 75
(lines 15-18). Like before, the motor will continue running
until the battery runs out or the user manually stops the
program as there is no command telling the program to stop
or the motor to stop.

19
Program 4
Write a program that will turn on the right motor at a speed
of 25 if the potentiometer value goes above 1,000 and will
have the right motor run at a speed of 100 if the
potentiometer value goes above 2000.

20
This program will cause the right motor to run at a
speed of 100 if the potentiometer value is greater than 2,000
(lines 19-22). If the potentiometer value drops below 2,000
but stays above 1,000, the right motor will start running at a
speed of 25 (lines 23-27). If the potentiometer goes below
1,000, the right motor stops running (line 28), but will start
running again once the value becomes higher than 1,000
because of the while loop surrounding all the other while
loops (lines 17-29). This behavior will stop once the program
is halted.

21
Program 5
Write a program that will start the right and left motors at a
speed of 50 until the line follower value goes below 500,
then both motors will stop.

22
Starting this program will launch the Killswitch task, then start
the left and right motors at a speed of 50 if the line follower value is 500
or higher (lines 20-24). If the line follower value drops below 500, both
motors will stop (lines 25-26). Once the value reaches 500 and higher,
the motors will start running again due to the loop
(lines 18-27).

23
Program 6
Create a while loop and explain how it works with a program
that will start both motors at a speed of 35 when a bump
switch is pushed and they will just keep running until the
bump switch is pushed again.

24
Once the program is started, it will wait for the bump
switched to be activated, and then start the Killswitch task
and the while loop (lines 17-20). The while loop starts the left
and right motor at a speed of 35 (lines 22-23), and if the
bump switch is ever activated again (line 24), it will stop all
the motors from running and then end the program (lines
26-28).

25
Conclusion
After looking through this book you should now have
a basic idea about how to program using ROBOTC Natural
Language PLTW. If you have any questions, you should
consider using this large and vast resource that costs $50 a
month called the Internet. And in this magical space there is
a thing called “Google” that will give you buttons that
teleport you to other remarkable places full of blocks of text
where people discuss various things using this unique
method of communication called “English” (known as
“forums”). Among these walls of text may be the answer to
your question. Otherwise, they may be hidden inside
electronically formatted books (or Portable Document
Format, or PDF) or digital presentations created by either
VEX or instructors who falsely believe presentations are the
best way to teach a class.

Overall, I hope you found this pile of joined pieces of


paper somewhat useful in one way or another. You should at
least be able to write a simple program that makes a motor
move. If not, then I have no other way to help you because
this is a book. Sorry

26
27
Notes
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________

28
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________

29
This book will show you
examples of ROBOTC so you
can figure out how to code by
yourself!

“This book was literally just a bunch of random words


and programs. I did not learn anything.”

-A Reader

“i h8 d15 b00k 17 wuz <REMOVED>”

-Yet Another Reader

1.000000 COPY SOLD!

Qalty Publish. Lim. ©


“Ownly da bes buukss” ™
666 Good St.
Pyongyang, NK

You might also like