Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

toothlessblue

Members
  • Content Count

    1
  • Joined

  • Last visited

Posts posted by toothlessblue

  1. Hello! I have appropriated code from Log's GPS system to make it better suit my situation.

    I need a very lightweight way for drones and microcontrollers to get their global position on startup, and Logs client code was too large, I really need the space on the EEPROM to fit everything else.

    To be clear, Log is entirely responsible for the algorithm, I've packed it up and gave it a nice interface.

     

    Usage (first, to entice you)

    - Broadcast "LOCATE", random number, on port 2

    - Wait less than a second for a "POSITION" response

    Easy peasy

    local component = require('component')
    local event = require('event')
    local modem = component.modem
    
    modem.open(2)
    modem.broadcast(2, 'LOCATE', math.random())
    
    local ev = {true}
    
    while ev[1] ~= nil do
        ev = { event.pull(1, 'modem_message') }
        if ev[1] then
            print(table.unpack(ev))
        end
    end

    The reason for broadcasting a random number along with the request is so the GPS network can identify which requests are related to each other.

     

    Setup

    The raw script is too large to fit on an EEPROM (6594 characters) so it needs to be crunched (to 3485 characters). You can install this with OPPM to crunch it yourself, but I've also attached the crunched GPS node file.

    You need at least 4 nodes.

    Here's my recommendation for components:

    image.png.416c03153479bac1d024f198368b7fbf.png

    - I've not tested it with less memory, but 1.5 isn't that much more expensive than 1.0.

    - The EEPROM should be flashed with gps-node.cr.lua

    - The sign upgrade is required, that's how the node will get its own position information on startup.

    image.png.a96ed8e4eb0eee064326145baca24a9b.png

    - It only works when the sign is placed on the front, not sure why, I guess microcontrollers can only read forwards (but the code is there to try every side)

    - Coordinates are ordered X, Y, Z

    - One coordinate per line

    If there's something wrong with the sign, the microcontroller will error and tell you the sign is wrong (it doesn't catch every case though)

    image.thumb.png.0fcf0da6418a4f73a87661aaa93c4bac.png

     

    Startup

    1. Start one node, wait between 5 and 10 seconds for it beep twice.

    2. Start every other node

     

    Example

    https://www.youtube.com/watch?v=x5yeGto9KTg

     

    Brief explanation

    1. Try to find master node

    2. Can't find one? become the master node

    3. Register with the master node, so it knows the position of the slave node

    4. Wait for a "LOCATE" packet

    5. Send distance data to the master node

    6. When the master node has enough information, calculate the position of the client

    7. Send the calculated position to the client

     

    Pros

    - Tiny client side code

    - Easy setup

    Cons

    - Difficult to change port

    - No space in microcontroller for solar power (wouldn't be too hard to hard code the position to the microcontroller, but I like the easy configurability)

    - Client must be in range of a master node (possibility of rewriting this in such a way that every node is a master node)

    client.lua gps-node.lua gps-node.cr.lua

    image.png

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.