• No results found

3.3 Implemented Embedded System Design

3.3.1 Multiple GPS Waypoint Navigation Implementation

The overall end goal for this portion of the project was to obtain a fully controllable GPS driven UAGV, where the user could define an assigned route for the UAGV to travel via feeding the UAGV an

arrangement of GPS waypoints. In order to achieve this objective, the UAGV must have some way of knowing when it is time to update and move on to the next waypoint. The implication here is that the UAGV must be able to intermittently check its current position relative to the waypoint it is heading towards. Since the X and Y coordinates of the current target GPS waypoint are obviously already known, Pythagorean’s theorem can then be applied for the two coordinates to compute the hypotenuse of the formed triangle once the updated X and Y coordinates corresponding to the UAGV’s current position are received over the CAN bus from the GPS node (which occurs at a base period frequency of 10 Hz). The hypotenuse of the triangle corresponds to the measured distance between the UAGV’s current position and the waypoint that the UAGV is currently approaching. This distance value will be referred to as the look-ahead distance (LD). Additionally, a radius defining a circle around the GPS waypoints can then be assigned to serve as the threshold for determining whether or not the UAGV is close enough to the waypoint that it can update and move on to the next GPS coordinate. This is the basic operating principle governing how the embedded system for the GPS navigation scheme was designed. This concept is illustrated below in Figure 3.10.

A simple timer peripheral was selected to be used in this design. All the timers on STM32 boards have the same general architecture as they are all designed to accommodate for both hardware and software related tasks. Software tasks mainly involve giving time bases, timeout event generation, and time triggers while hardware tasks primarily consist of generating waveforms on output pins (for PWM applications). For this particular application, a timer needs to be configured for the sole purpose of simply controlling the frequency at which an interrupt handler would execute. Naturally, the interrupt handler would contain the code for checking the robot’s position and then computing the corresponding distance between UAGV’s position and the current target waypoint. Thus, the UAGV’s position check will be governed by a timer driven interrupt. Figure 3.11 illustrates the logical functionality of the interrupt handler in block diagram form.

Figure 3.11 - Block diagram of the implemented interrupt handler used for the GPS navigation scheme

The timer peripheral needed to be configured such that it would count at an appropriate clock frequency and also have a suitable period. For this design, as noted in the figure above, it was decided that the UAGV should check its current position once every two seconds. Additionally, the radius defining the circle associated with each GPS waypoint was selected to be two meters, thus setting the error margin to be within plus or minus two meters of the goal GPS waypoint. Since the UAGV’s default speed was configured to be at around 1 meter per second, this setup should provide the UAGV with an ample

number of checks for the computed distance of the UAGV’s position to be within the range of the error tolerance radius.

Setting the interrupt frequency to 2 seconds required proper configuration of the associated timer peripheral. Thankfully, this was a relatively straight forward procedure as there were just a couple of design parameters that needed to be set accordingly. First, the timer4 peripheral was selected to be used which has a clock rate of 90 MHz. Selecting a pre-scaler of 45,000 divides tick frequency down to 2 kHz. Additionally, the top count value of the timer was selected to be 4,000 thereby yielding the desired period of 2 seconds. The top value determines the highest tick value the timer will count to before triggering the interrupt handler event and resetting the counter. A visualization of this setup can be observed below in Figure 3.12.

Figure 3.12 - Timing diagram for interrupt handler execution in microscale (top) and macroscale (bottom) form

As already implicated from Figure 3.11, the interrupt handler contains the code to compute the UAGV’s current distance relative to the waypoint it is currently approaching, using the latest position coordinates received from the GPS node. Once the distance is calculated, the system would then check to see if that distance was less than the defined radius being used for all of the GPS waypoints. If it is, the UAGV will

know that it is close enough to the current target waypoint and can therefore update and move on to the next waypoint in the assigned route. In the firmware, there was a statically declared one dimensional array which contained all of the GPS waypoints for the UAGV. Hence, the waypoint set gets updated via incrementing the index to that array. Additionally, whenever the UAGV moves on to the next waypoint, the new bearing angle is computed for the new waypoint set. Figure 3.13 gives an illustration that visually summarizes this entire procedure.

Figure 3.13 - GPS waypoint navigation process

Finally, when the last waypoint is reached (i.e., the index comes to the last coordinate in the waypoint array), all commands being routed from the controller node to the steering and motor driver nodes will cease as the robot has completed its assigned route and will therefore stop and exit out of GPS navigation mode.