# 7 – Always Moving

You’ve been working with a predict state function that takes in a current state and some change in time, dt. And it outputs a new state estimate based on a constant velocity motion model. It turns out a constant velocity model is actually a good simple model to use, especially if changes in time are very small. Now, to track the state of a car over time as the car moves, you have to repeatedly call this function passing in new state estimates at each time step. So as an example, let’s say we have this initial state at position x equals zero and velocity equals 50 meters per second. I’ll put these two values into a list, our initial state, and I’ll print them out. So, the initial state is x equals zero and velocity equals 50 meters per second. Next, I want to know the next state after two seconds have passed. So, I’ll use my predict state function passing in the initial state in the two-second time difference and I’ll call this state, est1, for the first state estimate and I’ll print out this result. Our position, x, is now at 100 meters and the velocity remains 50 meters per second. Then, say another three seconds, have passed. I’ll call The predict state function again. This time, I’ll pass in our latest state estimate, state_est1, and a three-second time difference and I’ll print out this value. Our position is now 250 meters and our velocity remains constant at 50 meters per second. What about after three more seconds? I’ll have to pass in our latest state estimate, state_est2, and three more seconds in time difference and I’ll print out the result. As you can see, we’re basically calling the same line of code over and over again but modifying the state input to be the latest state estimate. This repetition is tedious at best and it’s bad code. As a programmer, you should always try to avoid unnecessary repetition. Wouldn’t it be nice to just tell a car to move and have its state update automatically as it moved, as opposed to writing the same line of code manually keeping track of the state over and over again? Well, we can automatically keep track of state with the help of objects.