C-Robot Simulator: Program Structure
C-Robot Simulator: Program Structure
Learner’s Hand-outs
PROGRAM STRUCTURE
Two Main Functions
1. void set-up (){} – a function that runs the once.
Figure 1.1
FOR () / Parenthesis
The open and close parenthesis in a function is used to instruct statements / commands in braces in
order to do or repeat operation following the number of cycles required.
MOTOR ORIENTATION
Figure 1.2
C-ROBOT SIMULATOR
Learner’s Hand-outs
BASIC MOVEMENTS
1. FORWARD / BACKWARD
Example: motor(1,100);
motor(2,100);
2. SLEEP COMMAND
use to set duration of a command in millisecond.
Example: How long will your robot move forward?
sleep(duration in millisecond);
sleep(1000);
Figure 1.4
C-ROBOT SIMULATOR
Learner’s Hand-outs
3. TURN MOVEMENTS
3 DIFFERENT TURNS
Curve Turn – 1 motor is moving faster than the other motor.
Example: motor (1,100);
motor (2,30);
Pivot Turn – a kind of curve turn wherein 1 motor is moving forward and the other is at rest.
Example: motor (1,100);
motor( 2,0);
Spin Turn – both motors have the same speed, but 1 motor is moving the opposite direction
Example: motor (1,100);
motor (2,-100);
SENSOR CALIBRATION
lcd(“text”);
Figure 1.5
C-ROBOT SIMULATOR
Learner’s Hand-outs
Figure 1.6
Example: PA8
Figure 1.7
Figure 1.8
int - a data type used to define numeric variables holding whole number
a - variable name/ user define
analog(8) - analog port of the sensor you want to calibrate. (ex., PA8)
%d - variable value/sensor value
OBJECT DETECTION
B. Select the sensor port PA8 To enable the distance sensor, click Apply and OK.
*The command keep_up() is used to grab or carry the ball while keep_down() is used to
release the ball.
C-ROBOT SIMULATOR
Learner’s Hand-outs
LINE FOLLOWING
*Observe and remember the value for each of the sensors. The value of the IR sensor must be 1024
if placed in the White surface, and 0 if in the black line/surface.
Run Forward
SPIN LEFT
C-ROBOT SIMULATOR
Learner’s Hand-outs
SPIN RIGHT
TRY THIS!
Load Map 05
GLOBAL VARIABLE
CONDITION
INITIAL MOVEMENT
NOTE: *The robot will do the initial movement if no “if count statement” is being declared for a
particicular if intersection.
Example:
COLOR SORTING
Determine the number of intersections until the robot reaches the correct area where to release
the ball.
1 5 2
7 8 10
11
distance sensor
11th intersection,
DROP/RELEASE THE BALL