Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: if problems on: May 08, 2013, 11:14:00 am
that's mean their is no error in the code ?
thank you anyway for your help.
i am obliged to use fuzzy logic in this project i can't implement LP filter.
2  Using Arduino / Project Guidance / Re: IP cam and Arduino on: May 08, 2013, 10:27:05 am
can you give me links and codes for help. and how did you know the url command of each button of the ip cam web browser
i have WiFi shield and arduino mega, i appreciate any help.
3  Using Arduino / Programming Questions / Re: if problems on: May 08, 2013, 10:20:10 am
any help
4  Using Arduino / Programming Questions / Re: if problems on: May 08, 2013, 08:32:00 am
ok thats what happened, sensor give the distance and we go directly to the specific rule, but when the distance change, 2 rules are executed, and it loops in those 2 conditions only (see attachment)
5  Using Arduino / Programming Questions / Re: if problems on: May 08, 2013, 07:40:40 am
ok i will and i will put the output in here
thank you
6  Using Arduino / Programming Questions / Re: if problems on: May 08, 2013, 05:10:23 am
if we remove else and replace it with
Code:
if(rule1)
{
{
if(rule2)
{
}

i have the same problem
7  Using Arduino / Programming Questions / Re: if problems on: May 08, 2013, 03:35:39 am
ok i will make the test and reply to you
thanks for the advice
8  Using Arduino / Programming Questions / if problems on: May 07, 2013, 11:18:33 pm
hi,
i have problem with the following code, a sensor measure a distance, if the distance between 0 and 30 rule 1 should be executed, if distance is between 31 and 60 rule 2 should be executed, but here when the arduino mega enter a rule, he don't go out from it even when distance is changed.
this is the code:

Code:
#include <Fuzzy.h>
#include <FuzzyComposition.h>
#include <FuzzyInput.h>
#include <FuzzyIO.h>
#include <FuzzyOutput.h>
#include <FuzzyRule.h>
#include <FuzzyRuleAntecedent.h>
#include <FuzzyRuleConsequent.h>
#include <FuzzySet.h>

//fwd, bwd, left, right
int pin1 = 53;
int pin2 = 52;
int pin3 = 51;
int pin4 = 50;
//S1
int trig = 46;
int echo = 22;
float pertinence;
int distance;
Fuzzy* fuzzy = new Fuzzy();

//Creating fuzzy sets-input
FuzzySet* near = new FuzzySet(0, 10, 20, 30);
FuzzySet* far = new FuzzySet(31, 40, 50, 60);

//Creating fuzzy sets-output
FuzzySet* slow = new FuzzySet(0, 1, 2, 4);
FuzzySet* fast = new FuzzySet(5, 6, 7, 8);

void setup()
{
  Serial.begin(9600);
  pinMode(pin1, OUTPUT);
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
  pinMode(pin4, OUTPUT);
  
  
  FuzzyInput* distance = new FuzzyInput(1);
  distance->addFuzzySet(near);
  distance->addFuzzySet(far);
  fuzzy->addFuzzyInput(distance);
  
  FuzzyOutput* speedSS = new FuzzyOutput(1);
  speedSS->addFuzzySet(slow);
  speedSS->addFuzzySet(fast);
  fuzzy->addFuzzyOutput(speedSS);
  
  //Fuzzy rules
  //if distance = near then speedSS = slow
  FuzzyRuleAntecedent* ifDistanceNear = new FuzzyRuleAntecedent();
  ifDistanceNear->joinSingle(near);
  FuzzyRuleConsequent* thenspeedSSslow = new FuzzyRuleConsequent();
  thenspeedSSslow->addOutput(slow);
  
  FuzzyRule* fuzzyRule01 = new FuzzyRule(1, ifDistanceNear, thenspeedSSslow);
  
  fuzzy->addFuzzyRule(fuzzyRule01);
  
  //if distance = far then speedSS = fast
  FuzzyRuleAntecedent* ifDistanceFar = new FuzzyRuleAntecedent();
  ifDistanceFar->joinSingle(far);
  FuzzyRuleConsequent* thenspeedSSfast= new FuzzyRuleConsequent();
  thenspeedSSfast->addOutput(fast);
  
  FuzzyRule* fuzzyRule02 = new FuzzyRule(2, ifDistanceFar, thenspeedSSfast);
  
  fuzzy->addFuzzyRule(fuzzyRule02);
  
}

void loop()
{
  distance = getDistance(trig, echo);
  Serial.print(distance);
  Serial.print("\n");
  fuzzy->setInput(1, distance);
  fuzzy->fuzzify();
  float output = fuzzy->defuzzify(1);
  //Serial.print(output);
  Serial.print("\n");
  if(fuzzy->isFiredRule(1) == true){
    Serial.print("Rule 1, turn left!");
    turnLeft();
    
  }  else if(fuzzy->isFiredRule(2) == true){
    Serial.print("Rule 2, turn right!");
    turnRight();
    
  }
  //float output = fuzzy->defuzzify(1);
  //Serial.print(output);
  //delay(1000);
  

}
int turnRight()
{
  Serial.print("turning right!");
  digitalWrite(pin1, HIGH);
  digitalWrite(pin2, LOW);
  digitalWrite(pin3, LOW);
  digitalWrite(pin4, HIGH);
  delay(2000);
}
int turnLeft()
{
  Serial.print("turning left!");
  digitalWrite(pin1, HIGH);
  digitalWrite(pin2, LOW);
  digitalWrite(pin3, HIGH);
  digitalWrite(pin4, LOW);
  delay(2000);
}

int getDistance(int pin1, int pin2)
{
  long duration, cm;
  
  pinMode(pin1, OUTPUT);
  digitalWrite(pin1, LOW);
  delayMicroseconds(2);
  digitalWrite(pin1, HIGH);
  delayMicroseconds(5);
  digitalWrite(pin1, LOW);
  
  pinMode(pin2, INPUT);
  duration = pulseIn(pin2, HIGH);
  
  return duration / 29 / 2;
  
  delay(100);
//  Serial.print(" cm");
//  Serial.println();
//  delay(1000);
}
9  Using Arduino / Project Guidance / Re: IP cam and Arduino on: April 30, 2013, 10:09:45 am
i will buy a wifi shield and make a new webpage that control the ip cam, i have knowledge with html, if i see the View Source of the ip cam app on my pc can i try to use it the webserver code, tell me if that true.
thanks for your reply
10  Using Arduino / Project Guidance / Re: IP cam and Arduino on: April 30, 2013, 06:18:46 am
and how i control it with a pc, it have a software that i can control it through the computer but i want to control it from arduino according to sensors input i want it to turn to a specific point
11  Using Arduino / Project Guidance / IP cam and Arduino on: April 30, 2013, 02:26:23 am
hello,
i want to ask, how can i connect the ip cam to arduino mega and control her servo motor with it,
thank you.
12  Using Arduino / Installation & Troubleshooting / Re: problem with arduino mega 2560 on: April 26, 2013, 12:27:52 am
thank you,
the voltage was 4.5V, and thats what happened, when i connect the mega2560 to external power supply it run an old sktech that i upload as a test to make the car work, and when i writed a code to make the car avoiding obstacles only this sktech work when i connect the mega with the usb cable, yes this what happened. the led flashes two times when i click on the reset button but the car continue to work and no reset has done.
i have an uno too i think should replace the mega with it. smiley-razz
13  Using Arduino / Installation & Troubleshooting / Re: problem with arduino mega 2560 on: April 25, 2013, 01:27:24 pm
but why when i connect it to serial it take the new sktech ?
and what is the bootloader and how i fix it ?
thank you for your reply.
14  Using Arduino / Installation & Troubleshooting / problem with arduino mega 2560 on: April 25, 2013, 12:17:15 pm
hello,
i have a problem with arduino mega 2560, when i connected the mega with my laptop, and upload a new sketch, it take it and work properly, but when i remove the usb cable connection, the mega run the older sketch, and when i reconnected with the usb cable the new sktech work.
i tried to reset the arduino but it does not work.
help please.
thank you.
15  Using Arduino / Project Guidance / Re: fuzzy logic on: April 03, 2013, 09:26:18 am
send me a link about a post as same as my post to read it, i'm new to arduino community
thank you
Pages: [1] 2