Show Posts
Pages: 1 [2] 3 4 ... 7
16  Using Arduino / Sensors / Re: Digital gyro, acc, kalman, pitch, roll tutorial on: April 01, 2013, 03:00:22 pm
i dont quite know, haha. i copied that code. bACCx  is probably in a different function. do you want it?

It got sort out when I downloaded your code. It was simply an average of 100 samples when you start the sensor, with other word offset/bias value.

Thanks anyway mate smiley-wink
17  Using Arduino / Sensors / Re: Digital gyro, acc, kalman, pitch, roll tutorial on: March 28, 2013, 02:01:04 pm
Do you mind explaining why you are using the map function for the magnetometer? Is that really neccessary?
And where did you get the variable
Quote
bACCx
from ? Cant seem to find it anywhere else in your code.

Cheers
18  Using Arduino / Sensors / IMU GY-80 [HELP] on: March 26, 2013, 12:15:30 pm
Hello dear arduino community,

I recently ordered a 10DoF IMU, so when I received the IMU I sent him an email and asked for a datasheet for this particular chip. And it turned out that he had none, neither did he have the name of the chip.

However, I made some research on the net and it turned out it was a GY-80. Exactly the same look and same sensors.
The sensors included are
Quote
L3G4200D + the ADXL345 + HMC5883L + BMP085

I am in need of some help right now. Since I do not have a datasheet I do not know how to configure it.
When I want to configure it with I2C, should I assume that I do it for each of the sensors, I know that there are codes for each of the sensors in I2CDEV lib. or must I first configure the IMU board (gy-80) and then each sensor separately?

And atlast one more question, since it says: "Build-in Regulator and Logic converter to support  all (3.3V/5.0V) all types of microcontrollers", I do not need any pullups or such, to compensate for the voltage output from the Arduino?

Some links:
GY-80 (another link): http://www.logictoyz.com/development-board/gy-80-imu-10dof-9-axis-bmp085-3-axis-magnetic-field-acceleration-gyroscope-atmospheric-pressure-module-4-axis-flight-control-l3g4200d-adxl345-hmc5883-bmp085-multiwii-mwc-arduino.html

Schematic: http://img854.imageshack.us/img854/1790/gy80schematics.jpg

Cheers!
19  Using Arduino / Project Guidance / Re: Tricopter algorithm [HELP - CONFIRM] on: December 26, 2012, 10:26:11 am
Jabbado:
Well now it makes sense to me, lol.

All I can do is to thank for the help, and I will try to put this together later cuz I burned an esc and Im pretty pissed of (not the first one).

Cheers!
20  Using Arduino / Project Guidance / Re: Tricopter algorithm [HELP - CONFIRM] on: December 25, 2012, 06:16:34 am
Jabbado:
Now I have two PID configs, for the pitch and roll. And they output negative or positive value depending if the sensor is outputting +- values.

But I just can't seem to put the equation together on the mixer.

THROTTLE_PID_BACK               = Receiver_throttle_val + PID_pitch_output (if the output is positive)
THROTTLE_PID_FRONT_LEFT     = Receiver_throttle_val + PID_roll_output (if the output is positive) + PID_pitch_output (if the output is negative)
THROTTLE_PID_FRONT_RIGHT   = Receiver_throttle_val + PID_roll_output (if the output is negative) + PID_pitch_output (if the output is negative)

I hope you understand my dilemma here. I mean I can't seem to make it fit without IF statements.

Cheers!


21  Using Arduino / Project Guidance / Re: Tricopter algorithm [HELP - CONFIRM] on: December 24, 2012, 08:18:25 pm
PeterH:
It may be due to this line.
Goes from 0 - 180, maybe I should change it to -180 - 180.
Code:
myPID_Pitch_Plus.SetOutputLimits(0,180);

However if that will fix it, should I make a IF statement (for the roll axis):
if output is negative -> make absolute value of it and add it to the right motor
else add it to the left motor?

Jabbado:
Actually you did not miss that part, cuz there are none yet. But I will implent a servo that will Control the back motor to rotate in the roll axis which will Control the yaw.
22  Using Arduino / Project Guidance / Re: Tricopter algorithm [HELP - CONFIRM] on: December 24, 2012, 01:23:33 pm
PaulS:
I have tried this code. Ive successuly uploaded it to the arduino. But the last part is to set the correct kp,ki and kd values. But If it wouldnt work, I would never know where the problem is. If its with my algorithm or with the PID values.

PeterH:
From the beginning I had only one PID for the roll axid and one for the pitch axis.

But as you know the total output depends on the error.
Lets put up a scenario.
The setpoint is 180, and the input (sensor val) is higher than 180.
Error = setpoint - input -> this would generate a negative value, but in my code it only gives me a 0.

That is why I have two different PID for each axis. As one is:
DIRECT (plus) --> Will give me a value > 0 if sensor val < 180, but if sensor val > 180 I will get a 0.
REVERSE (minus) --> WIll give me a value  > 0 if sensor val > 180, but if sensor val < 180 I will get a 0.



You can also see this on the picture.

Isn't it supposed to look like this?

Cheers!

Edit:
Lets put up another scenario.
Make sure to look at the three last variables, that shall goto the motors (probably called the mixer), and remember 180 degree is stable.

Copter leaning forward (pitch) 200 degrees, roll are all stabe 180 degrees.

Error = Setpoint - Error
PID Roll:
Error (DIRECT- plus) = 180 - 180 = 0
Error (REVERSE - minus) = 180 - 180 = 0
--> No extra power from roll plus/minus.

PID Pitch:
Error (Direct - plus) = 180 - 200 < 0 = 0. Because there are no meaning to add extra power to the back motor, only the power from the throttle will be added.
Error (Direct - minus) = I believe it will be the opposite > 200 - 180 = 20. This will be added to the front two motors.

I hope I made it more clear for you guys now!
23  Using Arduino / Project Guidance / Tricopter algorithm [HELP - CONFIRM] on: December 24, 2012, 08:33:31 am
Hello dear members,

I believe that the time has come, where I have to ask you guys for some support over here.
And I also hope that this will help other people with similar projects.

However, I’m up for doing a tricopter. And right now I’m in the phase where I need you guys to confirm if my algorithm for stabilizing is correct.

I’ll post a picture to illustrate my thought. As they say, a picture can tell you more a thousand words (If you'd like to see the picture, go to the end of the post).

1. Read values from transmitter (throttle will give from 0 - ~180, the rest of the sticks gives ~90 in middle)
2. Read values from sensor (180 degrees if plan)
3. PID CONTROL
4. Combine PID outputs with throttle value
5. Output the values to the motors

For the PID configs
Code:
PID myPID_Roll_Plus(   &Input_Roll_Plus,    &Output_Roll_Plus,    &Setpoint_Roll_Plus,   1.5, 0.1, 0.5, DIRECT);
PID myPID_Roll_Minus(  &Input_Roll_Minus,   &Output_Roll_Minus,   &Setpoint_Roll_Minus,  1.5, 0.1, 0.5, REVERSE);
PID myPID_Pitch_Plus(  &Input_Pitch_Plus,   &Output_Pitch_Plus,   &Setpoint_Pitch_Plus,  1.5, 0.1, 0.5, DIRECT);
PID myPID_Pitch_Minus( &Input_Pitch_Minus,  &Output_Pitch_Minus,  &Setpoint_Pitch_Minus, 1.5, 0.1, 0.5, REVERSE);

Setting the values for the variables (OBS. setpoint is set to 90, because the sticks from the transmitter outputs 90 if not touched)
Code:
//////////////////////////////////////////////
/////          PID SETTINGS              /////
/////////////////////////////////////////////
void PID_SETTINGS(){
  myPID_Pitch_Plus.SetMode(AUTOMATIC);
  myPID_Pitch_Plus.SetOutputLimits(0,180);
  Setpoint_Pitch_Plus = 90;
  
  myPID_Pitch_Minus.SetMode(AUTOMATIC);
  myPID_Pitch_Minus.SetOutputLimits(0,180);
  Setpoint_Pitch_Minus = 90;
  
  myPID_Roll_Plus.SetMode(AUTOMATIC);
  myPID_Roll_Plus.SetOutputLimits(0,180);
  Setpoint_Roll_Plus = 90;
  
  myPID_Roll_Minus.SetMode(AUTOMATIC);
  myPID_Roll_Minus.SetOutputLimits(0,180);
  Setpoint_Roll_Minus = 90;
}



PID calculations (As I said before, the setpoint is set to 90. Thats why Im subtracting with 90. 180 - 90 = 90.
Code:
  Input_Pitch_Plus = kalAngleY-90;
   myPID_Pitch_Plus.Compute();
   Input_Pitch_Minus = kalAngleY-90;
   myPID_Pitch_Minus.Compute();
  
   Input_Roll_Plus = kalAngleX-90;  
   myPID_Roll_Plus.Compute();
   Input_Roll_Minus = kalAngleX-90;
   myPID_Roll_Minus.Compute();

The outputs for the motors
Code:
  THROTTLE_PID_BACK         = RECEIVER_THROTTLE_VAL + Output_Pitch_Plus;
   THROTTLE_PID_FRONT_LEFT   = RECEIVER_THROTTLE_VAL + Output_Roll_Plus + Output_Pitch_Minus;
   THROTTLE_PID_FRONT_RIGHT  = RECEIVER_THROTTLE_VAL + Output_Roll_Minus + Output_Pitch_Minus;

Here is the picture:
This will explain much better than the text above.


Ive also made a page on github, If ud like too see the whole code.
https://github.com/freak174/Tricopter--Build-phase-.git


Edit:
Forgot to mention that I am only trying to stabilize the tricopter by the throttle, which means Ive excluded all other sticks from the transmitter.
24  Using Arduino / Motors, Mechanics, and Power / Re: Reading a RC Airplane Receiver on: October 24, 2012, 11:24:31 am
Bump!
25  Using Arduino / Motors, Mechanics, and Power / Re: Reading a RC Airplane Receiver on: October 22, 2012, 03:43:00 pm
Hello again,

Ive now come a bit further with the project.
Quote
* Values from sensors (GYRO AND ACC.)
* Values from receiver (using a libraries called PPMrcIn and Statistic)
* The sensor will only do its work when the transmitter is not sending any new values/directions
- So, if you are flying the plane manually and then put your transmitter away. The plane will stabilize itself (roll and pitch)

I will post a bit of the code, showing my algorithms. And here I need you guys to help me improve my code.

One thing I know that is not working well, is the automatic stabilizer.
Lets say:
* Plane is straightforward = roll and pitch has a value of 180 degrees.
* Plane is leaning = roll has a value of 160 (which means leaning 20 degrees to the left, I believe)
--> Divide value by 2 and insert it in servo.write() function.

The problem is that the indication of the servos gets to small.
Should I make it into several intervals instead, or will it take to much memory?

Code:
Servo YAW_SERVO;
Servo PITCH_SERVO;
Servo ROLL_SERVO;

int flag_roll = 0;
int flag_pitch = 0;
int flag_yaw = 0;

//////////////////////////////////////////////
//////     INITIATION OF  SERVOS       ///////
//////////////////////////////////////////////
void init_servo_motor(){
  YAW_SERVO.attach(SERVO_YAW_PIN);
  PITCH_SERVO.attach(SERVO_PITCH_PIN);
  ROLL_SERVO.attach(SERVO_ROLL_PIN);
}


//////////////////////////////////////////////
//////     READING THE RECEIVER AND      /////
//////  MANIPULATING THE SERVOS THROUGH IT ///       
//////////////////////////////////////////////
void read_receiver(){
    YAW.readSignal();
    PITCH.readSignal();
    ROLL.readSignal();
//  THROTTLE.readSignal();

   
          //////////////////////////////////////////////
          ///    CONTROL SERVO THROUGH RECEIVER     ////
          //////////////////////////////////////////////
      if(ROLL.getVersus() != 0){
      ROLL_SERVO.write(map((ROLL.getSignal()), 1000,2000,0,179));
      flag_roll = 0;
      Serial.println("RECEIVER ROLL");
    }
    if(PITCH.getVersus() != 0){
      PITCH_SERVO.write(map((PITCH.getSignal()), 1000,2000,0,179));
      flag_pitch = 0;
      Serial.println("RECEIVER PITCH");
    }
    if(YAW.getVersus() != 0){
      YAW_SERVO.write(map((YAW.getSignal()), 1000,2000,0,179));
      flag_yaw = 0;
      Serial.println("RECEIVER YAW");
    }

    //CHECKING IF ALL OF THE LEVERS OF THE RECEIVER ARE OFF   
    if(ROLL.getVersus() == 0 && PITCH.getVersus() == 0 && YAW.getVersus() == 0){
      control_servo_sensor();
    }

 
}



void control_servo_sensor(){
 
    //////////////////////////////////
    ///    CONTROLLING THE SERVOS ////
    ///          WITH SENSOR      ////
    //////////////////////////////////
   
  get_sensor_values();
   
  // THIS IS FOR THE ROLL SERVO  //
    if(kalAngleX < 177 || kalAngleX > 182){
     
      Serial.println("SENSOR ROLL ");
      Serial.print(kalAngleX);
     
      int value_roll = kalAngleX/2;   
      ROLL_SERVO.write(value_roll);
     
      flag_roll = 0;
  }
 
    // THIS IS FOR THE PITCH SERVO //
  if(kalAngleY < 182 || kalAngleY > 185){   
   
    Serial.println("SENSOR PITCH ");
    Serial.print(kalAngleY);
   
    int value_pitch = kalAngleY/2;
    PITCH_SERVO.write(value_pitch);
   
    flag_pitch = 0;
  }
   
       /////////////////////////////////////////////////////////////////////// 
       // RESET TO ZERO POSITION JUST FOR SAFETY (ROLL, PITCH, YAW SERVOS) //
       ///////////////////////////////////////////////////////////////////////
       
     if(flag_roll == 0 && ROLL.getVersus() == 0 && kalAngleX > 177 && kalAngleX < 182){ 
       Serial.println("RESETING ROLL");
       
       ROLL_SERVO.write(90);
       flag_roll = 1;
   }

   if(flag_pitch == 0 && PITCH.getVersus() == 0 && kalAngleY > 182 && kalAngleY < 185){
     Serial.println("RESETING PTCH");
     PITCH_SERVO.write(90);
     flag_pitch = 1;
   }
   
     if(flag_yaw == 0 && YAW.getVersus() == 0){
     Serial.println("RESETING PTCH");
     YAW_SERVO.write(90);
     flag_yaw = 1;
   }
 

}





PS. Yes, I have the pinchangeint library installed. But lets forget about that since Ive found a quite good library now that satisfies me.
Cheers!
26  Using Arduino / Motors, Mechanics, and Power / Re: Reading a RC Airplane Receiver on: October 18, 2012, 01:22:25 pm
Sorry for hijacking your thread.
Im also about to make a rc plane controlled by the arduino processor. But at the moment Ill just go for stabilization and then upgrade with a barometer and such.

However, to the point where Im hijacking ur thread! Does your interrupt work good? I mean, when I try to go for interrupt with reciever it seems like its interrupting every second..
You know ur
Code:
#include <PinChangeInt.h>
, is it highlighted with orange colour? mine is grey but if you compare with others they have orange color..

27  Using Arduino / Motors, Mechanics, and Power / Re: To many changes in the servo makes processor stop [HELP] on: October 14, 2012, 08:03:48 am
Quote
Conclusions?

i conclude you should post your code if you want to consider the posibility you have bad code.  smiley

Ofcourse!

This isnt really a pushbutton, but I thought it would be more easy to explain in those terms.
It is a sensor, that outputs the inclination of the board (in degrees). The servos are controlled by an intervall of the degree values.
Code:
#include <Servo.h>
#include <Wire.h>
#include "Kalman.h"
#define LED_PIN 13

Servo YawServo;
long lastPulsing;
bool blinkState = false;



Kalman kalmanX;
Kalman kalmanY;

uint8_t IMUAddress = 0x68;

/* IMU Data */
int16_t accX;
int16_t accY;
int16_t accZ;
int16_t tempRaw;
int16_t gyroX;
int16_t gyroY;
int16_t gyroZ;

double accXangle; // Angle calculate using the accelerometer
double accYangle;
double temp;
double gyroXangle = 180; // Angle calculate using the gyro
double gyroYangle = 180;
double compAngleX = 180; // Calculate the angle using a Kalman filter
double compAngleY = 180;
double kalAngleX; // Calculate the angle using a Kalman filter
double kalAngleY;

uint32_t timer;

void setup() { 
  Serial.begin(115200);
  YawServo.attach(9);

  // configure LED for output
  pinMode(LED_PIN, OUTPUT);
 
  Wire.begin(); 
  i2cWrite(0x6B,0x00); // Disable sleep mode 
  if(i2cRead(0x75,1)[0] != 0x68) { // Read "WHO_AM_I" register
    Serial.print(F("MPU-6050 with address 0x"));
    Serial.print(IMUAddress,HEX);
    Serial.println(F(" is not connected"));
    while(1);
  }     
 
  kalmanX.setAngle(180); // Set starting angle
  kalmanY.setAngle(180);
  timer = micros();
  lastPulsing = millis() + 20;
}

void loop() {
  /* Update all the values */
  uint8_t* data = i2cRead(0x3B,14); 
  accX = ((data[0] << 8) | data[1]);
  accY = ((data[2] << 8) | data[3]);
  accZ = ((data[4] << 8) | data[5]); 
  tempRaw = ((data[6] << 8) | data[7]); 
  gyroX = ((data[8] << 8) | data[9]);
  gyroY = ((data[10] << 8) | data[11]);
  gyroZ = ((data[12] << 8) | data[13]);
 
  /* Calculate the angls based on the different sensors and algorithm */
  accYangle = (atan2(accX,accZ)+PI)*RAD_TO_DEG;
  accXangle = (atan2(accY,accZ)+PI)*RAD_TO_DEG;   
 
  double gyroXrate = (double)gyroX/131.0;
  double gyroYrate = -((double)gyroY/131.0);
  gyroXangle += gyroXrate*((double)(micros()-timer)/1000000); // Calculate gyro angle without any filter 
  gyroYangle += gyroYrate*((double)(micros()-timer)/1000000);
  //gyroXangle += kalmanX.getRate()*((double)(micros()-timer)/1000000); // Calculate gyro angle using the unbiased rate
  //gyroYangle += kalmanY.getRate()*((double)(micros()-timer)/1000000);
 
  compAngleX = (0.93*(compAngleX+(gyroXrate*(double)(micros()-timer)/1000000)))+(0.07*accXangle); // Calculate the angle using a Complimentary filter
  compAngleY = (0.93*(compAngleY+(gyroYrate*(double)(micros()-timer)/1000000)))+(0.07*accYangle); 
 
  kalAngleX = kalmanX.getAngle(accXangle, gyroXrate, (double)(micros()-timer)/1000000); // Calculate the angle using a Kalman filter
  kalAngleY = kalmanY.getAngle(accYangle, gyroYrate, (double)(micros()-timer)/1000000);
  timer = micros();
 
  temp = ((double)tempRaw + 12412.0) / 340.0;

 
  Serial.print(kalAngleX);Serial.print("\t");
  Serial.print(kalAngleY);Serial.print("\t");
 
    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);
   
   //SERVO 
   if(millis() >= lastPulsing + 20) {     
     if((180-kalAngleX) > 8){
       YawServo.write(180);
     }
     else if((180-kalAngleX) < 4){
       YawServo.write(0);
   }
   lastPulsing = millis();

 }
   
  Serial.print("\n");
 
  delay(1); // The accelerometer's maximum samples rate is 1kHz
}


void i2cWrite(uint8_t registerAddress, uint8_t data){
  Wire.beginTransmission(IMUAddress);
  Wire.write(registerAddress);
  Wire.write(data);
  Wire.endTransmission(); // Send stop
}
uint8_t* i2cRead(uint8_t registerAddress, uint8_t nbytes) {
  uint8_t data[nbytes]; 
  Wire.beginTransmission(IMUAddress);
  Wire.write(registerAddress);
  Wire.endTransmission(false); // Don't release the bus
  Wire.requestFrom(IMUAddress, nbytes); // Send a repeated start and then release the bus after reading
  for(uint8_t i = 0; i < nbytes; i++)
    data[i] = Wire.read();
  return data;
 

}
28  Using Arduino / Motors, Mechanics, and Power / Re: To many changes in the servo makes processor stop [HELP] on: October 13, 2012, 10:49:55 am
Hello DuaneB!
Yupp, I had another thread in the sensor forum. And Im still continuing with your advice, using an external power supply for the servo smiley
29  Using Arduino / Motors, Mechanics, and Power / To many changes in the servo makes processor stop [HELP] on: October 13, 2012, 10:22:32 am
Hello arduino community smiley

Does any one out there know why the arduino processor stops (freezes) when I give it to many values. Let me demonstrate with an example.

Lets say I have a button, it gives either +90 degrees or -90 degrees. So if I press once, it ill rotate +90 degrees, if I press it once again it will go -90 degrees.

If I let the servo go fully 90 degrees, and then push the button again, it will rotate back 90 degrees. As it should do.
BUT if I press it a couple of times before it has reached it locations, the arduino freezes and you will have to wait for like 10 seconds until the arduino responds again.

Ive tried both delays and millis.

Conclusions?

Cheers!

Edit:
I just gave it another shot and also notified that it also freezes even if you let it rotate 90 degrees and immediatly pushes the button again.
30  Community / Exhibition / Gallery / Re: Self balancing waiter tray. (or almost it) on: October 13, 2012, 08:59:30 am
What is the name of the sensor ur using?

Nice Project though.
cheers
Pages: 1 [2] 3 4 ... 7