Mood Brightener: ...more from Stay Homas. (Confination X)
Models: Implementing
Another place models are used is to predict what you would like to see next on FB or Amazon or your news feed. This helps us notice that after a model is created and evolves then there is the question of how it is applied or implemented. One name for the implementation of a model is an algorithm. Algorithms are in the tech news feed a lot because of concerns that they can easily have various biases embedded in them. It is certainly true that those who implement the model in computer code can intentionally create biases in the implementation. It seems that many of us think of this pathway when we hear about biased algorithms but it is actually more common for biases to occur through biases in the data from which the model was created. We are all suspectible to this sort of bias. The discussion of model bias and how it shows up in algorithms is an endless discussion and I only wanted to mention it in passing here so you're aware of it before we on to the tools that we might need to implement various models for our robot.
Approaching a Light:
Last class we discussed our models of what we do as we approach a light while driving. I suspect our model is quite complex for what seems like such a common and 'simple' thing we do every time we drive. This raises all sorts of interesting questions about how an autonomous vehicle is going to do that successfully.
It helps, as we build our models, to have some organizing ideas to work with. The image below describes three general patterns of decision making processes.
Think back to our early discussion of machines and robots. If a machine is something that executes a consistent series of actions that are the same very time does that not seem similar to a sequential process? No matter how complex the machine it does the same set of actions each time. Notice that the conditional process suggests that there is input from the environment that leads to possible changes in what the machine does. In our discussions this represented a characteristic of robots. Finally, the repeating behavior is, in some ways, typical of autonomous processes where the robot is constantly cycling through and repeating some set of processes that will be different depending on conditions.
We will discuss how these different types of processes are part of how we, as humans, respond as we approach a traffic light.
What are parts of the process that are SEQUENTIAL?
Class Discussion:
Once we decide to stop that is a sequence of steps that we generally take.
Before we get going when the light turns green from red we go through a mental checklist of potential hazards like pedestrians, deer, bikers, and other drivers before we move forward.
What are parts of the process that are CONDITIONAL?
Class Discussion:
The whole light thing is a giant conditional process depending on whether the light is red, yellow, or green.
If the light turns yellow as we approach we have lots of conditional decisions about how fast we are going, how close we are to the intersection, what is the person in front of us doing, or even how much overall traffic there is.
What are parts of the process that REPEAT?
Class Discussion:
General driving is a repetitive process of keeping the car on the road while checking repeatedly for risk factors or concerns (like deer on the side of the road). When something unexpected or that has a clear need to change process is observed then we stop the basic repeated driving behavior and move to some other process.
Even as we are executing some other process we are repeatedly check a sequential list of safety concerns which is another repeated process.
Implementing in Code:
How do we connect our model for driving with an autonomous robot or vehicle? Let's take the processes one at a time.
Sequential:
Not surprisingly a sequential process is simply an ordered list of instructions. This is precisely what you have done in your Blinky and Motor Control labs. Once the robot knows which pin(s) you want to access it then carries out your requests in order and does so exactly the same each time.
In the context of the traffic light setting this is like the series of actions you take to safely bring your car to a stop if the light is red.
Conditional:
No doubt we noticed that there are a large number of conditional decisions that we make at a traffic light that depend on everything from the color of the light when we notice it, how far away from the light we are, and others up to watching to see if someone seems like the might be going to run through the light after it turns. The coding version of this is called an If - Then - Else statement. In our robot code it will look something like this. Here is a link to the Arduino documentation for if().
if ("the light is red"){ //take foot off the gas //gently apply the brake //come to a stop before hitting anyone }
A couple of things to notice about the if() statement. When the test statement - "the light is red" - is true then the Arduino will do the things between the { and } brackets. After those steps have been executed the robot goes back to what it was doing. Notice the indentations that are shown. While these are not critical in Arduino code they are visually helpful in what instructions are 'inside' the brackets. In some computer code the indents are critically important but not for us.
Many times we do different things depending on the information we get. Something like this...
if ("the light is green"){ //keep going //watch for change of light } else { //take foot off the gas //check if light is red or yellow }
More realistically it's even a little more complex because we take different actions depending on whether it's red or yellow and also depending on how far from the light we are. This is called nesting of the conditional processes and looks like this.
if ("the light is green"){ //keep going //watch for change of light } else if ("the light is red") { //take foot off the gas //slow to a safe stop } else if ("we are very close to the light") { //be alert //move on through the intersection } else { //slow down as rapidly as possible //come to a safe stop }
This can certainly appear intimidating and complex but you make decisions like this all the time and what we are developing are tools for teaching a robot how to make similar decisions. Again, notice the alignment of the various { } brackets and comments that help us 'read' the code more easily.
Can you think of setting in which you make nested decisions like this in your kitchen?
Repeating:
After all of that complexity a process which is repetitive is perhaps a little easier to visualize. The void loop(){} expression in our robot code is an example of a repeating process. The robot goes through the code and when it's done it goes back to the beginning of the loop and does it again. All of these repeating processes are called 'loops' which hopefully seems clear. Another way of creating a loop is called a while(){ } statement. It looks something like this.
while ("there are no perceived dangers"){ //continue driving normally //keep checking for traffic lights //watch for idiots in the next lane }
A while loop is a great description of how highway driving proceeds. We keep driving normally and keep checking for risk factors. If we detect a risk of some kind we get out of the loop and respond in some way that depends (is conditional) on what the risk we detected is.
An awful lot of what we do during a day can be described by some combination of these processes.
Assignment Breadcrumb Reading: Bb Quiz
Decision Making:
What are the three primary decision processes described in this breadcrumb.
Before Next Class:
Assignment HW: Bb Assignment
In the Kitchen:
Describe, in words, a process, in your kitchen that requires both conditional and sequential instructions to complete. Convert that description into 'code' in the way that we did in this breadcrumb. Spend no longer than 30 min on this process.
Assignment HW: Bb Assignment
Avoid the Crash:
The Autopilot on Tesla EV's uses a model of the driving environment to determine what to do. Read this report that provides a synopsis of the final report of the National Transportation Safety Board's investigation of several Autopilot accidents. In the case of the accident in Delray Beach Florida what feature of the Autopilot 'model' of the driving environment probably contributed to the crash? Is this the last change to the Autopilot 'model' that Tesla will need to make? Explain your reasoning.
Looking Ahead:
Look ahead to the next Breadcrumb: Circuits I
Assignment Breadcrumb Reading: Bb Assignment
What would you miss?
Think of all the things that we depend on for electricity. If electricity were gone what would you miss most? Why? Can it be replaced by a machine?