]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
Merge branch 'shapedet'
authorMichal Vokac <vokac.m@gmail.com>
Fri, 6 May 2011 11:27:50 +0000 (13:27 +0200)
committerMichal Vokac <vokac.m@gmail.com>
Fri, 6 May 2011 11:27:50 +0000 (13:27 +0200)
Conflicts:
src/robofsm/map_handling.c

Conflict solved. We are testing shapedet for homologation.

17 files changed:
src/cand/cand.cc
src/display-qt/display_orte.cpp
src/display-qt/displayqt.cpp
src/eb_jaws_11/main.c
src/eb_lift_11/fsm_lift.c
src/eb_lift_11/main.c
src/joyd/joyd.cc
src/motor-control/brushless.c
src/pathplan/map.h
src/pxmc
src/robodim/robodim.h
src/robofsm/Makefile.omk
src/robofsm/actuators.c
src/robofsm/actuators.h
src/robofsm/homologation.cc
src/robofsm/robot.c
src/robofsm/robot_orte.c

index 60355862daf0d8cf7e8138f6ecb8dfdd7a90adaa..1925c0abcc9f9132859a9aabbf73e7f9c3516aa1 100644 (file)
@@ -105,10 +105,10 @@ int set_motor_speed(struct robottype_orte_data *orte_data)
 {
        unsigned char data[4];
 
-       data[0] = orte_data->motion_speed.right >> 8;
-       data[1] = orte_data->motion_speed.right & 0xff;
-       data[2] = orte_data->motion_speed.left >> 8;
-       data[3] = orte_data->motion_speed.left & 0xff;
+       data[0] = orte_data->motion_speed.left >> 8;
+       data[1] = orte_data->motion_speed.left & 0xff;
+       data[2] = orte_data->motion_speed.right >> 8;
+       data[3] = orte_data->motion_speed.right & 0xff;
        can_send(CAN_MOTION_CMD, 4, data);
 
        return 0;
@@ -242,9 +242,9 @@ void cand_parse_frame(struct robottype_orte_data *orte, struct can_frame frame)
 
                /* motion status */
                case CAN_MOTION_STATUS:
-                       orte->motion_status.err_left = 
+                       orte->motion_status.err_right =
                                        (frame.data[0]<<8)|(frame.data[1]);
-                       orte->motion_status.err_right = 
+                       orte->motion_status.err_left =
                                        (frame.data[2]<<8)|(frame.data[3]);
                        if(++status_cnt == 2) { // h8eurobot sends duplicite can messages
                                ORTEPublicationSend(orte->publication_motion_status);
index 71b80a456df1b18e0624207d26e5a44d15b28f13..2e4005d4629cc77f5df0b31c0fbdedd914e672dd 100644 (file)
@@ -1,5 +1,6 @@
 #include "display_orte.h"
 #include "ortesignals.h"
+//#include <can_msg_def.h>
 
 #include <time.h>
 
@@ -180,7 +181,7 @@ void rcv_lift_status_cb(const ORTERecvInfo *info, void *vinstance, void *recvCal
        static struct timespec last_sent;
        switch (info->status) {
                case NEW_DATA:
-                       if (m->flags == 0)
+                       if (m->flags)
                                status = STATUS_OK;
                        else
                                status = STATUS_WARNING;
index 073442d8ef19c8d9b9628dbc609a4fe3d5342b85..843f01dcb2bd45c0cfe760800f30f06538adb039 100644 (file)
@@ -123,10 +123,10 @@ void DisplayQT::setTeamColor(char color)
 {
        if(color==0){
                color=0;
-               ui->our_color->setStyleSheet("background-color: blue");
+               ui->our_color->setStyleSheet("background-color: rgb(213, 40, 24)");
        }else if(color==1){
                color=1;
-               ui->our_color->setStyleSheet("background-color: rgb(213, 40, 24)");
+               ui->our_color->setStyleSheet("background-color: blue");
        }
 }
 
index bfe3955c4ed4b9b2ef5c2277bb31c32f95681543..68eea98b4638b6d14465ca404e3fe34bb80960d2 100644 (file)
@@ -219,10 +219,17 @@ void blink_led()
                    up = (up+1)%12;
                */
                deb_led_change(LEDG);
+               
+               send_rs_str("LEFT_JAW: ");
                send_rs_int(fsm_jaw_left.act_pos);
-               send_rs_str("\n");
+               send_rs_str("\tLEFT_FLAGS: ");
+               send_rs_int(fsm_jaw_left.flags);
+               
+               send_rs_str("\tRIGHT_JAW: ");
                send_rs_int(fsm_jaw_right.act_pos);
-               send_rs_str("\n");
+               send_rs_str("\tRIGHT_FLAGS: ");
+               send_rs_int(fsm_jaw_right.flags);
+               
                send_rs_str("\n");
 
        }
@@ -351,14 +358,14 @@ int main(void)
        
        //close jaw, max_pos, open jaw min_pos
        //letf jaw potenciometer on ADC 0, header J32 on board
-       fsm_jaw_left.max_pos=0x310; //max 0x324
-       fsm_jaw_left.min_pos=0xB0; //min 0xC0
+       fsm_jaw_left.max_pos=0x320; //max 0x324
+       fsm_jaw_left.min_pos=0xB0; //min 0xC3
        fsm_jaw_left.act_pos = adc_val[0];
        
        //close jaw, max_pos, open jaw min_pos
        //letf jaw potenciometer on ADC 1, header J33 on board
-       fsm_jaw_right.max_pos=0x370; //max 0x382
-       fsm_jaw_right.min_pos=0x080; //min 0x8D
+       fsm_jaw_right.max_pos=0x380; //max 0x382
+       fsm_jaw_right.min_pos=0x010; //min 0xF5
        fsm_jaw_right.act_pos = adc_val[1];
        
        //left jaw engine is engine A, conector MOTA on board
index 360f21b1dc5c007c908486864420146c279f26c4..3561a7acc8831fa40b0cdfc1c6ba922ee319d342 100644 (file)
@@ -37,7 +37,7 @@ static void homing(struct fsm *fsm, enum event event)
                engine_A_pwm(50);
 
                if(fsm->flags & CAN_LIFT_SWITCH_DOWN){
-                       stop();
+                       engine_A_pwm(0);
                        fsm->act_pos = 0;
                        fsm->current_state = wait_for_cmd;
                        fsm->flags |= CAN_LIFT_HOMED;
index 4175533d72dbf923bc8b406f5d935d216eb13528..5fef3acf926f1016b6523dc105bd2100ee1bf576 100644 (file)
@@ -48,64 +48,72 @@ struct fsm fsm_lift;
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-#define END_SWITCH_UP   9       //pin 4, exp. port on board 
-#define END_SWITCH_DOWN 8       //pin 3, exp. port on board
-#define SWITCH_HOME 19       //pin 6, exp. port on board
+#define END_SWITCH_UP_PIN      9       //pin 4, exp. port on board
+#define END_SWITCH_DOWN_PIN    8       //pin 3, exp. port on board
+#define SWITCH_HOME_PIN                19      //pin 6, exp. port on board
+#define START_PIN              15      //pin 7, exp. port on board
+#define COLOR_PIN              18      //pin 5, exp. port on board
+
+#define START_SEND_PRIOD_FAST  50      /* [miliseconds] */
+#define START_SEND_PRIOD_SLOW  300     /* [miliseconds] */
+#define START_SEND_FAST_COUNT  10      /* How many times to send start with small period (after a change) */
+
+#define LIFT_IRC_VAL_MAX 0x19C
+#define LIFT_IRC_VAL_MIN 0x0
+
+#define IRC_A_PIN  2   //pin 1, exp. port on board
+#define IRC_B_PIN  3   //pin 2, exp. port on board
+
+#define IRC_A_MASK     0x04 //(1<<IRC_A)
+#define IRC_B_MASK     0x08 //(1<<IRC_B)
+#define IRC_AB_MASK    0x0C //((1<<IRC_A)&(1<<IRC_B))
 
 void lift_switches_handler(void);
 
 void lift_switches_handler()
 {
-       if (IO0PIN & (1<<END_SWITCH_UP)){
-               fsm_lift.flags |= CAN_LIFT_SWITCH_UP;
-               deb_led_on(LEDR);
-       } else {
+       if (IO0PIN & (1<<END_SWITCH_UP_PIN)){
                fsm_lift.flags &= ~CAN_LIFT_SWITCH_UP;
                deb_led_off(LEDR);
+       } else {
+               fsm_lift.flags |= CAN_LIFT_SWITCH_UP;
+               deb_led_on(LEDR);
        }
 
-       if (IO0PIN & (1<<END_SWITCH_DOWN)){
-               fsm_lift.flags |= CAN_LIFT_SWITCH_DOWN;
-               deb_led_on(LEDR);
-       } else {
+       if (IO0PIN & (1<<END_SWITCH_DOWN_PIN)){
                fsm_lift.flags &= ~CAN_LIFT_SWITCH_DOWN;
                deb_led_off(LEDR);
+       } else {
+               fsm_lift.flags |= CAN_LIFT_SWITCH_DOWN;
+               deb_led_on(LEDR);
        }
 
-       if (IO0PIN & (1<<SWITCH_HOME)){
-               fsm_lift.flags |= CAN_LIFT_SWITCH_HOME;
-               deb_led_on(LEDR);
-       } else {
+       if (IO0PIN & (1<<SWITCH_HOME_PIN)){
                fsm_lift.flags &= ~CAN_LIFT_SWITCH_HOME;
                deb_led_off(LEDR);
+       } else {
+               fsm_lift.flags |= CAN_LIFT_SWITCH_HOME;
+               deb_led_on(LEDR);
        }
-}
-
-#define LIFT_IRC_VAL_MAX 0x19C
-#define LIFT_IRC_VAL_MIN 0x0
-
-#define IRC_A  2       //pin 1, exp. port on board
-#define IRC_B  3       //pin 2, exp. port on board
-
-#define IRC_A_MASK     0x04 //(1<<IRC_A)
-#define IRC_B_MASK     0x08 //(1<<IRC_B)
-#define IRC_AB_MASK    0x0C //((1<<IRC_A)&(1<<IRC_B))
-
-int irc_read_tick(uint16_t *last_irc);
-void irc_init(void);
-
-void irc_init(void){
-       SET_PIN(PINSEL0, IRC_A, PINSEL_0);
-       SET_PIN(PINSEL0, IRC_B, PINSEL_0);
-
-       SET_PIN(PINSEL0, END_SWITCH_UP, PINSEL_0);
-       SET_PIN(PINSEL0, END_SWITCH_DOWN, PINSEL_0);
+//     if (IO0PIN & (1<<IRC_A_PIN)){
+//             deb_led_off(LEDR);
+//     } else {
+//             deb_led_on(LEDR);
+//     }
+//     if (IO0PIN & (1<<IRC_B_PIN)){
+//             deb_led_off(LEDR);
+//     } else {
+//             deb_led_on(LEDR);
+//     }
 }
 
 //source code from http://www.vosrk.cz/robotika/Stavba/Enkoder.pdf
-int irc_read_tick(uint16_t *last_irc){
+int32_t irc_read_tick(){
 
-       static char cnt = 0;
+       static uint16_t cnt_up = 0;
+       static uint16_t cnt_down = 0;
+       static uint16_t last_irc = 0;
+       static int32_t position = 0;
        uint16_t irc, temp;
 
        irc = IO0PIN & IRC_AB_MASK;
@@ -113,24 +121,28 @@ int irc_read_tick(uint16_t *last_irc){
        irc ^= IRC_A_MASK;
        }
 
-       temp = (irc - *last_irc) & IRC_AB_MASK;
+       temp = (irc - last_irc) & IRC_AB_MASK;
 
-       *last_irc = irc;
+       last_irc = irc;
 
        if (temp == IRC_A_MASK){
                /* count 100times slower - we do not need 250 ticks per milimeter*/
-               if (--cnt < 100) {
-                       cnt = 0;
-                       return -1;
+               if (++cnt_down >= 100) {
+                       cnt_down = 0;
+                       cnt_up = 0;
+                       deb_led_change(LEDB);
+                       return --position;
                }
        } else if (temp == IRC_AB_MASK){
                /* count 100times slower - we do not need 250 ticks per milimeter*/
-               if (++cnt > 100) {
-                       cnt = 0;
-                       return 1;
+               if (++cnt_up >= 100) {
+                       cnt_up = 0;
+                       cnt_down = 0;
+                       deb_led_change(LEDB);
+                       return ++position;
                }
        }
-       return 0;
+       return position;
 }
 
 void init_motors(void){
@@ -187,13 +199,6 @@ void timer0_irq() {
 
 
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-#define START_PIN      15              //pin 7, exp. port on board
-#define START_SEND_PRIOD_FAST  50      /* [miliseconds] */
-#define START_SEND_PRIOD_SLOW  300     /* [miliseconds] */
-#define START_SEND_FAST_COUNT  10      /* How many times to send start with small period (after a change) */
-
-
 void start_button(void)
 {
        can_msg_t msg;
@@ -281,9 +286,6 @@ void init_periphery(void){
 
        init_uart();
 //     init_adc(ADC_ISR);
-       irc_init();
-       
-       
 } 
 /*********************************************************/
 void can_send_status(void)
@@ -345,10 +347,6 @@ void blink_led()
        }
 }
 
-
-
-#define COLOR_PIN 18           //pin 5, exp. port on board
-
 void color_handler()
 {
        static uint32_t color_time = 0;
@@ -395,16 +393,23 @@ int main(void)
 {
        uint32_t main_time = timer_usec;
        uint32_t status_time = timer_usec;
-       
-        static uint16_t last_irc=0;
-        
+
        //lift motor is motor A, MOTA connctor on board
-       init_periphery();       
-       
-       SET_PIN(PINSEL0, START_PIN, PINSEL_0);          //init of start pin
-       SET_PIN(PINSEL0, 3, PINSEL_0);  //init of color pin
-        SET_PIN(PINSEL0, 4, PINSEL_0);  //init of home pin
-       
+       init_periphery();
+
+       SET_PIN(PINSEL0, IRC_A_PIN, PINSEL_0);
+       SET_PIN(PINSEL0, IRC_B_PIN, PINSEL_0);
+
+       SET_PIN(PINSEL0, END_SWITCH_UP_PIN, PINSEL_0);
+       SET_PIN(PINSEL0, END_SWITCH_DOWN_PIN, PINSEL_0);
+
+       SET_PIN(PINSEL0, START_PIN, PINSEL_0);  //init of start pin
+       SET_PIN(PINSEL1, (COLOR_PIN - 16), PINSEL_0);   //init of color pin
+        SET_PIN(PINSEL1, (SWITCH_HOME_PIN - 16), PINSEL_0);  //init of home pin
+
+       IO0DIR &= ~((1<<START_PIN) | (1<<SWITCH_HOME_PIN) | (1 << COLOR_PIN));
+       IO0DIR &= ~((1<<END_SWITCH_UP_PIN) | (1<<END_SWITCH_DOWN_PIN));
+       IO0DIR &= ~((1<<IRC_A_PIN) | (1<<IRC_B_PIN));
        send_rs_str("Lift started\n");
 
        fsm_lift.act_pos = 0;
@@ -431,7 +436,7 @@ int main(void)
                        can_send_status();
                }
 
-               fsm_lift.act_pos = fsm_lift.act_pos + irc_read_tick(&last_irc);
+               fsm_lift.act_pos = irc_read_tick();
 
                start_button();
                color_handler();
index 090c798da120981ea2ccfe5c43ebdc2a2735e0ce..a647d881c4a999869cc7176f6849852f927dc9fe 100644 (file)
@@ -70,8 +70,10 @@ static void button_act(char state, int id)
                        break;
                case BT2:
                        if(state) {
+                               act_lift(0, 0, 1);
                                //act ON
                        } else {
+                               act_lift(0, 0, 0);
                                ;//act OFF
                        }
                        break;
@@ -173,11 +175,11 @@ static void process_axis(int value, int id)
                case AXIS_S2:
                        switch (value) {
                        case 32767:
-                               act_lift(0, 0);
+                               act_lift(0, 0, 0);
                                printf("lift DOWN\n");
                                break;
                        case -32767:
-                               act_lift(0x190, 0);
+                               act_lift(0x190, 0, 0);
                                printf("lift UP\n");
                                break;
                        case 0:
index 4af5dc05ae3c58633c469f5f6b881ee34b39785a..f00c0ebf0bcdb7968356f98dee73d182cbccabed 100644 (file)
@@ -870,6 +870,9 @@ int main()
     printf("PXMC initialized (motor: %s)", pxmc_variant);
     printf("\n");
 
+    pxmc_set_const_out(&mcs_left,0);
+    pxmc_set_const_out(&mcs_right,0);
+
     int32_t receive_id[] = { CAN_MOTION_CMD, CAN_MOTION_RESET, -1 };
     canInit(0, 1000000, receive_id);
     printf("CAN initialized\n");
index 3870b21f35d1e4854e0567677c26da0e11c4b528..8996c9e53ea7279971889b7ba92ddf0fffbad76d 100644 (file)
 
 /** @name Map constaints */
 /**@{*/
-#define MAP_CELL_SIZE_MM          100  /**< Size of a cell in mm. The cell is a square. */
+#define MAP_CELL_SIZE_MM          50   /**< Size of a cell in mm. The cell is a square. */
 #define MAP_CELL_SIZE_M           (MAP_CELL_SIZE_MM/1000.0)
 #define MAP_WIDTH                 (PLAYGROUND_WIDTH_MM / MAP_CELL_SIZE_MM)    /**< Field width*/
 #define MAP_HEIGHT                (PLAYGROUND_HEIGHT_MM / MAP_CELL_SIZE_MM)    /**< Field height*/
index bd221cccd38c98b7c1c1a8a33ff9fa270aef66ec..dbf5745c67d46b5f6df45eae32615e8c94d5398c 160000 (submodule)
--- a/src/pxmc
+++ b/src/pxmc
@@ -1 +1 @@
-Subproject commit bd221cccd38c98b7c1c1a8a33ff9fa270aef66ec
+Subproject commit dbf5745c67d46b5f6df45eae32615e8c94d5398c
index 12d9e120a6d971a221c22c7b96bdffa53b5c4dea..921c6d0ece7b830a10e0752849f33e2ac85d16ad 100644 (file)
@@ -59,6 +59,8 @@
 #define ROBOT_JAWS_LENGHT_M (ROBOT_JAWS_LENGHT_MM/1000.0)
 #define ROBOT_LENGHT_WITH_PANWS_MM 170 /* PW */ 
 #define ROBOT_LENGHT_WITH_PAWNS_M (ROBOT_LENGHT_WITH_PANWS_MM/1000.0)
+#define ROBOT_AXIS_TO_FIGURE_CENTER_MM 280
+#define ROBOT_AXIS_TO_FIGURE_CENTER_M (ROBOT_AXIS_TO_FIGURE_CENTER_MM/1000.0)
 
 /**
  * PLAYGROUND DIMENSIONS
index c7795d9f82e0158389fd3908ee27993394e765aa..a798acec2f5035e7567230d1b0dbcf468147c389 100644 (file)
@@ -7,8 +7,8 @@ default_CONFIG = CONFIG_LOCK_CHECKING=n HAVE_PRIO_INHERIT=y
 config_include_HEADERS = robot_config.h
 robot_config_DEFINES = CONFIG_LOCK_CHECKING HAVE_PRIO_INHERIT
 
-#bin_PROGRAMS += demo
-#demo_SOURCES = demo.cc
+bin_PROGRAMS += homologation
+homologation_SOURCES = homologation.cc
 
 # Library with general support functions for the robot
 lib_LIBRARIES += robot
index 1d8cfb5f56edca478cfae1061290c178d5a68d2b..a9f0bee6623d2a30345730d7380b51afa02606e7 100644 (file)
@@ -44,13 +44,15 @@ void act_camera_off(void)
        ORTEPublicationSend(orte->publication_camera_control);
 }
 
-void act_lift(uint16_t position, char speed)
+void act_lift(uint16_t req_pos, char speed, char homing)
 {
-       orte->lift_cmd.req_pos = position;
+
+       orte->lift_cmd.req_pos = req_pos;
        orte->lift_cmd.speed = speed;
+       orte->lift_cmd.homing = homing;
        /* Remember the request so that we change check for matching
         * response in rcv_vidle_status_cb() */
-       lift_last_request = position;
+       lift_last_request = req_pos;
        ORTEPublicationSend(orte->publication_lift_cmd);
 }
 
@@ -58,20 +60,20 @@ void act_jaws(jaws_cmds cmd)
 {
   switch (cmd) {
       case OPEN:
-        orte->jaws_cmd.req_pos.left=0x1C3;
-        orte->jaws_cmd.req_pos.right=0x1B3;
-        break;
+         orte->jaws_cmd.req_pos.left = JAW_LEFT_OPEN;
+         orte->jaws_cmd.req_pos.right = JAW_RIGHT_OPEN;
+         break;
       case CLOSE:
-          orte->jaws_cmd.req_pos.left=0x30F;
-          orte->jaws_cmd.req_pos.right=0x36F;
+          orte->jaws_cmd.req_pos.left = JAW_LEFT_CLOSE;
+          orte->jaws_cmd.req_pos.right = JAW_RIGHT_CLOSE;
           break;
       case CATCH:
-          orte->jaws_cmd.req_pos.left = 0x25F;
-          orte->jaws_cmd.req_pos.right = 0x27F;
+          orte->jaws_cmd.req_pos.left = JAW_LEFT_CATCH;
+          orte->jaws_cmd.req_pos.right = JAW_RIGHT_CATCH;
           break;
       default:
-          orte->jaws_cmd.req_pos.left=0x1C3;
-          orte->jaws_cmd.req_pos.right=0x1B3;
+          orte->jaws_cmd.req_pos.left = JAW_LEFT_OPEN;
+          orte->jaws_cmd.req_pos.right = JAW_RIGHT_OPEN;
       }
 }
 
index 09b198f5e9072c3d0347c58b33ea577d6492f821..4997c676012faeb51b717abc8f5e7b22dd8ef91e 100644 (file)
@@ -39,6 +39,15 @@ typedef enum {
   CATCH
 } jaws_cmds;
 
+#define JAW_LEFT_OPEN  0x1C3
+#define JAW_RIGHT_OPEN 0x1B3
+
+#define JAW_LEFT_CLOSE 0x31F
+#define JAW_RIGHT_CLOSE        0x37F
+
+#define JAW_LEFT_CATCH 0x25F
+#define JAW_RIGHT_CATCH 0x27F
+
 #ifdef __cplusplus
 extern "C" {
 #endif 
@@ -48,7 +57,7 @@ void act_init(struct robottype_orte_data *ortedata);
 void act_camera_on(void);
 void act_camera_off(void);
 
-void act_lift(uint16_t position, char speed);
+void act_lift(uint16_t req_pos, char speed, char homing);
 void act_jaws(jaws_cmds cmd);
 
 uint16_t act_jaw_left_get_last_reqest(void);
index 4b376ad9bea26c0594aa91b65dc3527a12265ad3..a63dc3c1b73770c629b55c9dd04ade5f7b697e80 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * homologation.cc       08/04/29
- * 
+ *
  * Robot's control program intended for homologation (approval phase) on Eurobot 2009.
  *
  * Copyright: (c) 2009 CTU Dragons
@@ -24,7 +24,6 @@
 #include <string.h>
 #include <robodim.h>
 #include <error.h>
-#include "corns_configs.h"
 #include "actuators.h"
 #include <trgen.h>
 #include "match-timing.h"
@@ -47,21 +46,21 @@ struct TrajectoryConstraints tcFast, tcSlow, tcVerySlow;
 FSM_STATE_DECL(init);
 FSM_STATE_DECL(wait_for_start);
 /* movement states */
-FSM_STATE_DECL(climb_the_slope);
-FSM_STATE_DECL(sledge_down);
-FSM_STATE_DECL(to_container_diag);
+FSM_STATE_DECL(aproach_first_fugure);
+FSM_STATE_DECL(load_first_figure);
+FSM_STATE_DECL(to_red_square);
 FSM_STATE_DECL(to_container_ortho);
-FSM_STATE_DECL(experiment_decider);
-FSM_STATE_DECL(approach_next_corn);
-FSM_STATE_DECL(rush_the_corn);
-FSM_STATE_DECL(turn_around);
-FSM_STATE_DECL(zvedej_vidle);
+// FSM_STATE_DECL(experiment_decider);
+// FSM_STATE_DECL(approach_next_corn);
+// FSM_STATE_DECL(rush_the_corn);
+// FSM_STATE_DECL(turn_around);
+// FSM_STATE_DECL(zvedej_vidle);
 
 /************************************************************************
  * INITIAL AND STARTING STATES
  ************************************************************************/
 
-FSM_STATE(init) 
+FSM_STATE(init)
 {
        switch (FSM_EVENT) {
                case EV_ENTRY:
@@ -75,7 +74,7 @@ FSM_STATE(init)
                        tcVerySlow = trajectoryConstraintsDefault;
                        tcVerySlow.maxv = 0.05;
                        tcVerySlow.maxacc = 0.05;
-                       
+
                        FSM_TRANSITION(wait_for_start);
                        break;
                default:
@@ -86,14 +85,18 @@ FSM_STATE(init)
 void set_initial_position()
 {
        //FIXME:
-       robot_set_est_pos_trans(ROBOT_AXIS_TO_FRONT_M,
-                               PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2),
-                               DEG2RAD(180));
+       robot_set_est_pos_trans(0.4 - ROBOT_AXIS_TO_FRONT_M,
+                               PLAYGROUND_HEIGHT_M - 0.21,
+                               0);
 }
 
 void actuators_home()
 {
-       act_vidle(VIDLE_UP, VIDLE_FAST_SPEED);
+       act_jaws(CLOSE);
+       // drive lift to home position
+       act_lift(0, 0, 1);
+       // unset the homing request
+       act_lift(0, 0, 0);
 }
 
 #ifdef COMPETITION
@@ -127,7 +130,7 @@ FSM_STATE(wait_for_start)
                        sem_post(&robot.start);
                        actuators_home();
                        set_initial_position();
-                       FSM_TRANSITION(climb_the_slope);
+                       FSM_TRANSITION(aproach_first_fugure);
                        break;
                case EV_TIMER:
                        FSM_TIMER(1000);
@@ -142,84 +145,75 @@ FSM_STATE(wait_for_start)
                case EV_RETURN:
                case EV_MOTION_ERROR:
                case EV_MOTION_DONE:
-               case EV_VIDLE_DONE:
+               //case EV_VIDLE_DONE:
                case EV_SWITCH_STRATEGY:
                        DBG_PRINT_EVENT("unhandled event");
                        break;
                case EV_EXIT:
-                       robot.corns = get_all_corns(robot.corns_conf_side, robot.corns_conf_center);
-
-                       /*
-                       //opras na testovani zluteho:
-                       robot_set_est_pos_trans(PLAYGROUND_WIDTH_M - ROBOT_AXIS_TO_FRONT_M,
-                                               PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2),
-                                               DEG2RAD(0));
-                       robot.team_color = YELLOW;
-                       */
                        break;
        }
 }
 
-FSM_STATE(zvedej_vidle)
-{
-       static int cnt = 0;
-       switch(FSM_EVENT) {
-               case EV_ENTRY:
-               case EV_TIMER:
-                       FSM_TIMER(500);
-                       act_vidle((VIDLE_UP - VIDLE_DOWN)*cnt/3 + VIDLE_DOWN, VIDLE_FAST_SPEED);
-                       ul_logdeb("--------------------cnt: %d\n", cnt);
-                       cnt++;
-                       if(cnt >= 3) {
-                               robot_exit();
-                               //FSM_TRANSITION(sledge_down);
-                       }
-                       break;
-               case EV_START:
-               case EV_RETURN:
-               case EV_VIDLE_DONE:
-               case EV_MOTION_DONE:
-               case EV_MOTION_ERROR:
-               case EV_SWITCH_STRATEGY:
-                       DBG_PRINT_EVENT("unhandled event");
-               case EV_EXIT:
-                       break;
-       }
-}
+// FSM_STATE(zvedej_vidle)
+// {
+//     static int cnt = 0;
+//     switch(FSM_EVENT) {
+//             case EV_ENTRY:
+//             case EV_TIMER:
+//                     FSM_TIMER(500);
+//                     act_vidle((VIDLE_UP - VIDLE_DOWN)*cnt/3 + VIDLE_DOWN, VIDLE_FAST_SPEED);
+//                     ul_logdeb("--------------------cnt: %d\n", cnt);
+//                     cnt++;
+//                     if(cnt >= 3) {
+//                             robot_exit();
+//                             //FSM_TRANSITION(sledge_down);
+//                     }
+//                     break;
+//             case EV_START:
+//             case EV_RETURN:
+//             case EV_VIDLE_DONE:
+//             case EV_MOTION_DONE:
+//             case EV_MOTION_ERROR:
+//             case EV_SWITCH_STRATEGY:
+//                     DBG_PRINT_EVENT("unhandled event");
+//             case EV_EXIT:
+//                     break;
+//     }
+// }
 
 /************************************************************************
  * MOVEMENT STATES
  ************************************************************************/
 
-FSM_STATE(climb_the_slope)
+FSM_STATE(aproach_first_fugure)
 {
        switch(FSM_EVENT) {
                case EV_ENTRY:
                        // disables using side switches on bumpers when going up
-                       robot.use_left_switch = false;
-                       robot.use_right_switch = false;
-                       act_vidle(VIDLE_DOWN, VIDLE_FAST_SPEED);
-                       robot.ignore_hokuyo = true;
-                       robot_trajectory_new_backward(&tcSlow);
+                       robot.use_left_bumper = false;
+                       robot.use_right_bumper = false;
+                       robot.use_back_bumpers = false;
+
+                       robot_trajectory_new(&tcSlow);
                        robot_trajectory_add_point_trans(
-                               0.5 - ROBOT_AXIS_TO_BACK_M,
-                               PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2));
-                       /* position for collecting oranges*/
+                               0.4+0.05+0.25,
+                               PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) - 0.05);
                        robot_trajectory_add_final_point_trans(
-                               SLOPE_TO_RIM_M + SLOPE_LENGTH_M - ROBOT_AXIS_TO_BACK_M + 0.05,
-                               PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) +0.01,
-                               NO_TURN());
+                               0.4+0.05+0.25,
+                               0.29+0.28+0.28,
+                               TURN_CCW(0));
                        break;
                case EV_MOTION_DONE:
-                       FSM_TIMER(2000);
-                       act_vidle(VIDLE_UP, VIDLE_FAST_SPEED);
+                       FSM_TIMER(3000);
+                       act_jaws(OPEN);
+                       //FSM_TRANSITION(load_first_figure);
                        break;
                case EV_START:
                case EV_TIMER:
-                       FSM_TRANSITION(sledge_down);
+                       FSM_TRANSITION(load_first_figure);
                        break;
                case EV_RETURN:
-               case EV_VIDLE_DONE:
+               //case EV_VI_DONE:
                case EV_MOTION_ERROR:
                case EV_SWITCH_STRATEGY:
                        DBG_PRINT_EVENT("unhandled event");
@@ -228,95 +222,58 @@ FSM_STATE(climb_the_slope)
        }
 }
 
-FSM_STATE(sledge_down)
+FSM_STATE(load_first_figure)
 {
        switch(FSM_EVENT) {
                case EV_ENTRY:
-                       robot_trajectory_new(&tcFast);
-                       robot_trajectory_add_point_trans(
-                               1 -ROBOT_AXIS_TO_BACK_M,
-                               PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2)+0.01);
-                       robot_trajectory_add_point_trans(
-                               SLOPE_TO_RIM_M - ROBOT_AXIS_TO_BACK_M - 0.26,
-                               PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2) - 0.10);
-                       robot_trajectory_add_final_point_trans(0.50, PLAYGROUND_HEIGHT_M - 0.6, NO_TURN());
+                       robot_trajectory_new_backward(&tcSlow);
+                       robot_trajectory_add_final_point_trans(
+                               0.2+0.1+ROBOT_AXIS_TO_BACK_M,
+                               0.29+0.28+0.28, NO_TURN());
                        break;
                case EV_MOTION_DONE:
-                       act_vidle(VIDLE_UP, VIDLE_FAST_SPEED);
-                       FSM_TRANSITION(to_container_diag);
-                       //FSM_TRANSITION(to_container_ortho);
+                       FSM_TIMER(2000);
+                       act_jaws(CATCH);
                        break;
                case EV_START:
                case EV_TIMER:
+                       FSM_TRANSITION(to_red_square);
                case EV_RETURN:
-               case EV_VIDLE_DONE:
+               //case EV_VIDLE_DONE:
                case EV_MOTION_ERROR:
                case EV_SWITCH_STRATEGY:
                        DBG_PRINT_EVENT("unhandled event");
                case EV_EXIT:
                        // enables using side switches on bumpers
-                       robot.use_left_switch = true;
-                       robot.use_right_switch = true;
-                       robot.ignore_hokuyo = false;
+                       //robot.use_left_switch = true;
+                       //robot.use_right_switch = true;
+                       //robot.ignore_hokuyo = false;
                        break;
        }
 }
 
-FSM_STATE(to_container_diag)
+FSM_STATE(to_red_square)
 {
        switch(FSM_EVENT) {
                case EV_ENTRY:
-                       robot_trajectory_new(&tcFast);
+                       robot_trajectory_new(&tcSlow);
                        // face the rim with front of the robot
                        //robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.12, ARRIVE_FROM(DEG2RAD(-90), 0.10));
                        // face the rim with back of the robot
-                       robot_trajectory_add_point_trans(PLAYGROUND_WIDTH_M-0.6, 0.35);
-                       robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, ARRIVE_FROM(DEG2RAD(90),0.05));
+                       //robot_trajectory_add_point_trans(0.4+0.05+0.2, 0.35+0.35+0.17);
+                       robot_trajectory_add_final_point_trans(0.4+0.05+0.2 + ROBOT_AXIS_TO_FIGURE_CENTER_M + 0.05, 0.35+0.35+0.17, NO_TURN());
                        break;
                case EV_MOTION_DONE:
-                       FSM_TIMER(6000);
-                       act_vidle(VIDLE_DOWN, VIDLE_FAST_SPEED);
+                       FSM_TIMER(5000);
+                       act_jaws(OPEN);
                        break;
                case EV_TIMER:
-                       act_vidle(VIDLE_UP, VIDLE_FAST_SPEED);
-                       FSM_TRANSITION(approach_next_corn);
-                       break;
-               case EV_START:
-               case EV_RETURN:
-               case EV_VIDLE_DONE:
-               case EV_MOTION_ERROR:
-               case EV_SWITCH_STRATEGY:
-                       DBG_PRINT_EVENT("unhandled event");
-               case EV_EXIT:
-                       break;
-       }
-}
-
-FSM_STATE(to_container_ortho)
-{
-       switch(FSM_EVENT) {
-               case EV_ENTRY:
-                       robot_trajectory_new(&tcFast);
-                       robot_trajectory_add_point_trans(
-                               SLOPE_TO_RIM_M - ROBOT_AXIS_TO_BACK_M - 0.15,
-                               PLAYGROUND_HEIGHT_M - 0.355);
-                       robot_trajectory_add_point_trans(0.55, PLAYGROUND_HEIGHT_M - 0.65);
-                       robot_trajectory_add_point_trans(0.90, PLAYGROUND_HEIGHT_M - 0.75);
-                       robot_trajectory_add_point_trans(PLAYGROUND_WIDTH_M - 0.60, PLAYGROUND_HEIGHT_M - 0.7);
-                       robot_trajectory_add_point_trans(PLAYGROUND_WIDTH_M - 0.35, PLAYGROUND_HEIGHT_M - 0.9);
-
-                       // face the rim with front of the robot
-                       //robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.12, ARRIVE_FROM(DEG2RAD(-90), 0.10));
-                       // face the rim with back of the robot
-                       robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.40, TURN_CCW(DEG2RAD(90)));
-                       break;
-               case EV_MOTION_DONE:
-                       act_vidle(VIDLE_DOWN, VIDLE_FAST_SPEED);
+                       //act_jaws(OPEN);
+                       //FSM_TRANSITION(wait_for_start);
                        break;
                case EV_START:
-               case EV_TIMER:
                case EV_RETURN:
-               case EV_VIDLE_DONE:
+               //case EV_VIDLE_DONE:
                case EV_MOTION_ERROR:
                case EV_SWITCH_STRATEGY:
                        DBG_PRINT_EVENT("unhandled event");
@@ -325,135 +282,135 @@ FSM_STATE(to_container_ortho)
        }
 }
 
-static enum where_to_go {
-       CORN,
-       TURN_AROUND,
-       CONTAINER,
-       NO_MORE_CORN
-} where_to_go = CORN;
-
-static struct corn *corn_to_get;
-
-FSM_STATE(experiment_decider)
-{
-       
-       switch(FSM_EVENT) {
-               case EV_ENTRY:
-                       if (where_to_go == CORN) {
-                               FSM_TRANSITION(approach_next_corn);
-                       } else if (where_to_go == CONTAINER) {
-                               FSM_TRANSITION(rush_the_corn);
-                       } else if (where_to_go == TURN_AROUND) {
-                               FSM_TRANSITION(turn_around);
-                       } else /* NO_MORE_CORN */ { 
-                       }
-                       break;
-               case EV_START:
-               case EV_TIMER:
-               case EV_RETURN:
-               case EV_VIDLE_DONE:
-               case EV_MOTION_DONE:
-               case EV_MOTION_ERROR:
-               case EV_SWITCH_STRATEGY:
-                       DBG_PRINT_EVENT("unhandled event");
-               case EV_EXIT:
-                       break;
-       }
-}
-
-static int cnt = 0;
-FSM_STATE(approach_next_corn)
-{
-       switch(FSM_EVENT) {
-               case EV_ENTRY: {
-                               double x, y, phi;
-                               robot_get_est_pos(&x, &y, &phi);
-                               ul_logdeb("approach_next_corn: puck cnt: %d, est pos %.3f, %.3f, %.3f\n",
-                                       cnt, x, y, phi);
-
-                               corn_to_get = choose_next_corn();
-                               if (corn_to_get) {
-                                       Pos *p = get_corn_approach_position(corn_to_get);
-                                       corn_to_get->was_collected = true;
-                                       //robot_trajectory_new(&tcFast);
-                                       //robot_trajectory_add_final_point_trans(robot_trajectory_add_final_point_trans(p->x, p->y, TURN(p->phi));
-                                       robot_goto_trans(p->x, p->y, TURN(p->phi), &tcFast);
-                                       delete(p);
-                                       where_to_go = CONTAINER;
-                               } else {
-                                       where_to_go = NO_MORE_CORN;
-                               }
-                               break;
-                       }
-               case EV_MOTION_DONE:
-                       cnt++;
-                       FSM_TRANSITION(experiment_decider);
-                       break;
-               case EV_START:
-               case EV_TIMER:
-               case EV_RETURN:
-               case EV_VIDLE_DONE:
-               case EV_MOTION_ERROR:
-               case EV_SWITCH_STRATEGY:
-                       DBG_PRINT_EVENT("unhandled event");
-               case EV_EXIT:
-                       break;
-       }
-}
-
-FSM_STATE(rush_the_corn)
-{
-       switch(FSM_EVENT) {
-               case EV_ENTRY:
-                       double x;
-                       if (robot.team_color == BLUE) {
-                               x = corn_to_get->position.x;
-                       } else {
-                               x = PLAYGROUND_WIDTH_M - corn_to_get->position.x;
-                       }
-                       ul_logdeb("x = %.3f, %.3f \n", x, corn_to_get->position.y);
-                       remove_wall_around_corn(x, corn_to_get->position.y);
-                       robot_goto_trans(PLAYGROUND_WIDTH_M - 0.4, 0.15, ARRIVE_FROM(DEG2RAD(-90), 0.02), &tcFast);
-                       where_to_go = TURN_AROUND;
-                       break;
-               case EV_MOTION_DONE:
-                       FSM_TRANSITION(experiment_decider);
-                       break;
-               case EV_START:
-               case EV_TIMER:
-               case EV_RETURN:
-               case EV_VIDLE_DONE:
-               case EV_MOTION_ERROR:
-               case EV_SWITCH_STRATEGY:
-                       DBG_PRINT_EVENT("unhandled event");
-               case EV_EXIT:
-                       break;
-       }
-}
-
-// used to perform the maneuvre
-FSM_STATE(turn_around)
-{
-       switch(FSM_EVENT) {
-               case EV_ENTRY:
-                       robot_trajectory_new_backward(&tcFast);
-                       robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, TURN_CCW(90));
-                       break;
-               case EV_MOTION_DONE:
-                       where_to_go = CORN;
-                       FSM_TRANSITION(experiment_decider);
-                       break;
-               case EV_START:
-               case EV_TIMER:
-               case EV_RETURN:
-               case EV_VIDLE_DONE:
-               case EV_MOTION_ERROR:
-               case EV_SWITCH_STRATEGY:
-                       DBG_PRINT_EVENT("unhandled event");
-               case EV_EXIT:
-                       break;
-       }
-}
+// static enum where_to_go {
+//     CORN,
+//     TURN_AROUND,
+//     CONTAINER,
+//     NO_MORE_CORN
+// } where_to_go = CORN;
+//
+// static struct corn *corn_to_get;
+//
+// FSM_STATE(experiment_decider)
+// {
+//
+//     switch(FSM_EVENT) {
+//             case EV_ENTRY:
+//                     if (where_to_go == CORN) {
+//                             FSM_TRANSITION(approach_next_corn);
+//                     } else if (where_to_go == CONTAINER) {
+//                             FSM_TRANSITION(rush_the_corn);
+//                     } else if (where_to_go == TURN_AROUND) {
+//                             FSM_TRANSITION(turn_around);
+//                     } else /* NO_MORE_CORN */ {
+//                     }
+//                     break;
+//             case EV_START:
+//             case EV_TIMER:
+//             case EV_RETURN:
+//             case EV_VIDLE_DONE:
+//             case EV_MOTION_DONE:
+//             case EV_MOTION_ERROR:
+//             case EV_SWITCH_STRATEGY:
+//                     DBG_PRINT_EVENT("unhandled event");
+//             case EV_EXIT:
+//                     break;
+//     }
+// }
+
+// static int cnt = 0;
+// FSM_STATE(approach_next_corn)
+// {
+//     switch(FSM_EVENT) {
+//             case EV_ENTRY: {
+//                             double x, y, phi;
+//                             robot_get_est_pos(&x, &y, &phi);
+//                             ul_logdeb("approach_next_corn: puck cnt: %d, est pos %.3f, %.3f, %.3f\n",
+//                                     cnt, x, y, phi);
+//
+//                             corn_to_get = choose_next_corn();
+//                             if (corn_to_get) {
+//                                     Pos *p = get_corn_approach_position(corn_to_get);
+//                                     corn_to_get->was_collected = true;
+//                                     //robot_trajectory_new(&tcFast);
+//                                     //robot_trajectory_add_final_point_trans(robot_trajectory_add_final_point_trans(p->x, p->y, TURN(p->phi));
+//                                     robot_goto_trans(p->x, p->y, TURN(p->phi), &tcFast);
+//                                     delete(p);
+//                                     where_to_go = CONTAINER;
+//                             } else {
+//                                     where_to_go = NO_MORE_CORN;
+//                             }
+//                             break;
+//                     }
+//             case EV_MOTION_DONE:
+//                     cnt++;
+//                     FSM_TRANSITION(experiment_decider);
+//                     break;
+//             case EV_START:
+//             case EV_TIMER:
+//             case EV_RETURN:
+//             case EV_VIDLE_DONE:
+//             case EV_MOTION_ERROR:
+//             case EV_SWITCH_STRATEGY:
+//                     DBG_PRINT_EVENT("unhandled event");
+//             case EV_EXIT:
+//                     break;
+//     }
+// }
+
+// FSM_STATE(rush_the_corn)
+// {
+//     switch(FSM_EVENT) {
+//             case EV_ENTRY:
+//                     double x;
+//                     if (robot.team_color == BLUE) {
+//                             x = corn_to_get->position.x;
+//                     } else {
+//                             x = PLAYGROUND_WIDTH_M - corn_to_get->position.x;
+//                     }
+//                     ul_logdeb("x = %.3f, %.3f \n", x, corn_to_get->position.y);
+//                     remove_wall_around_corn(x, corn_to_get->position.y);
+//                     robot_goto_trans(PLAYGROUND_WIDTH_M - 0.4, 0.15, ARRIVE_FROM(DEG2RAD(-90), 0.02), &tcFast);
+//                     where_to_go = TURN_AROUND;
+//                     break;
+//             case EV_MOTION_DONE:
+//                     FSM_TRANSITION(experiment_decider);
+//                     break;
+//             case EV_START:
+//             case EV_TIMER:
+//             case EV_RETURN:
+//             case EV_VIDLE_DONE:
+//             case EV_MOTION_ERROR:
+//             case EV_SWITCH_STRATEGY:
+//                     DBG_PRINT_EVENT("unhandled event");
+//             case EV_EXIT:
+//                     break;
+//     }
+// }
+
+// // used to perform the maneuvre
+// FSM_STATE(turn_around)
+// {
+//     switch(FSM_EVENT) {
+//             case EV_ENTRY:
+//                     robot_trajectory_new_backward(&tcFast);
+//                     robot_trajectory_add_final_point_trans(PLAYGROUND_WIDTH_M-0.35, 0.45, TURN_CCW(90));
+//                     break;
+//             case EV_MOTION_DONE:
+//                     where_to_go = CORN;
+//                     FSM_TRANSITION(experiment_decider);
+//                     break;
+//             case EV_START:
+//             case EV_TIMER:
+//             case EV_RETURN:
+//             case EV_VIDLE_DONE:
+//             case EV_MOTION_ERROR:
+//             case EV_SWITCH_STRATEGY:
+//                     DBG_PRINT_EVENT("unhandled event");
+//             case EV_EXIT:
+//                     break;
+//     }
+// }
 
 
 /************************************************************************
index 640211418e2a7324b90b06454d5ea90c0fd8ab1c..94f216596fbfd5204f40a69e529e4f1fc785896a 100644 (file)
@@ -88,6 +88,12 @@ void fill_in_known_areas_in_map()
        ShmapSetRectangleFlag(1.85, 0, 2.55, 0.12, MAP_FLAG_WALL, 0);
        ShmapSetRectangleFlag(1.85, 0.12, 1.872, 0.25, MAP_FLAG_WALL, 0);
        ShmapSetRectangleFlag(2.528, 0.12, 2.55, 0.25, MAP_FLAG_WALL, 0);
+
+       /* playing area walls */
+       ShmapSetRectangleFlag(0, 0, PLAYGROUND_WIDTH_M, 0.1, MAP_FLAG_IGNORE_OBST, 0);
+       ShmapSetRectangleFlag(PLAYGROUND_WIDTH_M, 0, PLAYGROUND_WIDTH_M - 0.1, PLAYGROUND_HEIGHT_M, MAP_FLAG_IGNORE_OBST, 0);
+       ShmapSetRectangleFlag(0 ,PLAYGROUND_HEIGHT_M, PLAYGROUND_WIDTH_M, PLAYGROUND_HEIGHT_M - 0.1, MAP_FLAG_IGNORE_OBST, 0);
+       ShmapSetRectangleFlag(0 , 0, 0.1, PLAYGROUND_HEIGHT_M, MAP_FLAG_IGNORE_OBST, 0);
 }
 
 static void trans_callback(struct robo_fsm *fsm)
index 7c078e4f1266edf93a7aa4675e588879069264e7..0ee213b3a1a1d3800b3d2d4044bb682da21d6529 100644 (file)
@@ -150,11 +150,10 @@ void rcv_motion_irc_cb(const ORTERecvInfo *info, void *vinstance,
        double dleft, dright, dtang, dphi;
        static bool first_run = true;
        /* spocitat prevodovy pomer */
-       const double n = (double)(28.0 / 1.0); 
+       const double n = (double)(29.0 / 1.0);
 
        /* vzdalenost na pulz IRC */
-       const double c = (M_PI*2*ROBOT_WHEEL_RADIUS_M) / (n * 4*500.0);
-       
+       const double c = (M_PI*2*ROBOT_WHEEL_RADIUS_M) / (n * 4*512.0);
        switch (info->status) {
                case NEW_DATA:
                        if (first_run) {
@@ -165,8 +164,9 @@ void rcv_motion_irc_cb(const ORTERecvInfo *info, void *vinstance,
                                break;
                        }
                        
-                       dleft = ((robot.motion_irc.left - instance->left) >> 8) * c;
-                       dright = ((instance->right - robot.motion_irc.right) >> 8) * c;
+
+                       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);