GPS - Simulation & Boundary

Simulation of the fence.

Before we set the mower loose the fence can be simulated in the Smartphone APP.  This then checks that the fence coordinates are entered correctly, the boundary conditions are correct and the correct GPSMAX value is set for the fence.

We need to give the simulated mower a starting position within the fence so add these coordinates in the Fence code.

 

Start Simulation Via TFT Touchscreen 

1. Navigate using the TFT touchscreen to

SETUP>     NAV>    GPS>

2. Ensure that the APP WIFI is ON and that the Simulation button is ON.  Select the fence you would like to simulate using the Fence selection buttons.

 

 

3. Save these settings.

The ESP32 will now connect to your WIFI (ensure WIFI key, password and Blynk APP key is enetered in the ESP32 Arduino software) and create the GPS fence on the google map.

 

Start Simulation Via Arduino Code

To turn on the simulation via the code ensure the WIFI_Enabled = 1 and change the Simulation_Mode value to 1.  Ensure the correct Fence is selected.

 

Simulation in Action.

The simulation will now move the mower within the GPS Fence.  If the mower crosses the boundary line, the mower should turn around and move off in another direction.  

If the mower crosses the line then we need to adjust the boundary conditions for that section of the GPS fence in the code.

If the mower is prevented from entering an area then we need to adjust the boundary conditions to unlock that area which is currently being blocked by another fence line extending into that area.

See the guide below on setting boundary conditions.

 

Setting the Boundary Condition.

The Arduino sketch monitors the GEO Fence by calculating where the mowers position is (Lat & Long) compared to the theoretical line of the fence between the 2 nearest coordinates.  When the mower enters the zone of the 2 coordinates the software starts to compare the mowers coordinates to the projected line between the Geo points.  If the vehicle/mower crosses over the line between these 2 points the mower is reported as Out (0) of the fence.

 

Another way would be to calculate and create an array of all the possible GPS coordinates "IN" the fence and compare the vehicles/mowers position to this array.  This array however would/could be huge depending on the area being monitored and require a lot of processing power to manage, which we dont have available, or cant realistically afford or justify for these projects.

 
The equation based system allows large areas of terrain to be effectively monitored with relatively low processing power.
 

As this calculation is a triangular based equation the lower part of the projected fence line has a large area to report the mower as Out.  At the upper section of the detection zone the mower crosses the line and is almost immediately in the area again with no detection. (to the right of GEO point 0)

 

 

To give the software additional zone to detect that the mower has crossed the line (considering the accuracy of the GPS module reporting the vehicles position) , the detection zone can be extended out from the GPS Point 0 and 1 to infinity. This is done by setting the boundary condition to 1.

This extension of the out zone is always to the left of the boundary line.  i.e. you are standing at Point 0 looking at Point 1.  The boundary = 1 extends the out zone to left (only horizontally not vertically) of where you are standing between these 2 points.

 

For a GPS fence with only outer perimeter fence coordinates this is a perfect solution to give a large Out zone for detection.

In addition the Arduino code automatically sorts the highest (north) and lowest (south) GPS points and also declares everything over or under these points as out.

For a GPS fence with only outer perimeter coordinates all the boundary settings can be 1 for each GPS pair.

 

Boundary Condition = 2

For perimeter boundaries that "cut back", we need to change the boundary condition to avoid the software calculating false OUT's..

The GPS fence is generated in a clockwise direction.  Therefore the boundary=1 always creates an out zone to left of the direction of the line. (as explained above).  If this OUT zone cuts into another zone which should be an "IN" zone the software will get overridden and the mower will be considered to be in an "OUT" zone (even though its really in a safe area)..

 

Above shows what would happen if the fence 6-7 boundary condition was set to 1.  This extension of the boundary would cut the IN zone preventing the mower from entering the upper section, 

 

In the below example we would need to set the boundary as follows:

Line 2-3 : boundary = 1 (area to the left of the line horizontally is extended as OUT) 

Line 3-4 : boundary = 1 (area to the left of the line horizontally is extended as OUT) 

Line 4-5 : boundary = 2  (otherwise the infinity out zone would extend into line 6-7)

Line 5-6 : boundary = 2  (otherwise the infinity out zone would extend into line 6-7)

Line 6-7 : boundary = 2  (otherwise the infinity out zone would extend into line 4-5)

Line 7-8 : boundary = 1 (area to the left of the line horizontally is extended as OUT) 

Line 8-9 : boundary = 1 (area to the left of the line horizontally is extended as OUT) 

 

So in the above example the "cut in" of the fence needs to be considered in the boundary conditions. 

The line 4-5 needs to have a boundary condition of 2, otherwise the software would project an out zone to infinity which would also include some of the In zone in the area of 6-7.  The same is true for line 5-6.

Same is also true for line 6-7.  This would project an out zone (to the left) and limit the mowers travel to below point 6.

The boundary condition 2 is only used for these special cases. 

As a rule of thumb:

  • if you can project out from the 2 GPS fence coordinates in the Out direction without crossing into the IN zone of another fence set, the boundary should be 1.
  • if you project out from the 2 GPS fence coordinates and cross another area which is an IN zone. The boundary condition should be set as 2.
  • Pay special attention to areas of the fence which create cut in areas.

Simulation

The simulation tool can ensure that all the boundary conditions are set correctly before going live.  Let the mower move around the fence and see if the mower crosses the line.  If the mower crosses the line check which boundary condition needs to be changed.

If the mower is prevented from entering a certain section, then probably a part of the fence is projecting into that area and needs a change of boundary condition in the code.