Saved GPS reading is retained even after taking a new GPS reading

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
lmoriba
Posts: 56
Joined: June 10th, 2018, 6:21 pm

Saved GPS reading is retained even after taking a new GPS reading

Post by lmoriba »

Dear CSPRO community,

I have a big dilemma here with my application. For brevity, the application is designed to collect data about electric Poles: record Pole Numbers, GPS coordinate of the Poles and compounds connected to the poles. For any given pole varying number of compounds can be connected. I made the pole number a unique identifier variable and set the attribute to persistent. The GPS coordinate of the pole, I couldn't make as unique identifier because the gps uses decimals. So, I used save setting to save GPS coordinates of the pole so I can replicate and use for all compounds attached to the pole. So, In effect, I want to acquire a new gps reading anytime the pole number changes. The application seems to be working but the only hitch: if the pole is assigned a new number and a new gps reading is obtained, on saving, the application changes it to the old saved gps reading. So, am seeking for help, an urgent one for that matter.

Attached is the application with all the coding plus some test data.

nawec Survey.zip
(587.29 KiB) Downloaded 148 times
Last edited by lmoriba on February 14th, 2021, 5:18 am, edited 2 times in total.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Saved GPS reading is retained even after taking a new GPS reading

Post by josh »

Your application logic always loads the saved GPS coordinates and uses those without looking to see if the pole number changed. You could save the pole number as well using savesetting() and then only use the saved values when the saved pole number is the same as the pole number that was entered.

I also noticed that you are currently saving the GPS coordinates using savesetting() in the procs of POLE_LONGITUDE and POLE_LATITUDE. It would be better to do that in your getGPSPole() function instead. Otherwise if you capture the GPS before the POLE_LONGITUDE and POLE_LATITUDE procs you will not save the correct values.
lmoriba
Posts: 56
Joined: June 10th, 2018, 6:21 pm

Re: Saved GPS reading is retained even after taking a new GPS reading

Post by lmoriba »

Dear Josh,
Many thanks for the suggestions. However, I am still having problems, the Pole Latitude is always saved with constant gps reading whilst the Longitude is saved with correct reading. However, if I changed the Pole numbering the saved pole Latitude reading is retrieved whilst the Longitude reading is blank. Now here is the Changes I made in the

function getGPSPole()
gps(open);

if gps(read,60,10,"Reading GPS, Please wait...") = 1
and accept(maketext("Save this location? %f, %f",gps(latitude),gps(longitude)),"Yes","No") = 1 then

{if accept("Save this result", "Yes", "No") = 1 then}
POLE_LATITUDE = gps(latitude);
savesetting("POLE_LONGITUDE", maketext("%v",POLE_LONGITUDE));
POLE_LONGITUDE = gps(longitude);
savesetting("POLE_LONGITUDE", maketext("%v",POLE_LONGITUDE));

else
errmsg("GPS signal could not be acquired");
endif;
gps(close);
end;



For the Pole Number, I added this:

I11_POLENUMBER
preproc


if loadsetting("I11_POLENUMBER") <> "" then
I11_POLENUMBER = loadsetting("I11_POLENUMBER");
//noinput;
endif;

postproc

savesetting("I11_POLENUMBER", maketext("%v",I11_POLENUMBER));


For the Pole Latitude, I maintained this logic

PROC POLE_LATITUDE
preproc

ASK IF I11_POLENUMBER <> '0';
// Check for saved POLE_LATITUDE

//savesetting(clear);

if loadsetting("POLE_LATITUDE") <> "" then
POLE_LATITUDE = tonumber(loadsetting("POLE_LATITUDE"));
noinput;
endif;

Similarly, for the Pole Longitude, I maintained

POLE_LONGITUDE

preproc

ASK IF I11_POLENUMBER <> '0';
//savesetting(clear);
// Check for saved POLE_LONGITUDE
if loadsetting("POLE_LONGITUDE") <> "" then
POLE_LONGITUDE = tonumber(loadsetting("POLE_LONGITUDE"));
noinput;
endif;


I can't figure out where am going wrong?? Thanks in advance.
Attachments
NSurvey.rar
(99.08 KiB) Downloaded 153 times
Last edited by lmoriba on February 14th, 2021, 5:16 am, edited 1 time in total.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Saved GPS reading is retained even after taking a new GPS reading

Post by josh »

Problem might be here:

Code: Select all

POLE_LATITUDE = gps(latitude);
savesetting("POLE_LONGITUDE", maketext("%v",POLE_LONGITUDE));
POLE_LONGITUDE = gps(longitude);
savesetting("POLE_LONGITUDE", maketext("%v",POLE_LONGITUDE));
You probably want POLE_LATITUDE in the first call to savesetting. You have POLE_LONGITUDE in both.
lmoriba
Posts: 56
Joined: June 10th, 2018, 6:21 pm

Re: Saved GPS reading is retained even after taking a new GPS reading

Post by lmoriba »

Dear Josh,

Many thanks for the suggestion. I effected the rectification in the logic statements in function getgpsPole() as follows:-
function getGPSPole()
gps(open);

if gps(read,60,10,"Reading GPS, Please wait...") = 1
and accept(maketext("Save this location? %f, %f",gps(latitude),gps(longitude)),"Yes","No") = 1 then

{if accept("Save this result", "Yes", "No") = 1 then

Code: Select all

  POLE_LATITUDE = gps(latitude);
			savesetting("POLE_LATITUDE", maketext("%v",POLE_LATITUDE));
			POLE_LONGITUDE = gps(longitude);
			savesetting("POLE_LONGITUDE", maketext("%v",POLE_LONGITUDE));
[/color]

else
errmsg("GPS signal could not be acquired");
endif;
gps(close);
end;


However, I still have problem: the captured gps is different from gps that is saved. For example, the captured gps was (13.386803, -16.697432) this when saved became saved as (13.3868026, -16.6974318)? Secondly, when I want to do recording for a second compound supposedly on the same pole, Pole number remained the same as previously entered but the gps coordinates appeared blank. So that am compelled to take another reading.

The whole idea is to be able to store the Pole Number and the captured gps of the pole and use this information for a number of compounds connected to the same pole without Changing their values. The only time pole number and coordinate changes is when I moved to a new pole. In this case, I will input the new pole number details and obtain the new gps coordinates of the pole. Could the approach be wrong? Is there a better of implementing this more effectively. Is the savesetting not distorting the captured gps coordinate?

Please, I need urgent assistance because this is the only holding our field operations. Thanks in advance.

Find attached the application and the compiled one used as test in the android.
Last edited by lmoriba on February 14th, 2021, 5:22 am, edited 1 time in total.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Saved GPS reading is retained even after taking a new GPS reading

Post by josh »

What I was suggesting before is that if the pole number has changed that you clear the saved values of latitude and longitude if the pole number is different from the old value. Something like:
PROC I11_POLENUMBER
preproc

string
lastPoleNumber = loadsetting("I11_POLENUMBER");
if lastPoleNumber <> "" then
   
I11_POLENUMBER = lastPoleNumber;
endif;

postproc

if
lastPoleNumber <> I11_POLENUMBER then
    savesetting
("I11_POLENUMBER", I11_POLENUMBER);

    // pole changed, clear saved GPS
   
savesetting("POLE_LATITUDE", "");
   
savesetting("POLE_LONGITUDE", "");
endif;
Since you have the function that captures GPS coordinates on the userbar it makes it a bit more complicated since you have to account for the case where the GPS is captured before you get to the I11_POLENUMBER and where it is captured after. It would be better to have the GPS capture launched from a specific field on the form so you can better control when it happens.
lmoriba
Posts: 56
Joined: June 10th, 2018, 6:21 pm

Re: Saved GPS reading is retained even after taking a new GPS reading

Post by lmoriba »

Dear Josh,
Again many thanks. I still can't get it right!. I have now moved the gps capture as function to a variable now on the form. I tried to incorporate the logic you suggested for the Pole number as given below:

preproc

string lastPoleNumber = loadsetting("I11_POLENUMBER");
if lastPoleNumber <> "" then
I11_POLENUMBER = lastPoleNumber;
endif;

postproc

if lastPoleNumber <> I11_POLENUMBER then
savesetting("I11_POLENUMBER", I11_POLENUMBER);

// pole changed, clear saved GPS
savesetting("POLE_LATITUDE", "");
savesetting("POLE_LONGITUDE", "");
endif;

Also, for the pole gps taken, I put as variable on the form with following logic:

onfocus

if visualvalue(POLE_LATITUDE) = 99 or visualvalue(POLE_LATITUDE) = notappl then
setvalueset($, GPS_NOT_TAKEN_VS2);
else
setvalueset($, GPS_TAKEN_VS1);
endif;

postproc
if $ = 1 then
// Take new GPS reading
gps(open);

if gps(read,60,10,"Reading GPS, Please wait...") = 1
and accept(maketext("Save this location? %f, %f",gps(latitude),gps(longitude)),"Yes","No") = 1 then

{if accept("Save this result", "Yes", "No") = 1 then}
POLE_LATITUDE = gps(latitude);
savesetting("POLE_LATITUDE", "");

POLE_LONGITUDE = gps(longitude);
savesetting("POLE_LONGITUDE", "");

else
errmsg("GPS signal could not be acquired");
endif;
gps(close);
reenter;


elseif $ = 2 then
// Show current readings on map
//execsystem(maketext("gps:%f,%f",
// visualvalue(LI_LATITUDE),
// visualvalue(LI_LONGITUDE)));
// reenter;
elseif $ = 3 then
// Keep the readings and move to next field
skip to COMPOUND_NUMBER;
elseif $ = 9 then
// Remove current readings
POLE_LATITUDE = 99.000000000;
POLE_LONGITUDE = 99.000000000;

endif;

One thing I noticed is that the Pole gps is being read and saved correctly for the first compound. However, for the second compound connected to the pole, the pole number is saved but the acquired gps is blank suggesting that the Pole gps be acquired again. I expect already acquired pole gps reading to be saved. I only want to change Pole and Pole GPS reading if the pole number changes.

I will attach the application once more. Thanks in advance.
Last edited by lmoriba on February 14th, 2021, 5:22 am, edited 1 time in total.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Saved GPS reading is retained even after taking a new GPS reading

Post by josh »

Doing this:

skip to COMPOUND_NUMBER;

from PROC POLE_GPS_TAKEN is going to erase the values in POLE_LATITUDE and POLE_LONGITUDE. When you skip over fields they get set to blank when you save the data. You can use ADVANCE instead of SKIP. The easier way though is not to even put POLE_LATITUDE and POLE_LONGITUDE on the form at all. If they are in the dictionary but not on the form then they will get saved.
lmoriba
Posts: 56
Joined: June 10th, 2018, 6:21 pm

Re: Saved GPS reading is retained even after taking a new GPS reading

Post by lmoriba »

Dear Josh,

I refer you to two attachments: Capture1 and Capture2. Capture1, I started a new case and save partial. Because it is new case I read the gps and successully saved it, partially. In capture2 ,I started a new case because I want to input another compound on the same pole. I don't have to capture gps but retrieve the same gps coordinates in capture1. However, pole number remained the same but gps coordinates are blank? In the application attached I have now change the logic in Proc_Pole_GPS_taken
PROC POLE_GPS_TAKEN


onfocus

if visualvalue(POLE_LATITUDE) = 99 or visualvalue(POLE_LATITUDE) = notappl then
setvalueset($, GPS_NOT_TAKEN_VS2);
else
setvalueset($, GPS_TAKEN_VS1);
endif;

//postproc
if $ = 1 then
// Take new GPS reading
gps(open);

if gps(read,60,10,"Reading GPS, Please wait...") = 1
and accept(maketext("Save this location? %f, %f",gps(latitude),gps(longitude)),"Yes","No") = 1 then

{if accept("Save this result", "Yes", "No") = 1 then}
POLE_LATITUDE = gps(latitude);
savesetting("POLE_LATITUDE", "");
POLE_LONGITUDE = gps(longitude);

savesetting("POLE_LONGITUDE", "");
ADVANCE TO COMPOUND_NUMBER;

else
errmsg("GPS signal could not be acquired");
endif;
gps(close);
//reenter;


elseif $ = 2 then
// Show current readings on map
//execsystem(maketext("gps:%f,%f",
// visualvalue(LI_LATITUDE),
// visualvalue(LI_LONGITUDE)));
// reenter;
elseif $ = 3 then
// Keep the readings and move to next field
advance to COMPOUND_NUMBER;
elseif $ = 9 then
// Remove current readings
POLE_LATITUDE = 99.000000000;
POLE_LONGITUDE = 99.000000000;

endif;

Please, I want the Pole number and gps taken to be saved until, I finished capturing the details of N number of compounds attached to this pole. When I move to new pole I want to change the Pole number and acquire new gps to be used again for N number of compounds attached to that Pole.
Last edited by lmoriba on February 14th, 2021, 5:23 am, edited 1 time in total.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Saved GPS reading is retained even after taking a new GPS reading

Post by josh »

It looks like you deleted the logic that assigned the previously saved values to POLE_LATITUDE and POLE_LONGITUDE so of course they will be blank. In the preproc of POLE_GPS_TAKEN if there are saved values you need to set them. You use to have logic that did that but it seems to be gone in the list latest version:
PROC POLE_GPS_TAKEN
preproc
if loadsetting
("POLE_LATITUDE") <> "" then
   
POLE_LATITUDE = tonumber(loadsetting("POLE_LATITUDE"));
endif;
if loadsetting("POLE_LONGITUDE") <> "" then
   
POLE_LONGITUDE = tonumber(loadsetting("POLE_LONGITUDE"));
endif;
Post Reply