Week 12 – 2019 – Sara

Hi once again…

In this blog I’m just gonna be explaining how our competition code will work,and what we have to fix ( by we I mean me and Oliver).

This is the complete code…

MangoBots Competion Code

You can click on it to make it bigger…

That’s the code we’ll be using, but to make it easier to explain I’ve broken it into parts…here’s the first part…

Variables

These are our current variables.

The first is the Watertower, it’s a flag variable and it’s set to true that means it thinks it has already found a silver bit meaning it doesn’t need to find another one, instead the next time it sees silver it should just stop. If it were set to false it would be looking for the silver watertower dot.

The second variable, Speed. its currently set to 30

The next variable, Turn Angle. That variable tells the robot how aggressive its turn should be when following the line. Its set to 90.

The Reflected Light variable is set to 40, why… because if its over 40 we know its white, if its under 40 then we know its a dark colour. And that makes it easier for the robot to know when to follow a line.

The final variable, Last Action. It detects what side the robot last turned, left or right. Then when it knows the last action it uses that as a guide when following hints.

Left, Right and forward

That first orange block on the left side is detecting if the right sensor is greater than 40 then it should take the top path but if it isn’t then it should go down. If it goes up it gets asked another question, is the left sensor greater than 40? If yes then take the top path if no then go down. If for both those questions its a yes then it means the robots on white so it should go forward.

If the answers were yes for the first question and no for the second then that means the right sensor is white but the left sensor is on black. if thats the case then it should turn left to get back on track.

Now back to that first question… if the answer was no then it would go down, meaning the right sensor is black. Once again it gets asked a second question, is the left sensor greater than 40? If yes take the top path if no then go down. By taking that top path it means it needs to turn right to get back on track.

If to both those questions the answer was no then the robot will go down the 4th path…

Silver Finder

This is where it gets complicated to explain. The first 2 yellow blocks are detecting the reflected light, then that result gets put into the red block that takes those two answers and subtracts them. The answer to that gets put into the next red block which finds the absolute value of the number. That answer gets put into the next block and it asks if that number is less than 2. Then the yellow block checks if the right sensor is less than 20, if it is and if the absolute value of the other equation is less than 2 it should take the top path because it has found silver.

Silver

Since right in the beginning of the code the watertower variable was set to true then the robot will automatically take the top path. The top path makes the robot stop and stay still for a full 2 seconds, then after that it will start the can finding code.

Can Finder

Thats our Can finding code. What happens when this is activated is that the robot stays still and goes round a full 360 degrees until it detects a can, after its found it the first time it will keep moving to a point where it stops seeing it. Then it will stop and go to the middle of the two points (the point where it first saw it and the point where it last saw it). Then it advances forward and pushes the can out of the green zone.

The final part of the code…

Hints

For the hints it looks for green, when it finds it it will go forward for 0.025 of a wheel rotation before turning left or right.

That’s it the complete walkthrough of our working completion code…