Chris Arndt Lab 5 Write-up
From this lab I learned about the importance and usefulness of pulling functions and the use of the rand() function. In my code, I used 5 functions: safe (which ensures that the robot is not about to drive over a cliff), searchlight (which surveys an area for a bright light source and points the robot at it), followlight (which uses proportional control to drive the robot toward the light once the searchlight function has pointed the robot at it), wimp (which randomly positions the robot using a modified version of wimp mode from Lab 4), and randomdirection (which has the robot point in a random direction between 0 and 360 degrees). These all made it much easier and cleaner to implement code into the main function, which has the robot randomly position itself in the room using the wimp function and take a survey of the area using searchlight. If the brightest light source it sees is brighter than ambient room light, then it will use followlight to drive to the light until the sensor readings are greater than 599, in which case the robot stops. If the highest average reading is not greater than ambient room light, the code will snap back into the wimp function once again to randomly re-position the robot. Also, the randomdirection function has the robot point in a random direction using another function called the rand function. The rand function randomly selects a number between zero and whatever number you choose (in my case 360). This function uses something known as the modulo operator (%). This uses a random remainder from dividing the number you choose plus one by a random number, producing a random number. For example, if you wanted a random number between 0 and 360, the code would look like "rand()%361".
Links
My Code Δ
Lab 5 Flow Chart Δ
Searchlight Flow Chart Δ (used in Lab 5 Flow Chart)
Wimp Function Flow Chart Δ (used in Lab 5 Flow Chart)