Go Down

Topic: Compiling Problem - Help. (Read 6248 times) previous topic - next topic

cgifford74

I am trying to compile my program and am getting compilation error, but cannot figure out what it is or what it is related to.

Any ideas would help me out.

Thank you,
Coby.

Here is the error, followed by my code.


In file included from C:\Users\Gifford-Davis\Documents\Coby's Documents\Programming\Programming 2010\arduino-0019\arduino-0019\hardware\arduino\cores\arduino/WProgram.h:6,
                from C:\Users\Gifford-Davis\Documents\Coby's Documents\Programming\Programming 2010\arduino-0019\Arduino\libraries\OptiMouse\/OptiMouse.h:26,
                from C:\Users\Gifford-Davis\Documents\Coby's Documents\Programming\Programming 2010\arduino-0019\Arduino\libraries\OptiMouse\ADNS2083.cpp:28:
c:\users\gifford-davis\documents\coby's documents\programming\programming 2010\arduino-0019\arduino-0019\hardware\tools\avr\bin\../lib/gcc/avr/4.3.2/include/math.h:439: error: expected unqualified-id before 'double'
c:\users\gifford-davis\documents\coby's documents\programming\programming 2010\arduino-0019\arduino-0019\hardware\tools\avr\bin\../lib/gcc/avr/4.3.2/include/math.h:439: error: expected `)' before 'double'
c:\users\gifford-davis\documents\coby's documents\programming\programming 2010\arduino-0019\arduino-0019\hardware\tools\avr\bin\../lib/gcc/avr/4.3.2/include/math.h:439: error: expected `)' before 'double'





My Code:

// This example reads out the PixArt PAN3101 Optical Navigation Sensor
// It's used in many cheap optical mouses.
//
// For support for the Agilent ADNS-2051, ADNS-2083 or ADNS-2610, move
// the files for your mouse to the folder with the OptiMouse files.
// Then uncomment the right header files and object instances below.
//
// The Arduino will keep track of a (x, y) coordinate by increasing
// or decreasing the x and y variables by dx and respectively dy.
// Every 128th sample it reports the current (x, y) over the Serial.
//
// Written by Martijn The -> post [at] martijnthe.nl
// Tutorial: http://www.martijnthe.nl/optimouse/
// Based on the sketches by Beno[ch65533]t Rousseau

//#include "PAN3101.h"
// #include "ADNS2051.h"
// #include "ADNS2610.h"
#include "ADNS2083.h"


#define SCLK 2                            // Serial clock pin on the Arduino
#define SDIO 3                            // Serial data (I/O) pin on the Arduino

//PAN3101 Optical1 = PAN3101(SCLK, SDIO);   // Create an instance of the PAN3101 object
// ADNS2051 Optical1 = ADNS2051(SCLK, SDIO);
// ADNS2610 Optical1 = ADNS2610(SCLK, SDIO);
ADNS2083 Optical1 = ADNS2083(SCLK, SDIO);

signed long x = 0;                        // Variables for our 'cursor'
signed long y = 0;                        //

int c = 0;                                // Counter variable for coordinate reporting

void setup()
{
 Serial.begin(38400);
 Optical1.begin();                       // Resync (not really necessary?)
}

void loop()
{

//  The status commands are available only for the PAN3101 and the ADNS2051:

//  Optical1.updateStatus();                // Get the latest motion status
//  if (Optical1.motion())                  // If the 'Motion' status bit is set,
//  {

   x = Optical1.dx();                   // Read the dX register and in/decrease X with that value
   y = Optical1.dy();                   // Same thing for dY register.....

//  }
 
 if (c++ & 0x80)
 {                                       // Report the coordinates once in a while...
   Serial.print("x=");
   Serial.print(x, DEC);
   Serial.print(" y=");
   Serial.print(y, DEC);
   Serial.println();
   c = 0;                                // Reset the report counter
 }
}



RuggedCircuits

I'm guessing the error is in ADNS2083.h. Can we see that one too?

--
Need a custom shield? Let us design and build one for you.

cgifford74

Thanks, RuggedCircuits.

Here are the code text from the .h files referenced.
I appreciate your help.


Code Inside ADNS2083.h :

#ifndef ADNS2083_h
#define ADNS2083_h

#include "WProgram.h"
#include <inttypes.h>
#include "OptiMouse.h"

class ADNS2083 : public OptiMouse
{
 private:
 public:
     ADNS2083(uint8_t, uint8_t);
     signed char dx(void);
     signed char dy(void);
};

#endif


Code from OptiMouse.h
#ifndef OptiMouse_h
#define OptiMouse_h

#include "WProgram.h"
#include <inttypes.h>

class OptiMouse
{
 private:
 protected:
     uint8_t _sclkPin;
   uint8_t _sdioPin;
     uint8_t readRegister(uint8_t);
     void writeRegister(uint8_t, uint8_t);
 public:
   OptiMouse(uint8_t, uint8_t);
   void begin(void);
     signed char dx(void);
     signed char dy(void);
};

#endif

RuggedCircuits

Looks like I was wrong...I can't see anything amiss in your code.

Without 0019 installed yet, I can't see what's up with the math.h file at line 439. That file is not in the location your compiler says it's in on my 0018 system. Can you load that file in an editor and see what's up at line 439?

c:\users\gifford-davis\documents\coby's documents\programming\programming 2010\arduino-0019\arduino-0019\hardware\tools\avr\bin\../lib/gcc/avr/4.3.2/include/math.h

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

cgifford74

Thanks for the help.

Line 439: double round (double __x) __ATTR_CONST__;




THE WHOLE MATH.H BELOW:
[code]/* Copyright (c) 2002,2007 Michael Stumpf

  Portions of documentation Copyright (c) 1990 - 1994
  The Regents of the University of California.

  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

  * Neither the name of the copyright holders nor the names of
    contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE. */

/* $Id: math.h,v 1.21.2.2 2008/04/10 13:39:16 arcanum Exp $ */

/*
  math.h - mathematical functions

  Author : Michael Stumpf
           Michael.Stumpf@t-online.de

  __ATTR_CONST__ added by marekm@linux.org.pl for functions
  that "do not examine any values except their arguments, and have
  no effects except the return value", for better optimization by gcc.
*/

#ifndef __MATH_H
#define __MATH_H

/** \file */
/** \defgroup avr_math <math.h>: Mathematics
   \code #include <math.h> \endcode

   This header file declares basic mathematics constants and
   functions.

   \par Notes:
   - In order to access the functions delcared herein, it is usually
     also required to additionally link against the library \c libm.a.
     See also the related \ref faq_libm "FAQ entry".
   - Math functions do not raise exceptions and do not change the
     \c errno variable. Therefore the majority of them are declared
     with const attribute, for better optimization by GCC.    */

/**
  \ingroup avr_math

  The constant \c pi. */
#define M_PI 3.141592653589793238462643

/**
  \ingroup avr_math

  The square root of 2. */
#define M_SQRT2 1.4142135623730950488016887

/**
  \ingroup avr_math

  NAN constant. */
#define NAN    __builtin_nan("")

/**
  \ingroup avr_math

  INFINITY constant. */
#define INFINITY    __builtin_inf()

#ifndef __ATTR_CONST__
# define __ATTR_CONST__ __attribute__((__const__))
#endif

#ifdef __cplusplus
extern "C" {
#endif

 /**
    \ingroup avr_math

    The cos() function returns the cosine of \a __x, measured in radians.
 */
extern double cos(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The fabs() function computes the absolute value of a floating-point
    number \a __x.
 */
extern double fabs(double __x) __ATTR_CONST__;
#if 0
/* fabs seems to be built in already */
static inline double fabs( double __x )
 { double __res;
   __asm__ __volatile__ ("andi %D0,0x7F \n\t"
       : "=d" (__res) : "0" (__x) );
   return __res;
 }
#endif

 /**
    \ingroup avr_math

    The function fmod() returns the floating-point remainder of <em>__x /
    __y</em>.
 */
extern double fmod(double __x, double __y) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The modf() function breaks the argument \a __x into integral and
    fractional parts, each of which has the same sign as the argument.
    It stores the integral part as a double in the object pointed to by
    \a __iptr.

    The modf() function returns the signed fractional part of \a __x.
   
    \note
    This implementation skips writing by zero pointer.
 */
extern double modf(double __x, double *__iptr);

 /**
    \ingroup avr_math

    The sin() function returns the sine of \a __x, measured in radians.
 */
extern double sin(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The sqrt() function returns the non-negative square root of \a __x.
 */
extern double sqrt(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The tan() function returns the tangent of \a __x, measured in
    radians.
 */
extern double tan(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The floor() function returns the largest integral value less than or
    equal to \a __x, expressed as a floating-point number.
 */
extern double floor(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The ceil() function returns the smallest integral value greater than
    or equal to \a __x, expressed as a floating-point number.
 */
extern double ceil(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The frexp() function breaks a floating-point number into a normalized
    fraction and an integral power of 2.  It stores the integer in the \c
    int object pointed to by \a __pexp.

    If \a __x is a normal float point number, the frexp() function
    returns the value \c v, such that \c v has a magnitude in the
    interval [1/2, 1) or zero, and \a __x equals \c v times 2 raised to
    the power \a __pexp. If \a __x is zero, both parts of the result are
    zero. If \a __x is not a finite number, the frexp() returns \a __x as
    is and stores 0 by \a __pexp.

    \note  This implementation permits a zero pointer as a directive to
    skip a storing the exponent.
 */
extern double frexp(double __x, int *__pexp);

 /**
    \ingroup avr_math

    The ldexp() function multiplies a floating-point number by an integral
    power of 2.

    The ldexp() function returns the value of \a __x times 2 raised to
    the power \a __exp.
 */
extern double ldexp(double __x, int __exp) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The exp() function returns the exponential value of \a __x.
 */
extern double exp(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The cosh() function returns the hyperbolic cosine of \a __x.
 */
extern double cosh(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The sinh() function returns the hyperbolic sine of \a __x.
 */
extern double sinh(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The tanh() function returns the hyperbolic tangent of \a __x.
 */
extern double tanh(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The acos() function computes the principal value of the arc cosine of
    \a __x.  The returned value is in the range [0, pi] radians. A domain
    error occurs for arguments not in the range [-1, +1].
 */
extern double acos(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The asin() function computes the principal value of the arc sine of
    \a __x.  The returned value is in the range [-pi/2, pi/2] radians. A
    domain error occurs for arguments not in the range [-1, +1].
 */
extern double asin(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The atan() function computes the principal value of the arc tangent
    of \a __x.  The returned value is in the range [-pi/2, pi/2] radians.
 */
extern double atan(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math
   
    The atan2() function computes the principal value of the arc tangent
    of <em>__y / __x</em>, using the signs of both arguments to determine
    the quadrant of the return value.  The returned value is in the range
    [-pi, +pi] radians.
 */
extern double atan2(double __y, double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The log() function returns the natural logarithm of argument \a __x.
  */
extern double log(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The log10() function returns the logarithm of argument \a __x to base
    10.
  */
extern double log10(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The function pow() returns the value of \a __x to the exponent \a __y.
 */
extern double pow(double __x, double __y) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The function isnan() returns 1 if the argument \a __x represents a
    "not-a-number" (NaN) object, otherwise 0.
 */
extern int isnan(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The function isinf() returns 1 if the argument \a __x is positive
    infinity, -1 if \a __x is negative infinity, and 0 otherwise.
 */
extern int isinf(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The function square() returns <em>__x * __x</em>.

    \note
    This function does not belong to the C standard definition.
 */
extern double square(double __x) __ATTR_CONST__;

 /**
    \ingroup avr_math

    The copysign() function returns \a __x but with the sign of \a __y.
    They work even if \a __x or \a __y are NaN or zero.
*/
__ATTR_CONST__ stat

RuggedCircuits

Any chance you have a "#define round(x) ...." somewhere in a file you haven't posted yet? This looks like 'round' has already been defined somewhere by the time math.h gets around to being compiled.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

cgifford74

The only place that I see "define round" is in the file "wiring.h".
In "wiring.h" it is defined as follows:
Code: [Select]
#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))

"OptiMouse.h" includes "WProgram.h" which includes "wiring.h"

From "WProgram.h":
Code: [Select]
#ifndef WProgram_h
#define WProgram_h
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <avr/interrupt.h>
#include "wiring.h"


I don't know enough C++ to see what's wrong here.
It looks like round is declared as a long, but is used as a double in "math.h" ???? I don't know much, though.


RuggedCircuits

This looks like it might be the problem. Somehow "wiring.h" is being included before <math.h> and the #define of round is messing up the function definition of round() in <math.h>. This shouldn't happen as WProgram.h is being included in your code before anything else. Unless I'm missing it somewhere.....

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

cgifford74

Rugged Circuits,

We've got it.
Your last post sent me searching further.
Without knowing a whole lot about C++ I did find a .cpp file associated with our .h file.

In "ADNS2083.cpp" I found the following duplicate declarations:
Code: [Select]
#include "WProgram.h"
#include <inttypes.h>
#include "ADNS2083.h"


So, I removed the first two lines you see and viola . . . it compiled.
The first two lines there don't need to be called because they are already declared in another header file.

Thanks for all your help.
I am off and running again.

Coby.


kunkmiester

I'm getting similar errors, but with the 2610 library.  This library was built for a much older version of the IDE, and I and my programmer brothers are thinking thats where a lot of errors end up coming from.  Is it worth it to try to continue messing with this, or is the PS/2 library more up to date?  It's be nice to not have to deal too much with updating libraries, particularly one as complicated as the optimouse one is.

cgifford74

I think it is worth sticking with the 2610.
Once you get the libraries working it is somewhat simple because it only does a few things.


Also, go to Mouser.com and you can download the manual for it.
I just bought five more of the 2610's on Mouser.com for less than a $1 each because they are working well and one of the easier ones to still find.


I had to fix the code for both the .cpp file and the .h file, but here is the code for both of those below.

Hope this helps.


Here is corrected code for the ADNS 2610.cpp file:
Code: [Select]
/*
ADNS2610.cpp - Part of optical mouse sensor library for Arduino
Copyright (c) 2008 Martijn The.  All right reserved.
http://www.martijnthe.nl/

Based on sketches by Benoît Rousseau.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/******************************************************************************
* Includes
******************************************************************************/

#include "ADNS2610.h"

/******************************************************************************
* Definitions
******************************************************************************/

#define Delta_Y                         0x02
#define Delta_X                         0x03

/******************************************************************************
* Constructors
******************************************************************************/


ADNS2610::ADNS2610(uint8_t sclkPin, uint8_t sdioPin) : OptiMouse::OptiMouse(sclkPin, sdioPin)
{

}

/******************************************************************************
* User API
******************************************************************************/

signed char ADNS2610::dx(void)
{
       return (signed char) readRegister(Delta_X);
}

signed char ADNS2610::dy(void)
{
       return (signed char) readRegister(Delta_Y);
}

// Private Methods /////////////////////////////////////////////////////////////




Here is the corrected code for the ADNS2610.h file:
Code: [Select]
/*
ADNS2610.h - Part of optical mouse sensor library for Arduino
Copyright (c) 2008 Martijn The.  All right reserved.
http://www.martijnthe.nl/

Based on sketches by Benoît Rousseau.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef ADNS2610_h
#define ADNS2610_h

#include <inttypes.h>
#include "OptiMouse.h"

Class ADNS2610: Public OptiMouse
{
 private:
 public:
       ADNS2610(uint8_t, uint8_t);
       signed char dx(void);
       signed char dy(void);
};

#End If



kunkmiester

Thanks loads, that will make things much easier.  Are there any changes to be made to the optimouse.cpp/.h, or just the chip library?

cgifford74

#12
Nov 10, 2010, 02:25 pm Last Edit: Nov 10, 2010, 02:30 pm by cgifford74 Reason: 1
I made no changes to the optimouse.cpp/.h library that I was using assuming you have the exact same fies.  I only made changes to the chip libraries and they were minimal.

Anyhow, everything has been working great for me.  

I must admit that I am not that steeped in C++ since most of my programming time has been in VB.  But, from what I could see there was a conflict when compiling.  And, I also noticed that on only the chip types that I had problems with, "WProgram.h", "inttypes.h" were being loaded multiple times in the compilation process.



My solution was this:
When the compiler ran, I noticed that there was some type of conflict as if variables already declared were being called to declare again??  So, I poked around and found that in the two chip library files there were a couple of #include declarations for particular files at the top of the code that were also in the main library for the same files.  So, I asked myself the question, "why would we need the compiler to include the same files twice when this is already accomplished by the time the compiler gets to the chip library files because the main file likely loads first?".  Then, I noticed that the only Optimouse type that I had working, the 3101 or something did not have these #inclusion statements in its chip libararies, yet the libraries were exactly the same otherwise.  So, I removed the two statements since it made sense to do so, and it compiled.


Everything has worked ever since.



Go Up