Course 6 / Lecture 7:

# Determine the collision point(calculate and predict)

After taking this lecture you will be able to predict where two robots travelling toward each other will meet. We call this point the collision point. To calculate the collision point you must take into account robot speed, and travelled distance. You will also learn how to verify the calculation using real life robots. Figure 1 - Determine the collision point

## Express the time from the velocity equation!

Before you start driving your Sniffers to each other, you should learn how to calculate their collision point. It is good to know that both Sniffers move towards to each other for an equal time period, but it do not necessarily to make the same distance as their speed may be different. You can calculate the passed time by using the velocity equation. As you learned in the previous lecture, you can get the distance if you multiply the velocity equation by the passed time. After that you should simply divide that equation by the speed to see how to get the passed time like on Figure 2. Figure 2 - Expressing the time from the velocity equation

## Write down the time expressed from the velocity equation for both robots. Join the equations, because the time for collision is equal!

After you realised how to get the movement time from the velocity equation, you can write this equation for each Sniffer. Please use number ideces to make difference between each robot's equation. Because your Sniffers move for the same amount of time you can make one equation from the previous two equation. First you can connect the two equations with the time in the middle and leave the distance and speed ratios on both sides. Finally you can leave its middle to get the final equation (Figure 3). You can think about it. Both robots start moving towards eachother in the same time and collide in the same time, which creates the equation on the bottom of Figure 3. Figure 3 - Make one equation from the two robot's movement equation

## Create a program to start and stop the robots at the same time by using two keys!

After you learned how to get the basic equation to calculate the collision point, you should open your SNAP. Then please place two different 'when [key] key pressed' blocks as entry points of your program, and set their 'key' fields to 's' and 't'. The first one will start the robots, and the second one will stop them. So at first, attach a 'Motor select [Motor_1]' block to the first entry point to select the motors of the first robot. After that, insert a 'Drive [A+D] [forward] at  %' block to start moving it forward. Then you should select the another robot's motors and also start them forward. Finally, you should stop them by pressing the 't' key. The complete program code can be seen on Figure 4. Figure 4 - Control two Sniffer towards eachother

## Predict where the collision point will be after running the code!

After creating your program, you can control both Sniffers. You should calculate your Sniffer's collision point using the equation what you got in Task #2. Because you used the same speed value for both robots, therefore you can replace the second Sniffer's speed variable with the first Sniffer's speed variable, which helps you easily multiply the whole equation by the speed variable. This means that both Sniffers will move the same distance (Figure 5). Finally after starting the program, you will realise that the collision point is at the half between them, since the speeds are equal. So if the robots move toward each other and their speeds are equal, the collision point will be exactly the middle of the track. Figure 5 - Easily calculate distance since the robot speeds are equal

## Change the program to move the second robot with 50% power!

After you calculated the collision point when you move your Sniffers with the same speed, you should test what will happen if you move your Sniffers towards each other with different speed. First you should modify your program what you created in Task #3. To simplify the task, set the second Sniffer's speed to the half of the first Sniffer's speed by setting the speed value to fifty percent as can be seen on Figure 6. Please do not change any other parameter in your program. Figure 6 - Modify the program to move the second robot with 50% power

## Predict the collision point with the modified speed and verify it by running your modified program!

After you modified your program, you should calculate the point of collision. You can begin the calculation with the equation what you got in Task #2. First you can replace the first Sniffer's speed variable with the second Sniffer's speed variable multiplied by 2, because the second Sniffer's speed is half of the first Sniffer's speed. After that, you can multiply your equation on both side by the second Sniffer's speed multiplied by 2. Finally you get that the first Sniffer's travel distance will be twice as much as the second Sniffer's travel distance (Figure 7). If you started your modified program, you should see that the collision point is at the one third on the road between the starting points of the two Sniffer. You will see that it is closer to the Sniffer that goes at 50% speed. Figure 7 - This is how you calculate the ratio between distance 1 and 2

## Program code Figure 8 - Program code that start and stops both Sniffers