some help needed with the TinyGPS library


hello -

i trying use of functions written in tinygps.h find heading, need on how call function. know if have define "currentcourse" string or float? right have float.

here's function trying call library:

const char *tinygps::cardinal (float course)
{
static const char* directions[] = {"n", "nne", "ne", "ene", "e", "ese", "se", "sse", "s", "ssw", "sw", "wsw", "w", "wnw", "nw", "nnw"};

int direction = (int)((course + 11.25f) / 22.5f);
return directions[direction % 16];
}

and code below, see function:void processgps()


also i'm getting error function saying "expected primary-expression before '==' token" --

i have long code attached , posted below. , guidance appreciated new arduino. if there's else find in code, can enhance or modify make better, please let me know. thanks!

code: [select]
/* dieudonné kaswa
 *  
 * goal of project similate self-driving car.
 *
 * */
 
 /*
  * hc-sr04 ping distance sensor:
  * vcc arduino 5v
  * gnd arduino gnd
  * trig arduino: right - pin13,  ctr - pin11, left - pin9
  * echo arduino: right - pin 12, ctr - pin10, left - pin8
 */

 /*
  * ublox - neo6m gps receiver
  * vcc arduino 5v
  * gnd arduino gnd
  * transmit signal on pin 4 arduino
  * receive  signal on pin 3 arduino
 */

// gps library , software serial
#include <softwareserial.h>
#include <tinygps.h>

// setting serial port , gps module
softwareserial gpsserial(4,3);            //rx,tx
tinygps gps;                              // creates gps object

// digital compass library & variables
#include <wire.h>
#include <adafruit_sensor.h>
#include <adafruit_lsm303_u.h>
#include <waypointclass.h>

// pin assignments
#define trigleft    9    // trigger left    sensor
#define trigctr     11   // trigger center  sensor
#define trigright   13   // trigger right   sensor
#define echoleft    8    // echo  left      sensor
#define echoctr     10   // echo  center    sensor
#define echoright   12   // echo  right     sensor
#define front1      a0   // motor 1, out 1
#define front2      a1   // motor 1, out 2
#define rear1       a2   // motor 2, out 3
#define rear2       a3   // motor 2, out 4
#define loaden      a4   // enable sig solenoid on a5
#define loaddrop    a5   // solenoid, out 4
#define greenled    7    // green led
#define redled      2    // red   led
#define ena         6    // enable sig mot1 pwm, black wire
#define enb         5    // enable sig mot2 pwm, brown wire
#define gpstx       4    // transmit signal pin, purple wire gps --> yellow wire arduino
#define gpsrx       3    // receive signal pin, blue wire
#define headingtol 10    // tolerance +/- (in degrees) within don't attempt turn intercept targetheading
/* waypoints */
#define waypoint_dist_tolerance  1   // tolerance in meters waypoint; once within tolerance, advance next waypoint
#define number_waypoints 3          // enter number of way points here (will run 0 (n-1))

// values initialization
/* motor speed variables */
int slowsp = 190;                     // rear motor slow spin speed
int maxrsp = 210;                     // rear motor max spin speed
int maxfsp = 250;                     // front motor max turn angle
/* ping sensor variables */
long duration;                        // duration used calculate distance ping sensor
int distance, distlft, distrgt;       // distance center ping sensor
/* compass variables */
int targetheading;                    // face reach destination
int currentheading;                   // facing
int headingerror;                     // signed (+/-) degrees difference between targetheading , currentheading
/* gps variables */
float currentcourse;
string latitude;  
string longitude;
float currentlat,
      currentlong,
      targetlat,
      targetlong;
int distancetotarget,                 // current distance target (current waypoint)
    originaldistancetotarget;         // distance original waypoing when started navigating it
int waypointnumber = -1;              // current waypoint number; run 0 (number_waypoints -1); start @ -1 , gets
                                      // initialized during setup()
waypointclass waypointlist[number_waypoints] = {
                                                waypointclass(30.508496, -97.832872),   // paul's douse
                                                waypointclass(30.508419, -97.832757),   // our house
                                                waypointclass(30.508296, -97.832618),   // ron's house
                                              };
adafruit_lsm303_mag_unified mag = adafruit_lsm303_mag_unified(12345);


// code begins
void setup()
{
  serial.begin(115200);     // connect serial
  gpsserial.begin(9600); // connect gps sensor

  //compass setup
  serial.println("magnetometer test"); serial.println("");
  
  // initialise magnetometer sensor
  if(!mag.begin())
  {
    // there problem detecting lsm303 ... check connections
    serial.println("ooops, no lsm303 detected ... check wiring!");
    while(1);
  }
  
  
 }

void loop()                       // main program loop
  {
    gpsloop();
    calcdesiredturn();  // calculate how optimatally turn, without regard obstacles          
    departled();
    movefwd();
    brake();
    dropload();
    delay (2000);
    destled();
    delay (2000);
    retunhome();
  }

void gpsloop()
{
  while(gpsserial.available())            // check gps data
  {
    if(gps.encode(gpsserial.read()))      // encode gps data
    {
      gps.f_get_position(&lat,&lon);      // latitude , longitude
     // gps.cardinal(course);              // tested
      // display position in serial window
      serial.print("latitude:");
      serial.print(lat,6);
      serial.print(";");
      serial.print("longitude:");
      serial.println(lon,6);  
      processgps();                       // process data gathered gps
     }
   }
    
    serial.println(lat);
    serial.println(lon);
        
    // navigate
    currentheading = readcompass();    // our current heading
}

// called after new gps data received; updates our position , course/distance waypoint
void processgps()
{
  currentlat = convertdegmintodecdeg(lat);
  currentlong = convertdegmintodecdeg(lon);
            
  if (gps.cardinal(currentcourse)) == 's')            // make them signed
    serial.println(gps.cardinal(currentcourse));
    currentlat = -currentlat;
  
  if (gps.cardinal(currentcourse)) == 'w')            // make them signed
    serial.println(gps.cardinal(currentcourse));
    currentlong = -currentlong;
            
  // update course , distance waypoint based on our new position
  //distancetowaypoint();
  gps.distance_between(currentlat, currentlong, targetlat, targetlong);
  //coursetowaypoint();
  gps.course_to(currentlat, currentlong, targetlat, targetlong);

}   // end of processgps(void)

int readcompass(void)
{
  /* new sensor event */
  sensors_event_t event;
  mag.getevent(&event);
  
  float pi = 3.14159;
  
  // calculate angle of vector y,x
  float heading = (atan2(event.magnetic.y,event.magnetic.x) * 180) / pi;
  
  // normalize 0-360
  if (heading < 0)
  {
    heading = 360 + heading;
  }
  //serial.print("compass heading: ");
  //serial.println(heading);
  //delay(500);
} // end of readcompass()

// way turn car , face destination?
void calcdesiredturn(void)
{
    // calculate need turn head destination
    headingerror = targetheading - currentheading; // signed (+/-) diff btw targetheading , currentheading
    
    // adjust compass wrap
    if (headingerror < -180)      
      headingerror += 360;
    if (headingerror > 180)
      headingerror -= 360;
  
    // calculate way turn intercept targetheading
    if (abs(headingerror) <= headingtol)      // if within tolerance of +/- 10
      serial.println("no turns");
    else if (headingerror < 0)
      turnleft();
    else if (headingerror > 0)
      turnright();
    else
      serial.println("no turns");
 
}  // end of calcdesiredturn()


// had chop of code make fit here within limits

please use code tags (</> button on toolbar) when post code or warning/error messages. reason forum software can interpret parts of code markup, leading confusion, wasted time, , reduced chance problem. make easier read code , copy ide or editor. if browser doesn't show posting toolbar can manually add code tags:
[code]// code here[/code]
using code tags , other important information explained in how use forum post. please read it.

when have error message need full thing, not fragment think might relevant. please use code tags when posting error/warning messages also.

code: [select]
  if (gps.cardinal(currentcourse)) == 's')            // make them signed
count parentheses.

since you're "fairly new" recommend use braces ({}) enclose code controlled if statements, if there 1 line. makes easier understand intent of code , avoids tricky bugs.


Arduino Forum > Using Arduino > Programming Questions > some help needed with the TinyGPS library


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???