Pages: 1 [2] 3 4 ... 6   Go Down
Author Topic: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01  (Read 4343 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so far here is the transmit seems to be working

Code:

    typedef struct
    {
    float roll; // place roll value here
    float pitch;// place pitch value here
    float yaw;  // place yaw value here
   }RPYT_type; // lable the struct

  RPYT_type imuVal = {inRoll,inPitch,inYaw}; // give float roll in RPYT_type value from incoming function argumet inRoll
  Serial.println("");
    Serial.print(imuVal.roll);
  Serial.print(" , ");
    Serial.print(imuVal.pitch);
  Serial.print(" , ");
    Serial.print(imuVal.yaw);
  Serial.println("");
  byte vals[3];
  vals[0] = imuVal.roll;
  vals[1] = imuVal.pitch; 
  vals[2] = imuVal.yaw;
  Mirf.setTADDR((byte *)"base1"); // set name of Reciever
  Mirf.send(vals); // figure out how to access and transmit second array segment containing inRoll,inPitch,inYaw

but on my rec side i have
Code:
void RPYT(byte data[3]){
  //*********** Start convertion from byte to float *********
  typedef struct{
    float roll;
    float pitch;
    float yaw;
   } RPYT_type;
  RPYT_type imuVal = {data[0],data[1],data[2]};
 
  Serial.print(imuVal.roll);
  Serial.print("'");
  Serial.print(imuVal.pitch);
  Serial.print("'");
  Serial.print(imuVal.yaw);
  Serial.println("");

my TX is sending this
Code:
-0.00 , -0.01 , 0.01
3.23 , -0.33 , 0.10
2.43 , 0.01 , 0.09
1.95 , -0.39 , 0.08
0.64 , 0.37 , 0.07
RX is displaying this
Code:
0.00, 0.00, 0.00
3.00, 0.00, 0.00
2.00, 0.00, 0.00
1.00, 0.00, 0.00
0.00, 0.00, 0.00

i know im tired but i am seriously stumped
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

looks like there getting mucked with before i send them im assuming from making a byte array out of them. so question how do i get the floats out of the struct in a way the NRF will accept them or am i missing something with Mirf and the NRF24 it self that is causing me to have to use bytes and not send floats.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

welp heading to bed  smiley-sleep, maybe it will come to me in the morning. smiley-eek-blue
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well so far so good maybe? it's late agin  5:18am here need some sleeps got 2 hours on yesterday

TX
Code:
float Tflo2byte12(float inRoll, float inPitch, float inYaw){

  union inRoll2byte_t {
    byte  inRollout[4];
    float inRollin;
  }
  inRoll2byte;
  inRoll2byte.inRollin = inRoll;

  union inPitch2byte_t {
    byte  inPitchout[4];
    float inPitchin;
  }
  inPitch2byte;
  inPitch2byte.inPitchin = inPitch;
 
  union inYaw2byte_t {
    byte  inYawout[4];
    float inYawin;
  }
  inYaw2byte;
  inYaw2byte.inYawin = inYaw;
 
  byte output[12];
  output[0] = inRoll2byte.inRollout[0];
  output[1] = inRoll2byte.inRollout[1]; 
  output[2] = inRoll2byte.inRollout[2];
  output[3] = inRoll2byte.inRollout[3];
 
 output[4] = inPitch2byte.inPitchout[0];
  output[5] = inPitch2byte.inPitchout[1]; 
  output[6] = inPitch2byte.inPitchout[2];
  output[7] = inPitch2byte.inPitchout[3];

  output[8] = inYaw2byte.inYawout[0];
  output[9] = inYaw2byte.inYawout[1]; 
  output[10] = inYaw2byte.inYawout[2];
  output[11] = inYaw2byte.inYawout[3];


  Mirf.setTADDR((byte *)"base1"); // set name of Reciever
  Mirf.send(output); // data to send
  while(Mirf.isSending()){
  }
  delay(10);
}

RX above setup
Code:

union inRollrf_t{
  byte  incomRoll[4];
  float imuRoll;
}
inRollrf;

union inPitchrf_t{
  byte  incomPitch[4];
  float imuPitch;
}
inPitchrf;

union inYawrf_t{
  byte  incomYaw[4];
  float imuYaw;
}
inYawrf;
Loop
Code:
void loop(){
  //-+-+-+>>>>Start data collection from transciever<<<<<<-+-+-+
  byte data[Mirf.payload];
  if(Mirf.dataReady()){
    do{
      Mirf.getData(data);
      inB2F(data); // send to byte to float converter
      delay(10);
    }
    while(!Mirf.rxFifoEmpty());
  }
    Serial.print(inRollrf.imuRoll);
    Serial.print(", ");
    Serial.print(inPitchrf.imuPitch);
    Serial.print(", ");
    Serial.print(inYawrf.imuYaw);
    Serial.println("");
} // end of program

external called form loop
Code:
void inB2F(byte data[]){
  //*********** Start convertion from byte to float *********
  inRollrf.incomRoll[0] = data[0];
  inRollrf.incomRoll[1] = data[1];
  inRollrf.incomRoll[2] = data[2];
  inRollrf.incomRoll[3] = data[3];
 
  inPitchrf.incomPitch[0] = data[4];
  inPitchrf.incomPitch[1] = data[5];
  inPitchrf.incomPitch[2] = data[6];
  inPitchrf.incomPitch[3] = data[7];
 
  inYawrf.incomYaw[0] = data[8];
  inYawrf.incomYaw[1] = data[9];
  inYawrf.incomYaw[2] = data[10];
  inYawrf.incomYaw[3] = data[11];


think i am getting closer.  formatted text is nice but only first field is filling? -0.15, 0.00, 0.00
any guidance would be great i am so far out in uncharted territory for me is unreal. and why am i only getting xx.xx and not xx.xxx ? yes that amount of precision would be handy.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mirf.payload = 4 * sizeof(byte); needed to be 12  Mirf.payload = 12 * sizeof(byte); on both and BOOM!. aint she perdy!
pointing the bot a lil NE and more or less flat
Code:
0.47, -0.30, -3.59
0.47, -0.30, -3.59
0.47, -0.30, -3.59
0.47, -0.30, -3.59
south and flat
Code:
0.69, 0.22, -119.77
0.69, 0.22, -119.77
0.69, 0.22, -119.77
0.69, 0.22, -119.77
tilted back 90 degrees and facing south.
Code:
87.48, 0.42, -104.21
87.48, 0.42, -104.21
87.48, 0.42, -104.21
87.48, 0.42, -104.21
87.48, 0.42, -104.21
on it side facing south
Code:
-15.87, -89.33, -122.80
-15.87, -89.33, -122.80
-15.87, -89.33, -122.80
-15.87, -89.33, -122.80
-15.87, -89.33, -122.80
-15.87, -89.33, -122.80
-15.87, -89.33, -122.80

looks like i got it! yes i am very excited.  smiley-lol smiley-cool smiley-lol
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

now why cant i get more than xx.xx is it because of the float > byte > float conversion?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
now why cant i get more than xx.xx is it because of the float > byte > float conversion?
Not at all. It is because the Serial.print() function defaults to printing only 2 digits after the decimal place.

Try
Serial.print(inRollrf.imuRoll, 47);
and see what happens.

Also think about whether you are actually able to measure pitch, roll, and yaw to more than 2 decimal places.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

more to the point i asked my self if i WANT that much precision and i found i told my self to kiss off. smiley-twist that said xx.xx is juuuust fine. now i just need to transmit this heap of wholesome goodness
Code:
$GPRMC,140053.00,A,4454.1740,N,09325.0143,W,000.0,128.7,300508,001.1,E,A*2E
$GPGGA,140053.00,4454.1740,N,09325.0143,W,1,09,01.1,00289.8,M,-030.7,M,,*5E
$GPGSA,A,3,21,15,18,24,26,29,06,22,,03,,,02.0,01.1,01.7*04
$GPGSV,3,1,12,21,75,306,40,15,59,075,46,18,57,269,49,24,56,115,46*79
$GPGSV,3,2,12,26,48,059,43,29,27,188,48,06,25,308,41,22,18,257,33*7D
$GPGSV,3,3,12,08,14,060,,03,11,320,32,09,06,144,,16,04,311,*7C
$GPRMC,140054.00,A,4454.1740,N,09325.0143,W,000.0,128.7,300508,001.1,E,A*29
$GPGGA,140054.00,4454.1740,N,09325.0143,W,1,09,01.1,00289.8,M,-030.7,M,,*59
$GPGSA,A,3,21,15,18,24,26,29,06,22,,03,,,02.0,01.1,01.7*04
$GPGSV,3,1,12,21,75,306,40,15,59,075,46,18,57,269,49,24,56,115,46*79
$GPGSV,3,2,12,26,48,059,43,29,27,188,48,06,25,308,41,22,18,257,33*7D
$GPGSV,3,3,12,08,14,060,,03,11,320,32,09,06,144,,16,04,311,*7C

Hmmm let's see if me missed anything.. floats/doubles check, chars and ints yup got plenty of those and most of shift + 1-9 yup got me some of those in spades. yeah there so has to be a better way of cramming that into the NRF FIFO and sucking it back out on the other end. please tell me there is PaulS please? smiley-eek
« Last Edit: January 27, 2013, 10:40:34 am by Cyric » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
floats/doubles check, chars and ints yup got plenty of those
floats/doubles? Not a single one in sight. Chars? Plenty of those. Fortunately, they are the same size as bytes. Ints? Not a one of those in sight.

What is the problem with using Mirf.send()?
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

4454.1740, 09325.0143, -030.7 not a float because of the decimal point? i was under the impression arduino stored numbers as integers?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
4454.1740, 09325.0143, -030.7 not a float because of the decimal point? i was under the impression arduino stored numbers as integers?
4454.1740 could be a float. The stuff you posted, though, looks like data received from a GPS. Unless you have a really off-the-wall GPS, the data that it sends to the Arduino is character data. There is no indication that you have parsed that data to make floats and doubles from it, nor is there any indication that the device that receives the data from the GPS should parse it.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes it's a GPS Locosys LS20031 it's a serial ( yes i just realised what i just said) so because it comes in serial it's not a float? if so what makes a float a float?
is it not till it's in a calculation like 2.32 * 2 = float * int and 2.32 by it's self is just a num period num num char string?
gunna laugh alot in a min if i find out that is true. if so why did i need to store my roll pitch yaw as floats and not chars?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
because it comes in serial it's not a float?
No, it's because the data is sent as characters, not floats.

Quote
if so what makes a float a float?
Declaring a variable as the correct type.

Quote
is it not till it's in a calculation like 2.32 * 2 = float * int and 2.32 by it's self is just a num period num num char string?
No. There are functions like atoi() and atof() to turn arrays of characters into ints and floats.

Quote
if so why did i need to store my roll pitch yaw as floats and not chars?
Because you have that data AS floats, not characters. You could convert the float to an array of characters, using dtostrf(), and send that array of characters. On the other end, you'd need to use atof() to convert the characters back to a float.

Sending more than one float that way becomes a challenge, because where one value as string ends and other value as string starts is an issue. Also, it takes time to convert from float to string and from string to float. And, finally, a float as 4 bytes is smaller than a float as a character string, so it takes less time to send (and is more accurate, since no translations have occurred).
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 131
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i get it. so the incoming NMEA GPS data is char and given the amount of it i dont think i would want to make an array for it or i would eat up loads of memory correct?

 i would love to clock the data in at like 3 or 4 sec intervals local on the bot and toss it out ( GPS not being that precise, mine seems to be off here and there by about 1.2metersish) .

Is there any efficent wat of packing up the full NEMA set and sending or should i just "streem" it one by one across the radios like it comes in from serial.

i think i would need to convert from char to byte befor Mirf will eat it and crap it out the other end yes/no?.

geting a sentence is easy
Code:
gps.sentence()
and a initialize NMEA gps (type) ALL or GPRMC or any of the standard NEMA.

i remember you said before something about a lying to mirf about the real type the data was?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i think i would need to convert from char to byte befor Mirf will eat it and crap it out the other end yes/no?.
No. char and byte are the same size. You just tell Mirf that the char array is really a byte array.
Code:
Mirf.send((byte *)gps_data, strlen(gps_data));
Assuming, of course, that gps_data is a char array and contains the data from the GPS.

Logged

Pages: 1 [2] 3 4 ... 6   Go Up
Jump to: