This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Acceleration active and deactivate GPS

Dear, 

Im trying to use the motion to activate the GPS and deactivate GPS:

    1. when it moves, GPS will be activated: Position-ON 

   2. when it stops, GPS will be activated again: Position-OFF

Currently, I used the sensor_trigger_set() to enable GPS when it detects the motion as in :https://github.com/NordicPlayground/fw-nrfconnect-nrf/tree/master/applications/asset_tracker

But, I dont know how to implement the step 2:  when it stops, GPS will be activated again: Position-OFF

Could you plz help me, thanks so much 

My HW: THINGY:91 

Modem FW: v1.1.1

ncs_1.2.0

BR, 

Hoang Ng

Parents Reply Children
  • How do you define the "STOP" position? Is it to be detected based on a sensor event, or a timeout event? How to distinguish a stop at a traffic light vs. an actual stop?

    I tried to use the timeout event, for example in 1mn, if no motion --> actual stop 

    One way of doing this can be: if you store the time since last registered movement, then start the GPS a given amount of time after the last movement was detected.

    Ja,  I will try this one Smiley

    Thanks 

    BR

  • Hi

    I tried: 

    1. accelerate trigger will : 

           1.1. Reset the timer: Timer 

           1.2. Start the timer: Timer

    2. If the Timer > 5mn (no motion in 5mn) -->Stop --> enable GPS to find Stop-Position 

    So, I need a function for the timer , and i found :

     https://devzone.nordicsemi.com/f/nordic-q-a/59950/timers-in-nrf9160-soc/244049#244049

    And, i modified the timer_cb() to test:

    void timer_cb(nrf_timer_event_t event_type, void * p_context) {
        printk("start GPS ..\n");
        gps_control_init(&application_work_q, gps_trigger_handler);
        printk("set_gps_enable----------\r");
        set_gps_enable(true);
    }

    i want i can start the GPS, but I got the error:

    start GPS ..
     gps_control_init(struct k_work_q  gps_trigger_handler_t handler 
    
     device_get_binding ---------- 
    
     gps_trigger_set ---------- 
    
    ASSERTION FAIL [!arch_is_in_isr()] @ C:/Demos/nordic/ncs_09032020/zephyr/kernel/include/ksched.h:269
    	
    [00:00:01.542,327] [1B][1;31m<err> os: r0/a1:  0x00000004  r1/a2:  0x0000010d  r2/a3:  0x00000001[1B][0m
    [00:00:01.551,177] [1B][1;31m<err> os: r3/a4:  0x40008000 r12/ip:  0x00000000 r14/lr:  0x0002e7cb[1B][0m
    [00:00:01.560,058] [1B][1;31m<err> os:  xpsr:  0x6100001f[1B][0m
    [00:00:01.565,368] [1B][1;31m<err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000[1B][0m
    [00:00:01.575,988] [1B][1;31m<err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000[1B][0m
    [00:00:01.586,639] [1B][1;31m<err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000[1B][0m
    [00:00:01.597,259] [1B][1;31m<err> os: s[12]:  0x00000000  s[13]:  0x00000002  s[14]:  0x00000000  s[15]:  0x00000000[1B][0m
    [00:00:01.607,910] [1B][1;31m<err> os: fpscr:  0x4000f000[1B][0m
    [00:00:01.613,220] [1B][1;31m<err> os: Faulting instruction address (r15/pc): 0x00033284[1B][0m
    [00:00:01.621,307] [1B][1;31m<err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0[1B][0m
    [00:00:01.629,180] [1B][1;31m<err> os: Fault during interrupt handling
    

    How can I use the timer to start the GPS?

    Do you have any suggestions?

    Thanks so much 

  • Hi,

     

    You are asserting because a kernel function is called from interrupt context. Try setting a flag and handle it in main, or push the work to a workqueue instead.

    Note that all socket operations will trigger an interrupt to communicate with the modem, so no socket functions should be called from an interrupt.

     

    Kind regards,

    Håkon

  • Thank

    I will read and try to understand your guide. Thanks a lot ( Sorry, I don't have knowledge about programming )

    BR, 

    Hoang Nguyen

  • Hi Hoang,

     

    Its not stated directly that you shouldn't call socket operations directly from interrupt, nor that the kernel timers are executed in interrupt context, and we should document this a bit better. I'll write it down as a improvement and report it internally.

     

    Kind regards,

    Håkon

Related