Go Down

Topic: Library Problem (Read 2 times) previous topic - next topic

hanoush

I am building a small Fuzzy logic control library and I am not used to c++. I did exactly like the library tutorial said but I am sure that I didn't something wrong that I can't notice.
The main class is called FuzzySets,it contains 2 classes "Trape" and "MemberShip".Trape contains a class called point.

Here is the Code:

FuzzySets.h
Code: [Select]
#ifndef FuzzySets_H
#define FuzzySets_H
#include <Trape.h>
#include <MemberShip.h>

class FuzzySets
{
 public:
FuzzySets(void);
~FuzzySets(void);
Trape *Low,*Medium,*High;
MemberShip *L,*M,*H;

};

#endif


FuzzySets.cpp :
Code: [Select]
#include <Trape.h>
#include <MemberShip.h>
#include <FuzzySets.h>
FuzzySets::FuzzySets(void) {  // default constructor
    Low = new Trape();
    Medium = new Trape();
    High = new Trape();
     
    L= new MemberShip();
    M= new MemberShip();
    H= new MemberShip();
}
FuzzySets::~FuzzySets(void)
{

}


Trape.h :
Code: [Select]
#ifndef Trape_H
#define Trape_H
#include <Point.h>
class Trape
{
 public:
     Trape(void);
     ~Trape(void);
     Point *a,*b,*c,*d;
};
#endif


Trape.cpp :
Code: [Select]
#include <Trape.h>
#include <Point.h>
Trape::Trape() {  // default constructor
   a = new Point();
   b = new Point();
   c = new Point();
   d = new Point();
}
Trape::~Trape(void)
{
}


MemberShip.h :
Code: [Select]
#ifndef MemberShip_H
#define MemberShip_H
class MemberShip
{
 public:
MemberShip(void);
MemberShip(float);
~MemberShip(void);
float getMem(void);
void setMem(float);
private:
float member_value;
};

#endif


MemberShip.cpp :
Code: [Select]
#include <MemberShip.h>
MemberShip::MemberShip(){
member_value=0;
}
MemberShip::MemberShip(float m) {  // default constructor
   member_value=m;
}
MemberShip::~MemberShip(){
}
float MemberShip::getMem(void)
{
return member_value;
}

void MemberShip::setMem(float m)
{
member_value=m;
}


Point.h :
Code: [Select]
#ifndef Point_H
#define Point_H
class Point
{
 public:
     Point(void);
     Point(float,float);
     ~Point(void);
     float getX(void);
     float getY(void);
     void setX(float);
     void setY(float);
 private:
     float x,y;
};

#endif


Point.cpp:
Code: [Select]
#include <Point.h>
Point::Point(void) {
   x = 0;
   y = 0;
}
Point::Point(float i,float j) {
   x = i;
   y = j;
}
Point::~Point(void)
{

}
float Point::getX()
{
return x;
}

float Point::getY()
{
return y;
}

void Point::setX(float n)
{
x=n;
}

void Point::setY(float n)
{
y=n;
}



and here is how I use them in my sketch file,the Problem is that I can't initialize a FuzzySets but it doesn't give me and error if I made and object of it and referenced it setup() or loop() but I cann't reference it with global variables.

Code: [Select]
#include <FuzzySets.h>
#include <MemberShip.h>
#include <Point.h>
#include <Trape.h>
FuzzySets *SonicFuzz,*SonicFuzz2,*MotorFuzz;

void setup() {
 Serial.begin(115200);  
 initFuzz();

}
void initFuzz()
{
//First ultraSonic Sensor
 SonicFuzz->Low->a->setX(0);
 SonicFuzz->Low->a->setY(0);
 SonicFuzz->Low->b->setX(0);
 SonicFuzz->Low->b->setY(1);
 SonicFuzz->Low->c->setX(180);
 SonicFuzz->Low->c->setY(1);
 SonicFuzz->Low->d->setX(200);
 SonicFuzz->Low->d->setY(0);

 SonicFuzz->Medium->a->setX(180);
 SonicFuzz->Medium->a->setY(0);
 SonicFuzz->Medium->b->setX(200);
 SonicFuzz->Medium->b->setY(1);
 SonicFuzz->Medium->c->setX(450);
 SonicFuzz->Medium->c->setY(1);
 SonicFuzz->Medium->d->setX(500);;
 SonicFuzz->Medium->d->setY(0);

 SonicFuzz->High->a->setX(450);
 SonicFuzz->High->a->setY(0);
 SonicFuzz->High->b->setX(500);
 SonicFuzz->High->b->setY(1);
 SonicFuzz->High->c->setX(644);
 SonicFuzz->High->c->setY(1);
 SonicFuzz->High->d->setX(644);
 SonicFuzz->High->d->setY(0);

 //Second UltraSonic Sensor
 SonicFuzz2->Low->a->setX(0);
 SonicFuzz2->Low->a->setY(0);
 SonicFuzz2->Low->b->setX(0);
 SonicFuzz2->Low->b->setY(1);
 SonicFuzz2->Low->c->setX(180);
 SonicFuzz2->Low->c->setY(1);
 SonicFuzz2->Low->d->setX(200);
 SonicFuzz2->Low->d->setY(0);

 SonicFuzz2->Medium->a->setX(180);
 SonicFuzz2->Medium->a->setY(0);
 SonicFuzz2->Medium->b->setX(200);
 SonicFuzz2->Medium->b->setY(1);
 SonicFuzz2->Medium->c->setX(450);
 SonicFuzz2->Medium->c->setY(1);
 SonicFuzz2->Medium->d->setX(500);
 SonicFuzz2->Medium->d->setY(0);

 SonicFuzz2->High->a->setX(450);
 SonicFuzz2->High->a->setY(0);
 SonicFuzz2->High->b->setX(500);
 SonicFuzz2->High->b->setY(1);
 SonicFuzz2->High->c->setX(644);
 SonicFuzz2->High->c->setY(1);
 SonicFuzz2->High->d->setX(644);
 SonicFuzz2->High->d->setY(0);


 //Motor fuzzy set
 MotorFuzz->Low->a->setX(140);
 MotorFuzz->Low->a->setY(0);
 MotorFuzz->Low->b->setX(140);
 MotorFuzz->Low->b->setY(1);       //Will be Changed
 MotorFuzz->Low->c->setX(150);
 MotorFuzz->Low->c->setY(1);       //Will be Changed
 MotorFuzz->Low->d->setX(160);
 MotorFuzz->Low->d->setY(0);

 MotorFuzz->Medium->a->setX(160);
 MotorFuzz->Medium->a->setY(0);
 MotorFuzz->Medium->b->setX(170);
 MotorFuzz->Medium->b->setY(1);       //Will be Changed
 MotorFuzz->Medium->c->setX(180);
 MotorFuzz->Medium->c->setY(1);       //Will be Changed
 MotorFuzz->Medium->d->setX(190);
 MotorFuzz->Medium->d->setY(0);

 MotorFuzz->High->a->setX(190);
 MotorFuzz->High->a->setY(0);
 MotorFuzz->High->b->setX(200);
 MotorFuzz->High->b->setY(1);       //Will be Changed
 MotorFuzz->High->c->setX(254);
 MotorFuzz->High->c->setY(1);       //Will be Changed
 MotorFuzz->High->d->setX(254);
 MotorFuzz->High->d->setY(0);
}



I don't get any errors if I did this but I know that I am doing something wrong.

if I tried to do this

Code: [Select]
#include <FuzzySets.h>
#include <MemberShip.h>
#include <Point.h>
#include <Trape.h>

FuzzySets *SonicFuzz,*SonicFuzz2,*MotorFuzz
SonicFuzz = new FuzzySets();


I get this error:

error: expected constructor, destructor, or type conversion before '=' toke

and if I tried to do this
Code: [Select]
#include <FuzzySets.h>
#include <MemberShip.h>
#include <Point.h>
#include <Trape.h>

FuzzySets *SonicFuzz,*SonicFuzz2,*MotorFuzz
 SonicFuzz->Low->a->setX(0);

I get this error:
error: expected constructor, destructor, or type conversion before '->' token


I know that I doing something stupid but please help.


Anachrocomputer

Code: [Select]
FuzzySets *SonicFuzz,*SonicFuzz2,*MotorFuzz

Surely there should be a semicolon on the end of that line:

Code: [Select]
FuzzySets *SonicFuzz,*SonicFuzz2,*MotorFuzz;

hanoush

I have semicolon in my code,it is just copy and paste mistake because I removed all the variables that have nothing to do with the problem.

hanoush

I forgot to say that my files is in folder called FuzzySets in Hardware/libraries.

mikalhart

Hanoush, the "new" operator is not defined in Arduino land.

Mikal

hanoush

Yea I noticed that.Everything worked when I removed all the pointers.

Patrik

I'm looking for a fuzzy logic library or code to getting me started with fuzzy logic. Have you finished the library? Could I get it?
The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

Go Up