2 * robot_orte.c 08/04/21
6 * Copyright: (c) 2008 CTU Dragons
7 * CTU FEE - Department of Control Engineering
12 #include <roboorte_generic.h>
13 #include <roboorte_eb2008.h>
15 #include <robot_eb2008.h>
16 #include <movehelper_eb2008.h>
19 #include <laser-nav.h>
20 #include "map_handling.h"
22 /* ----------------------------------------------------------------------
23 * PUBLISHER CALLBACKS - GENERIC
24 * ---------------------------------------------------------------------- */
26 void send_ref_pos_cb(const ORTESendInfo *info, void *vinstance,
27 void *sendCallBackParam)
29 struct ref_pos_type *instance = (struct ref_pos_type *)vinstance;
32 *instance = robot.ref_pos;
33 ROBOT_UNLOCK(ref_pos);
36 void send_est_pos_cb(const ORTESendInfo *info, void *vinstance,
37 void *sendCallBackParam)
39 struct est_pos_type *instance = (struct est_pos_type *)vinstance;
42 *instance = robot.est_pos;
43 ROBOT_UNLOCK(est_pos);
46 void send_dummy_cb(const ORTESendInfo *info, void *vinstance,
47 void *sendCallBackParam)
51 /* ----------------------------------------------------------------------
52 * SUBSCRIBER CALLBACKS - GENERIC
53 * ---------------------------------------------------------------------- */
55 void rcv_motion_irc_cb(const ORTERecvInfo *info, void *vinstance,
56 void *recvCallBackParam)
58 struct motion_irc_type *instance = (struct motion_irc_type *)vinstance;
59 static struct motion_irc_type prevInstance;
60 static int firstRun = 1;
61 /* spocitat prevodovy pomer */
62 double n = (double)(28.0 / 1.0);
63 /* vzdalenost na pulz - 4.442 je empiricka konstanta :) */
64 double c = (M_PI*2*ROBOT_WHEEL_RADIUS_M) / (n * 4*500.0);
71 switch (info->status) {
74 prevInstance = *instance;
79 aktk0 = ((prevInstance.left - instance->left) >> 8) * c;
80 aktk1 = ((instance->right - prevInstance.right) >> 8) * c;
81 prevInstance = *instance;
83 deltaU = (aktk0 + aktk1) / 2;
84 deltAlfa = (aktk1 - aktk0) / (2.0*ROBOT_ROTATION_RADIUS_M);
86 struct mcl_robot_odo *odo = malloc(sizeof(struct mcl_robot_odo));
87 memset(odo, 0, sizeof(*odo));
90 odo->dangle = deltAlfa;
91 FSM_SIGNAL(LOC, EV_ODO_RECEIVED, odo);
92 robot.hw_status[STATUS_MOTION] = HW_STATUS_OK;
95 robot.hw_status[STATUS_MOTION] = HW_STATUS_FAILED;
96 DBG("ORTE deadline occurred - motion_irc receive\n");
101 void rcv_motion_speed_cb(const ORTERecvInfo *info, void *vinstance,
102 void *recvCallBackParam)
104 switch (info->status) {
108 DBG("ORTE deadline occurred - motion_speed receive\n");
113 void rcv_motion_status_cb(const ORTERecvInfo *info, void *vinstance,
114 void *recvCallBackParam)
116 switch (info->status) {
120 DBG("ORTE deadline occurred - motion_status receive\n");
125 void rcv_joy_data_cb(const ORTERecvInfo *info, void *vinstance,
126 void *recvCallBackParam)
128 struct joy_data_type *instance = (struct joy_data_type *)vinstance;
130 switch (info->status) {
132 ROBOT_LOCK(joy_data);
133 robot.joy_data = *instance;
134 ROBOT_UNLOCK(joy_data);
137 DBG("ORTE deadline occurred - joy_data receive\n");
142 void rcv_pwr_voltage_cb(const ORTERecvInfo *info, void *vinstance,
143 void *recvCallBackParam)
145 switch (info->status) {
147 robot.hw_status[STATUS_POWER]=HW_STATUS_OK;
150 robot.hw_status[STATUS_POWER]=HW_STATUS_FAILED;
151 DBG("ORTE deadline occurred - pwr_voltage receive\n");
156 void rcv_pwr_ctrl_cb(const ORTERecvInfo *info, void *vinstance,
157 void *recvCallBackParam)
159 switch (info->status) {
163 DBG("ORTE deadline occurred - pwr_ctrl receive\n");
168 /* ----------------------------------------------------------------------
169 * SUBSCRIBER CALLBACKS - EB2008
170 * ---------------------------------------------------------------------- */
172 void rcv_servos_cb(const ORTERecvInfo *info, void *vinstance,
173 void *recvCallBackParam)
175 switch (info->status) {
179 DBG("ORTE deadline occurred - servos receive\n");
184 void rcv_drives_cb(const ORTERecvInfo *info, void *vinstance,
185 void *recvCallBackParam)
187 struct drives_type *instance = (struct drives_type *)vinstance;
189 switch (info->status) {
191 ROBOT_LOCK(carousel);
192 robot.drives = *instance;
193 ROBOT_UNLOCK(carousel);
196 DBG("ORTE deadline occurred - drives receive\n");
201 void rcv_laser_data_cb(const ORTERecvInfo *info, void *vinstance,
202 void *recvCallBackParam)
204 struct laser_data_type *instance = (struct laser_data_type *)vinstance;
206 switch (info->status) {
208 struct mcl_laser_measurement *meas_angles;
209 meas_angles = malloc(sizeof(*meas_angles));
210 memset(meas_angles, 0, sizeof(*meas_angles));
212 meas_angles->count = 1;
213 meas_angles->val[0] =
214 (double)TIME2ANGLE(instance->period,
216 // DBG("a=%f\n", RAD2DEG(robot.meas_angles.val[0]));
219 FSM_SIGNAL_TIMED(LOC, EV_LASER_RECEIVED, meas_angles, 20/*ms*/, &sent);
221 DBG("%s: MCL is busy - not updating\n", __FUNCTION__);
225 robot.hw_status[STATUS_LASER] = HW_STATUS_OK;
228 robot.hw_status[STATUS_LASER] = HW_STATUS_FAILED;
229 DBG("%s: ORTE deadline occurred\n", __FUNCTION__);
234 void rcv_cmu_cb(const ORTERecvInfo *info, void *vinstance,
235 void *recvCallBackParam)
237 struct cmu_type *instance = (struct cmu_type *)vinstance;
238 static last_color = NO_BALL;
239 static unsigned char first = 1;
241 switch (info->status) {
244 robot.cmu = *instance;
247 last_color = robot.cmu.color;
250 if (robot.cmu.color != NO_BALL) {
251 if (last_color != robot.cmu.color) {
252 last_color = robot.cmu.color;
253 FSM_SIGNAL(MAIN, EV_BALL_INSIDE, NULL);
256 robot.hw_status[STATUS_CMU] = HW_STATUS_OK;
260 robot.hw_status[STATUS_CMU] = HW_STATUS_FAILED;
261 DBG("%s: ORTE deadline occurred\n", __FUNCTION__);
266 void rcv_bumper_cb(const ORTERecvInfo *info, void *vinstance,
267 void *recvCallBackParam)
269 struct bumper_type *instance = (struct bumper_type *)vinstance;
271 switch (info->status) {
274 robot.bumper = *instance;
275 ROBOT_UNLOCK(bumper);
279 DBG("%s: ORTE deadline occurred\n", __FUNCTION__);
284 void rcv_sharps_cb(const ORTERecvInfo *info, void *vinstance,
285 void *recvCallBackParam)
287 struct sharps_type *instance = (struct sharps_type *)vinstance;
288 //struct sharps_type *for_mcl;
290 switch (info->status) {
292 update_map(instance);
296 DBG("%s: ORTE deadline occurred\n", __FUNCTION__);
301 void robot_init_orte()
303 robot.orte.strength = 20;
304 robot.gorte.strength = 20;
306 eb2008_roboorte_init(&robot.orte);
307 generic_roboorte_init(&robot.gorte);
309 /* creating publishers */
310 generic_publisher_motion_irc_create(&robot.gorte, NULL, &robot.gorte);
311 generic_publisher_motion_speed_create(&robot.gorte, NULL, &robot.gorte);
312 generic_publisher_motion_status_create(&robot.gorte, NULL, &robot.gorte);
313 generic_publisher_ref_pos_create(&robot.gorte, send_ref_pos_cb, &robot.gorte);
314 generic_publisher_est_pos_create(&robot.gorte, send_est_pos_cb, &robot.gorte);
315 generic_publisher_joy_data_create(&robot.gorte, NULL, &robot.gorte);
316 generic_publisher_pwr_voltage_create(&robot.gorte, NULL, &robot.gorte);
317 generic_publisher_pwr_ctrl_create(&robot.gorte, NULL, &robot.gorte);
319 eb2008_publisher_servos_create(&robot.orte, send_dummy_cb, &robot.orte);
320 eb2008_publisher_drives_create(&robot.orte, send_dummy_cb, &robot.orte);
322 /* create generic subscribers */
323 generic_subscriber_motion_irc_create(&robot.gorte, rcv_motion_irc_cb, &robot.gorte);
324 generic_subscriber_motion_speed_create(&robot.gorte, rcv_motion_speed_cb, &robot.gorte);
325 generic_subscriber_motion_status_create(&robot.gorte, rcv_motion_status_cb, &robot.gorte);
326 generic_subscriber_joy_data_create(&robot.gorte, rcv_joy_data_cb, &robot.gorte);
327 generic_subscriber_pwr_voltage_create(&robot.gorte, rcv_pwr_voltage_cb, &robot.gorte);
328 generic_subscriber_pwr_ctrl_create(&robot.gorte, rcv_pwr_ctrl_cb, &robot.gorte);
330 /* create eb2008 subscribers */
331 eb2008_subscriber_servos_create(&robot.orte, rcv_servos_cb, &robot.orte);
332 eb2008_subscriber_drives_create(&robot.orte, rcv_drives_cb, &robot.orte);
333 eb2008_subscriber_laser_data_create(&robot.orte, rcv_laser_data_cb, &robot.orte);
334 eb2008_subscriber_cmu_create(&robot.orte, rcv_cmu_cb, &robot.orte);
335 eb2008_subscriber_bumper_create(&robot.orte, rcv_bumper_cb, &robot.orte);
336 eb2008_subscriber_sharps_create(&robot.orte, rcv_sharps_cb, &robot.orte);