Loading...

Extracting data from your T-Bot to use in your python scripts

There are two steps to extracting data from your T-Bot. The first is to make a small change to the T-bot's software. The second is to run serial_GetGyroData.py to get the gyro and accelerometer data or serial_GetUSData.py to get the Ultrasound data.

Getting the gyro and accelerometer data.

Locate the following lines in functions.ino

  /*
  Serial.print(dt); Serial.print("\t");
  Serial.print(pitch); Serial.print("\t");
  Serial.print(gyroYrate); Serial.print("\t");
  Serial.print(CFilteredlAngleY); Serial.print("\t");
  //Serial.print(gyroYangle); Serial.print("\t");
  Serial.print("\n");
  */

Remove /* and */ to enable the serial output. Upload the code to the T-Bot.

Now run the serial_GetGyroData.py python script.

It looks like this:

import numpy as np
from time import sleep
import serial


try:
    ser = serial.Serial('/dev/ttyUSB0', 38400)
except:
    ser = serial.Serial('/dev/ttyUSB1', 38400)
ii=1
sleep(2)
t=0
def serial2v():
    v1=ser.readline()
    a=np.array(list(map(float,v1.split('\t')[:-1])))
    return a
v1=np.array([[]]*5).T # expecting 5 columns 
for ii in range(1000):
    try:
        v1 = np.vstack([v1,serial2v()])
    except:
        v1 = np.vstack([v1,serial2v()])
    print(serial2v())
np.savetxt('T-Bot_FilteredData.dat',v1)

Getting the Ultrasound Data

Locate the following lines in TBot.ino

import numpy as np

  /*
  Serial.print(pingval); Serial.print("\t");
  Serial.print(fping); Serial.print("\t");
  Serial.print("\n");
 */

Remove /* and */ to enable the serial output. Upload the code to the T-Bot.

Now run the serial_GetUSData.py python script.

It looks like this:

import numpy as np
import numpy as np
from time import sleep
import serial

try:
    ser = serial.Serial('/dev/ttyUSB0', 38400)
except:
    ser = serial.Serial('/dev/ttyUSB1', 38400)
ii=1
sleep(2)
t=0
def serial2v():
    v1=ser.readline()
    a=np.array(list(map(float,v1.split('\t')[:-1])))
    return a
v1=np.array([[]]*2).T # expecting 5 columns 
for ii in range(200):
    try:
        v1 = np.vstack([v1,serial2v()])
    except:
        v1 = np.vstack([v1,serial2v()])
    print(serial2v())


np.savetxt('T-Bot_UltrasoundData.dat',v1)