Staying inside a rectangle
How can simulate sensor input to change the behavior of our robot ?
Use the position of the ground sensors and check if it falls within the boundaries of a rectangular area. For this we define two boolean values to see if the sensor position is inside the rectangle defined by the points
We use this information inside the animation script of the slider time t to determine if the robot needs to turn.
A=A+v*v_f*dt
If[out_0, SetValue[θ, θ-dθ],If[out_1, SetValue[θ, θ+dθ]]]
To give a visual feedback when the sensor is outside the rectangle, we momentarily increase the size from 3 to 15.
SetPointSize[C_0, If[out_0, 15, 3]]
SetPointSize[C_1, If[out_1, 15, 3]]