Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Check whether two numbers are within a range

by Anonymous Monk
on Feb 26, 2021 at 16:37 UTC ( [id://11128847]=note: print w/replies, xml ) Need Help??


in reply to Check whether two numbers are within a range

You could use Manhattan (a.k.a. L1) distance, that is, check if abs($x - $x0) + abs($y - $y0) <= $thresh, but the area where the expression is true is a square on the latitude/longitude grid. You could also use the Euclidean (L2) distance, i.e. sqrt(($x - $x0)**2 + ($y - $y0)**2) <= $thresh, which designates a circle with radius $thresh around the point ($x0, $y0).

On a very small scale, you can ignore the fact that the latitude and longitude grid describes a spheregeoid instead of a flat area and keep the assumptions above (about the square and the circle). If you are truly interested, you can find out the coordinates of the corners of the garage and check if the point falls inside the polygon described by those coordinates.

By the way, is your GPS precise enough to position your car when inside the garage?

Replies are listed 'Best First'.
Re^2: Check whether two numbers are within a range
by stevieb (Canon) on Feb 26, 2021 at 17:04 UTC
    "By the way, is your GPS precise enough to position your car when inside the garage?"

    100% yes (even if it lost GPS signal, I assume the car itself would be able to calculate speed, direction etc enough to formulate its position within a high degree of accuracy. For example, last week I drove through a long snow tunnel on my way to and fro Vancouver, and the car had no complaints driving itself and keeping track of its position on the map. I don't pretend to know exactly how it all works though).

    Update: I am reading directly from Tesla's API which provides vehicle data from the car's internal systems, including GPS.

      > I assume the car itself would be able to calculate speed, direction etc enough to formulate its position

      my guess is rather the grid of local wifi (UD: and Bluetooth) signals. GPS accuracy is dumbed down for military reasons.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Re^2: Check whether two numbers are within a range
by LanX (Saint) on Feb 26, 2021 at 17:24 UTC
    > but the area where the expression is true is a square on the latitude/longitude grid.

    Yes, a 90° rotated square with the tips on the axes.

    I think abs($x - $x0) <= $d_x and abs($y - $y0) <= $d_y is more intuitive here.

    This really depends on the local geometry though and torsion between geo-grid and garage (i.e. a rotation could help, too)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      I'll also be using two HC-SR04 sonar-based proximity sensors to doubly confirm that the car is actually where it says it is, as I'm also including the ability for the garage door to close once the vehicle is in place, so the GPS is just initial location data to start firing the proximity sensors.

      A HC-SR501 PIR sensor will sense motion which will start monitoring GPS for proximity to its proper place in the garage. Once it's within the desired range (2 metres or so), it'll fire the sonar sensors to ensure it's inside the garage so the door can shut. If it's just someone in the garage and the car isn't anywhere near the house, we stop doing all work.

      I'm using a Raspberry Pi Zero for the backend API logic which will communicate to a Wemos D1 mini over bluetooth in the garage which will automate the garage door, display the charge level via LED strip, and sound the audible "PLUG IN YOUR DAMNED CAR" warning if battery percent is lower than my desired level.

        Cool!

        Nice to see Elon is providing you a Muskberry Pi to play with... ;)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11128847]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-16 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found