Delay in sensor reading update


hi people,

i have control unit on car sends number of sensor readings arduino mega's serial port 1. have xbee pro 60mw wire antenna - series 1 , on mega sends data arduino uno xbee pro 60mw wire antenna - series 1 on it's top connected via usb laptop. moreover, control unit has software allows me connect laptop via usb , monitor variety of sensor readings on well.
the control unit provides me vehicle's throttle position percentage. when monitor throttle position on control unit's software, gently press pedal, percentage value increases. but, there delay associated refreshing of throttle position when receiving data wireless.
i not sure whether because of limitations of xbees or because of code. thinking because of code, can not see how  or why?
here code:
code: [select]
/*
in "working_wireless_on_the_car_with_processing_v2" , intended increase performance speed of
microcontroller improving coding structure
*/
#include <stdlib> // standard library

/*
the data bytes defined below constants
*/

const int throt_pos1 = 6;
const int throt_pos2 = 7;
const int eng_tmp1 = 12;
const int eng_tmp2 = 13;
const int air_tmp1 = 18;
const int air_tmp2 = 19;
const int bat_vol1 = 10;
const int bat_vol2 = 11;
const int oil_prs1 = 34;
const int oil_prs2 = 35;

/*
end of data byte definition
*/

const unsigned int max_input = 104; // maximum number of bytes received on serial connection ecu

void setup ()
{
  serial.begin (19200);
  // serial1.begin(19200);  // if using mega
} // end of setup

/*
the block of code calculates crc-32 starts here
*/

static progmem prog_uint32_t crc_table[16] = {
  0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
  0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
  0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
  0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};

unsigned long crc_update(unsigned long crc, byte data)
{
  byte tbl_idx;
  tbl_idx = crc ^ (data >> (0 * 4));
  crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4);
  tbl_idx = crc ^ (data >> (1 * 4));
  crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4);
  return crc;
}

unsigned long crc_string( unsigned char *s, unsigned int length)
{
  unsigned long crc = ~0l;
  unsigned int i;
  //while (*s)
  for(i = 0; i<length;i++){
    crc = crc_update(crc, *s++);
  }
  crc = ~crc;
  return crc;
}

/*
the end of crc-32 block
*/


// here process incoming serial data after terminator received

void process_data (unsigned char *data)
{
  static unsigned long whole_four = 0; // variable holds last 4 bytes of received bytes crc bytes


  if (*data == 0x82 && *(data+1) == 0x81 && *(data+2) == 0x80)  //checking starting 3 header bytes
  {

    whole_four = ((unsigned long)(*(data+(max_input-4)))<< 24)  | ((unsigned long)(*(data+(max_input-3)))<< 16) | ((unsigned long)(*(data+(max_input-2)))<< 8) | ((unsigned long)(*(data+(max_input-1)))); // forming hexadecimal value 4 crc bytes
    if (crc_string(data,(max_input-4))==whole_four) // checking if calculated crc bytes match received crc bytes
    {
      //calculating , formatting air temperature dispalying
      float l = (((*(data+air_tmp1)) << 8)+ (*(data+air_tmp2)))/10;
      serial.print("air temp ");
      serial.print(l);
      serial.print("c[ ");

      //calculating , formatting throttle position dispalying
      float = (((*(data+throt_pos1)) << 8)+ (*(data+throt_pos2)))/10;
      serial.print("throttle position ");
      serial.print(a);
      serial.print("%? ");


      //calculating , formatting engine temperature dispalying
      float o = (((*(data+eng_tmp1)) << 8)+ (*(data+eng_tmp2)))/10;
      serial.print("engine temp ");
      serial.print(o);
      serial.print("c, ");

      //calculating , formatting battery voltage dispalying
      float y = (((*(data+bat_vol1)) << 8)+ (*(data+bat_vol2)))/100;
      serial.print("battery voltage ");
      serial.print(y);
      serial.print("v; ");

      //calculating , formatting oil pressure dispalying
      float k = (((*(data+oil_prs1)) << 8)+(*(data+oil_prs2)))/10;
      serial.print("oil pressure ");
      serial.print(k);
      serial.print("kpa: ");
    }


  }

}  // end of process_data

/*
this function processes data come serial buffer
*/

void processincomingbyte (unsigned char inbyte)
{
  static unsigned char input_line [max_input]; //self-defined buffer data
  static unsigned int input_pos = 0; //to determine index of data in self-defined buffer



  switch (input_pos)
  {

  case max_input:   // when arrive end of self-defined buffer, process , format data

    process_data (input_line);

    // reset buffer next time
    input_pos = 0; 
    break;

    //case '\r':   // discard carriage return
    // break;

  default:
    // keep adding if not full
    if (input_pos < (max_input))
      input_line [input_pos++] = inbyte;

    break;

  }  // end of switch

} // end of processincomingbyte 


void loop()
{
  // if serial data available, process it
  if (serial.available () > 0)
    processincomingbyte (serial.read ());

  // other stuff here testing digital input (button presses) ...

}  // end of loop



do have ideas or hints?

quote
do have ideas or hints?

yes.
code: [select]
  serial.begin (19200);
pick pace. 115200 6 times fast.

what baud rate xbees using?

code: [select]
  if (*data == 0x82 && *(data+1) == 0x81 && *(data+2) == 0x80)  //checking starting 3 header bytes
ugh!

code: [select]
if(data[0] == 0x82 && data[1] == 0x81 && data[2] == 0x80)
would lot more readable.

do need send useless text? "a,xx.xxx; t,xx.xxx; e,xx.xxx; b,xx.xxx; o,xx.xxx!" convey same information in lot fewer byte. and, receiver know when end of packet had arrived.


Arduino Forum > Using Arduino > Programming Questions > Delay in sensor reading update


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support