NXT internal data logging via Bluetooth

 

Debugging a real-time control embedded software is a diffucult job even if you had a powerful debugger (setting break point at the specific line does not help you to debug a NXTway-GS...). So typical real-time control software developer uses some data measurement tool to analyze the run time behavior of the application. nxtOSEK provides a Bluetooth data logging API (ecrobot_bt_data_logger) and this API sends pre-configured data (Sensor data, Motor rev and internal status) to the NXT GamePad utility on the host PC. If you stop a data logging, you can save all logging data into a CSV file, then you can analyze what was happened inside of your NXT.

samples\datalogging\data.csv

Saved CSV file contains the below data.
Time: time stamp in msec
Data1/Data2: user configurable data
Battery: battery voltage im mV
Motor Rev A/B/C: motor revolutions in degree for all three ports
ADC S1/S2/S3/S4: A/D Sensor raw data for all four ports
I2C: Ultrasonic Sensor data in cm

You can visualize the logging data in data analysis software (e.g. Microsoft Excel, MATLAB...)




samples\datalogging\datalogging.c

/* datalogging.c */
#include "kernel.h"
#include "kernel_id.h"
#include "ecrobot_interface.h"

/* OSEK declarations */
DeclareCounter(SysTimerCnt);
DeclareTask(Task1);

/* nxtOSEK hooks */
void ecrobot_device_initialize()
{
  ecrobot_init_sonar_sensor(NXT_PORT_S2);
  ecrobot_init_bt_slave("LEJOS-OSEK");
}

void ecrobot_device_terminate()
{
  ecrobot_term_sonar_sensor(NXT_PORT_S2);
  ecrobot_term_bt_connection();
}

/* nxtOSEK hook to be invoked from an ISR in category 2 */
void user_1ms_isr_type2(void)
{
  StatusType ercd;

  ercd = SignalCounter(SysTimerCnt); /* Increment OSEK Alarm Counter */
  if (ercd != E_OK)
  {
    ShutdownOS(ercd);
  }
}

/* Task1 executed every 50msec */
TASK(Task1)
{
  static S8 i,j;
  int sonar;

  sonar = ecrobot_get_sonar_sensor(NXT_PORT_S2);

  /* send Sensor/Motors/NXT internal status to the host.
   * NXT GamePad in the host PC accumulates all logging data
   * and later you can save the logging data into a CSV file
   */

  ecrobot_bt_data_logger(i++, j--);

  /* display Sensors/Motors/NXT internal status */
  ecrobot_status_monitor("Data Logging");

  TerminateTask();
}

samples\datalogging\datalogging.oil

#include "implementation.oil"

CPU ATMEL_AT91SAM7S256
{
  OS LEJOS_OSEK
  {
    STATUS = EXTENDED;
    STARTUPHOOK = FALSE;
    ERRORHOOK = FALSE;
    SHUTDOWNHOOK = FALSE;
    PRETASKHOOK = FALSE;
    POSTTASKHOOK = FALSE;
    USEGETSERVICEID = FALSE;
    USEPARAMETERACCESS = FALSE;
    USERESSCHEDULER = FALSE;
  };

  /* Definition of application mode */
  APPMODE appmode1{};

  /* Definition of Task1 */
  TASK Task1
  {
    AUTOSTART = FALSE;
    PRIORITY = 1; /* Smaller value means lower priority */
    ACTIVATION = 1;
    SCHEDULE = FULL;
    STACKSIZE = 512; /* Stack size */
  };

  /* Definition of OSEK Alarm Counter */
  COUNTER SysTimerCnt
  {
    MINCYCLE = 1;
    MAXALLOWEDVALUE = 10000;
    TICKSPERBASE = 1; /* One tick is equal to 1msec */
  };

  /* Definition of Task1 execution timing */
  ALARM cyclic_alarm
  {
    COUNTER = SysTimerCnt;
    ACTION = ACTIVATETASK
    {
      TASK = Task1;
    };
    AUTOSTART = TRUE
    {
      ALARMTIME = 1;
      CYCLETIME = 50; /* Task1 is executed every 50msec */
      APPMODE = appmode1;
    };
  };
};

 

 

 

Back to Samples