Pages: [1]   Go Down
Author Topic: Help new library problems  (Read 1600 times)
0 Members and 1 Guest are viewing this topic.
Milan
Offline Offline
Edison Member
*
Karma: 2
Posts: 1128
gioblu.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys, I am writing down a library that helps who want to build cheap distance sensors.
We use the IR LED capacitance to determine the distance of the object, with two readings: ambient light check and ir light emission check

I try to write down a library to help people to use free this system but I get some errors:
ERER.cpp:64: error: no ‘void ERER::init(int)’ member function declared in class ‘ERER’


here it is the cpp:
Code:
/*
  ---------------------------------------------------
  ERER.cpp - Library for ERER sensors.
  Use 2 infrared LEDs to build a distance sensor
  After that think about to matrix it with this - _-
  ---------------------------------------------------
  Created by Giovanni Blu Mitolo, March 11, 2011.
  www.gioblu.com - gioscarab@gmail.com
  Released with Creative Commons Attribution licence
  ---------------------------------------------------
*/

#include "WProgram.h"
#include "ERER.h"

void ERER::emitterN(int emitterNegative){
 pinMode(emitterN, OUTPUT);
 _irEmitterP = emitterNegative;
}

void ERER::receiverN(int receiverNegative){
 _irReceiverN = receiverNegative;
}

void ERER::receiverP(int receiverPositive){
 _irReceiverP = receiverPositive;
}

void ERER::gain(int setGain){
 _gain = setGain;
}

void ERER::maxRangeValue(int setMaxRangeValue){
 _maxRangeValue = setMaxRangeValue;
}

void ERER::maxRange(int setMaxRange){
 _maxRange = setMaxRange;
}
/////////////////////////////////////////////////////////////////////////////


void ERER::distanceCheck() {
  if(currentInit == 0){if(digitalRead(_irReceiverN) == LOW) ERER::ambientCheck();}
  if(currentInit == 1){if(digitalRead(_irReceiverN) == LOW) ERER::emissionCheck();}
}

void ERER::ambientCheck() {
  ambient = micros() - lightTime;
  ERER::init(1);
}

void ERER::emissionCheck(){
  rawData = micros() - lightTime;
  distance = rawData * (ambient / (ambient - rawData));
  distance = map(distance, 0, _maxRangeValue, 0, _maxRange);
  if(distance <= 0) distance = 0;
  if(distance > 15) distance = sqrt(distance) * _gain;
  rawData = 0;
  ambient = 0;
  ERER::init(0);
}

void ERER::init(int emitter) {
  if(emitter == 0)digitalWrite(_irEmitterP, LOW);   
  if(emitter == 1)digitalWrite(_irEmitterP, HIGH);
  lightTime = micros();
  pinMode(_irReceiverN, OUTPUT);
  digitalWrite(_irReceiverN, HIGH); //carico ricevitore di induttanza
  pinMode(_irReceiverN, INPUT);
  digitalWrite(_irReceiverN, LOW);
  if(emitter == 1) currentInit = 1;
  if(emitter == 0) currentInit = 0;
}

here it is the .h:
Code:
/*
  ERER.cpp - Library for ERER sensors.
  (use 2 infrared LEDs to build a distance sensor)
  Created by Giovanni Blu Mitolo, March 11, 2011.
  Released with Creative Commons Attribution licence
*/
#ifndef ERER_h
#define ERER_h

class ERER {
  public:
    long ambient;
    void ambientCheck();
    long currentInit;
    long distance;
    void distanceCheck();
    void emissionCheck();
    void gain(int setGain)
    void init(int emitter);
    long lightTime;
    void maxRangeValue(int setMaxRangeValue);
    void maxRange(int setMaxRange);
    long rawData;
    void emitterN(int emitterNegative);
    void receiverN(int receiverNegative);
    void receiverP(int receiverPositive);
  private:
    int _irEmitterP;
    int _irReceiverP;
    int _irReceiverN;
    int _gain;
    long _maxRange;
    long _maxRangeValue;
};

#endif

pleease help  smiley-mr-green
Logged

Community robotica / programmazione Arduino
www.gioblu.com

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 652
Posts: 50861
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are using the scope resolution operator on your call to init(), in ambientCheck(), but init() is not declared a static function, so this call won't work.

The ambientCheck function will be called for an instance of the class. That same instance should be used to invoke the init() function, shouldn't it?
Logged

Milan
Offline Offline
Edison Member
*
Karma: 2
Posts: 1128
gioblu.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Pauls! How are you? Do you remember me?
I worked a lot on this but i can't figure how come out of this problem

shoul'd I write in ERER.h this?
 
Code:
   static void init(int emitter);
instead of
 
Code:
void init(int emitter);
to fix it?


here it is the ide code that I use:
Code:
#include <ERER.h>
ERER sensore1;

sensore1.receiverN(2);
sensore1.receiverP(5);
sensore1.emitterP(13);
sensore1.gain(4);
sensore1.maxRangeValue(666666);
sensore1.maxRange(2000);

void setup(){
  Serial.begin(9600);
}

void loop(){
 sensore1.distanceCheck();
}
Logged

Community robotica / programmazione Arduino
www.gioblu.com

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 652
Posts: 50861
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think that you want init() to be static. As defined, it is accessing non-static fields. I think you should just drop the ERER:: from in front of the ERER::init() call.
Logged

Milan
Offline Offline
Edison Member
*
Karma: 2
Posts: 1128
gioblu.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I edit the code following your advise.
This is the actual code:

ERER.h
Code:
/*
  ERER.cpp - Library for ERER sensors.
  (use 2 infrared LEDs to build a distance sensor)
  Created by Giovanni Blu Mitolo, March 11, 2011.
  Released with Creative Commons Attribution licence
*/
#ifndef ERER_h
#define ERER_h

class ERER {
  public:
    long ambient;
    void ambientCheck();
    long currentInit;
    long distance;
    void distanceCheck();
    void emissionCheck();
    void gain(int setGain)
    void init(int emitter);
    long lightTime;
    void maxRangeValue(int setMaxRangeValue);
    void maxRange(int setMaxRange);
    long rawData;
    void emitterN(int emitterNegative);
    void receiverN(int receiverNegative);
    void receiverP(int receiverPositive);
  private:
    int _irEmitterP;
    int _irReceiverP;
    int _irReceiverN;
    int _gain;
    long _maxRange;
    long _maxRangeValue;
};

#endif


ERER.cpp
Code:
/*
  ---------------------------------------------------
  ERER.cpp - Library for ERER sensors.
  Use 2 infrared LEDs to build a distance sensor
  After that think about to matrix it with this - _-
  ---------------------------------------------------
  Created by Giovanni Blu Mitolo, March 11, 2011.
  www.gioblu.com - gioscarab@gmail.com
  Released with Creative Commons Attribution licence
  ---------------------------------------------------
*/

#include "WProgram.h"
#include "ERER.h"

void ERER::emitterN(int emitterNegative){
 pinMode(emitterN, OUTPUT);
 _irEmitterP = emitterNegative;
}

void ERER::receiverN(int receiverNegative){
 _irReceiverN = receiverNegative;
}

void ERER::receiverP(int receiverPositive){
 _irReceiverP = receiverPositive;
}

void ERER::gain(int setGain){
 _gain = setGain;
}

void ERER::maxRangeValue(int setMaxRangeValue){
 _maxRangeValue = setMaxRangeValue;
}

void ERER::maxRange(int setMaxRange){
 _maxRange = setMaxRange;
}
/////////////////////////////////////////////////////////////////////////////


void ERER::distanceCheck() {
  if(currentInit == 0){if(digitalRead(_irReceiverN) == LOW) ERER::ambientCheck();}
  if(currentInit == 1){if(digitalRead(_irReceiverN) == LOW) ERER::emissionCheck();}
}

void ERER::ambientCheck() {
  ambient = micros() - lightTime;
  init(1);
}

void ERER::emissionCheck(){
  rawData = micros() - lightTime;
  distance = rawData * (ambient / (ambient - rawData));
  distance = map(distance, 0, _maxRangeValue, 0, _maxRange);
  if(distance <= 0) distance = 0;
  if(distance > 15) distance = sqrt(distance) * _gain;
  rawData = 0;
  ambient = 0;
  init(0);
}

void init(int emitter) {
  if(emitter == 0)digitalWrite(_irEmitterP, LOW);  
  if(emitter == 1)digitalWrite(_irEmitterP, HIGH);
  lightTime = micros();
  pinMode(_irReceiverN, OUTPUT);
  digitalWrite(_irReceiverN, HIGH); //carico ricevitore di induttanza
  pinMode(_irReceiverN, INPUT);
  digitalWrite(_irReceiverN, LOW);
  if(emitter == 1) currentInit = 1;
  if(emitter == 0) currentInit = 0;
}

IDE code
Code:
#include <ERER.h>
ERER sensore1;

sensore1.receiverN(2);
sensore1.receiverP(5);
sensore1.emitterP(13);
sensore1.gain(4);
sensore1.maxRangeValue(666666);
sensore1.maxRange(2000);

void setup(){
  Serial.begin(9600);
}

void loop(){
 sensore1.distanceCheck();
}

With this i get:
ERER.cpp:73: error: ‘currentInit’ was not declared in this scope

arrrrrggggg I am going crazy, seems very simple but i can't figure out why I get this error and where is it!!  smiley-eek
Logged

Community robotica / programmazione Arduino
www.gioblu.com

central nervous system
Offline Offline
Full Member
***
Karma: 0
Posts: 135
Causing havoc inside your brain since 1980
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You forget to declare currentInit inside ERER.cpp.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 652
Posts: 50861
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I copied your .h, .cpp, and .pde files into the 0022 version of the IDE.

You have more errors than you listed.

Code:
    void gain(int setGain)
Needs a ; at the end;

Code:
void ERER::emitterN(int emitterNegative){
 pinMode(emitterN, OUTPUT);
 _irEmitterP = emitterNegative;
}
In the pinMode statement, emitterN is the name of the function, not the pin to be set.

Code:
void init(int emitter) {
What happened to the ERER::?

Your class is missing a constructor.

Code:
void ERER::distanceCheck() {
  if(currentInit == 0){if(digitalRead(_irReceiverN) == LOW) ERER::ambientCheck();}
  if(currentInit == 1){if(digitalRead(_irReceiverN) == LOW) ERER::emissionCheck();}
}
Get rid of the scope resolution operator. Again.

Code:
sensore1.receiverN(2);
sensore1.receiverP(5);
sensore1.emitterP(13);
sensore1.gain(4);
sensore1.maxRangeValue(666666);
sensore1.maxRange(2000);
Executable code needs to be inside a function.
Logged

Pages: [1]   Go Up
Jump to: