Show Posts
Pages: 1 2 3 [4] 5 6 ... 9
46  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 02, 2013, 04:28:23 am
I removed the GPS and AP out and just tied to trans a smaller struct. befor it was all 0.00 stuff but now i have some stuff coming across. it's it a packet size issue?
i stopped pre defining a packet size and do it with sizeof in the write/read call
Code:
printf_begin();
  printf("\n\rRadio Setup\n\r");
  radio.begin();
  radio.setDataRate(RF24_2MBPS);
  radio.setCRCLength(RF24_CRC_16);
 // radio.setPayloadSize(32);
  radio.setChannel(2);
  radio.setAutoAck(true);
  radio.openReadingPipe(1,0xF0F0F0F0E1LL);
  radio.openWritingPipe(0xF0F0F0F0D2LL);
  radio.startListening();
  radio.printDetails();
Code:
radio.write((byte *)&StructBuff, sizeof(StructBuff)); TX side
radio.read((byte *)&StructBuff, sizeof(StructBuff)); RX side
Code:
typedef struct {
  float imuRoll;
  float imuPitch;
  float imuYaw;
}strbuff_t;
strbuff_t StructBuff;
now my output is like this
TX
Code:
Ok..
-0.00,-0.00,0.01,
Ok..
-0.25,-0.00,0.00,
Ok..
-0.10,-0.03,0.00,
Ok..
-0.24,0.13,0.00,
Ok..
-0.18,0.18,-0.00,
Ok..
-0.17,0.30,-0.00,
Ok..
-0.14,0.33,-1.96,
Ok..
-0.06,0.23,-3.70,
Ok..
-0.11,0.23,-5.43,


RX Side
Code:
0.00,0.00,0.00,
0.00,0.00,0.00,
0.00,0.00,0.00,
-1.50,-1.50,-1.50,
0.00,0.00,0.00,
0.19,0.19,0.19,
0.00,0.00,0.00,
0.00,0.00,0.00,
-0.00,-0.00,-0.00,
47  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 02, 2013, 12:39:26 am
am i not pointing to StructBuff correctly from radio.read?
Code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
RF24 radio(8,9);
//---------------------

struct StructBuff_t {
  char GPS[100]; 
  float imuRoll;
  float imuPitch;
  float imuYaw;
  unsigned int AP;
  //  char SenBuffersAll[28];
}
StructBuff;
//---------------------
void setup(void){
  Serial.begin(57600);
  printf_begin();
  printf("\n\rRadio Setup\n\r");
  radio.begin();
  radio.setDataRate(RF24_2MBPS);
  radio.setCRCLength(RF24_CRC_16);
  radio.setPayloadSize(32);
  radio.setChannel(2);
  radio.setAutoAck(true);
  radio.openReadingPipe(1,0xF0F0F0F0D2LL);
  radio.openWritingPipe(0xF0F0F0F0E1LL);
  radio.startListening();
  radio.printDetails();
}
void loop(void){
  if ( radio.available() )
  {
    radio.startListening();
    bool ok = radio.read(&StructBuff,sizeof(StructBuff));
    if (ok)
      displayStructBuff(); 
    else 
      printf("failed.\n\r");
    delay(10);
  }
}



void displayStructBuff(){
  //  Serial.print("!"); 
  //  Serial.print("ANG:"); 
  Serial.print(StructBuff.imuRoll);
  Serial.print(",");
  Serial.print(StructBuff.imuPitch);
  Serial.print(",");
  Serial.print(StructBuff.imuYaw);
  Serial.print(",");
  Serial.print(StructBuff.AP);
  Serial.println();
  Serial.println(StructBuff.GPS);
}
output is
Code:
0.00,0.00,0.00,0
48  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 01, 2013, 01:08:24 pm
TX = b,-13.42,6.98,0.42,55
RX = bbbbbbbbbbbb,0.00,0.00,0.00,0
rx char buffer is 10 so just getting stuffed with b's but why no floats or ints get through?

TX= f,-13.42,6.98,0.42,55
RX =f,0.00,0.00,0.00,0
had to change them to 1* sizeof(byte) in Payload(); dont know why realy. but the floats and ints still are not coming throuhg?
and what exactly does the (byte *) part do. i know the &StructBuff is & refrence to the pointer for the struct yes?
49  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 01, 2013, 01:01:02 pm
TX = b,-13.42,6.98,0.42,55
RX = bbbbbbbbbbbb,0.00,0.00,0.00,0
rx char buffer is 10 so just getting stuffed with b's but why no floats or ints get through?
50  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 01, 2013, 12:48:53 pm
OHHH so accessing StructBuff with no .*** will access the full stuct? and therefore transmit it? did not realize you can just call the structure it self like that. so somthing like this.
TX
Code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
#include <PString.h>
RF24 radio(48,49);
void setup(){
  Serial.begin(57600);
  //**************Start Transiever (NRF24L01) config**************
  printf_begin();
  printf("\n\rRadio Setup\n\r");
  radio.begin();
  radio.setDataRate(RF24_2MBPS);
  radio.setCRCLength(RF24_CRC_16);
  radio.setPayloadSize(12 * sizeof(byte));
  radio.setChannel(2);
  radio.setAutoAck(true);
  radio.openReadingPipe(1,0xF0F0F0F0E1LL);
  radio.openWritingPipe(0xF0F0F0F0D2LL);
  radio.startListening();
  radio.printDetails();
  //**************End Transiever (NRF24L01) config**************

struct StructBuff_t {
  char GPS[10]; 
  float imuRoll;
  float imuPitch;
  float imuYaw;
  unsigned int AP;
}
StructBuff;

//**************************************************
//************* Start Main Loop section ************
//**************************************************
void loop()
{
  ///////////////////////////////////////////////////////// 
  char myChar = 'A';                                     //
  PString(StructBuff.GPS, sizeof(StructBuff.GPS),myChar);//
  StructBuff.imuRoll  = -13.42;                          //
  StructBuff.imuPitch =   6.98;                          //Temp Values
  StructBuff.imuYaw   =   0.42;                          //
  StructBuff.AP       =  55;                             //
  /////////////////////////////////////////////////////////

   TransStruct();
}
//**************************************************
//************* END Main Loop section***************
//**************************************************
//-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+
void TransStruct(){

  radio.stopListening();
  bool ok = radio.write((byte *)&StructBuff, sizeof(StructBuff));
  if (ok)
    printf("ok...\n\r");
  else 
    printf("failed.\n\r");
  delay(10);

}
//-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+



RX
Code:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
#include <PString.h>
RF24 radio(8,9);
void setup(){
  Serial.begin(57600);
  //**************Start Transiever (NRF24L01) config**************
  printf_begin();
  printf("\n\rRadio Setup\n\r");
  radio.begin();
  radio.setDataRate(RF24_2MBPS);
  radio.setCRCLength(RF24_CRC_16);
  radio.setPayloadSize(12 * sizeof(byte));
  radio.setChannel(2);
  radio.setAutoAck(true);
  radio.openReadingPipe(1,0xF0F0F0F0D2LL);
  radio.openWritingPipe(0xF0F0F0F0E1LL);
  radio.startListening();
  radio.printDetails();
  //**************End Transiever (NRF24L01) config**************

struct StructBuff_t {
  char GPS[10]; 
  float imuRoll;
  float imuPitch;
  float imuYaw;
  unsigned int AP;
}
StructBuff;

//**************************************************
//************* Start Main Loop section ************
//**************************************************
void loop()
{
 
   RecStruct();
  Serial.println(StructBuff.GPS);
  Serial.println(StructBuff.imuRoll);
  Serial.println(StructBuff.imuPitch);
  Serial.println(StructBuff.imuYaw);
  Serial.println(StructBuff.AP);
}
//**************************************************
//************* END Main Loop section***************
//**************************************************
//-+-+-+>>>> Start Struct Transmit section<<<<<<-+-+-+
void RecStruct(){

  radio.startListening();
  bool ok = radio.read((byte *)&StructBuff, sizeof(StructBuff));
  if (ok)
    printf("ok...\n\r");
  else 
    printf("failed.\n\r");
  delay(10);

}
//-+-+-+>>>> END Struct Transmit section<<<<<<-+-+-+


51  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 01, 2013, 11:23:22 am
ok i see what your sing about the struct and the box bit but why is it even odd much less apparently not correct to store the large array with the smaller arrays?
on the send the box note with out converting them im assuming something along the following?
Code:
struct StructBuff_t {
  char GPS[100];  
  float imuRoll[4];
  float imuPitch[4];
  float imuYaw[4];
  unsigned int AP[?];
}
StructBuff;
and then by some programing voodoo send that across radio.write and receive it and know what it is? ( what stumps me is how you send that stuct in one shot) and what baffels me is after it is crammed into radio.write how do i even know what it is or what var goes in what slot.. ( another assumption, another struct made the same on the other side to store them in i get that or i think i do) but radio.read is gunna spew out some stuff ( another assumption, in the order it was received in the "type" it was sent).
so something like..

radio.write( voodooS) ---------->{some packet that has like char gps float imuRoll etc.}-------> radio read(voodooR) ----->(then what radio.read is starting to spew into voodooR i some how parse voodooR and just take like say the first 100 chars (put GPS) next float (put imuRoll) and next float (put etc.). because they come out the same order they were received?.
if above is correct then how do you send the box i through you accessed each element through the stuct not the stuct it self.
now that i have swapped out to RF24 i can send raw data and not in bytes so i get why i do not need to convert them.
so to wrap out i love the make box collect data in native form in box send box idea a lot seems the most efficient way to me. so maby a link to a resorce that shows how to use structs or some other "box" your thinking of that can alow me to radio.write it across and an idea how to "parse" it back into the box there ( or did i just stick a box in a box?)


BTW THANK YOU PaulS. for "dealing with me" through this. i am enjoying learning programing from you. 3 weeks ago i could not even get a for loop going right lol. so thank you seriously.
52  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 01, 2013, 10:40:14 am
Code:
struct StructBuff_t {
  char GPS[100]; 
  char imuRoll[6];
  char imuPitch[6];
  char imuYaw[6];
  char AP[3];
  char SenBuffersAll[128];
}
StructBuff;
This is STILL wrong. Until you fix it, I can't help you.

You either store the GPS data as character data and the other stuff as floats (or strings) in the struct, OR you store all the data in and array.

What you have now is a box of stuff to send. Then, you make a copy of the stuff to send, and put the copy in an envelope. Then, you throw the envelope in the box, and send the box. That hardly makes sense.
Ok my understanding was collect all the data in each of there native types chars/floats use PStrings to convert and stuff them into there char type arrays so they can now be use and referenced as char strings collect the char strings up into one and offload it. your saying i have extra steps in there ?
Code:
struct StructBuff_t { // Global struct
  char GPS[100];   // being filled with PString(StructBuff.GPS, sizeof(StructBuff.GPS), inGPS);
  char imuRoll[6];  // being filled with PString(StructBuff.imuRoll, sizeof(StructBuff.imuRoll), inRoll); // Was a float now a char stings in a char array yes no?
  char imuPitch[6]; // being filled with PString(StructBuff.imuPitch, sizeof(StructBuff.imuPitch), inPitch); "                                                                              "
  char imuYaw[6];  // being filled with   PString(StructBuff.imuYaw, sizeof(StructBuff.imuYaw), inYaw); "                                                                                    "
  char AP[3];  // being filled with   PString(StructBuff.AP, sizeof(StructBuff.AP), inAP);  was an int now a char yes no?     
  char SenBuffersAll[128]; // being filled with strlcat after pulling the newly filled char arrays with sensor data in .GPS .imuRoll etc?
}
StructBuff;
use radio.write StructBuff.SenBuffersAll with completed formatted string?
if not show me where i am going wrong. because that looks like 1234 rinse and repeat to me. (1).get data bits (2).store data bits (3).combine each data bit into data string (4).send datastring
53  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 01, 2013, 10:03:03 am
Part(2) of (2)
Code:
void loop()
{
  MinImu9();
  StuffStructBuff(ToDeg(roll),ToDeg(pitch),ToDeg(yaw),averagePing(),*gps.sentence());  
  BuildTransBuffer();
  //  TransSenBuffers();
}
//**************************************************
//**************************************************
//************* END Main Loop section***************
//**************************************************
//**************************************************
//-+-+-+>>>> Start Buffer Transmit section<<<<<<-+-+-+
/*
void DisplayGPSBuffer(){
 for (int i=0; i < sizeof(StructBuff.GPS);i++){
 Serial.print(StructBuff.GPS[i]);
 }  
 Serial.println("GPS buffer");
 }
 */
void StuffStructBuff(float inRoll, float inPitch, float inYaw, unsigned int inAP, char inGPS){//**Working**
  //////////////////////////////////////////////////////////////////////////////////////////////////
  //**Working**Collect data and fill StructBuff elements                                                     //
  // Struct your Buffers here                                                         //+1 for \0 //
  PString(StructBuff.GPS, sizeof(StructBuff.GPS), inGPS);                 //+100 Buff //  
  //----------------------Delimitor------------------------------------------                     //
  PString(StructBuff.imuRoll, sizeof(StructBuff.imuRoll), inRoll);            //+6   Buff //
  //----------------------Seperator------------------------------------------                     //
  PString(StructBuff.imuPitch, sizeof(StructBuff.imuPitch), inPitch);
  //----------------------Seperator------------------------------------------                     //
  PString(StructBuff.imuYaw, sizeof(StructBuff.imuYaw), inYaw);               //+6   Buff //
  //----------------------Delimitor------------------------------------------                     //
  PString(StructBuff.AP, sizeof(StructBuff.AP), inAP);
  //----------------------Delimitor------------------------------------------         //+12  PrSu //
  //////////////////////////////////////////////////////////////////////////////////////Buffer = 134  
  ///Spew to local serial
  //for (int i = 0; i < sizeof(StructBuff.imuRoll); i++){
  //        Serial.print(StructBuff.imuRoll[i]);
  //      }  
  //      Serial.println();
  //////////////////////////////////////////////////////////////////////////////////////  
}
void BuildTransBuffer(){   //***NOT WORKING?***
  ////////////////////////////////////////////////////////////////////////////////////
  //***NOT WORKING?*** format the string for transmit array.
  //<<<|$GPRMC,XXXXXX.00,A,4454.1740,N,XXXXX.0143,W,000.0,128.7,300508,001.1,E,A*2E|-3.87^34.01^0.13|33|>>>  
  //Start string append
  strlcat(StructBuff.SenBuffersAll,"<<<|",sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,StructBuff.GPS,sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,"|",sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,StructBuff.imuRoll,sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,",",sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,StructBuff.imuPitch,sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,",",sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,StructBuff.imuYaw,sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,"|",sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,StructBuff.AP,sizeof(StructBuff.SenBuffersAll));
  strlcat(StructBuff.SenBuffersAll,"|>>>",sizeof(StructBuff.SenBuffersAll));
  //End string append
  //Formatting done.
  /////////////////////////////////////////////////////////////////////////////////////////////////////////
  ///Spew StructBuff.SenBuffersAll to local serial
  for (int i = 0; i < sizeof(StructBuff.SenBuffersAll); i++){
    Serial.print(StructBuff.SenBuffersAll[i]);
  }  
  Serial.println();
  ///////////////////////////////////
}
void TransSenBuffers(){
  radio.stopListening();
  bool ok = radio.write(StructBuff.SenBuffersAll,sizeof(StructBuff.SenBuffersAll));
  if (ok)
    printf("ok...Tflow2byte12\n\r");
  else  
    printf("failed.Tflow2byte12\n\r");
  delay(10);
}
//-+-+-+>>>> END Buffer Transmit section<<<<<<-+-+-+


//-+-+-+>>>> Start Type conversion section<<<<<<-+-+-+
void Tflo2byteIMU(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];
  radio.stopListening();
  bool ok = radio.write(output,sizeof(output));
  if (ok)
    printf("ok...Tflow2byteIMU\n\r");
  else  
    printf("failed.Tflow2byteIMU\n\r");
  delay(10);
}
//-+-+-+>>>> End Type conversion section<<<<<<-+-+-+
//-+-+-+>>>> START Sensor readings section<<<<<<-+-+-+
void PrnGpsNmea() {
  if (Serial2.available() > 0 ) {
    // read incoming character from GPS and feed it to NMEA type object
    if (gps.decode(Serial2.read())) {
      Serial.println (gps.sentence());
    }
  }
}
unsigned int  ping(){
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  return uS / US_ROUNDTRIP_CM;
}
unsigned int averagePing(){
  total= total - readings[index]; // subtract the last reading:
  readings[index] = ping();   // read from the sensor:  
  total= total + readings[index];   // add the reading to the total:
  index = index + 1;  // advance to the next position in the array:  
  if (index >= numReadings)  // if we're at the end of the array...
    index = 0;   // ...wrap around to the beginning:                          
  average = total / numReadings;   // calculate the average:
  delay(1);        // delay in between reads for stability            
  return average;   // send it as ASCII digits
}
unsigned int PingScan(unsigned int Fwddist){
}  
//-+-+-+>>>>START POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
void MinImu9() //PoloLU MINIMU -9DOF
{
  if((millis()-timer)>=20)  // Main loop runs at 50Hz
  {
    counter++;
    timer_old = timer;
    timer=millis();
    if (timer>timer_old)
      G_Dt = (timer-timer_old)/1000.0;    // Real time of loop run. We use this on the DCM algorithm (gyro integration time)
    else
      G_Dt = 0;
    // *** DCM algorithm
    // Data adquisition
    Read_Gyro();   // This read gyro data
    Read_Accel();     // Read I2C accelerometer
    if (counter > 5)  // Read compass data at 10Hz... (5 loop runs)
    {
      counter=0;
      Read_Compass();    // Read I2C magnetometer
      Compass_Heading(); // Calculate magnetic heading  
    }
    // Calculations...
    Matrix_update();
    Normalize();
    Drift_correction();
    Euler_angles();
    // ***
    //   VTprintdata();
    // printdata();
  }
}
//-+-+-+>>>> END POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
//-+-+-+>>>> END Sensor readings section<<<<<<-+-+-+

54  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 01, 2013, 10:02:00 am
Part (1)of(2)
Code:
#include <NewPing.h>
#include <Arduino.h>
#include <Wire.h>
#include <stdio.h>
#include <nRF24L01.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
#include <nmea.h>
#include <PString.h>
#include <string.h>
//-+-+-+>>>> START Ultrasonic Sensor section<<<<<<-+-+-+
#define TRIGGER_PIN  23  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     22  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
//-+-+-+>>>> END Ultrasonic Sensor section<<<<<<-+-+-+
//-+-+-+>>>> START GPS Vars section<<<<<<-+-+-+
#define WPT_IN_RANGE_M 1
//-+-+-+>>>> END GPS Vars section<<<<<<-+-+-+
//-+-+-+>>>> SRTART POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
// LSM303 accelerometer: 8 g sensitivity
// 3.8 mg/digit; 1 g = 256
#define GRAVITY 256  //this equivalent to 1G in the raw data coming from the accelerometer
#define ToRad(x) ((x)*0.01745329252)  // *pi/180
#define ToDeg(x) ((x)*57.2957795131)  // *180/pi
// L3G4200D gyro: 2000 dps full scale
// 70 mdps/digit; 1 dps = 0.07
#define Gyro_Gain_X 0.07 //X axis Gyro gain
#define Gyro_Gain_Y 0.07 //Y axis Gyro gain
#define Gyro_Gain_Z 0.07 //Z axis Gyro gain
#define Gyro_Scaled_X(x) ((x)*ToRad(Gyro_Gain_X)) //Return the scaled ADC raw data of the gyro in radians for second
#define Gyro_Scaled_Y(x) ((x)*ToRad(Gyro_Gain_Y)) //Return the scaled ADC raw data of the gyro in radians for second
#define Gyro_Scaled_Z(x) ((x)*ToRad(Gyro_Gain_Z)) //Return the scaled ADC raw data of the gyro in radians for second
// LSM303 magnetometer calibration constants; use the Calibrate example from
// the Pololu LSM303 library to find the right values for your board
#define M_X_MIN -602
#define M_Y_MIN -668
#define M_Z_MIN -592
#define M_X_MAX 391
#define M_Y_MAX 422
#define M_Z_MAX 524
#define Kp_ROLLPITCH 0.02
#define Ki_ROLLPITCH 0.00002
#define Kp_YAW 1.2
#define Ki_YAW 0.00002
//OUTPUTMODE=1 will print the corrected data,
//OUTPUTMODE=0 will print uncorrected data of the gyros (with drift)
#define OUTPUTMODE 1
//#define PRINT_DCM 0     //Will print the whole direction cosine matrix
#define PRINT_ANALOGS 0 //Will print the analog raw data
#define PRINT_EULER 1   //Will print the Euler angles Roll, Pitch and Yaw
#define STATUS_LED 13
//-+-+-+>>>> END POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
//-+-+-+>>>> SRTART POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
int SENSOR_SIGN[9] = {
  1,1,1,-1,-1,-1,1,1,1}; //Correct directions x,y,z - gyro, accelerometer, magnetometer
float G_Dt=0.02;    // Integration time (DCM algorithm)  We will run the integration loop at 50Hz if possible
long timer=0;   //general purpuse timer
long timer_old;
long timer24=0; //Second timer used to print values
int AN[6]; //array that stores the gyro and accelerometer data
int AN_OFFSET[6]={
  0,0,0,0,0,0}; //Array that stores the Offset of the sensors
int gyro_x;
int gyro_y;
int gyro_z;
int accel_x;
int accel_y;
int accel_z;
int magnetom_x;
int magnetom_y;
int magnetom_z;
float c_magnetom_x;
float c_magnetom_y;
float c_magnetom_z;
float MAG_Heading;
float Accel_Vector[3]= {
  0,0,0}; //Store the acceleration in a vector
float Gyro_Vector[3]= {
  0,0,0};//Store the gyros turn rate in a vector
float Omega_Vector[3]= {
  0,0,0}; //Corrected Gyro_Vector data
float Omega_P[3]= {
  0,0,0};//Omega Proportional correction
float Omega_I[3]= {
  0,0,0};//Omega Integrator
float Omega[3]= {
  0,0,0};
// Euler angles
float roll;
float pitch;
float yaw;
float errorRollPitch[3]= {
  0,0,0};
float errorYaw[3]= {
  0,0,0};
unsigned int counter=0;
byte gyro_sat=0;
float DCM_Matrix[3][3]= {
  {
    1,0,0                                  }
  ,{
    0,1,0                                  }
  ,{
    0,0,1                                  }
};
float Update_Matrix[3][3]={
  {
    0,1,2                                }
  ,{
    3,4,5                                }
  ,{
    6,7,8                                }
}; //Gyros here
float Temporary_Matrix[3][3]={
  {
    0,0,0                                  }
  ,{
    0,0,0                                  }
  ,{
    0,0,0                                  }
};
//-+-+-+>>>> END POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
//-+-+-+>>>> START Ultrasonic Sensor section<<<<<<-+-+-+
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
const int dangerThresh = 10; //threshold for obstacles (in cm)
int leftDistance, rightDistance, centerDistance; //distances on either side
//-+-+-+>>>> END Ultrasonic Sensor section<<<<<<-+-+-+
//-+-+-+>>>> Start US PING averaging section<<<<<<-+-+-+
//------------------Avrageing-----------------------------------
const int numReadings = 5;
int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average
//------------------Avrageing-----------------------------------
//-+-+-+>>>> END US PING averaging section<<<<<<-+-+-+
//-+-+-+>>>> START GPS INIT section<<<<<<-+-+-+
NMEA gps(ALL);    // GPS data connection to all sentence types
//-+-+-+>>>> END GPS INIT section<<<<<<-+-+-+
//-+-+-+>>>> Start VT100 INIT section<<<<<<-+-+-+
String OFF = "\033[0m";
String BOLD = "\033[1m";
String CLR = "\e[2J";  
String CLRl = "\e[2K";
String BYB = "\e[1;33;40m";
//-+-+-+>>>> END VT100 INIT section<<<<<<-+-+-+

RF24 radio(48,49);
void setup()
{
  Serial.begin(57600);
  Serial2.begin(57600); //GPS INPUT (LocoSYS LS20031)
  //**************Start Transiever (NRF24L01) config**************
  printf_begin();
  printf("\n\rRadio Setup\n\r");
  radio.begin();
  radio.setDataRate(RF24_2MBPS);
  radio.setCRCLength(RF24_CRC_16);
  radio.setPayloadSize(12 * sizeof(byte));
  radio.setChannel(2);
  radio.setAutoAck(true);
  radio.openReadingPipe(1,0xF0F0F0F0E1LL);
  radio.openWritingPipe(0xF0F0F0F0D2LL);
  radio.startListening();
  radio.printDetails();
  //**************End Transiever (NRF24L01) config**************
  //-+-+-+>>>> Start US PING averaging section<<<<<<-+-+-+
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;        
  //-+-+-+>>>> END US PING averaging section<<<<<<-+-+-+
  //-+-+-+>>>> Start VT100 INIT section<<<<<<-+-+-+  
  // Serial.print(BYB);
  //  Serial.println(CLR);  
  //-+-+-+>>>> END VT100 INIT section<<<<<<-+-+-+
  //-+-+-+>>>> START POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
  Serial.println("IMU INIT ... "); // Print some stuff to serial
  I2C_Init();
  delay(1500);
  Accel_Init();
  Compass_Init();
  Gyro_Init();
  delay(20);
  for(int i=0;i<32;i++)    // We take some readings...
  {
    Read_Gyro();
    Read_Accel();
    for(int y=0; y<6; y++)   // Cumulate values
      AN_OFFSET[y] += AN[y];
    delay(20);
  }
  for(int y=0; y<6; y++)
    AN_OFFSET[y] = AN_OFFSET[y]/32;
  AN_OFFSET[5]-=GRAVITY*SENSOR_SIGN[5];
  for(int y=0; y<6; y++)
    delay(2000);  
  timer=millis();
  delay(20);
  counter=0;
  Serial.println("IMU Stream active ... "); // Print some stuff to serial
  //-+-+-+>>>> END POLOLU MINIMU - 9DOF Sensor section<<<<<<-+-+-+
}

struct StructBuff_t {
  char GPS[100];  
  char imuRoll[6];
  char imuPitch[6];
  char imuYaw[6];
  char AP[3];
  char SenBuffersAll[128];
}
StructBuff;
//**************************************************
//**************************************************
//************* Start Main Loop section ************
//**************************************************
//**************************************************
55  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: February 01, 2013, 10:00:53 am
having problems geting my sensors to refresh. now i know in the StuffStructBuff function the data is being pulled and sent to the individual elements of the struct StructBuff because i can parse them out to the term from the function so i know there geting filled with constant fresh data streams.
but the main "formatted" buffer seems to stop at 3 strings ( should be 1 but the GPS data is missing for some reason). so it seems strlcat is working and is making a full formatted string and it is making it into the SenBuffersAll array just fine? or not or seems to stop refreshing it. do i need to "flush it?" or some other trick?

here is the output then i will post the code base so far ( might take a couple posts it's kinda big)
Code:
<<<||0.00,0.01,0.00|0|>>><<<||-0.78,-0.69,-0.00|1|>>><<<||-0.75,-0.24,-0.00|2|>>><<<||-0.18,0.33,-0.01|3|>>><<<||-0.44,0.87,0.0
<<<||0.00,0.01,0.00|0|>>><<<||-0.78,-0.69,-0.00|1|>>><<<||-0.75,-0.24,-0.00|2|>>><<<||-0.18,0.33,-0.01|3|>>><<<||-0.44,0.87,0.0
<<<||0.00,0.01,0.00|0|>>><<<||-0.78,-0.69,-0.00|1|>>><<<||-0.75,-0.24,-0.00|2|>>><<<||-0.18,0.33,-0.01|3|>>><<<||-0.44,0.87,0.0
<<<||0.00,0.01,0.00|0|>>><<<||-0.78,-0.69,-0.00|1|>>><<<||-0.75,-0.24,-0.00|2|>>><<<||-0.18,0.33,-0.01|3|>>><<<||-0.44,0.87,0.0
 
now it is correct is size to the array but since the GPS is not parsing in it's bot full to the 128 chars so it fill with the new strings etc.
"SHOULD" look like this IF the GPS was making it in.
Code:
<<<|$GPRMC,XXXXXX.00,A,4454.1740,N,XXXXX.0143,W,000.0,128.7,300508,001.1,E,A*2E|-3.87,34.01,0.13|33|>>>
ill post the complete code next.
56  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: January 31, 2013, 01:52:18 pm
Ok geting closer i think

Code:
void BuildTransBuffer(){
//////////////////////////////////////////////////////////////////////////////////////////////////
//Collect data and fill StructBuff elements
// Struct your Buffers here                                                         //+1 for \0
   PString(StructBuff.GPS, sizeof(StructBuff.GPS), gps.sentence());                 //+100 Buff   
//----------------------Delimitor------------------------------------------
   PString(StructBuff.imuRoll, sizeof(StructBuff.imuRoll), ToDeg(roll));            //+6   Buff
//----------------------Seperator------------------------------------------
   PString(StructBuff.imuPitch, sizeof(StructBuff.imuPitch), ToDeg(pitch));         //+6   Buff
//----------------------Seperator------------------------------------------
   PString(StructBuff.imuYaw, sizeof(StructBuff.imuYaw), ToDeg(yaw));               //+6   Buff
//----------------------Delimitor------------------------------------------
   PString(StructBuff.AP, sizeof(StructBuff.AP), averagePing());                //+3   Buff = 122
//----------------------Delimitor------------------------------------------         //+12 for Pre Suf Del Sep
//////////////////////////////////////////////////////////////////////////////////// 134 point buffer
// format the string for transmit array.
//<<<|$GPRMC,XXXXXX.00,A,4454.1740,N,XXXXX.0143,W,000.0,128.7,300508,001.1,E,A*2E|-3.87^34.01^0.13|33|>>> 
//Start string append
strlcat(StructBuff.SenBuffersAll,"<<<|",sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,StructBuff.GPS,sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,"|",sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,StructBuff.imuRoll,sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,",",sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,StructBuff.imuPitch,sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,",",sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,StructBuff.imuYaw,sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,"|",sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,StructBuff.AP,sizeof(StructBuff.SenBuffersAll));
strlcat(StructBuff.SenBuffersAll,"|>>>",sizeof(StructBuff.SenBuffersAll));
//End string append
//Formatting done.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
///Spew the String to local serial
//for (int i = 0; i < sizeof(StructBuff.SenBuffersAll); i++){
//        Serial.print(StructBuff.SenBuffersAll[i]);
//      } 
//      Serial.println();
///////////////////////////////////
}




output is this tho

Code:
<<<||0.00,0.00,0.00|3|>>>
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>>
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>>
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>>
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>>
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||0.0
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||0.0
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||0.0
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||0.0
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||0.0
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||0.0
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||0.0
<<<||0.00,0.00,0.00|3|>>><<<||0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||0.0
0.00,0.00,0.00|4|>>><<<||0.00,0.00,0.00|4|>>><<<||0.0

display code
Code:
void DisplayTransBuffer(){
  for (int i = 0; i < sizeof(StructBuff.SenBuffersAll); i++){
        Serial.print(StructBuff.SenBuffersAll[i]);
      } 
      Serial.println();
    }
57  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: January 31, 2013, 12:33:23 pm
my understanding of strings are they are stored as arrays yes?
so liking say sGPS = StructBuff.GPS even tho it's  a char array strings should be able to read it? the compiler seems to think it's ok.
commented best i could so show what my goal is.
Code:
void BuildTransBuffer(){
//////////////////////////////////////////////////////////////////////////////////////////////////
//Collect data and fill StructBuff elements
// Struct your Buffers here                                                         //+1 for \0
   PString(StructBuff.GPS, sizeof(StructBuff.GPS), gps.sentence());                 //+100 Buff   
//----------------------Delimitor------------------------------------------
   PString(StructBuff.imuRoll, sizeof(StructBuff.imuRoll), ToDeg(roll));            //+6   Buff
//----------------------Seperator------------------------------------------
   PString(StructBuff.imuPitch, sizeof(StructBuff.imuPitch), ToDeg(pitch));         //+6   Buff
//----------------------Seperator------------------------------------------
   PString(StructBuff.imuYaw, sizeof(StructBuff.imuYaw), ToDeg(yaw));               //+6   Buff
//----------------------Delimitor------------------------------------------
   PString(StructBuff.UltS, sizeof(StructBuff.UltS), averagePing());                //+3   Buff = 122
//----------------------Delimitor------------------------------------------         //+12 for Pre Suf Del Sep
//////////////////////////////////////////////////////////////////////////////////// 134 point buffer
String Prefix, Suffix, Seperator, Delimit, sGps, sRoll, sPitch, sYaw, sAP, SenBuff;
  Prefix    = String('<');        ////////////////////////
  Suffix    = String('>');        //
  Seperator = String('^');        //Prefix/Sufix/Sep/Delim
  Delimit   = String('|');        //
  sGps      = StructBuff.GPS;     //---------------------
  sRoll     = StructBuff.imuRoll; //char arrays with sensor
  sPitch    = StructBuff.imuPitch;//data collected with PString
  sYaw      = StructBuff.imuYaw;  //
  sAP       = StructBuff.UltS;    //---------------------
  SenBuff   = String("");         //formatted string of sen data.
                                  ///////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// format the string for transmit array.
//<<<|$GPRMC,XXXXXX.00,A,4454.1740,N,XXXXX.0143,W,000.0,128.7,300508,001.1,E,A*2E|-3.87^34.01^0.13|33|>>> 
//Start string append
  SenBuff += Prefix; SenBuff += Prefix; SenBuff += Prefix;   SenBuff += Delimit;
  SenBuff += sGps; SenBuff += Delimit; SenBuff += sRoll; SenBuff += Seperator; SenBuff += sPitch;
  SenBuff += Seperator; SenBuff += sYaw; SenBuff += Delimit; SenBuff += sAP; SenBuff += Delimit;
  SenBuff += Suffix;  SenBuff += Suffix;  SenBuff += Suffix;
//End string append
//Formatting done.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////PString formatted senbuff string into SenBuffersAll array in StuctBuff struct
  PString(StructBuff.SenBuffersAll, sizeof(StructBuff.SenBuffersAll), SenBuff);
///Spew the String to local serial
  Serial.println(SenBuff);
///////////////////////////////////
}

58  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: January 31, 2013, 12:14:48 pm
Mega 2560's are what im using.
im trying to format the output from the struct into the last array in the struct with my prefix and suffix data so when i send it i can parse it and stick them where they belong.

so PStrings seemed to be a easy way to gather my data and input them into the StructBuff.GPS StructBuff.imu*** etc.

i call them and push them into the struct one last time for fresh data and then pull each array and format it for the main StructBuff.SenBuffersAll past holding what should be something like
Code:
<<<|$GPRMC,XXXXXX.00,A,4454.1740,N,XXXXX.0143,W,000.0,128.7,300508,001.1,E,A*2E|-3.87^34.01^0.13|33|>>>
it worked with dummy data in the strings sGps = String("blabalbla"); guess i cant just pass it gps.sencence(). at any rate, you know of a less memory eating method to format the output of  5 arrays of varying size inside a stuct and stuffing them into a main one holding all the parse data for the receiver to know what data bits belong where?.
59  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: January 31, 2013, 11:38:57 am
this ones has me stumped
Code:
struct StructBuff_t {
  char GPS[100]; 
  char imuRoll[6];
  char imuPitch[6];
  char imuYaw[6];
  char UltS[3];
  char SenBuffersAll[133];
}
StructBuff;

Code:
void BuildTransBuffer(){
// Struct your Buffers here
   PString(StructBuff.GPS, sizeof(StructBuff.GPS), gps.sentence());                 //+100 Buff   
//----------------------Delimitor------------------------------------------
   PString(StructBuff.imuRoll, sizeof(StructBuff.imuRoll), ToDeg(roll));         //+6   Buff
//----------------------Seperator------------------------------------------
   PString(StructBuff.imuPitch, sizeof(StructBuff.imuPitch), ToDeg(pitch));         //+6   Buff
//----------------------Seperator------------------------------------------
   PString(StructBuff.imuYaw, sizeof(StructBuff.imuYaw), ToDeg(yaw));               //+6   Buff
//----------------------Delimitor------------------------------------------
   PString(StructBuff.UltS, sizeof(StructBuff.UltS), averagePing());                //+3   Buff = 124
//----------------------Delimitor------------------------------------------
// 132 point buffer
 
  String Prefix, Suffix, Seperator, Delimit, sGps, sRoll, sPitch, sYaw, sAP, SenBuff;
Prefix    = String('<');
  Suffix    = String('>');
  Seperator = String('^');
  Delimit   = String('|');
  sGps      = gps.sentence();
 // sGps      = String(gps.sentence());
  sRoll     = StructBuff.imuRoll;
//  sRoll     = String(StructBuff.imuRoll);
  sPitch    = StructBuff.imuPitch;
//  sPitch    = String(StructBuff.imuPitch);
  sYaw      = StructBuff.imuYaw;
//  sYaw      = String(StructBuff.imuYaw);
//  sAP       = averagePing();    //cant use unsigned int as char string
//  sAP       = String(averagePing());

  SenBuff   = String("");
 
  //Start string append
  SenBuff += Prefix; SenBuff += Prefix; SenBuff += Prefix;   SenBuff += Delimit;
  SenBuff += sGps; SenBuff += Delimit; SenBuff += sRoll; SenBuff += Seperator; SenBuff += sPitch;
  SenBuff += Seperator; SenBuff += sYaw; SenBuff += Delimit; SenBuff += sAP; SenBuff += Delimit;
  SenBuff += Suffix;  SenBuff += Suffix;  SenBuff += Suffix;
  //End string append
PString(StructBuff.SenBuffersAll, sizeof(StructBuff.SenBuffersAll), SenBuff);
Serial.println(SenBuff);
}
SenBuff/StructBuff.SenBuffersAll
Code:
contence of SenBuff
<<<||0.00^0.00^0.00||>>>
<<<||0.00^0.00^0.00||>>>
i can see there filling with my Trigger and Delimit and Separators but i guess it's just not that simple to stuff function output into strings? LOL cant blame a guy for trying. ill keep tinkering while i wait for your advice and witty slice and dice i am sure you will use to render my code impotent. till then.
BTW thanks for all the help with this. i have been learning a lot i think
60  Using Arduino / Programming Questions / Re: Problem with transmitting IMU/GPS/Ultrasonic data over Nrf24L01 on: January 29, 2013, 06:14:47 pm
thanks PaulS, so what method would be best for collecting all the data types from GPS (char)/IMU (float)/Ultra sonic (INT) and sending them in a constantly predictable order so on the RX end i can receive them and know what sensor they are from and type of data they are char float int. i was thinking structures because i could do like
sensors{
char  GPS
float IMU1,2,3
int    Ultrasonic
int/byte/float/char other stuffs etc.
}sensors;
but how could i pack that all up and send it in one buffer?
sensors.All
i supose i could delimit the data with some odd strings like.

<(@#:dataID,GPS|DataType,char|DataBits,$GPRMC,140053.00,A,4454.1740,N,09325.0143,W,000.0,128.7,300508,001.1,E,A*2E|:~&!>

so find < is next ( next@ next #? yes= good start find next : now look at tag DataID wich RX will then have a var for it predefined with type so it can hold it.
look for next | and get next tag id, DataType,type of data. would i not need to do it this way so the RX side knows how to parse each type?

or would it be simpler the make a char array and converts all types to it RF out the array rebuild it and convert back?
Pages: 1 2 3 [4] 5 6 ... 9