I want to write a NXC program to sort 4 color bricks (Blue, Green, Red and Yellow) by a Lego Color Sensor into relevant color baskets.
There are 4 empty color baskets (Blue, Green, Red and Yellow) to be fixed in a moving train which is controlled by M1.
The train moves, to and fro, to collect a color brick by the relevant color basket, after scanning by the Color Sensor.
M2 is used to allow a color brick to drop into a basket each time along the Outlet after brick scanning.
The four color baskets in the train are placed in the order of [G] [R] [Y], where , [G], [R], [Y] representing by Blue, Green, Red and Yellow
color baskets respectively.
The distance, between any two adjacent color baskets (or degree of motor M1 to be rotated from one color basket to the adjacent color
basket) is denoted by d.
The starting point is the red color basket facing the Outlet from which it drops.
The estimate chances are as follows:
Group 1: →[G] = d, →[R]= 2d, →[Y]=3d,
Group 2: [G]→ = -d, [G]→[R]= d, [G]→[Y]=2d,
Group 3: [R]→ = -2d, [R]→[G] = -d, [R]→[Y]=d,
Group 4: [Y]→ =-3d, [Y]→[G] = -2d, [Y]→[R]=-d.
How about the program?
Can you help give a hint or suggestion?
YH Chan
Sort Color Bricks Problem
Re: Sort Color Bricks Problem
Hi Chan
Have you built the sorter in LEGO yet, or are you writing the program first?
I'll assume you have the sorter built. Next step could be to write some pseudo code to figure out how the machine should work, eg:
The pseudo code is a great help to understand the problems involved, and to illustrate for others how you intend your program should work.
Kindly,
Povl
Have you built the sorter in LEGO yet, or are you writing the program first?
I'll assume you have the sorter built. Next step could be to write some pseudo code to figure out how the machine should work, eg:
Code: Select all
start program
start conveyor belt
while sort bricks
wait for a brick to arrive at the colour sensor
colour= scan the brick colour
switch colour
case red ...
case blue ...
...
case unknown ...
end switch
end while
stop all motors
end program
Kindly,
Povl
Who is online
Users browsing this forum: No registered users and 8 guests