]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/robofsm/robot_orte.c
Unify ORTE initialization
[eurobot/public.git] / src / robofsm / robot_orte.c
index b6bd0c2582ab47ca08a5fba803d355840729fbd6..abb34f54e5aa9f5338e6d77b1c9b2b9f3dfd13ed 100644 (file)
@@ -23,6 +23,7 @@
 #include <math.h>
 #include <robomath.h>
 #include "map_handling.h"
+#include "match-timing.h"
 #include <string.h>
 #include <can_msg_def.h>
 #include <actuators.h>
@@ -86,6 +87,17 @@ void send_dummy_cb(const ORTESendInfo *info, void *vinstance,
 {
 }
 
+void send_match_time_cb(const ORTESendInfo *info, void *vinstance,
+                       void *sendCallBackParam)
+{
+       struct match_time_type *instance = (struct match_time_type *)vinstance;
+
+        if (robot.start_state == POWER_ON || robot.start_state == START_PLUGGED_IN) {
+                instance->time = 90;
+        } else {
+                instance->time = 90 - robot_current_time();
+        }
+}
 /* ---------------------------------------------------------------------- 
  * SUBSCRIBER CALLBACKS - GENERIC
  * ---------------------------------------------------------------------- */
@@ -111,13 +123,15 @@ void rcv_odo_data_cb(const ORTERecvInfo *info, void *vinstance,
                                break;
                        }
                        
-                       dleft = ((robot.odo_data.left - instance->left) >> 8) * c;      // TODO >> 8 ?
-                       dright = ((instance->right - robot.odo_data.right) >> 8) * c;
+                       dleft = ((robot.odo_data.left - instance->left) >> 8) * c * robot.odo_cal_a;    // TODO >> 8 ?
+                       dright = ((instance->right - robot.odo_data.right) >> 8) * c * robot.odo_cal_b;
 
                        dtang = (dleft + dright) / 2.0;
                        dphi = (dright - dleft) / (2.0*ODOMETRY_ROTATION_RADIUS_M);
 
                        ROBOT_LOCK(est_pos_indep_odo);
+                       robot.odo_distance_a +=dleft;
+                       robot.odo_distance_b +=dright;
                        double a = robot.est_pos_indep_odo.phi;
                        robot.est_pos_indep_odo.x += dtang*cos(a);
                        robot.est_pos_indep_odo.y += dtang*sin(a);
@@ -170,7 +184,7 @@ void rcv_motion_irc_cb(const ORTERecvInfo *info, void *vinstance,
                        This was neccessary to view motor odometry correctly in robomon. */
                        dright = ((robot.motion_irc.left - instance->left) >> 8) * c;
                        dleft = ((instance->right - robot.motion_irc.right) >> 8) * c;
-
+                       
                        dtang = (dleft + dright) / 2.0;
                        dphi = (dright - dleft) / (2.0*ROBOT_ROTATION_RADIUS_M);
 
@@ -417,7 +431,7 @@ void rcv_robot_switches_cb(const ORTERecvInfo *info, void *vinstance,
                case NEW_DATA:
                        robot.team_color = instance->team_color;
 
-                       if (!last_strategy && instance->strategy && (robot.start_state == POWER_ON)) {
+                       if (!last_strategy && instance->strategy) {
                                        /* strategy switching */
                                        FSM_SIGNAL(MAIN, EV_SWITCH_STRATEGY, NULL);
                        }
@@ -435,7 +449,7 @@ void rcv_robot_bumpers_cb(const ORTERecvInfo *info, void *vinstance,
        static bool last_left, last_right;
        switch (info->status) {
                case NEW_DATA:
-                       if (instance->bumper_right_across || instance->bumper_left_across || instance->bumper_rear)
+                       if (instance->bumper_right_across || instance->bumper_left_across || instance->bumper_rear_left || instance->bumper_rear_right)
                                FSM_SIGNAL(MOTION, EV_OBSTACLE_BEHIND, NULL);
 
                        if (instance->bumper_left || instance->bumper_right) {
@@ -465,8 +479,6 @@ int robot_init_orte()
 {
        int rv = 0;
 
-       robot.orte.strength = 20;
-
        rv = robottype_roboorte_init(&robot.orte);
        if (rv)
                return rv;
@@ -477,6 +489,7 @@ int robot_init_orte()
        robottype_publisher_est_pos_odo_create(&robot.orte, send_est_pos_odo_cb, &robot.orte);
        robottype_publisher_est_pos_indep_odo_create(&robot.orte, send_est_pos_indep_odo_cb, &robot.orte);
        robottype_publisher_est_pos_best_create(&robot.orte, send_est_pos_best_cb, &robot.orte);
+       robottype_publisher_match_time_create(&robot.orte, send_match_time_cb, &robot.orte);
        //???robottype_publisher_pwr_ctrl_create(&robot.orte, NULL, &robot.orte);
 
        // I didn't know what was the difference between the callback function pointer