We need the PID controller running on the Arduino to update the acceleration of the vehicle based on the vehicle's current speed. There are two main steps required to achieve this.
The first step is to add two functions for exchanging serial data with
the Arduino. The first one checks for serial input each time through the
draw() loop. This is how we will receive
instructions from the Arduino. The second function sends the current speed
to the Arduino for input into the controller. This function runs at the
end of the
draw() loop so that the speed
value includes the latest updates.
The concepts required to complete this step are the same as you used in the practical exercise which introduced the Processing environment. To check that the communications are working, you will need to be able to view the values being sent between the applications.
The second step is to implement the controller using the Arduino PID library. The link in the resources box takes you to the download page. Install the library and use the examples at the bottom of the page to help you create the PID required function. Remember that the PID controller depends on the error - ie the difference between the set point and the current actual value.