Close

Getting Detection Data from Jetson TX2 to TC275

A project log for Autonomous Agri-robot Control System

Controlling autonomous robots the size of a small tractor for planting, weeding and harvesting

capt-flatus-oflahertyCapt. Flatus O'Flaherty ☠ 10/25/2018 at 15:230 Comments

Some work arounds are better than others and ideally I'd just send the bounding box data from the Jetson TX2 directly to the TC275, which controls the WEEDINATOR motors. However, there's a few critical restraints in that both the Jetson and the TC275 will only work in 'Master' mode and will not communicate with each other through the I2C bus in any shape or form! 

The first workaround I researched was using an Arduino as an intermediator on the I2C bus, which would work as a slave for both the Jetson and the TC275 …… and this might just have worked if I'd included an auxiliary RTC clock and a digital 'tie line'.  I spent a few days researching this and eventually realised that as work arounds go, this was a very poor one …. lots of work with coding and wiring and still there was the, if somewhat unlikely,  possibility that the whole thing would fail and lock up the I2C bus by having the 2 masters try to access the I2C bus at the same time.

After a bit more head scratching, the solution became clearer - use I2C to receive data into the intermediator and then hardware serial to send it out again !!! This proved to be by far the simplest solution and I managed to simulate the whole thing on my living room dining table:


The code, as always, is on GitHub HERE.

Intermediator: (NB. There's no 'Serial.print' here as this would slow things down excessively.)

#include <Wire.h>
void setup() 
{
  Wire.begin(0x70);                // join i2c bus with address
  Wire.onReceive(receiveEvent);    // register event
  Serial.begin(115200);            // start serial for output
}
void loop() 
{
  delay(100); // Must have delay here.
}
void receiveEvent(int howMany) 
{
  int x = Wire.read();    // receive byte as an integer
  Serial.write(x);        // send a byte
}

 TC275 (simulated):

int incomingByte = 0;   // for incoming serial data
long y[4][4];
int a;
int b;
int c;
int d;
long x =0;
int i;
int j;
int numberOfBoxes;
int xMax;

void setup() 
{
        Serial.begin(115200);     // opens serial port, sets data rate to 9600 bps
        Serial.println("TEST ");
}

void loop()
{
  if (Serial.available() > 0) 
  {
    x = Serial.read();  // read the incoming byte:
/////////////////////////////////////////////////////////////////////////////////
    if(x>199)
    {
      numberOfBoxes = x-200;
    }
    if((x>139)&&(x<200))
    { 
      j=x-140;Serial.print("Number of boxes: ");Serial.print(numberOfBoxes);Serial.print(", Box number: ");Serial.println(j); 
    }
    if(x==120){ i =-1; }
    if(i==0){ y[0][0] = x*1000; }
    if(i==1){ y[0][1] = x*100; }
    if(i==2){ y[0][2] = x*10; }
    if(i==3){ y[0][3] = x;}
    a= y[0][0]+y[0][1]+y[0][2]+y[0][3];

    if(x==121){ i = 4;  Serial.print("  corner a:  ");Serial.println(a);}
    if(i==5){ y[1][0] = x*1000; }
    if(i==6){ y[1][1] = x*100; }
    if(i==7){ y[1][2] = x*10; }
    if(i==8){ y[1][3] = x; }
    b = y[1][0]+y[1][1]+y[1][2]+y[1][3];


    if(x==122){ i = 9;  Serial.print("  corner b:  ");Serial.println(b);}
    if(i==10){ y[2][0] = x*1000; }
    if(i==11){ y[2][1] = x*100; }
    if(i==12){ y[2][2] = x*10; }
    if(i==13){ y[2][3] = x;   }
    c= y[2][0]+y[2][1]+y[2][2]+y[2][3];


    if(x==123){ i = 14;  Serial.print("  corner c:  ");Serial.println(c);}
    if(i==15){ y[3][0] = x*1000; }
    if(i==16){ y[3][1] = x*100; }
    if(i==17){ y[3][2] = x*10; }
    if(i==18){ y[3][3] = x;  }
    d= y[3][0]+y[3][1]+y[3][2]+y[3][3];
    if(i==18){  Serial.print("  corner d:  ");Serial.println(d);Serial.println("");}

    i++;
  }
}

Discussions