Robot Agent  1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
task_control.c
Go to the documentation of this file.
1 
11 /* -- Includes -- */
12 /* system libraries */
13 
14 /* project libraries */
15 #include "task.h"
16 
20 void task_control(void)
21 {
22  // Check if task is enabled
24  {
25  int speed;
26  int req_time;
27 
28  // Update sensors Odometer
29 #ifndef s_CONFIG_TEST_ENABLE
30  // Request only if the allowed period has passed
32  if(req_time > s_CONFIG_OI_REQUEST_PERIOD)
33  {
37  }
38  else
39  {
40  printf("NOISE!\n");
41 
42  g_ois->oiss->distance = 0;
43  g_ois->oiss->angle = 0;
45  }
46 #endif
47  // Motion Update (Particle filter)
50 
52  {
53  speed = g_config.robot_speed / 2;
54  }
55  else
56  {
57  speed = g_config.robot_speed;
58  }
59 
60  // Send robot pose (add data to communication queue)
61  debug_printf("Pose: %d, %d, %f\n", g_robot->x, g_robot->y, g_robot->a);
62 
64 
65  // Check pipe for event
67  {
68 
69  // If there is new move then send drive command to robot
71  {
72  case s_PH_LEFT :
73  debug_printf("PH_LEFT\n");
74  openinterface_drive(g_ois, speed, 200);
75  break;
76  case s_PH_TOP_LEFT :
77  debug_printf("PH_TOP_LEFT\n");
78  openinterface_drive(g_ois, speed, 100);
79  break;
80  case s_PH_TOP :
81  debug_printf("PH_TOP\n");
82  openinterface_drive(g_ois, speed, 0x8000);
83  break;
84  case s_PH_TOP_RIGHT :
85  debug_printf("PH_TOP_RIGHT\n");
86  openinterface_drive(g_ois, speed, 0xFFFF - 100);
87  break;
88  case s_PH_RIGHT :
89  debug_printf("PH_RIGHT\n");
90  openinterface_drive(g_ois, speed, 0xFFFF - 200);
91  break;
92  case s_PH_NONE :
93  debug_printf("PH_NONE\n");
95  default :
96  // Do nothing
97  break;
98  }
99 
100  // Reset event
102  }
103  }
104 }
void debug_printf(const char *format,...)
Definition: debug.c:25
#define s_DATA_STRUCT_TYPE_ROBOT
Definition: def.h:68
struct timeval request_timer
Definition: task.h:74
int enabled
Definition: task.h:46
config_t g_config
Definition: config.c:22
#define s_OI_SENSOR_PACKET_2
void task_control(void)
Definition: task_control.c:20
robot_t * g_robot
Definition: task.c:27
float a
Definition: robot.h:29
openinterface_sensor_t * oiss
doublylinkedlist_t * g_list_send
Definition: task.c:32
#define s_CONFIG_OI_REQUEST_PERIOD
Definition: config.h:94
#define s_TASK_EVENT_SET
Definition: task.h:111
void pf_drive(pf_t *pfs, int distance, int angle, int uncertain)
Definition: pf.c:99
task_t g_task_control
Definition: task.c:41
double timelib_timer_get(struct timeval tv)
Definition: timelib.c:43
taskpipe_navigate_control_t g_tp_navigate_control
Definition: task.c:54
#define s_CONFIG_ACCURACY_LIMIT
Definition: config.h:96
enviroment_t * g_envs
Definition: task.c:23
double timelib_timer_reset(struct timeval *tv)
Definition: timelib.c:64
#define s_TASK_EVENT_RESET
Definition: task.h:112
void pf_estimate(pf_t *pfs, robot_t *robot)
Definition: pf.c:215
int robot_speed
Definition: config.h:50
int openinterface_drive(openinterface_t *ois, int velocity, int radius)
openinterface_t * g_ois
Definition: task.c:24
int openinterface_sensors_update(openinterface_t *ois, const unsigned int sensor_id, const unsigned int size)
void doublylinkedlist_insert_end(doublylinkedlist_t *dlls, void *data, int data_type)
int pf_accuracy(pf_t *pfs, enviroment_t *envs)
Definition: pf.c:294
#define s_TRUE
Definition: def.h:60
#define s_OI_SENSOR_PACKET_2_SIZE
task_control_t g_task_control_data
Definition: task.c:49
pf_t * g_pfs
Definition: task.c:26