Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: trying to get to work lisy gyro... float issues etc... on: February 12, 2011, 01:04:59 pm
I just went over my code and I think it runs pretty well already...
I realized I did it far too complicated, and also, I had a delay in
the main loop which of course destroyed my results. As I said it
runs pretty good already, I'm just not so sure about some values...

here you go:
Code:
  if (millis() >= pastTime + 50){ // every 50 milliseconds
    gyroData = analogRead(gyroPin);
    pastTime = millis();

    if(gyroData < gyroDefault){
      rotationSpeed = (gyroDefault - gyroData);
    }

    else{
      rotationSpeed = -(gyroData - gyroDefault);
    }

    if(rotationSpeed > 3 || rotationSpeed < -3){ //threshold
      rotationSpeedAvg = rotationSpeedAvg + rotationSpeed;
    }

ok, about this part I'm not so sure. I divide the added values by 20, because I sampled
every 50 milliseconds (or 20 samples/second). the main issue I have is the scale factor.
I assume the following: there are 1024 possible values, the sensor outputs a maximum
of 300 degrees/sec in positive and negative direction. that leads to a total possible degrees
of 601 degrees. dividing 1024 by 601 gives me the degree/sec/analog value. correct?

Code:
    gyroHeading = (rotationSpeedAvg/20)*(1024/601); //2*300 degrees + 0 degrees

    Serial.print("heading: ");
    Serial.println(gyroHeading);
  }
2  Using Arduino / Programming Questions / Re: trying to get to work lisy gyro... float issues etc... on: February 12, 2011, 06:58:37 am
I'm taking samples every 1 seconds right now, and then integrate.
because it's the average of all the samples taken during second
*1 second you don't see the integration. at least that's how I
understand how this should work. maybe I'm wrong?

I'm glad for any advice in this...

(I'll also use a magnetometer for heading calculation, I hope
that'll help to get more precise heading information)
3  Using Arduino / Programming Questions / Re: trying to get to work lisy gyro... float issues etc... on: February 11, 2011, 04:08:23 pm
thanks for your reply, I didn't think of that, but maybe that's really the issue...
I guess I'll try to avoid floats in the future smiley.

can anyone comment on how I'm handling the gyro integration? I really don't have
any experience with gyros. I don't really know if I did understand everything right,
and I'm not sure if the lack of precision is part of my code or just the way gyros work...

thanks
yves
4  Using Arduino / Programming Questions / trying to get to work lisy gyro... float issues etc... on: February 11, 2011, 02:50:31 pm
hi there

I'm trying to use a lisy gyro to integrate the heading of my robot. please look at my code.
would you say this is the way to go? and then I have an issue with float values. I'll explain
that in code...

Code:
int gyroPin = 0;
float gyroData;

float gyroDefault;
float rotationSpeed; // degrees/sec
float rotationSpeedAvg;
boolean sampleGyro;

unsigned long currentTime;
unsigned long pastTime;

float sampleCount;
float gyroHeading;

void readGyro(){

  if(sampleGyro == false){

    Serial.println("warming up...");
    delay(5000);

    for(int i = 0; i < 10; i++){
      gyroData = analogRead(gyroPin);
      gyroDefault = gyroDefault + gyroData;
      delay(50);
    }

    gyroDefault = gyroDefault/10.0;
    Serial.print("GyroDefault: ");
    Serial.println(gyroData);
    sampleGyro = true;

  }

  gyroData = analogRead(gyroPin);

  if(gyroData < gyroDefault){
    rotationSpeed = (gyroDefault - gyroData)*(1023.0/600.0); // maximum of the gyro is 300°/sec in both directions
  }

  else{
    rotationSpeed = -(gyroData - gyroDefault)*(1023.0/600.0);
  }

///
OK, until here the code runs fine. I can print out the rotationSpeed and it gives me the degrees/sec. problems start in the next part...
///
  currentTime = millis();

  if(currentTime < pastTime + 100){
    rotationSpeedAvg = rotationSpeedAvg + rotationSpeed; ///HERE: all types are float, but adding the values just results in 0.00. why is that?
    sampleCount++;
  }
  else{

    rotationSpeedAvg = rotationSpeedAvg/sampleCount;
    gyroHeading = gyroHeading + rotationSpeedAvg/10.0; // before I sampled every second, so I didn't need float. I wanted to increase response/accuracy by sampling every 10th of a second...


    pastTime = millis();
    sampleCount = 0;
    rotationSpeedAvg = 0;

  }

  //Serial.print("heading: ");
  //Serial.println(gyroHeading);
}

thanks for your help. this is the first time I work with gyros.
just using ints gives me more or less exact results, but depending
alot on how fast I turn the gyro. help is appreciated as always...

greetings
yves
5  Using Arduino / Programming Questions / Re: weird calculation issue on: January 28, 2011, 03:49:31 pm
thanks alot you two! I'll try that out asap.
I have another tiny question. as you can see
I print out some debug information to an lcd
display. how would I print out these float values
to the display? is there an easy way to convert
a float value to a char array?

thanks!
6  Using Arduino / Programming Questions / weird calculation issue on: January 28, 2011, 02:46:19 pm
hi everyone

I'm in the process of building a simple robot that can navigate by dead reckoning.
I've come to a really weird issue and I'm not really sure exactly what's the problem,
though I think it has something to do with data types, in this case specifically floats.
I'm using stepper motors to control wheel movement and try to calculate how much
steps are necessary to travel a certain distance for example. Maybe you can look at the
code... the thing is if I calculate the steps by hand it turns out perfectly, though if
I let it be calculated by my arduino there seems to be some kind of error happening:

Code:

int DIR1 = 2;
int STEP1 = 3;
int DIR2 = 4;
int STEP2 = 5;

float pi = 3.14159265;
float wheelCircumference = 0.949;
float wholeTurn = 0.422*pi; //distance of the two wheels
float gearRatio = 11/3;


void doTurn(double radius){ //turn around certain radius

  lcdWrite("do turn", "radius");

  float stepAmount;
  stepAmount = (radius/360)*(wholeTurn/wheelCircumference)*1600*gearRatio;

 //360° turn would equal: 8196 steps
 //judging by the behavior of my robot, something else gets calculated, if I enter
 // 8196 directly everything works fine...

  if (stepAmount < 0){
    digitalWrite(DIR1, HIGH);
    digitalWrite(DIR2, HIGH);
  }

  else{
    digitalWrite(DIR1, LOW);
    digitalWrite(DIR2, LOW);
  }

  int i = 0;

  while (i < stepAmount){

    i++;
    digitalWrite(STEP1, LOW);
    digitalWrite(STEP2, LOW);
    delayMicroseconds(1200);
    digitalWrite(STEP1, HIGH);
    digitalWrite(STEP2, HIGH);

  }
}


can anybody help me with that?
thanks in advance!
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: help: really weird problem with char and arrays... on: August 21, 2009, 06:24:52 am
ok, we are getting there I think...!
as far as I can tell, I didn't allocate any memory to them.

I tried to do it like this:
Code:
char* listOfDevices[7][18];

This is accepted, but if I try to compare like this:
Code:
if (listOfDevices[device_count][0] == device_adress[0]){

It's not accepted because of this error:
In function 'void parseSerial()':
error: ISO C++ forbids comparison between pointer and integer In function 'void emptyDeviceList()':


So how would I do that?
yves
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: help: really weird problem with char and arrays... on: August 21, 2009, 06:17:18 am
hi there

I followed your advice and commented most of the debug serial communication out.
no luck though so far. I have four unsigned longs in use (for timer uses), could they
cause trouble?

I'm using an arduino mini by the way...

thanks so much for your help!
yves
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: help: really weird problem with char and arrays... on: August 21, 2009, 05:12:22 am
do you mean that bit?

Code:
char device_adress[18];
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: help: really weird problem with char and arrays... on: August 21, 2009, 04:36:40 am
it's a MAC adress that looks for example like this:
01:23:45:67:89:ab

thanks for looking at my code, I'm really getting desperate here...
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: help: really weird problem with char and arrays... on: August 21, 2009, 04:23:26 am
hi!

no, I actually like for loops  smiley. It was just a very quick thing to nail down
where the problem was...

hm the code is too long to post here, I think but I'll add the assignments here:

the assignment for message:
Code:
char message[128];

the code where the addresses are assigned:
Code:
          if (known_device == false){ // adding device to the list
                    
                    device_count = 0; // finding a free spot for the new device adress
                    while(listOfDevices[device_count][0] != '?')// no entry
                    {
                    device_count ++;
                    }

                    listOfDevices[device_count] = device_adress;
                    
                    Serial.println("device added to the list");
                    bluetoothBlink();
                    friendlyDeviceAround = true;
                    led_bluetoothOn = 1;
                    
                }// end if
12  Forum 2005-2010 (read only) / Syntax & Programs / help: really weird problem with char and arrays... on: August 21, 2009, 04:01:34 am
hi everyone

I have this really weird problem right now and I would be very glad
if anyone could look at my code...

The code parses a bluetooth adress that is recieved over the serial connection.
As you can see, I have an array listOfDevices, that stores 5 device adresses.
Now my problem is that after I parse the bluetooth code there is a change
in this array that shouldn't be: the first item of the array changes to the
newest parsed adress, even though I didn't change the item.

The change really happens between the first and the second time I print out the adress.
Do you have any idea why this could happen?

I'm thankful for any help with this...

Yves

            char device_adress[18];
            char* listOfDevices[7]; // all the listOfDevices that may connect to the power thingy


            if (message[0] == char(82) && message[1] == char(73) && message[2] == char(78) && message[3] == char(71)){
            // RING, device tries to connect
            Serial.println("RING RING RING");
            
                Serial.println("device list start:");                    
                Serial.println(listOfDevices[0]);     ///////////// shows the latest adress correctly
                Serial.println(listOfDevices[1]);
                Serial.println(listOfDevices[2]);
                Serial.println(listOfDevices[3]);
                Serial.println(listOfDevices[4]);
                Serial.println("device list end:");
                
                
                device_adress[0] = message[7]; // parsing the bluetooth adress
                device_adress[1] = message[8];
                device_adress[2] = message[9];
                device_adress[3] = message[10];
                device_adress[4] = message[11];
                device_adress[5] = message[12];
                device_adress[6] = message[13];
                device_adress[7] = message[14];
                device_adress[8] = message[15];
                device_adress[9] = message[16];
                device_adress[10] = message[17];
                device_adress[11] = message[18];
                device_adress[12] = message[19];
                device_adress[13] = message[20];
                device_adress[14] = message[21];
                device_adress[15] = message[22];
                device_adress[16] = message[23];
                
                
                Serial.println("device list start:");                    
                Serial.println(listOfDevices[0]);    suddenly shows device_adress, even though I didn't assign it to this array index?!?
                Serial.println(listOfDevices[2]);
                Serial.println(listOfDevices[3]);
                Serial.println(listOfDevices[4]);
                Serial.println("device list end:");
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: equivalent to unbinary() in processing? on: July 11, 2009, 02:32:40 pm
ok, I now have the equivalent to using the table method.
this code converts a binary string (in this case 16 figures long)
to its decimal equivalent:

Code:
 for (i = 0; i < 16; i++){
    settingsValue = settingsValue + settings[15-i]*int(pow(2,i));
  }

I think such a method should be added to arduino...

best
yves
edit: settings(i) is the array that contains the binary values as integer
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: equivalent to unbinary() in processing? on: July 08, 2009, 06:30:54 am
thank you for the explanation! I'll try to code the same
with the table method, just to get a better understanding
of the matter.

best
yves
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: equivalent to unbinary() in processing? on: July 08, 2009, 06:13:16 am
I just found a good page on how to convert binary to decimal:
http://www.wikihow.com/Convert-from-Binary-to-Decimal

So I'll try to use this method and write my own code.
I think you did the same thing in your example, 16 being
2^4, but I'll have to code it myself to understand it smiley-wink .

thank you anyway!
Pages: [1] 2 3 4