Storing the noisemap

Discussion in 'Presence Sensor' started by Andrey G, Jul 19, 2018.

  1. Andrey G

    Andrey G New Member

    My goal is to use the stored noise map after each reboot instead of building it up from scratch every time I reset the module.
    My sketch is based on `X4M300_plot_movementlist.py`


    What I've tried is storing the noisemap right after the initialization is done:

    ...
    while state == XTS_VAL_PRESENCE_PRESENCESTATE_INITIALIZING:

    d = x4m300.read_message_presence_movinglist()
    state = d.presence_state
    print("Initializing Done!")

    print("Storing noisemap...")
    x4m300.store_noisemap()

    And then loading it on the next boot:

    ...
    print("Start profile execution.")
    x4m300.set_sensor_mode(XTID_SM_RUN, 0) # Make sure no profile is running.

    print("Loading noisemap...")
    x4m300.load_noisemap()
    But I'm getting `XTS_SPR_ERROR` trying to load it. I understand that noisemap control (`set_noisemap_control()`) is broken right now, but `set/load_noisemap()` should still work? What am I doing wrong?
     
  2. Christian Rødli Amble

    Christian Rødli Amble Member Staff Member

    Hello Andrey,

    set_noisemap_control() is not generally broken, the problem in the linked thread was that not all settings were supported and it gave an error when trying to set it to an unimplemented mode. With the latest version I think it just ignores trying to turn off adaptive mode.

    Loading a noisemap with a profile running, however, is not implemented. To load a stored noisemap the "use stored noise map" setting in set_noisemap_control() must be turned on (in previous versions this was called turning "initialize on reset" off) some time between loading the profile and setting sensor mode run. The setting will be stored associated with the profile. Please refer to the datasheet for a complete description of how this works.

    There is also a quite involved python example included, X4M200_X4M300_manipulate_noisemap.py, that shows how to initialize, download and upload noisemaps.
     
  3. Andrey G

    Andrey G New Member

    Cool, it seems like it works.

    I had to spend some time figuring it out, and from what I can tell with `XTID_NOISEMAP_CONTROL_INIT_ON_RESET` turned off, a new noisemap initialized only if:

    xep.delete_file(XTFILE_TYPE_NOISEMAP_FAST, 0)
    xep.delete_file(XTFILE_TYPE_NOISEMAP_SLOW 0)

    Are called prior to `app.set_sensor_mode(XTID_SM_RUN, 0)`. Is that correct?

    I have two questions:

    1. Is there a better way to gauge when the initialization is done other than wait for 130 (w/ new noisemap) or 20 (w/o)?

    I've been using this function with some success, but for some reason I'm still getting `XTS_VAL_PRESENCE_PRESENCESTATE_PRESENCE` while the device is still initializing (the LED is green):


    def initialize():
    time.sleep(20)
    while True:

    state = app.read_message_presence_movinglist().presence_state
    if state != XTS_VAL_PRESENCE_PRESENCESTATE_INITIALIZING:

    break

    2. At the end of `X4M200_X4M300_manipulate_noisemap.py`, how does this code update the noisemap?

    nms_fast = []
    nms_slow = []
    for ix in range(5):

    time.sleep(50)
    app.store_noisemap()
    time.sleep(10)
    nms_fast.append(xep.get_file(XTFILE_TYPE_NOISEMAP_FAST, 0))
    nms_slow.append(xep.get_file(XTFILE_TYPE_NOISEMAP_SLOW, 0))

    Are `nms_fast/slow` interacting with `store_noisemap()` in some way?
     
  4. Christian Rødli Amble

    Christian Rødli Amble Member Staff Member

    A new noisemap is initialized if one doesn't exist stored in the sensor (either because the sensor is new, or because it was deleted as in the lines you posted), or if the size of the one stored doesn't match the noisemap size of the requested profile/detection zone.

    1. You may be reading old messages. In Module Connector, incoming messages are placed in a queue with a maximum size of 1000, and are read in order of arrival by the read method. This may include messages buffered in the sensor from before you connected. You may try flushing the queue after loading the profile:
    Code:
    while x4m300.peek_message_presence_movinglist(): # returns queue size, stops when 0
        x4m300.read_message_presence_movinglist()
    After that, reading until you hit something other than initializing should work.

    2. XEP has a primitive file system that is used to store the noisemap, which is what is used in the example. (The latest version also has a delete_noisemap() command accessible through the X4M300 interface, which essentially does the same thing. Sooner or later we'll get around to implement similar easy to use functions for the other functionality.) The store_noisemap() command writes the noisemap that is currently active in the sensor to this filesystem. When the "use stored noisemap" is on (or, equivalently, ""initialize on reset" is off), it will also store the noisemap after the initialization period as if store_noisemap() had been called. In the quoted lines, store_noisemap() is called and overwrites the internally stored noisemap, and the updated noisemap is then read out of the filesystem and appended to the lists. The end result is that each list contains five noisemaps, stored every minute over five minutes. Only the last noisemap pair remains on the sensor.