Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Project Guidance / Compute linear algebra equations in arduino. on: April 21, 2014, 04:47:21 am
Hello,

Has anyone coded complicated matrix equations in arduino? Like for example, X_hat_1=X_hat+ AX+BU+L(Y-CX), where all the variables are matrices. Is there some way i could code this the way I do in Matlab? I'm using arduino dumilanalov. Any help would be greatly appreciated.
2  Using Arduino / Networking, Protocols, and Devices / RF module library that uses timer 0. on: March 13, 2013, 03:29:34 pm
Hey, I'm using the arduino dumilanalov, and i wanted to communicate between 2 arduinos wirelessly. What are my options of an RF module ( xbee, cc2500......) which has a library in arduino and which uses timer 0. I want the pwm capabilities on pins 9,10,11 and 3. Earlier i was using virtualwire , but it uses timer 1, and pwm capabilities on pins 9 and 10 were affected.
3  Using Arduino / Programming Questions / fifo overflow while using MPU-6050. on: March 11, 2013, 08:08:50 am
Hello,

I'm working on a quadcopter, which is controlled by means of a visual studio application. I'm making use of those $5 transmitter/receiver to communicate between the PC and the quadcopter. I'm using the MPU-6050 to obtain the Euler angles. Everything worked out well when i coded the wireless transmission, getting euler angles of the DMP of mpu-6050, but when i tried combining the two, FIFO overflow keeps occurring. I understand that I'm not taking data off the fifobuffer, as frequently as it requires, or i'm taking data at a much slower rate.

How do i time my intervals when i take data off the MPU-6050 such that this overflow doesn't occur?

Here's the code,

Code:
#include <VirtualWire.h>
#include <ServoTimer2.h>
#include <PID_v1.h>
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
MPU6050 mpu;


ServoTimer2 motor1,motor2,motor3,motor4;

int j=0,pwm,a,b;






// MPU control/status vars
bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

float euler[3];         // [psi, theta, phi]    Euler angle container
Quaternion q;           // [w, x, y, z]         quaternion container



// PID control variables and initialisation

//0.38  0.08  0.1

float conskp=.38, conski=.08, conskd=.1, aggkp=.38, aggki=.08, aggkd=.1;
/*conskp=.38;
conski=.08;
conskd=.1;
aggkp=.38;
aggki=.08;
aggkd=.1;*/
double setPoint_pitch, input_pitch, output_pitch;
PID pid_pitch(&input_pitch, &output_pitch, &setPoint_pitch, conskp, conski, conskd, DIRECT);


//*******INTERRUPT DETECTION SUB-ROUTINE***********//

volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
void dmpDataReady()
{
    mpuInterrupt = true;
}







void setup()
{
 
  motor1.attach(9);
  motor2.attach(6);
  motor3.attach(5);
  motor4.attach(7);
 
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
   pinMode(3,OUTPUT);
    //****************************PID INITIALISING CODE*******************//
   
    pid_pitch.SetOutputLimits(-20,20);
    pid_pitch.SetMode(AUTOMATIC);
    setPoint_pitch=0;
   
   //*******************ASK receiver INITIALISING CODE*******************//
  vw_set_rx_pin(11);
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_rx_start(); //start the PLL running
 
 
  //*******************MPU-6050 INITIALISING CODE*******************//
 
   Wire.begin();
  Serial.begin(115200);
  mpu.initialize();
 
   while (Serial.available() && Serial.read());// empty buffer
   devStatus = mpu.dmpInitialize();// load and configure DMP
   
    if (devStatus == 0) {
             
        mpu.setDMPEnabled(true);  // turn on the DMP, now that it's ready

        // enable Arduino interrupt detection
       
        attachInterrupt(0, dmpDataReady, RISING);
        mpuIntStatus = mpu.getIntStatus();

        // set our DMP Ready flag so the main loop() function knows it's okay to use it
       
        dmpReady = true;

        // get expected DMP packet size for later comparison
        packetSize = mpu.dmpGetFIFOPacketSize();
    }
    else
    Serial.print("DMP initialization failed");
 
 
 
}

void loop()
{
  digitalWrite(12,HIGH);
   if (!dmpReady) return;
 
   while (!mpuInterrupt && fifoCount < packetSize)
   {
   }
 
  // reset interrupt flag and get INT_STATUS byte
    mpuInterrupt = false;
    mpuIntStatus = mpu.getIntStatus();

    // get current FIFO count
    fifoCount = mpu.getFIFOCount();
   
     // check for overflow (this should never happen unless our code is too inefficient)
    if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
        // reset so we can continue cleanly
        mpu.resetFIFO();
        Serial.println(F("FIFO overflow!"));

    // otherwise, check for DMP data ready interrupt (this should happen frequently)
    } else if (mpuIntStatus & 0x02) {
        // wait for correct available data length, should be a VERY short wait
        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

        // read a packet from FIFO
        mpu.getFIFOBytes(fifoBuffer, packetSize);
       
        // track FIFO count here in case there is > 1 packet available
        // (this lets us immediately read more without waiting for an interrupt)
        fifoCount -= packetSize;
    } 
       
         
            // display Euler angles in degrees
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetEuler(euler, &q);
            Serial.print("euler\t");
            Serial.print(euler[0] * 180/M_PI);
            Serial.print("\t");
            Serial.print(euler[1] * 180/M_PI);
            Serial.print("\t");
            Serial.println(euler[2] * 180/M_PI);
       
//  transmission();
 // if(j==5)
 // hover();
 
 
 
}

void transmission()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN],i=0;
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    char msg[10],starter1[2]="a",starter2[2]="b",starter3[2]="c",starter4[2]="d",starter5[2]="e";
   
   //
   
    if (vw_get_message(buf, &buflen))
    {
     
      digitalWrite(13,HIGH);
      //pwm=atoi(buf);
      for(i=0;i<buflen;i++)         
      msg[i]=buf[i];     
      msg[i]='\0';
      if(strcmp(msg,starter1)==0)
      start1();
      else if(strcmp(msg,starter2)==0)
      start2();
      else if(strcmp(msg,starter3)==0)
      start3();
      else if(strcmp(msg,starter4)==0)
      start4();
       else if(strcmp(msg,starter5)==0)
      start5();
       digitalWrite(13,LOW);
    }
   
      switch(j)
      {
        case 1:
       
        digitalWrite(2,HIGH);
        pwm=atoi(msg);
        Serial.println(pwm);
        motor1.write(pwm);
        digitalWrite(2,LOW);
        break;
       
        case 2:
       
        digitalWrite(3,HIGH);
         pwm=atoi(msg);
        Serial.println(pwm);
        motor2.write(pwm);
        digitalWrite(3,LOW);
        break;
       
         case 3:
       
        digitalWrite(3,HIGH);
         pwm=atoi(msg);
        Serial.println(pwm);
        motor3.write(pwm);
        digitalWrite(3,LOW);
        break;
       
          case 4:
         
        digitalWrite(3,HIGH);
         pwm=atoi(msg);
        Serial.println(pwm);
        motor4.write(pwm);
        digitalWrite(3,LOW);
        break;
       
        case 5:
        digitalWrite(3,HIGH);

        pwm=atoi(msg);
             
        a=pwm;
        b=pwm;
        hover();
         digitalWrite(3,LOW);
       
       
      }
}

/*void angle()
{
 
}*/
 
void start1()
{
  j=1;
  delay(20);
}
void start2()
{
  j=2;
  delay(20);
}
void start3()
{
  j=3;
  delay(20);
}
void start4()
{
  j=4;
  delay(20);
}

void start5()
{
  j=5;
  delay(20);
}

void hover()
{
 
 
  float pitch_gap= abs(setPoint_pitch-euler[1]);
   if(pitch_gap<3)
  pid_pitch.SetTunings(conskp,conski,conskd);
  else
  pid_pitch.SetTunings(aggkp,aggki,aggkd);
 
 pid_pitch.Compute();
 if(output_pitch>0)
 {
   a++;
   motor4.write(a);
   
 
 }
 else
 {
   b++;
   motor2.write(b);
   
 }
             
             Serial.print(a);
              Serial.print("\t");
           
             Serial.println(b);
}
   
     
     
     
 
4  Using Arduino / Installation & Troubleshooting / Re: PWM pins 5 and 6 not working as expected. on: February 13, 2013, 06:20:44 am
Thank you. And yes, there were troubles with reception, but with adding longer wires to the antenna pin or, sometimes by touching the tip of the wires, the reception works like magic. smiley
5  Using Arduino / Installation & Troubleshooting / Re: PWM pins 5 and 6 not working as expected. on: February 12, 2013, 08:38:27 am
@retrolefty, thanks to your advice, my testing worked out great. But i had to choose ServoTimer2 library as the servo library and the virtualwire library( for wireless transmission) use timer 1. Heres a video to what i was doing. smiley

6  Using Arduino / Installation & Troubleshooting / Re: Error message "avrdude: stk500_getsync(): not in sync: resp=0x30" on: February 08, 2013, 06:10:45 pm
Make sure you've chosen the right board and port.
7  Using Arduino / Installation & Troubleshooting / Re: PWM pins 5 and 6 not working as expected. on: February 08, 2013, 01:23:02 pm
Thanks, retrolefty. smiley
8  Using Arduino / Installation & Troubleshooting / Re: PWM pins 5 and 6 not working as expected. on: February 08, 2013, 12:39:20 pm
Quote
Why are you using analogWrite commands to try and control ESCs?

I didn't just try, it worked like i told, in pwm pins 3 and 11. It doesn't work only on pins 5 and 6. I didn't want to add another library to code and increase its size. Could you tell me what difference there is between the two?

Thanks
9  Using Arduino / Installation & Troubleshooting / PWM pins 5 and 6 not working as expected. on: February 08, 2013, 09:45:02 am
I'm working on a project ( a quadcopter). the brushless DC motors are driven by an Electronic Speed controller which drives the motors at varying speeds depending upon the PWM values inputted to the ESC. I'm varying the pwm by means of a visual studio application that i designed.

So, basically,   PC-->arduino dumilanalov-->RF transmitter     ---       RF receiver-->arduino dumilanalov-->ESC-->brushless DC motor

The motor starts when i gradually increase the pwm. When i tried using pwm pins 3 and 11, the motor worked perfectly, but pins 5 and 6 didn't seem to work. So i tried connecting an LED to it. But the LED responded correctly. VirtualWire(the library i used for the wireless communication) takes over Arduino Timer1, and this will affect the PWM capabilities of the digital pins 9 and 10.


In the arduino reference page, it is given
Quote
Notes and Known Issues
The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.

Here is code on the receiver arduino,

Code:
#include <VirtualWire.h>


const int pin=5;

void setup() //reception-12, motor-3
{
  Serial.begin(9600);//debugging purposes
  pinMode(13,OUTPUT);
  pinMode(pin,OUTPUT);
   pinMode(2,OUTPUT);
  vw_set_rx_pin(12);
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_rx_start(); //start the PLL running
}

void loop()
{
  transmission();
}

void transmission()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN],pwm;
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    char msg[10],start[2]="s";
    int i=0;
   //
   
    if (vw_get_message(buf, &buflen))
    {
     
      digitalWrite(13,HIGH);
      //pwm=atoi(buf);
      for(i=0;i<buflen;i++)         
      msg[i]=buf[i];     
      msg[i]='\0';
     
      if(strcmp(msg,start)==0) // checking for an input from PC for automatic start
      starter();
     
      pwm=atoi(msg);
      Serial.println(pwm);
      analogWrite(pin,pwm);

      digitalWrite(13,LOW);
    }
}
void starter()
{
  digitalWrite(2,HIGH);
     analogWrite(pin,0);
      delay(200);
      analogWrite(pin,50);
      delay(1000);
      analogWrite(pin,80);
      delay(1000);
      analogWrite(pin,100);
      delay(2000);
      analogWrite(pin,150);
      delay(1000);
      digitalWrite(2,LOW);
}
 
 
10  Using Arduino / Microcontrollers / Bootloading troubles on the 328P-PU.... on: January 22, 2013, 08:32:24 am
I'm trying to bootload the atmega328P-PU, exactly as shown in here, http://arduino.cc/en/Tutorial/ArduinoISP. I have a 328P-PU on my arduino dumilanalov, to which i burnt the arduino ISP sketch, then i tried burning the bootloader to the 328P-PU in breadboard.
I keep getting this error,
Quote
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

I rechecked the avrdude.conf file and the device signature was still " 0x1e 0x95 0x0F", which I'm guessing is the right one for 328P-PU. I also tried disabling auto reset by placing a 10uF cap across RESET and GND, but i keep getting the same error.

Any help will be deeply appreciated.... smiley-sad
11  Using Arduino / Microcontrollers / Re: bootloading the atmega328-pu on: January 20, 2013, 02:15:57 am
What is the correct device signature of the Atmega328P-PU?

I tried bootloading it with my bootloaded Atmega328P-PU, but i was getting 
Quote
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.
, when i made no changes to the avrdude.conf file and the device signature was still 1E 95 0F.

I tried editing the avrdude.conf file entry, of signature from 1E 95 0F to 1E 95 14. It still shows,
Quote
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

Any thoughts?
12  Using Arduino / Microcontrollers / Re: Bootloading the Atmega168. on: January 13, 2013, 12:06:58 am
Attaching, boards.txt.
13  Using Arduino / Microcontrollers / Re: Bootloading the Atmega168. on: January 12, 2013, 03:37:34 am


Quote
I get:

Code:
Error 503 Service Unavailable

Service Unavailable

Guru Meditation:

XID: 1077305799

Varnish cache server

Sorry about that..I've added a screenshot, if that doesn't help could you pm me your id. I'll mail it to you. There seems to be some problem while opening the boards.txt attachment. Not quite sure, why.
14  Using Arduino / Microcontrollers / Re: Bootloading the Atmega168. on: January 12, 2013, 01:57:25 am
Quote
Did you restart the IDE?  It only reads boards.txt at startup.

Yes. I did try restarting the IDE, it isn't coming in the menu.Is there anything wrong with my entry into the boards.txt?
15  Using Arduino / Microcontrollers / Re: Bootloading the Atmega168. on: January 07, 2013, 11:16:51 am
Sorry for the late reply...

As Westfw, told, i added the entry to my boards.txt, but it isn't appearing in the boards menu in the IDE o.O. I'm attaching the boards.txt.
Pages: [1] 2 3 ... 5