Adafruit motor control shield for Arduino PID

hi everyone, i use adafruit motor control shield and i defined some pins like,

Motor1.setSpeed(150);
Motor2.setSpeed(100);
Motor1.run(FORWARD);
Motor2.run(FORWARD);

but i want to set pid controller for motors,
i tried PID_v1.h but i couldnt set output pin to motors

also i tried

 analogWrite(AF_DCMotor Motor1(),Output);

but i had error, is there any way to do this??

i exactly use this one
http://cdn.instructables.com/FB0/YN75/I1PH1XA3/FB0YN75I1PH1XA3.LARGE.gif

i really need help and i have no time pls help

hi everyone, i use adafruit motor control shield and i defined some pins like,

Motor1.setSpeed(150);
Motor2.setSpeed(100);
Motor1.run(FORWARD);
Motor2.run(FORWARD);

That is not defining any pins.

but i want to set pid controller for motors,
i tried PID_v1.h but i couldnt set output pin to motors

The output is not a pin. It is a value that is to be written to a pin. But, since we can't see your code, we can't guess what your inputs and outputs are, so we can't guess how you should be using output. Probably as a speed value, but, who knows?

also i tried

analogWrite(AF_DCMotor Motor1(),Output);

So, you tried to pass a new instance of the AF_DCMotor class as the pin number. I'm not at all surprised that that didn't work.

i exactly use this one
http://cdn.instructables.com/FB0/YN75/I1PH1XA3/FB0YN75I1PH1XA3.LARGE.gif

If you can't be bothered to explain what "this one" means, and post a link properly, I can't be bothered to cut and paste.

i really need help and i have no time pls help

Homework is not supposed to be left until the night before it is due.

 #include <PID_v1.h>

#include <NewPing.h>
#include <AFMotor.h>
#define TRIGGER_PIN  A4
#define ECHO_PIN     A5

AF_DCMotor Motor1(1);
AF_DCMotor Motor2(2);
NewPing DistanceSensor(TRIGGER_PIN, ECHO_PIN, 200);
int cm = DistanceSensor.ping_cm();
 


double Setpoint, Input, Output;
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);


void setup()
{

  Serial.begin(9600);
 Input = DistanceSensor.ping_cm();
  Setpoint = 10;
  myPID.SetMode(AUTOMATIC);



}

void loop()
{



  cm = DistanceSensor.ping_cm();
  Serial.print("Distance: ");
  Serial.print(cm);
  Serial.println("cm");
  delay(50);
  
  
 Input = DistanceSensor.ping_cm();
  myPID.Compute();
  
    analogWrite(Motor1(),Output);

  //  AÇ KAPA SETPOINT   10
  //    if(cm <10 ) {
  //    Motor1.setSpeed(150);
  //    Motor2.setSpeed(100);
  //     Motor1.run(FORWARD);
  //    Motor2.run(FORWARD);
  //    }
  //
  //
  //   else  if (cm >10) {
  //    Motor1.setSpeed(100);
  //    Motor2.setSpeed(150);
  //     Motor1.run(FORWARD);
  //    Motor2.run(FORWARD);
  //
  //    }
  //
  //    else {
  //      Motor1.setSpeed(120);
  //    Motor2.setSpeed(120);
  //     Motor1.run(FORWARD);
  //    Motor2.run(FORWARD);
  //
  //    }
  //
}

this is my code and i have problem with pid :frowning:

PaulS:
That is not defining any pins.
The output is not a pin. It is a value that is to be written to a pin. But, since we can't see your code, we can't guess what your inputs and outputs are, so we can't guess how you should be using output. Probably as a speed value, but, who knows?
So, you tried to pass a new instance of the AF_DCMotor class as the pin number. I'm not at all surprised that that didn't work.
If you can't be bothered to explain what "this one" means, and post a link properly, I can't be bothered to cut and paste.
Homework is not supposed to be left until the night before it is due.

its my son hw

@serinoz: Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the "Code" icon above the posting area. It is the first icon, with the symbol: </>


its my son hw

So who passes the course? You or him?

    analogWrite(Motor1(),Output);

What PaulS said. analogWrite takes a pin number, not whatever-that-is-supposed-to-be.

analogWrite(Motor1(),Output);

is gives me error message like that

Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Uno"

sens_r.ino: In function 'void loop()':

sens_r.ino:46:24: error: no match for call to '(AF_DCMotor) ()'

Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

is gives me error message like that

Sure it does. Motor1() is not a function that returns a pin number.

You have the motors attached to a shield. The shield hard-wires the motor #1 to some pins. The shield hard-wires the motor #2 to some pins. You have to figure out which pins those are, and which one of the two pins controls the speed of the motor. It is that pin that you use in the call to analogWrite().

 Input = DistanceSensor.ping_cm();

Call the function, saving the result in some variable. Print the variable. Call the function again, and get some other distance. Use that, without a clue what it is. Why?

  myPID.Compute();

This is going to use the set point (10) and the input (some distance) to compute a correction factor. What, exactly, are you going to correct with that? There is no correlation between distance and the speed of the motor.

actually i couldnt make any correlatiton between controller and motors. i edit code what u said.

i edit code what u said.

But you elected to keep the unknown changes to yourself. Well, I guess we'll be keeping future answers to ourselves.

What, exactly, it is you are expecting the PID system to control? Typically, PID is used for things like holding a constant temperature, where the set point is the temperature to maintain, the input is the current temperature, and the output is a correction factor, positive or negative, that is used to drive a heater (when negative) or a cooler (when positive).

Your set point is a constant (what does it represent?) Your input is a distance. What do you think you will do with the correction factor? Typically, that would be used to steer closer towards, or farther away from, a wall that you are trying to keep a constant distance from. But, that output would be mapped to servo angle and used to drive a steering servo.

Why did you choose to have PID be part of your program, and what are you trying to accomplish with it?

PaulS:
What, exactly, it is you are expecting the PID system to control?

PaulS i want to make wall following robot and i use adafruit motor speed controller i think motors have to work correlated but i couldnt do this in my code.
i wrote if block for it but i couldnt do it