Pages: [1]   Go Down
Author Topic: Library Problem  (Read 1734 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
#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:
#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:
#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:
#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:
#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:
#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:
#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:
#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:
#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:
#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.

Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 0
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
FuzzySets *SonicFuzz,*SonicFuzz2,*MotorFuzz

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

Code:
FuzzySets *SonicFuzz,*SonicFuzz2,*MotorFuzz;
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Austin, TX USA
Offline Offline
God Member
*****
Karma: 4
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Mikal
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

Pages: [1]   Go Up
Jump to: