31 #define TASK1_PERIOD_US 20000 //20ms
32 #define TASK2_PERIOD_US 100000 //100ms
53 volatile double t0 = 0.0;
110 spi_param.
speed=375000;
120 perror(
"Unsuccesful devices initialization");
125 perror(
"Unsuccesful datalogger initialization");
130 perror(
"Unsuccesful user interface initialization");
152 #if ANU_COMPILE_FOR_OVERO
195 int current_datalogger_status;
256 previous_datalogger_status = current_datalogger_status;
280 int i, j, k, equal=0;
332 sigval.sival_int = 0;
338 sigval.sival_int = 0;
344 struct itimerspec itimer;
345 struct sigevent sigev;
350 itimer.it_interval.tv_sec=0;
352 itimer.it_value=itimer.it_interval;
354 memset(&sigev, 0,
sizeof (
struct sigevent));
356 sigev.sigev_value.sival_int = 0;
357 sigev.sigev_notify = SIGEV_THREAD;
358 sigev.sigev_notify_attributes = NULL;
361 if (timer_create(CLOCK_REALTIME, &sigev, &
timer_task_1) < 0)
363 fprintf(stderr,
"[%d]: %s\n", __LINE__, strerror(erno));
369 fprintf(stderr,
"[%d]: %s\n", __LINE__, strerror(erno));
377 struct itimerspec itimer;
378 struct sigevent sigev;
383 itimer.it_interval.tv_sec=0;
385 itimer.it_value=itimer.it_interval;
387 memset (&sigev, 0,
sizeof (
struct sigevent));
388 sigev.sigev_value.sival_int = 0;
389 sigev.sigev_notify = SIGEV_THREAD;
390 sigev.sigev_notify_attributes = NULL;
393 if(timer_create(CLOCK_REALTIME, &sigev, &
timer_task_2) < 0)
395 fprintf(stderr,
"[%d]: %s\n", __LINE__, strerror(erno));
401 fprintf(stderr,
"[%d]: %s\n", __LINE__, strerror(erno));
411 fprintf(stderr,
"[%d]: %s\n", __LINE__, strerror(erno));
421 fprintf(stderr,
"[%d]: %s\n", __LINE__, strerror(erno));
429 static struct timeval timereset;
430 static struct timeval time;
431 static struct timeval time_exec_start;
432 static struct timeval time_exec_end;
433 static double T_task,t_task,t_task_previous;
434 static double T_task_mean,T_task_min,T_task_max,T_task_exec;
436 gettimeofday(&time_exec_start, NULL);
441 gettimeofday(&timereset, NULL);
449 gettimeofday(&time, NULL);
450 t_task = ((time.tv_sec - timereset.tv_sec) + (time.tv_usec - timereset.tv_usec)*1e-6);
451 T_task = t_task - t_task_previous;
452 t_task_previous = t_task;
456 T_task_mean = T_task;
463 T_task_mean = 0.05*T_task + 0.95*T_task_mean;
464 if(T_task < T_task_min) T_task_min = T_task;
465 if(T_task > T_task_max) T_task_max = T_task;
471 gettimeofday(&time_exec_end, NULL);
472 T_task_exec = ((time_exec_end.tv_sec - time_exec_start.tv_sec) + (time_exec_end.tv_usec - time_exec_start.tv_usec)*1e-6);
486 static struct timeval timereset;
487 static struct timeval time;
488 static struct timeval time_exec_start;
489 static struct timeval time_exec_end;
490 static double T_task,t_task,t_task_previous;
491 static double T_task_mean,T_task_min,T_task_max,T_task_exec;
493 gettimeofday(&time_exec_start, NULL);
498 gettimeofday(&timereset, NULL);
506 gettimeofday(&time, NULL);
507 t_task = ((time.tv_sec - timereset.tv_sec) + (time.tv_usec - timereset.tv_usec)*1e-6);
508 T_task = t_task - t_task_previous;
509 t_task_previous = t_task;
513 T_task_mean = T_task;
519 T_task_mean = 0.05*T_task + 0.95*T_task_mean;
520 if(T_task < T_task_min) T_task_min = T_task;
521 if(T_task > T_task_max) T_task_max = T_task;
527 gettimeofday(&time_exec_end, NULL);
528 T_task_exec = ((time_exec_end.tv_sec - time_exec_start.tv_sec) + (time_exec_end.tv_usec - time_exec_start.tv_usec)*1e-6);
545 int get_time(
double *time_control_task_s,
double *Ts_control_task_s,
double *mean_time_control_task_s,
double *t0_control_task_s)
550 *t0_control_task_s =
t0;
volatile int flag_task_2_firstexecution
struct IMU_PARAM_STRUCT::param_mag mag
void actuate(int spi_dev, MRA_DATA_STRUCT *mra_data)
Applies the control signal to the actuator.
int ui_close(void)
Close UI.
int datalogger_set_Ts(double Ts)
volatile double T_task_2_max_global
#define DATALOGGER_RUNNING
volatile double T_task_1_mean_global
void timer_function_task_1(void)
volatile int flag_task_1_firstexecution
volatile double T_task_1_min_global
volatile double t_task_2_global
void calibrate_all(IMU_DATA_STRUCT *imu_data)
Calibrate all sensors.
int datalogger_close(void)
volatile int task_1_period_us
void f_timer_task_2(union sigval sigval)
SPI_PARAM_STRUCT spi_param
volatile double T_task_2_exec_global
int periodic_task_2(void)
DATA_XYZ mag
Magnetormeter Vector.
int datalogger_write_file(void)
volatile double t_task_1_global
int datalogger_init(void)
struct IMU_PARAM_STRUCT::param_gyr gyr
struct IMU_PARAM_STRUCT::param_acc acc
int datalogger_update(double t_s, double t_control_exec_s, double t_ui_exec_s, double t0_s, IMU_DATA_STRUCT *pimu_data, EFF_DATA_STRUCT *peff_data, MRA_DATA_STRUCT *pmra_data)
unsigned int telemetry_mode
void timer_stop_task_2(void)
void timer_function_task_2(void)
volatile int task_2_period_us
int periodic_task_1(void)
DATA_XYZ acc
Accel Vector.
#define DATALOGGER_NOT_RUNNING
#define DATALOGGER_SUCCESS
void timer_start_task_2(void)
int devices_init(IMU_PARAM_STRUCT *imu_param, SPI_PARAM_STRUCT *spi_param, MRA_DATA_STRUCT *mra_data)
INITIALIZATION OF SENSORS AND DEVICES.
void f_timer_task_1(union sigval sigval)
volatile double T_task_1_exec_global
void timer_start_task_1(void)
int read_all_data(int i2c_dev, int spi_dev, IMU_DATA_STRUCT *imu_data, EFF_DATA_STRUCT *eff_data, MRA_DATA_STRUCT *mra_data, ENC_DATA_STRUCT *enc_data)
READ ALL DATA FROM SENSORS AND ADC.
int get_time(double *time_control_task_s, double *Ts_control_task_s, double *mean_time_control_task_s, double *t0_control_task_s)
Review of this function:
volatile double T_task_2_mean_global
void timer_stop_task_1(void)
int ui_init(void)
Initialize UI.
int devices_close(IMU_PARAM_STRUCT *imu_param, SPI_PARAM_STRUCT *spi_param, MRA_DATA_STRUCT *mra_data)
Fuction to close all communication with the sensors and devices.
DATA_XYZ gyr
Gyrometer Vector.
int ui_update(IMU_DATA_STRUCT *pimu_data, EFF_DATA_STRUCT *peff_data, MRA_DATA_STRUCT *pmra_data, ENC_DATA_STRUCT *enc_data, int total, int failure)
Update Screen with new data of sensors.
IMU_PARAM_STRUCT imu_param
short int v_ctl
Voltage level for control output.
void exit_program(void)
Internal function to end program.
volatile double T_task_2_min_global
int datalogger_status(void)
volatile double T_task_1_max_global
int datalogger_stop(void)