Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Cannot integrate PID in my Quadcopter? Is this the right way? on: November 03, 2013, 11:31:18 am
If you do, you'll see that 1.0 might not be reasonable. Those values are a bit like trying to boil a teaspoon of water using a blast furnace.

Hmmm awesome Example. I thought I did understand but I didn't think it would have that much impact like your example..... So i will get into that then...
2  Using Arduino / Programming Questions / Re: Cannot integrate PID in my Quadcopter? Is this the right way? on: November 03, 2013, 11:08:28 am


A cast may be necessary of the type you have is not the same as that that a function expects, and the type can not be safely converted. For instance, the delay() function takes a value that is unsigned long. An int easily fits in an unsigned long, so no cast is needed.

Ahaaaaaa.. I see what ur saying ur right... And, yes For the PID constants...... I didn't know what to start off with soo just did 1,1,1 but at some point I will use the PID tuning library to get the dynamic constants...
3  Using Arduino / Programming Questions / Re: Cannot integrate PID in my Quadcopter? Is this the right way? on: November 03, 2013, 10:56:53 am
Code:
PID myPID(&Input_roll, &rollOffset, &Setpoint_roll,1,1,1, DIRECT);
1.0, 1.0, and 1.0 are not good initial values for kP, kI, and kD.

Code:
        int valCW1 = servoCW1.readMicroseconds();
        int valCW2 =  servoCW2.readMicroseconds();
Can't remember what you last wrote, huh? Not good.

Code:
        servoCW1.writeMicroseconds((int)valCW1);
        servoCW2.writeMicroseconds((int)valCW2);
I've never understood the need to cast an int to an int. Can you explain why you need to?

You are right about readMicroseconds()......
And In Docs for Servo: the value of the parameter in microseconds (int)
So, it says the writeMicroseconds param must be in Int
4  Using Arduino / Programming Questions / Cannot integrate PID in my Quadcopter? Is this the right way? on: November 03, 2013, 10:35:11 am
I am working in my quadcopter. Right now I am just testing for take- off and Roll angle. I tried to integrate PID library in my code but it keeps generating 100 and my quadcopter goes blasting. Right now I am just giving 1,1,1 for kp,ki and kd. I know this is not right but like I said, I am just playing. Here is my Code. ..


#define CHNL_HIGH 1900
      #define CHNL_LOW 1100

      #define THROTTLE_CHNL 2
      #define CW1_IN 9
      #define CW2_IN 10
      #define CW3_IN 11
      #define CW4_IN 12
      #define ARM_DEG 21
      #define THROTTLE_FLAG 1
      Servo servoCW1;
      Servo servoCW2;
      Servo servoCW3;
      Servo servoCW4;

      int servoCW1_DEG = 0;
      int servoCW2_DEG = 0;
      volatile uint8_t bUpdateFlagsShared;
      volatile uint16_t unThrottleInShared;
      volatile int throttleOffset;
      uint32_t ulThrottleStart;

      float ypr[3]; // yaw pitch roll

      //Define Variables we'll be connecting to
      double Input_roll,rollOffset,Setpoint_roll;


      PID myPID(&Input_roll, &rollOffset, &Setpoint_roll,1,1,1, DIRECT);

      // Set the FreeIMU object
      FreeIMU my3IMU = FreeIMU();

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

        delay(5);
        my3IMU.init(); // the parameter enable or disable fast mode

         //initialize the variables we're linked to

        Setpoint_roll = -5.00;

        //turn the PID on
        myPID.SetMode(AUTOMATIC);
        myPID.SetOutputLimits(-100.00, 100.00);

        servoCW1.attach(CW1_IN);
        servoCW2.attach(CW2_IN);

        servoCW3.attach(CW3_IN);
        servoCW4.attach(CW4_IN);

        Serial.println("GET IT");
        arm();
        attachInterrupt(0, calcThrottle,CHANGE);


        delay(5);
      }


      void loop()
      {

        static uint16_t unThrottleIn;
        static uint8_t bUpdateFlags;

        // check shared update flags to see if any channels have a new signal
        if(bUpdateFlagsShared)
        {
          noInterrupts();

          bUpdateFlags = bUpdateFlagsShared;

          if(bUpdateFlags & THROTTLE_FLAG)
          {
            unThrottleIn = unThrottleInShared;
          }

          bUpdateFlagsShared = 0;

          interrupts(); // we have local copies of the inputs, so now we can turn interrupts back on

        }

       if(bUpdateFlags & THROTTLE_FLAG)

       {
            throttleChange(unThrottleIn);


       }
        my3IMU.getYawPitchRoll(ypr);
        Input_roll = ypr[2];
        myPID.Compute();
        rollChange(rollOffset);
        bUpdateFlags = 0;
      }



      void rollChange(double rollOffset)
      {
        int valCW1 = servoCW1.readMicroseconds();
        int valCW2 =  servoCW2.readMicroseconds();
      Serial.print("offset:       ");
        Serial.println(rollOffset);
        valCW1 = valCW1 + rollOffset;
        valCW2 = valCW2 - rollOffset;
       Serial.print("valCW1:       ");
        Serial.println(valCW1);

        Serial.print("valCW2:      ");
        Serial.println(valCW2);
         Serial.println("");
          Serial.println("");

        servoCW1.writeMicroseconds((int)valCW1);
        servoCW2.writeMicroseconds((int)valCW2);
      }
      void arm()
      {

        servoCW1.write(ARM_DEG);
        servoCW2.write(ARM_DEG);

        servoCW3.write(ARM_DEG);
        servoCW4.write(ARM_DEG);

      }

      void throttleChange(int cha_val)
      {


          servoCW1.writeMicroseconds(cha_val);
          servoCW2.writeMicroseconds(cha_val);

          servoCW3.writeMicroseconds(cha_val);
          servoCW4.writeMicroseconds(cha_val);

      }

      void calcThrottle()
      {
        if(digitalRead(THROTTLE_CHNL) == HIGH)
        {
          ulThrottleStart = micros();
        }else
        {

          unThrottleInShared = (uint16_t)(micros() - ulThrottleStart);
          bUpdateFlagsShared |= THROTTLE_FLAG;
        }
      }


I am getting an rollOffset from the PID controller. And action is taken in the rollchange() function. My setpoint is -5.00.

Problem: The PID outputs 100 most of the time. And, I don't think it is helping to reach my setpoint but it is really destroying it. So my question is am I really using the output from PID the right way.


5  Using Arduino / Programming Questions / Re: AttatchInterrupt Constantly interrupts on: August 24, 2013, 03:34:12 pm
Quote
I meant to configue the Transmitter not to send Pulse, But constant voltage.
What kind of equipment are we talking about here?
What good would an interrupt do in such a situation?

I have no idea.. I am just curious If you can get a constant voltage from a transmitter .  Well in case of  "What good would an interrupt do in such a situation?" If you can just change 0 to 5, that should interrupt the program don't you think ?
6  Using Arduino / Programming Questions / Re: AttatchInterrupt Constantly interrupts on: August 24, 2013, 02:31:55 pm
Quote
Is there no way to configure the radio PWM signal to a regular signal
What is a "regular signal"?

Oops!! I meant to configue the Transmitter not to send Pulse, But constant voltage.
7  Using Arduino / Programming Questions / Re: AttatchInterrupt Constantly interrupts on: August 24, 2013, 02:30:28 pm
Ok I saw a similar problem before.

Tel me are you using a Mega you bouth from China? And also are you using a nrf24 unit?

If it's the case, your problem probably reside in a faulty 3,3volt alimentation on you Mega unit. Just try to use a external power supply that give 3,3v Like a computer power supply.

Yes ... I tried with the  Mega From  China.. But, I also tried a geniune Arduino UNO from adafruit.com . It's the same.. But it makes sense I think. Because the radio transmitter sends PWM. And even when I don't move the transmitter handle it's sending 0  , 2.6 , 0 , 2.6.... when the handle is moves to the right  0,  3. 2 and on left 0,  2.0 .. So if there is an interrupt on Change or Rising or Falling ,, it will constantly interrupt  because of the Pulses. Don't you think ?
8  Using Arduino / Programming Questions / Re: AttatchInterrupt Constantly interrupts on: August 24, 2013, 01:44:11 pm
Understood, but because the output from the receiver is a PWM signal which constantly goes from zero to five volts and back an interrupt is not going to work as far as I can see.

How long does one iteration of your loop() function take compared to how often you need to read the inputs from the receiver ?

How about reading the inputs in loop() and using a timer interrupt to trigger the PID calculations ? 

Are you using a PID library or have you written your own ?  The PID library that I have used has a method to set the sample time http://playground.arduino.cc//Code/PIDLibrarySetSampleTime

That is a simple approach. Sounds great. I will go that route then...  But just curious... Is there no way to configure the radio PWM signal to a regular signal
9  Using Arduino / Programming Questions / Re: AttatchInterrupt Constantly interrupts on: August 24, 2013, 01:19:10 pm
OK

Given
I am a new to electronics.
and
i am a beginner.

I was trying to establish a baseline here.
Less than reasonable?

I see what you are doing..  Ok I tried your  code. And, yes it did interrupt when i touch the pin to the ground.

So, the interrupt works when the pin goes to 0V.  Now, ask yourself how often the output from the RC channel goes to 0V bearing in mind the previous answers.

Are you sure that you need to use an interrupt at all ?

Try this
Code:
int pin = 7;  //connect the receiver output to this pin.  You also need a common ground or power the Rx from the Arduino
unsigned long duration;

void setup()
{
  Serial.begin(115200);
  pinMode(pin, INPUT);
}

void loop()
{
  duration = pulseIn(pin, HIGH);
  Serial.println(duration);
  delay(100);
}

Yes this works Fine. But this is a small problem I took out from my Project. It's a quadcopter Project. I am doing Radio control through Interrupt and PID tuning in the void loop()
10  Using Arduino / Programming Questions / Re: AttatchInterrupt Constantly interrupts on: August 24, 2013, 01:15:40 pm
An RC receiver puts out PWM to the servos, right?
Yes.  So it is constantly turning on and off and causing an interrupt, which I think was your point.

So you probably don't need the Arduino at the receiver end?


You can have better control if you use arduino in the middle, SInce you can write your own PWM based on the Transmitter's response. This takes away the hassle of configuring your radio transmitter.
11  Using Arduino / Programming Questions / Re: AttatchInterrupt Constantly interrupts on: August 24, 2013, 01:08:59 pm
What he was trying to do was break the problem into smaller problems.
a) first make sure the interrupt works as it should
b) then connect the receiver.

And. Btw. don't use Serial in interrupt. Could cause corruption

As for your case, it is unknown how the signal looks from your receiver. What kind of output is it? does it need pull-up (i.e. the 10K resistor)?
happen to have a scope?
he interrupt alternative will work so then your problem shoudl be found in either crap connections or the receiver might be sending out garbage.

I see.  I have triple checked my connection, and I think there should be no problem with the connection. I also tried with the 10K resistor same problem. So now I am leaning towards the " reciever might be sending out garbage" . So how do I resolve this or check if it is sendin garbage. ? Thank you
12  Using Arduino / Programming Questions / Re: AttatchInterrupt Constantly interrupts on: August 24, 2013, 01:05:58 pm
OK

Given
I am a new to electronics.
and
i am a beginner.

I was trying to establish a baseline here.
Less than reasonable?

I see what you are doing..  Ok I tried your  code. And, yes it did interrupt when i touch the pin to the ground.
13  Using Arduino / Programming Questions / Re: AttatchInterrupt Constantly interrupts on: August 24, 2013, 11:37:06 am
I am sorry I don't follow.   I am trying to get an interrupt from the radio transmitter. So, when I move the channel 1 handle on the tranmitter it generates a Interrupt, 
Since, the reciever's channel is connected to the interrupt pin. And again it's not that I am not getting any interrupt, but I am getting a constant interrupt regardless of me moving the transmitter handle . I am sorry i am a beginner. Does that makes sense?
14  Using Arduino / Programming Questions / AttatchInterrupt Constantly interrupts on: August 24, 2013, 10:53:36 am
I am a new to electronics. I am trying to setup the radio control for the arduino. I hooked up the Reciever's Channel 1 to the Arduino Mega 2560's Digital pin 2, Reciever Vin to Arduino 5V, and Ground to Ard Ground. Here is my Source Code.

void setup() {
        Serial.begin(9600);
        attachInterrupt(0 , blink, CHANGE);
     }

void loop() {
   Serial.println("I AM IN THE LOOP");       

}


void blink()
{

     Serial.println("I AM IN THE INTERRUPT"); 
}
I tried using other interrupt pins,3.3 V instead of 5 and also tried Arduino Uno and differnt kinds of Interrupt Values like RISING, LOW and FALLING but it constantly prints " I AM IN THE INTERRUPT" without me touching the transmitter. Any suggestions.
15  Topics / E-Textiles and Craft / 9DOF Sensor stick on: July 13, 2013, 03:00:44 pm
I am trying to buy the 9DOF Sensor stick for my Arduino Uno to use in a Quadcopter Project. This product is not available in sparkfun. It is retired. I found couple in Amazon.com. Since, I am a noob  I don't really know if it will be compatible or not. Can anyone suggest me where should I go ?
Pages: [1] 2