View unanswered posts | View active topics It is currently Sat Oct 25, 2014 3:01 pm






Reply to topic  [ 4 posts ] 
Dexterindustries dGPS_for_RobotC_-_Datalog_to_KML.c Program 
Author Message
Rookie

Joined: Mon Jun 04, 2012 9:31 am
Posts: 6
Post Dexterindustries dGPS_for_RobotC_-_Datalog_to_KML.c Program
I compiled the dGPS_for_RobotC_-_Datalog_to_KML.c program with ROBOTC version 3.51
The only thing that I changed was the driver to "dexterind-gps.h".
I get two errors on line 118 and 119 when compiling the program:
"Invalid cast type from 'float' to 'string' "
on the two lines of code:
string slat = (string)Lat;
string slon = (string)Lon;

Any help would be much appreciated.
Joe


Wed Nov 21, 2012 7:11 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Dexterindustries dGPS_for_RobotC_-_Datalog_to_KML.c Pro
This is off the top of my head, but try this:
Code:
sprintf(slat, "%f", Lat);
sprintf(slon, "%f", Lon);

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Nov 22, 2012 1:41 am
Profile WWW
Rookie

Joined: Mon Jun 04, 2012 9:31 am
Posts: 6
Post Re: Dexterindustries dGPS_for_RobotC_-_Datalog_to_KML.c Pro
Thanks,
Using the Dexter Industries DGPS, are there sample robotc programs for navigating a NXT TETRIX robot from point A to point B?

Joe


Mon Dec 03, 2012 10:30 am
Profile
Rookie

Joined: Mon Apr 08, 2013 12:50 pm
Posts: 10
Post Re: Dexterindustries dGPS_for_RobotC_-_Datalog_to_KML.c Pro
Hello Community!

I have modified the google earth kml-programm of Xander a little bit.
It is now possible to modify logging interval of data or pause datalogging.
You have to save the path.txt file to *.kml file for google earth e.g. with
windows editor.
It works very well! I used RobotC Vers. 3.60 and latest drivers from Xander.

Bye, Sigtrygg



Code:
#pragma config(Sensor, S1,     DGPS,                sensorI2CCustom)
#include "drivers/dexterind-gps.h"

// This program is based off of work done by Xander.  Visit his website at http://mightor.wordpress.com/
// Read the Dexter Industries GPS sensor for positional data.  For more on the Dexter Industries GPS Sensor
// vist http://www.dexterindustries.com
// This code is an example of reading the GPS sensor for positional data.
//
// This program datalogs a journey, and saves the coordinates in KML style format for display on google earth.
// It first generates a header.
// Then it adds lat/long data into the file.
// When the program is stopped with the red button, the footer is inserted.
// The file can be saved to the computer.  Use notepad (or equivalent) to "Save As" *.kml
// You should be able to pull the file up and see on Google Earth.

// Note that the default filename in this program is "Path.txt".  You can
// rename it anything you like, as long as it's *.txt.

// Give a file name.
// Will have to rename this as a .kml file after downloading to desktop.


//*****************************************************************************************************************

string slat = "";
string slon = "";
int mode_continous=0;
int mode_datapoint=0;
int mode_exit=0;
int interval=10; //continous mode writes data every 10 seconds
int maxtime;
int recordtime;
long valTime10;
const string sFileName = "Path.txt";  // Our destination KML File
[color=#4000FF][/color]
TFileIOResult nIoResult;
TFileHandle hFileHandle;
// NOTE ON FILESIZE:  Note that the header that's inserted by default is about 800 bytes.
// NOTE ON FILESIZE:  Every data point added is about 30 bytes in size.
int nFileSize = 30000; //about 162 min datalogging with an interval of 10s

void write_header()
{

   WriteString(hFileHandle, nIoResult, "<?xml version=\'1.0\'");
   WriteString(hFileHandle, nIoResult, " encoding= \'UTF-8\'");
   WriteString(hFileHandle, nIoResult, "?>");
   WriteText(hFileHandle, nIoResult, "\r\n");

   WriteString(hFileHandle, nIoResult, "<kml xmlns=");
   WriteText(hFileHandle, nIoResult, "\'http://www.opengis");
   WriteText(hFileHandle, nIoResult, ".net/kml/2.2\'");
   WriteText(hFileHandle, nIoResult, ">");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "  <Document>\r\n");
   WriteText(hFileHandle, nIoResult, "    ");
   WriteText(hFileHandle, nIoResult, "<name>Paths</name>");
   WriteText(hFileHandle, nIoResult, "\r\n");

   WriteText(hFileHandle, nIoResult, "    <description>");
   WriteText(hFileHandle, nIoResult, "</description>\r\n");
   WriteText(hFileHandle, nIoResult, "    <Style id=\'yel");
   WriteText(hFileHandle, nIoResult, "lowLineGreenPoly\'>");
   WriteText(hFileHandle, nIoResult, "\r\n");

   WriteText(hFileHandle, nIoResult, "      <LineStyle>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "        <color>7f0");
   WriteText(hFileHandle, nIoResult, "0ffff</color>");
   WriteText(hFileHandle, nIoResult, "\r\n");

   WriteText(hFileHandle, nIoResult, "        <width>4</");
   WriteText(hFileHandle, nIoResult, "width>\r\n");
   WriteText(hFileHandle, nIoResult, "      </LineStyle>");
   WriteText(hFileHandle, nIoResult, "\r\n");

   WriteText(hFileHandle, nIoResult, "      <PolyStyle>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "        <color>7f0");
   WriteText(hFileHandle, nIoResult, "0ff00</color>");
   WriteText(hFileHandle, nIoResult, "\r\n");

   WriteText(hFileHandle, nIoResult, "      </PolyStyle>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "    </Style>");
   WriteText(hFileHandle, nIoResult, "\r\n");

   WriteText(hFileHandle, nIoResult, "    <Placemark>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "      <name>Absol");
   WriteText(hFileHandle, nIoResult, "ute Extruded</name>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "      <description>");
   WriteText(hFileHandle, nIoResult, "</description>\r\n");
   WriteText(hFileHandle, nIoResult, "      <styleUrl>#");
   WriteText(hFileHandle, nIoResult, "yellowLineGreenPoly");
   WriteText(hFileHandle, nIoResult, "</styleUrl>\r\n");
   WriteText(hFileHandle, nIoResult, "      <LineString>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "        <extrude>");
   WriteText(hFileHandle, nIoResult, "10</extrude>\r\n");
   WriteText(hFileHandle, nIoResult, "        <tessellate");
   WriteText(hFileHandle, nIoResult, ">10</tessellate>\r\n");
   WriteText(hFileHandle, nIoResult, "        <altit");
   WriteText(hFileHandle, nIoResult, "udeMode>clampToG");
   WriteText(hFileHandle, nIoResult, "round");
   WriteText(hFileHandle, nIoResult, "</altitudeMode>\r\n");
   WriteText(hFileHandle, nIoResult, "        ");
   WriteText(hFileHandle, nIoResult, "<coordinates> ");
   //Phew!
}

void write_footer()
{

   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "        ");
   WriteText(hFileHandle, nIoResult, "</coordinates>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "      </LineString>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "    </Placemark>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "  </Document>");
   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "</kml>");
   WriteText(hFileHandle, nIoResult, "\r\n");
}

void write_GPS_coords()
{
   // Function reads coordinates from GPS, converts to decimal degrees.
   // Writes coordinates to file.

   float Lat = (float)DGPSreadLatitude(S1)/1000000;     // Lat will be in decimal degrees
   float Lon = (float)DGPSreadLongitude(S1)/1000000;    // Lon will be in decimal degrees

   nxtDisplayStringAt(0, 20, "Lat:");
   nxtDisplayStringAt(0, 10, "Lon:");

   nxtDisplayStringAt(30, 20, "%3.6f", Lat);
   nxtDisplayStringAt(30, 10, "%3.6f", Lon);

   StringFormat(slat, "%3.6f", Lat);
   StringFormat(slon, "%3.6f", Lon);

   WriteText(hFileHandle, nIoResult, "\r\n");
   WriteText(hFileHandle, nIoResult, "   ");
   WriteText(hFileHandle, nIoResult, slon);
   WriteText(hFileHandle, nIoResult, ",");
   WriteText(hFileHandle, nIoResult, slat);
   WriteText(hFileHandle, nIoResult, ",");
   WriteText(hFileHandle, nIoResult, "0");

}

void startscreen()
{
   nxtDisplayStringAt(0, 60, "GPS Datalogger");
   nxtDisplayStringAt(0, 50, "Waiting!");
   nxtDisplayStringAt(0, 40, "Left: single point");
   nxtDisplayStringAt(0, 30, "Right: continuous");
   nxtDisplayStringAt(0, 20, "Center: stop");
}

task checkbutton()
{
   while (true)
   {
      wait1Msec(800);// make sure, that button is pressed for 800 ms, because to avoid unintentionally pressing
      switch(nNxtButtonPressed)
      {
      case 1:
         mode_continous=1;
         ClearTimer(T1);
         recordtime=recordtime*60;
         break;

      case 2:
         mode_datapoint=1;
         break;

      case 3:
         mode_exit=1;
      }
      if (mode_continous==1 && mode_datapoint==1) //pause of continous mode
      {
         eraseDisplay();
         startscreen();
         mode_continous=0;
         mode_datapoint=0;
      }
      if (mode_exit==1)
      {
         //end of datalogging
         wait1Msec(500);
         write_footer();
         Close(hFileHandle, nIoResult);
         StopAllTasks();
      }
   }
}


task main()
{
   hFileHandle = 0;
   Delete(sFileName, nIoResult);
   OpenWrite(hFileHandle, nIoResult, sFileName, nFileSize);
   write_header(); //  Writes the header of the kml file.

   eraseDisplay();
   nxtDisplayTextLine(0,"Eingabe des Daten");
   nxtDisplayTextLine(1,"intervalls[s]");

   while (nNxtButtonPressed!=3)
   {
      if (nNxtButtonPressed==1)
      interval++;
      wait1Msec(150);
      if (nNxtButtonPressed==2)
      interval--;
      wait1Msec(150);
      maxtime=(long)(nFileSize-800)*interval/(60*30);//in minutes
      nxtDisplayTextLine(3,"Intervall[s]:%d",interval);
      nxtDisplayTextLine(5,"max.Zeit[min]:%d",maxtime );
   }
   eraseDisplay();
   StartTask(checkbutton);

   while (mode_exit !=1)
   {
      if(mode_datapoint==1)
      {
         nxtDisplayStringAt(0, 60, "GPS Datalogger");
         nxtDisplayStringAt(0, 30, "Writing Point");
         write_GPS_coords();
         wait1Msec(1000);
         eraseDisplay();
         mode_datapoint=0;
      }
      if (mode_continous==1)
      {
         eraseDisplay();
         valTime10 = time10[T1];
         recordtime=(recordtime+valTime10/100)/60;
         nxtDisplayStringAt(0, 60,"Recordtime: %d",recordtime);
         nxtDisplayStringAt(0, 50,"Max.time: %d",maxtime);
         write_GPS_coords();
         wait10Msec(interval*100);//write data according interval!

         if (recordtime==maxtime-1)
         {
            wait1Msec(500);
            write_footer();
            Close(hFileHandle, nIoResult);
            StopAllTasks();
            mode_exit=1;//when reaching the max. recordtime, exit with closing file
            eraseDisplay();
         }

      }

      startscreen();
   }


}

//modified by Sigtrygg, April 2013


Fri May 17, 2013 4:16 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.