# I need little clue to solve the mess

Dear All
Have a nice day
Please give me a little help ( logic ) to program above task
My robot is working successfully ( I mean follow the line )it takes all the bends very shaftly

1 The robot starts from the the START Location
2 All the black boxes put to the right side and All the white boxes put to the LEFT side
3 The boxes can be placed any random method at the start
4. The Rectangle “A” can be used to place the boxes temporally during swap the boxes
5 Finally robot must stop in the rectangle ‘A’ to end task

My robot pick and place and color detection mess following are working

The only problem is what kind of logic to be used to solve the given task
I am not requesting entire codes but I am expecting clear logic

I am using Arduino Uno and pololu 3pi Arduino library

Have you already checked this? Was it of any help?

Hello.

There are probably a few different processes you could follow to do that. The first way I though of is to check the boxes on the left side one at a time, and whenever you come to one that is wrong, put that box in Rectangle A, then go and check the boxes on the right side until you find one to replace it with. After making that replacement, you fill in the now empty right location with the box stored in Rectangle A.

I wrote that procedure out as a pseudocode below. In my pseudocode, `position(1)` corresponds to the position between the first two boxes, `position(2)` corresponds to the position between the second two boxes, and so on.

``````x = 1
y = 1

while x <= 3 and y <= 3
go to position(x)
check color of left box
if left box is black
put the box in Rectangle A
while y <= 3
go to position(y)
check color of right box
if right box is black
y = y + 1
else if the box is white
put the box in the left side of position(x)
get the box in Rectangle A
put the box in right side of position(y)
y = y + 1
break from the nested while loop
x = x + 1

Got to Rectangle A
``````

- Patrick

1 Like

Dear Patric

Thank for grate help and Now it is little clear for me

Suppose we found at first left a wrong box , Then we have to put it to Rectangle A . Then robot should travel first left turn and straight ahead until Rectangle A but as we know robot is following left or right turn algorithm. Can you please help me to overcome this issue

In simply …How do we tell to the robot to turn left at first intersection and remaining go straight ahead as per the above scenario

Pasindu

Hello.

If you know what intersection you start at, then it seems like you should be able to just count intersections. Then after you pass the last intersection, you will know the next time all of the line following sensors read white you will have reached Rectangle A.

Alternatively, maybe you could identify whether you are at Rectangle A or an intersection by continuing to drive straight whenever all of your outermost line sensors detect white. Then after some time or distance interval, look at the outermost sensors again. If they detect black, you passed an intersection, and if they detect white, you have probably reached Rectangle A.

- Patrick

Dear Sir Can you please give me a some improved version of code that I can’t understand the pseudocode well

If you have a specific question, I would be happy to answer, but in general I think that the pseudocode and my descriptions already provide plenty of detail, and any further improvements or detail will probably depend on your specific robot’s design.

- Patrick

1 Like

Dear Sir

1.Let suppose at the beginning robot checked first left box and suppose that box color is black
2. Then that box put to the Rectangle A.
3. to put the box to the rectangle A robot should pass one Left angle and three straight
That mean

``````unsigned char path1[4]={'L','S','S','S'}  ;`
``````

Then robot should come to check first right box
That mean robot should travel

``````unsigned char path2 [4]={'S','S','S','L'}  ;`
``````

So my question is
Do I need to create array’s for every destination that robot travel or do we have any other simplified algorithm

Your proposal seems like it could work. There are other solutions, but whether it is worth developing a more efficient or elegant algorithm depends on your project’s criteria.

In general, if you do want to develop a different algorithm, but are having trouble getting started, it might help to write out many (or all) of the possible starting/target position combinations and their solutions. That might make it easier to recognize a relationship between them and check whether an idea will work or not.

- Patrick

Can you please give us little details code that you point out in your post 3/9
This is grate help us