Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Macros | Functions | Variables
main.c File Reference
#include <stdio.h>
#include <math.h>
#include "communication/communication.h"
#include "main.h"
#include "taskScheduler.h"
#include "ui.h"
#include "datalogger.h"
#include "calibration/calibration.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define TASK_UI_PERIOD   200000
 
#define TASK_CONTROL_PERIOD   20000
 

Functions

int main (void)
 
static void main_task (int signo)
 
static void ui_hook (int signo)
 
static void control_hook (int signo)
 
static void ui_task ()
 
static void control_task ()
 
int reset_timer (void)
 
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: More...
 
void exit_program (void)
 Internal function to end program. More...
 

Variables

TASK_S task1
 Main rotine for control: More...
 
TASK_S task_ui
 
TASK_S task_control
 
IMU_PARAM_STRUCT imu_param
 
SPI_PARAM_STRUCT spi_param
 
EFF_DATA_STRUCT eff_data
 
IMU_DATA_STRUCT imu_data
 
ENC_DATA_STRUCT enc_data
 
MRA_DATA_STRUCT mra_data
 
int total = 0
 
int failure = 0
 
int acquire = 0
 
int quittask = 0
 
int t0 = 0
 

Macro Definition Documentation

#define TASK_CONTROL_PERIOD   20000

Definition at line 22 of file main.c.

Referenced by main().

#define TASK_UI_PERIOD   200000

Definition at line 21 of file main.c.

Referenced by main().

Function Documentation

static void control_hook ( int  signo)
static

Definition at line 113 of file main.c.

References timer_function_task().

Referenced by main().

113  {
115  //control_task();
116 }
void timer_function_task(TASK_S *task)
Definition: taskScheduler.c:76
TASK_S task_control
Definition: main.c:18

Here is the call graph for this function:

Here is the caller graph for this function:

static void control_task ( )
static

Definition at line 127 of file main.c.

References actuate(), calibrate_all(), DATALOGGER_NOT_RUNNING, DATALOGGER_RUNNING, datalogger_set_Ts(), datalogger_status(), datalogger_update(), failure, IMU_PARAM_STRUCT::i2c_dev, TASK_S::period_us, read_all_data(), reset_timer(), SPI_PARAM_STRUCT::spi_dev, SUCCESS, t0, TASK_S::T_exec_global, TASK_S::t_global, total, and MRA_DATA_STRUCT::v_ctl.

Referenced by main(), and main_task().

127  {
128  static int previous_datalogger_status = DATALOGGER_NOT_RUNNING;
129  int current_datalogger_status; // Used to detect rising edge
130  char user =0;
131 
132 
133  total++;
134 
135 /*Input*/
137 
139 
140  current_datalogger_status = datalogger_status();
141  if( (current_datalogger_status == DATALOGGER_RUNNING))
142  {
143  if(previous_datalogger_status == DATALOGGER_NOT_RUNNING) // Rising edge
144  {
146  reset_timer();
147  }
148  datalogger_update(task_control.t_global, task_control.T_exec_global, task_ui.T_exec_global, t0, &imu_data, &eff_data, &mra_data /*&imu_measure, &magnetometer_measure, &estimation_data, &control_data*/);
149  }
150  previous_datalogger_status = current_datalogger_status;
151 /* Control */
152  //mra_data.v_ctl= 1275 - (uint8_t)(800*cosf(task_control.t_global*1000));
153  mra_data.v_ctl = ((int)(total*4))%409;
154  //control_test(task1.t_global,&imu_data,&eff_data,&mra_data);
155 /* Actuate */
157 }
MRA_DATA_STRUCT mra_data
Definition: main.c:32
volatile double T_exec_global
Definition: taskScheduler.h:23
int t0
Definition: main.c:40
void actuate(int spi_dev, MRA_DATA_STRUCT *mra_data)
Applies the control signal to the actuator.
int datalogger_set_Ts(double Ts)
Definition: datalogger.c:540
#define DATALOGGER_RUNNING
Definition: datalogger.h:30
ENC_DATA_STRUCT enc_data
Definition: main.c:31
SPI_PARAM_STRUCT spi_param
Definition: main.c:26
void calibrate_all(IMU_DATA_STRUCT *imu_data)
Calibrate all sensors.
Definition: calibration.c:8
IMU_PARAM_STRUCT imu_param
Definition: main.c:25
TASK_S task_control
Definition: main.c:18
IMU_DATA_STRUCT imu_data
Definition: main.c:30
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)
Definition: datalogger.c:272
int failure
Definition: main.c:36
#define SUCCESS
Definition: calibration.h:6
#define DATALOGGER_NOT_RUNNING
Definition: datalogger.h:29
TASK_S task_ui
Definition: main.c:18
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.
Definition: communication.c:94
int reset_timer(void)
Definition: main.c:160
EFF_DATA_STRUCT eff_data
Definition: main.c:29
volatile int period_us
Definition: taskScheduler.h:27
short int v_ctl
Voltage level for control output.
int datalogger_status(void)
Definition: datalogger.c:571
volatile double t_global
Definition: taskScheduler.h:22
int total
Definition: main.c:35

Here is the call graph for this function:

Here is the caller graph for this function:

void exit_program ( void  )

Internal function to end program.

Definition at line 180 of file main.c.

180  {
181  quittask = 1;
182  return;
183 }
int quittask
Definition: main.c:39
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:

Definition at line 167 of file main.c.

Referenced by ui_overview_data().

168 {
169  *time_control_task_s = task1.t_global;
170  *Ts_control_task_s = (task1.period_us)/1e6;
171  *mean_time_control_task_s = task1.T_mean_global;
172  *t0_control_task_s = t0;
173 
174  return SUCCESS;
175 }
volatile double T_mean_global
Definition: taskScheduler.h:24
int t0
Definition: main.c:40
#define SUCCESS
Definition: calibration.h:6
TASK_S task1
Main rotine for control:
Definition: main.c:18
volatile int period_us
Definition: taskScheduler.h:27
volatile double t_global
Definition: taskScheduler.h:22

Here is the caller graph for this function:

int main ( void  )

Definition at line 42 of file main.c.

42  {
43  int return_value = SUCCESS;
44 
45 /*Setting config values:*/
46  // Parameters for IMU
48  imu_param.acc.rate=100;
49  imu_param.acc.range=16;
50  imu_param.gyr.rate=100;
51  imu_param.gyr.lpf_bw=188;
53  imu_param.gyr.act="XYZ";
54  imu_param.mag.rate=75;
59 
60  // Parameters for SPI
61  spi_param.mode=0;
62  spi_param.speed=375000;
63  spi_param.cs=0;
64 
65  // Periodic task :
68 
69 /*Initialization:*/
71  perror("Unsuccesful devices initialization");
72  return FAILURE;
73  }
74 
75  if(ui_init()!=SUCCESS){
76  perror("Unsuccesful user interface initialization");
77  return FAILURE;
78  }
79 
80  //timer_start_task(&task1,TASK1_PERIOD);
83 
84 /* Main loop: */
85  while(quittask == 0){
86  //ui_task(0);
87  }
88 
89 /*Shutting Down:*/
92  usleep(2000);
93 
94  if(ui_close()==FAILURE){
95  return_value = FAILURE;
96  }
97 
99 
100  return return_value;
101 }
MRA_DATA_STRUCT mra_data
Definition: main.c:32
int quittask
Definition: main.c:39
struct IMU_PARAM_STRUCT::param_mag mag
static void control_task()
Definition: main.c:127
int ui_close(void)
Close UI.
Definition: ui.c:41
#define TASK_CONTROL_PERIOD
Definition: main.c:22
SPI_PARAM_STRUCT spi_param
Definition: main.c:26
#define FAILURE
Definition: calibration.h:7
IMU_PARAM_STRUCT imu_param
Definition: main.c:25
TASK_S task_control
Definition: main.c:18
void timer_stop_task(TASK_S *task)
Stop some task.
struct IMU_PARAM_STRUCT::param_gyr gyr
struct IMU_PARAM_STRUCT::param_acc acc
#define TASK_UI_PERIOD
Definition: main.c:21
static void ui_task()
Definition: main.c:118
void timer_start_task(TASK_S *task, void(*alertFunction)(int), int period_us)
Start some task.
Definition: taskScheduler.c:27
#define SUCCESS
Definition: calibration.h:6
TASK_S task_ui
Definition: main.c:18
int devices_init(IMU_PARAM_STRUCT *imu_param, SPI_PARAM_STRUCT *spi_param, MRA_DATA_STRUCT *mra_data)
INITIALIZATION OF SENSORS AND DEVICES.
Definition: communication.c:12
static void ui_hook(int signo)
Definition: main.c:108
void timer_new_task(TASK_S *task, void(*runFunction)(void))
Create a task.
Definition: taskScheduler.c:16
int ui_init(void)
Initialize UI.
Definition: ui.c:26
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.
Definition: communication.c:82
static void control_hook(int signo)
Definition: main.c:113
static void main_task ( int  signo)
static

Definition at line 103 of file main.c.

References control_task(), and ui_task().

103  {
104  ui_task();
105  control_task();
106 }
static void control_task()
Definition: main.c:127
static void ui_task()
Definition: main.c:118

Here is the call graph for this function:

int reset_timer ( void  )

Definition at line 160 of file main.c.

Referenced by control_task().

161 {
163  return SUCCESS;
164 }
int t0
Definition: main.c:40
TASK_S task_control
Definition: main.c:18
#define SUCCESS
Definition: calibration.h:6
volatile double t_global
Definition: taskScheduler.h:22

Here is the caller graph for this function:

static void ui_hook ( int  signo)
static

Definition at line 108 of file main.c.

References timer_function_task().

Referenced by main().

108  {
110  //ui_task();
111 }
void timer_function_task(TASK_S *task)
Definition: taskScheduler.c:76
TASK_S task_ui
Definition: main.c:18

Here is the call graph for this function:

Here is the caller graph for this function:

static void ui_task ( )
static

Definition at line 118 of file main.c.

References failure, IMU_PARAM_STRUCT::i2c_dev, read_all_data(), SPI_PARAM_STRUCT::spi_dev, SUCCESS, total, and ui_update().

Referenced by main(), and main_task().

118  {
119  total++;
120 
122 
124 
125 }
MRA_DATA_STRUCT mra_data
Definition: main.c:32
ENC_DATA_STRUCT enc_data
Definition: main.c:31
SPI_PARAM_STRUCT spi_param
Definition: main.c:26
IMU_PARAM_STRUCT imu_param
Definition: main.c:25
IMU_DATA_STRUCT imu_data
Definition: main.c:30
int failure
Definition: main.c:36
#define SUCCESS
Definition: calibration.h:6
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.
Definition: communication.c:94
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.
Definition: ui.c:53
EFF_DATA_STRUCT eff_data
Definition: main.c:29
int total
Definition: main.c:35

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

int acquire = 0

Definition at line 37 of file main.c.

EFF_DATA_STRUCT eff_data

Definition at line 29 of file main.c.

ENC_DATA_STRUCT enc_data

Definition at line 31 of file main.c.

int failure = 0

Definition at line 36 of file main.c.

Referenced by control_task(), and ui_task().

IMU_DATA_STRUCT imu_data

Definition at line 30 of file main.c.

IMU_PARAM_STRUCT imu_param

Definition at line 25 of file main.c.

MRA_DATA_STRUCT mra_data

Definition at line 32 of file main.c.

int quittask = 0

Definition at line 39 of file main.c.

Referenced by exit_program(), and main().

SPI_PARAM_STRUCT spi_param

Definition at line 26 of file main.c.

int t0 = 0

Definition at line 40 of file main.c.

Referenced by control_task(), get_time(), reset_timer(), and ui_overview_data().

TASK_S task1

Main rotine for control:

Author
Rafael Lima
Version
0.1

Definition at line 18 of file main.c.

TASK_S task_control

Definition at line 18 of file main.c.

TASK_S task_ui

Definition at line 18 of file main.c.

int total = 0

Definition at line 35 of file main.c.

Referenced by control_task(), and ui_task().