CIS 721: Real Time Systems
Programming Assignment # 2
BRICK SORTER PROBLEM
The project is a Brick Sorter using the ‘Lego MindStorms Kit’.
The brick sorter is capable of sorting brick of three different color: black, grey and red.
Brick Sorter Design:
The model consists of a rotating arm which sorts the bricks of 3 different colors. The
brick injector and brick chute together form the rotating arm.
The model consists of brick chute which holds bricks to be sorted. The bricks will slide
(due to gravity) down the chute which is inclined at an angle to the rotating arm. Each
brick is removed from the bottom of the stack and pushed into the bin by the brick
The rotating arm mounted on a fixed base, is driven by a motor. The rotating arm has 180
degrees of freedom. The rotating arm also has a color (light) sensor which identifies the
color of each brick. The light sensor is placed opposite to the chute. This ensures that
when the brick slides down chute, the light sensor identifies the color of the brick. The
direction of movement of the rotating arm is controlled by the RCX which in turn
depends on the value returned from the light sensor. The light sensor is connected to
input 1 of the RCX and the motors driving the injector and rotating arm are connected to
the RCX outputs A and C. The program uses the input from the light sensor to direct its
sequence of action. The brick is pushed into the bin by the brick injector (deflector).
A barrier is positioned behind the piston to make ensure that when the bricks get jammed,
the piston hits back on the touch sensor and the system comes to a halt.
The barrier only serves as a safeguard against the system being jammed by a brick.
Working of the Brick Sorter:
Initially the brick injector and rotating arm are idle. The bricks to be sorted are positioned
in the brick chute, close to the light sensor. The piston of the injector is moved backwards
and the brick is close the light sensor.
The light sensor will identify the color of the brick and send the appropriate signal to the
program. Accordingly the motor will drive the rotating arm to move in a direction
(predefined for each color in the program) such that the brick is ‘sorted’ or pushed into
the appropriate bin. The rotating arm returns back to the original position.
The next brick then slides the chute and the above process is repeated for each brick .
A count is maintained of the brick in the program. The program will move the rotating
arm in such a way, that one first brick if sorted or pushed to the output bin in a direction
while the next brick is sorted to the opposite side. In general, if the program starts
counting bricks with no 1, then the next brick, no 2, will be pushed in the opposite
Brick Sorter Design
Class Diagram :
State Diagrams for Brick Sorter Controls:
Motor 1 Control:
Motor 2 Control:
Light Sensor Capsule:
//Source code for Brick sorting
int k = 1;
int i = 0;
ok = 1;
ok = 0;
execi(&CheckJam, 0, NULL, 10, DEFAULT_STACK_SIZE);
a = SENSOR_1;
j = LIGHT_1;
if ( first )
prev = j;
first = 0;
if ( j - prev <= 4 )
//Push the Piston
if ( j - prev <=4 )