]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
Merge branch 'master' of sojka@rtime.felk.cvut.cz:/var/git/eurobot
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 24 Apr 2009 04:53:51 +0000 (06:53 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 24 Apr 2009 04:53:51 +0000 (06:53 +0200)
Conflicts:
src/types/robottype.idl

15 files changed:
src/camera/rozpuk/Makefile.omk
src/camera/rozpuk/hue.c
src/camera/rozpuk/rozpuk.c
src/cand/cand.cc
src/common/can_ids.h
src/eb_sberac_09/Makefile.omk
src/eb_sberac_09/main.c
src/robofsm/actuators.h
src/robofsm/fsmact.c
src/robofsm/robot.c
src/robofsm/robot.h
src/robofsm/robot_orte.c
src/robofsm/test/test_actuators.cc
src/types/robottype.idl
src/types/robottype.ortegen

index a2b5a69b7c7b1288192d963cc715ebfe46f900e9..24f18e8d9b6bcd3cdca22e706bb98e20ac39e762 100644 (file)
@@ -2,7 +2,7 @@
 
 bin_PROGRAMS = rozpuk camgrab
 
-rozpuk_SOURCES = rozpuk.c camera.c decjpeg.c hue.c likelimg.c
-rozpuk_LIBS = jpeg robodim
+rozpuk_SOURCES = rozpuk.c camera.c decjpeg.c hue.c likelimg.c rozporte.c
+rozpuk_LIBS = jpeg robodim pthread roboorte robottype robottype orte
 
 camgrab_SOURCES = camgrab.c camera.c
\ No newline at end of file
index 902c67ed60303999b6b1288ee145962dc517052a..3b021778c167dc30fee92707d17b76439ba09589 100644 (file)
@@ -45,7 +45,9 @@ void image_threshold(uint8_t *img, char *bitmap, unsigned length,
   for (ip = ib = 0; ip < length; ib++) {
     bitmap[ib] = 0;
     for (b = 1<<7; b; b >>= 1, ip++)
-      if ((img[ip] < t1) || (img[ip] > t2))
+      if ((t2 > t1)
+         ? ((img[ip] < t1) || (img[ip] > t2))
+         : ((img[ip] > t2) && (img[ip] < t1)))
        bitmap[ib] += b;
   }
 }
index bcbc72385fffb372ff78dcf3ea51e2913896b448..b3269a288dd3a4f5d0dc5d0bfd1ddcf92c55db58 100644 (file)
@@ -1,6 +1,7 @@
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <semaphore.h>
 #include <getopt.h>
 
 #include <robodim.h>
 #include "decjpeg.h"
 #include "hue.h"
 #include "likelimg.h"
+#include "rozporte.h"
 
-#define N_LOTS        10
-#define HUE_THR_LOW   106
-#define HUE_THR_HIGH  235
+#define N_LOTS                 10
+#define DEFAULT_HUE_THR_FROM  106
+#define DEFAULT_HUE_THR_TO    235
 
 #define HUE_SIZE (IMG_WIDTH*IMG_HEIGHT)
 #define RGB_SIZE (2*HUE_SIZE*3)
 
 
 pdfmask_t pdf_green[N_SPOTS], pdf_red[N_SPOTS];
+uint8_t hue_thr_from = DEFAULT_HUE_THR_FROM, hue_thr_to = DEFAULT_HUE_THR_TO;
 uint8_t rgb[RGB_SIZE], hue[HUE_SIZE];
 char bitmap[HUE_SIZE/8];
+/* show opts */
+int show_skip = 15, show_rgb = 0, show_proc = 0;
 
 
 void process_jpeg_frame(void *jpeg) {
   jpeg_decode(jpeg, JPEG_SIZE, rgb, RGB_SIZE, NULL, NULL);
 }
 
-int rozpuk(pdfmask_t *pdf) {
+int recognize_lot(pdfmask_t *pdf) {
   double W[N_SPOTS], L[N_LOTS], max = -1;
   int i, j, k, lot = 0;
   char b;
@@ -65,52 +70,115 @@ int rozpuk(pdfmask_t *pdf) {
   return lot;
 }
 
+void rozpuk() {
+  int lot;
+
+  sem_init(&running_sem, 0, 0);
+
+  for (;;) {
+    while (camera_on("/dev/video0", 640, 480, V4L2_PIX_FMT_MJPEG)) {
+      perror("camera_on");
+      usleep(500*1000);
+    }
+
+    while (running) {
+      camera_get_frame(process_jpeg_frame, 1000 /* msec */);
+      image_hue(rgb, hue, 320*480);
+      image_threshold(hue, bitmap, 320*480, hue_thr_from, hue_thr_to);
+      lot = recognize_lot((game_color == 0) ? pdf_green : pdf_red);
+      orte_send(lot);
+      printf("(%s) %2d\n", game_color?"RED":"GREEN", 1+lot);
+    }
+
+    camera_off();
+    while (!running)
+      sem_wait(&running_sem);
+  }
+}
+
+/* debug: grab/process image */
+void show() {
+  int i, j, k, tmp, lot;
+
+  while (camera_on("/dev/video0", 640, 480, V4L2_PIX_FMT_MJPEG)) {
+    perror("camera_on");
+    usleep(500*1000);
+  }
+
+  for (i = 0; i < show_skip; i++)
+    camera_get_frame(NULL, 0);
+  
+  camera_get_frame(process_jpeg_frame, 0);
+  image_hue(rgb, hue, 320*480);
+  image_threshold(hue, bitmap, 320*480, hue_thr_from, hue_thr_to);
+
+  if (show_rgb) {
+    printf("P6\n640 480\n255\n");
+    fwrite(rgb, 640*480*3, 1, stdout);
+  }
+  if (show_proc) {
+    printf("P6\n320 480\n255\n");
+    for (i = j = 0; i < 320*480; i++, j += 3) {
+      rgb[j] = hue[i];
+      rgb[j+1] = 0;
+      rgb[j+2] = (bitmap[i/8] & (1<<(7-(i%8)))) ? 255 : 0;
+    }
+    fwrite(rgb, 320*480*3, 1, stdout);
+  }
+
+  lot = recognize_lot((game_color == 0) ? pdf_green : pdf_red);
+  fprintf(stderr, "%2d\n", 1+lot);
+}
+
 int main(int argc, char *argv[]) {
   FILE *f;
-  int i, lot;
-  int do_grab = 0, do_hue = 0;
+  int opt, tmp, do_show;
 
-  if (argc > 1) {
-    switch (argv[1][0]) {
-    case 'g':
-      do_grab = 1;
-      break;
+  while ((opt = getopt(argc, argv, "c:s:rp")) != -1)
+    switch (opt) {
     case 'c':
-      do_hue = 1;
+      game_color = atoi(optarg);
+      fprintf(stderr, "selected %s game color\n", game_color?"RED":"GREEN");
+      break;
+    case 's':
+      if (optarg != NULL)
+       show_skip = atoi(optarg);
+      break;
+    case 'r':
+      show_rgb = 1;
+      break;
+    case 'p':
+      show_proc = 1;
       break;
     }
+  if (optind + 1 < argc) {
+    tmp = atoi(argv[optind]);
+    if ((tmp >= 0) && (tmp < 256))
+      hue_thr_from = (uint8_t)tmp;
+    tmp = atoi(argv[optind+1]);
+    if ((tmp >= 0) && (tmp < 256))
+      hue_thr_to = (uint8_t)tmp;
+    fprintf(stderr, "hue thr: %d/%d\n", hue_thr_from, hue_thr_to);
   }
+  do_show = show_rgb || show_proc;
 
-  f = fopen("pdfmask.bin", "rb");
-  pdfmask_load_all(f, pdf_green);
-  //pdfmask_load_all(f, pdf_red);
+  while (((f = fopen("pdfmask.bin", "rb")) == NULL) ||
+        pdfmask_load_all(f, pdf_green) ||
+        pdfmask_load_all(f, pdf_red)) {
+    perror("pdfmask.bin: fopen/pdfmask_load_all");
+    usleep(250*1000);
+  }
   fclose(f);
 
-  camera_on("/dev/video0", 640, 480, V4L2_PIX_FMT_MJPEG);
-
-  for (i = 0;;) {
-    camera_get_frame(process_jpeg_frame, 0);
-    image_hue(rgb, hue, 320*480);
-
-    if (do_grab || do_hue) {
-      if (i++ > 15) {
-       if (do_grab) {
-         printf("P6\n640 480\n255\n");
-         fwrite(rgb, 640*480*3, 1, stdout);
-       }
-       if (do_hue) {
-         printf("P5\n320 480\n255\n");
-         fwrite(hue, 320*480, 1, stdout);
-       }
-       return 0;
-      }
-    }
-    else {
-      image_threshold(hue, bitmap, 320*480, HUE_THR_LOW, HUE_THR_HIGH);
-      lot = rozpuk(pdf_green);
-      printf("%2d\n", 1+lot);
-    }
+  while (orte_init() && !do_show) {
+    perror("orte_init");
+    usleep(500*1000);
   }
 
+  if (do_show)
+    show();
+  else
+    rozpuk();
+
   return 0;
 }
index 7b820380bcab5de29b20d3db8830be86f882ba2c..d5378a21c5c1b8ab34f829052384434d9494e14e 100644 (file)
@@ -331,9 +331,9 @@ int cand_parse_frame(struct robottype_orte_data *orte, struct can_frame frame)
                        ORTEPublicationSend(orte->publication_actuator_status);
                        break;
                /* laser data */
-               case CAN_CMU:
-                       orte->cmu.color = frame.data[0];
-                       ORTEPublicationSend(orte->publication_cmu);
+               case CAN_PUCK:
+                       orte->puck_inside.status = frame.data[0];
+                       ORTEPublicationSend(orte->publication_puck_inside);
                        break;
 
                default:
@@ -532,11 +532,11 @@ int main(int argc, char *argv[])
        robottype_publisher_motion_status_create(&orte, NULL, NULL);
        robottype_publisher_motion_irc_create(&orte, NULL, NULL);
        robottype_publisher_robot_cmd_create(&orte, NULL, NULL);
-       robottype_publisher_cmu_create(&orte, NULL, NULL);
        robottype_publisher_corr_trig_create(&orte, NULL, NULL);
        robottype_publisher_corr_distances_create(&orte, NULL, NULL);
        robottype_publisher_puck_distance_create(&orte, NULL, NULL);
        robottype_publisher_actuator_status_create(&orte, NULL, NULL);
+       robottype_publisher_puck_inside_create(&orte, NULL, NULL);
        printf("Publishers OK\n");
 
        /* creating subscribers */
index 8bb037ee48022e455abb93ee9f1afc7dcd48e692..821b08e74b9e4ceee74b719b2f030d87f7c42543 100644 (file)
                                        /* spodni 3 bity: zapnout. dalsi 3 b zapnout */
 
 #define CAN_PWR_ADC1 to_boa(0x41)      /* PER->BOA */
-
 #define CAN_PWR_ADC2 to_boa(0x42)      /* PER->BOA */
                                        /* napeti na jednotlivych vetvich, 4B hodnoty */
 
 //#define CAN_BRUSHES_STATUS   to_boa(0x44)    // FIXME: (F.J.) rename me, ...
 
+#define CAN_PUCK               to_boa(0x43)
+
+
 #define CAN_CMU                        to_boa(0x46)            /* PER->BOA */
 #define CAN_HOKUYO_PITCH       to_per(0x47)            /* BOA->PER */
 
 //#define CAN_ERROR            to_boa(0x48)    // FIXME: (F.J.) rename me, ...
 
+
+
 #define CAN_LP_CMD             to_per(0x80)    // lift + pusher command    
 #define CAN_LP_STATUS          to_boa(0x49)    // Lift + Pusher Status   2B pusher position + 2B lift position + 1B status
 #define CAN_LIFT               to_per(0x4A) /**< BOA->PER @copydetails set_lift()*/
index c057a3cd1ca98e5cdcbeaba540a8012a662d87b2..5afec76ed50fa62745f7ba012dc209905e0c281e 100644 (file)
@@ -5,4 +5,6 @@ bin_PROGRAMS = eb_sberac_09
 eb_sberac_09_SOURCES = main.c 
 eb_sberac_09_LIBS = can ebb uart_nozen
 
+link_VARIANTS = flash
+
 
index bdf0c061070228d9f3768742505beba432cefe87..81f4b85e6df35b27c038ea676f5676d0a754ae18 100644 (file)
@@ -73,7 +73,7 @@
 
 
 
-#define START_TIME     50
+#define START_TIME     16
 
 
 
@@ -189,7 +189,7 @@ void go_to_sleep()
        deb_led_off(LEDY);
        deb_led_off(LEDB);
        deb_led_off(LEDG);
-       deb_led_on(LEDR);
+//     deb_led_on(LEDR);
        PCON = 2;                               // bye bye 
 }
 
@@ -203,9 +203,7 @@ void can_rx(can_msg_t *msg) {
        switch (rx_msg.id) {            
                case CAN_CHELAE:
                        deb_led_on(LEDB);
-                       time_timeout = time_ms + TIMEOUT_DELAY;
-                       deb_led_off(LEDY);
-                       
+                       time_timeout = time_ms + TIMEOUT_DELAY;                 
                        set_servo(CHELAE_L , CHELAE_L_MIN + rx_msg.data[0] * (CHELAE_L_MAX - CHELAE_L_MIN)/255 );
                        set_servo(CHELAE_R , CHELAE_R_MIN + (0xFF - rx_msg.data[1]) * (CHELAE_R_MAX - CHELAE_R_MIN)/255 );
 
@@ -221,7 +219,6 @@ void can_rx(can_msg_t *msg) {
                        
                        deb_led_on(LEDB);
                        time_timeout = time_ms + TIMEOUT_DELAY;
-                       deb_led_off(LEDY);
                        set_pwm(PWM_CHAN_B, rx_msg.data[0]);
                        set_pwm(PWM_CHAN_A, rx_msg.data[1]);
                        break;
@@ -278,26 +275,65 @@ void init_perip(void)        // inicializace periferii mikroprocesoru
 
 void timeout(void)
 {
-       set_servo(CHELAE_L , CHELAE_L_MIN) ;
-       set_servo(CHELAE_R , CHELAE_R_MAX) ;
-       set_servo(HOKUYO , HOKUYO_AHEAD) ;
+//     set_servo(CHELAE_L , CHELAE_L_MIN) ;
+//     set_servo(CHELAE_R , CHELAE_R_MAX) ;
+//     set_servo(HOKUYO , HOKUYO_AHEAD) ;
        engine_A_pwm(0);
        engine_B_pwm(0);
 }
 
 
 
+#define PUCK_PIN       18      // MISO1
+uint32_t time_puck = 0;
+#define  PUCK_TIME     50
+
+void puck_switch(void)
+{
+    if (time_puck == 0) time_puck= time_ms + PUCK_TIME;        
+    
+    if (time_ms > time_puck)
+    {
+      time_puck = time_ms + PUCK_TIME;
+      
+      can_msg_t msg_puck; 
+       msg_puck.id = CAN_PUCK;
+       msg_puck.dlc = 1;
+       
+      if(IO0PIN & (1<< PUCK_PIN))
+      {
+       msg_puck.data[0] = 0;
+       deb_led_off(LEDR);
+      }
+      else
+      {
+       msg_puck.data[0] = 1;
+       deb_led_on(LEDR);
+      }
+      
+      while (can_tx_msg(&msg_puck));
+       
+    }
+}
+
+
 uint8_t start_bt = 0;
 uint32_t time_start = 0;
+uint8_t start_cnt = 0;
 #define START_PIN      15              // start pin
 
 void start_button(void)
 {
        if (start_bt > 10) 
        {
-               if ((IO0PIN & (1<<START_PIN))==0) start_bt=0;
+               if ((IO0PIN & (1<<START_PIN))==0) 
+               {       
+                 start_bt = 0;
+                 start_cnt = 0;
+               }
                return;
        }
+       
        if (time_start == 0) time_start = time_ms + START_TIME; 
        
        
@@ -308,20 +344,24 @@ void start_button(void)
                
                if (IO0PIN & (1<<START_PIN)) 
                {
-                       ++start_bt;
-                       msg.data[0] = 1;
-                       deb_led_off(LEDY);
+                       ++start_cnt;
+                       if(start_cnt > 3)
+                       {
+                         ++start_bt;
+                         msg.data[0] = 1;
+                         deb_led_off(LEDY);
+                       }
                }
                else 
                {
                        deb_led_on(LEDY);
                        msg.data[0] = 0;
+                       start_cnt = 0;
                }
 
                msg.id = CAN_ROBOT_CMD;
                msg.flags = 0;
                msg.dlc = 1;
-               //msg.data[0] = (~(IO0PIN >> START_PIN)) & 1;
                while (can_tx_msg(&msg));
        }
 }
@@ -355,18 +395,20 @@ int main (void)  {
 
        
        SET_PIN(PINSEL0, START_PIN, PINSEL_0);
+       SET_PIN(PINSEL1, (PUCK_PIN - 15), PINSEL_0);
 
        while(1)
        {
 
-//             if( time_ms > time_timeout) 
-//             {
-//                     timeout();
-//                     deb_led_on(LEDY);
-//             }
+               if( time_ms > time_timeout) 
+               {
+                       timeout();
+                       //deb_led_on(LEDY);
+               }
                start_button();
                led_blik(LEDG);
                send_adc();
+               puck_switch();
 
                if(adc_update_adc & 1)  adc_filter(0);
                if(adc_update_adc & 2)  adc_filter(1);
index 541db7f392700162d6a29b667b2993dffaef8d40..1e97b30c155438c43d13e8b013393f9c4706a070 100644 (file)
@@ -48,8 +48,9 @@ of the robot.
 
 #define LIFT_SHIFT             0x1C
 /* Positions of lift */
+#define LIFT_MIN               0x0
 #define LIFT_GROUND_POS                0x0028 // used for pucks loading
-#define LIFT_TRAVEL_POS                0x0040
+#define LIFT_TRAVEL_POS                0x0030
 #define LIFT_BELOW_HOLDER_POS  0x00E0
 #define LIFT_IN_HOLDER_POS     0x0118
 #define LIFT_FLOOR0            0x0030 // used for unloading
index 402808c43f93a949cd53b284b960b881e4340d45..f7352e69d4e3c63081df66744aca554f44b3bff4 100644 (file)
@@ -23,7 +23,7 @@ typedef enum {
 BASIC_LIFT_POSITION basic_lift_position = HIGH;
 int pucks_loaded = 0;
 bool lintel_present = 1;
-unsigned char floor_to_unload;
+int floor_to_unload;
 
 /************************************************************
  *  STATE DECLARATIONS
@@ -48,7 +48,7 @@ FSM_STATE(wait_for_command)
 {
        switch (FSM_EVENT) {
        case EV_ENTRY:
-               printf("wait_for_command_state_entered\n");
+               printf("wait_for_command_state_entered, number of pucks stored: %d\n", pucks_loaded);
                // put all actuators to defined initial positions
                act_belts(BELTS_OFF, BELTS_OFF);
                if (pucks_loaded<4) {
@@ -60,18 +60,18 @@ FSM_STATE(wait_for_command)
                act_lift(basic_lift_position);
                switch(basic_lift_position) {
                case (LOW):
-                       printf("basic lift position set to LOW");
+                       printf("basic lift position set to LOW\n");
                        break;
                case (HIGH):
-                       printf("basic lift position set to HIGH");
+                       printf("basic lift position set to HIGH\n");
                        break;
                }
                act_pusher(PUSHER_INSIDE);
                act_hokuyo(HOKUYO_PITCH_HORIZONTAL);
                break;
        case EV_PREPARE_FOR_LOAD:
-               basic_lift_position = HIGH;
-               FSM_TRANSITION(wait_for_command);
+               //basic_lift_position = LOW;
+               //FSM_TRANSITION(wait_for_command);
                break;
        case EV_SCRABBLE:
                FSM_TRANSITION(scrabble);
@@ -199,20 +199,21 @@ FSM_STATE(suck_the_puck)
        static int timer_arrival_count;
        switch (FSM_EVENT) {
        case EV_ENTRY:
+               act_lift(LIFT_MIN);
+       case EV_LIFT_IN_POS:
                timer_arrival_count = 0;
                printf("suck_the_puck state entered\n");
-               FSM_TIMER(2000);
+               FSM_TIMER(800);
+               //FSM_TIMER(2000);
                act_chelae(CHELA_TIGHT, CHELA_TIGHT);
                act_belts(BELTS_IN, BELTS_IN);
                break;
        case EV_PUCK_INSIDE:
+       case EV_TIMER:
                printf("puck inside\n");
-               act_belts(BELTS_OFF, BELTS_OFF);
-               act_chelae(CHELA_OPEN, CHELA_OPEN);
-               act_holder(HOLDER_OPENED);
                FSM_TRANSITION(store_pucks_in_holder);
                break;
-       case EV_TIMER:
+       /*case EV_TIMER:
                switch (timer_arrival_count) {
                case 0:
                        act_belts(BELTS_OUT, BELTS_OUT);
@@ -227,11 +228,10 @@ FSM_STATE(suck_the_puck)
                        FSM_TRANSITION(wait_for_command);
                        break;
                }
-               timer_arrival_count++;
+               timer_arrival_count++; */
                break;
        case EV_RETURN:
        case EV_LOAD_THE_PUCK:
-       case EV_LIFT_IN_POS:
        case EV_PUSHER_IN_POS:
        case EV_PREPARE_THE_UNLOAD:
        case EV_UNLOAD_PUCKS:
@@ -252,8 +252,10 @@ FSM_STATE(store_pucks_in_holder)
        static int i;
        switch (FSM_EVENT) {
        case EV_ENTRY:
+               act_holder(HOLDER_OPENED);
                if (pucks_loaded > 2) {
                        pucks_loaded++; // FIXME: (?) change this variable only here in this state?
+                       basic_lift_position = HIGH;
                        FSM_TRANSITION(wait_for_command);
                        FSM_SIGNAL(MAIN, EV_ACTION_DONE, (void*)pucks_loaded);
                } else {
@@ -270,6 +272,7 @@ FSM_STATE(store_pucks_in_holder)
                        break;
                case 1:
                        pucks_loaded++; // FIXME: (?) change this variable in EV_ENTRY and only in one place?
+                       basic_lift_position = HIGH;
                        FSM_TRANSITION(wait_for_command);
                        FSM_SIGNAL(MAIN, EV_ACTION_DONE, (void*)pucks_loaded);
                }
@@ -301,6 +304,7 @@ FSM_STATE(unload_pucks)
 {
        switch (FSM_EVENT) {
        case EV_ENTRY:
+               act_chelae(CHELA_OPEN, CHELA_OPEN);
                printf("unloading pucks\n");
                if (pucks_loaded < 4) {
                        act_lift(LIFT_BELOW_HOLDER_POS);
index d0d9d04e8310fdd9ac74969e329790f3aaf9e772..2419d2af09497c25850e642ffd6768e8f6dfaf23 100644 (file)
@@ -255,6 +255,9 @@ void robot_exit()
 void robot_destroy()
 {
        motion_control_done();
+
+       act_chelae(CHELA_OPEN, CHELA_OPEN);
+       act_holder(HOLDER_OPENED);
        
        robottype_roboorte_destroy(&robot.orte);
 
index 0d23627dc84dc38de7b5cfa282e18cfa85aac048..0cefd7b4f35263c1a0b4f4bc56b6e1490b47ccd9 100644 (file)
@@ -114,6 +114,7 @@ extern struct lock_log robot_lock_log;
 #define __robot_lock_disp              lock_disp
 #define __robot_lock_motion_irc         lock
 #define __robot_lock_corr_distances     lock
+#define __robot_lock_camera_result      lock_camera
 
 /* robot's main data structure */
 struct robot {
@@ -123,6 +124,7 @@ struct robot {
        pthread_mutex_t lock_meas_angles;
        pthread_mutex_t lock_joy_data;
        pthread_mutex_t lock_disp;
+       pthread_mutex_t lock_camera;
 
        /* competition parameters */
         enum team_color team_color;
@@ -173,7 +175,6 @@ struct robot {
        double puck_distance;   /* sharp sensor to puck distance in meters */
 
        struct hokuyo_scan_type hokuyo;
-       struct cmu_type cmu;
 
        struct map *map;        /* Map for pathplanning (no locking) */
 
index facf8a27b34e96c2d803dac5678930165857b363..d54c1c422d45457c4553aa867fec4ebee3fd1100 100644 (file)
@@ -230,6 +230,24 @@ void rcv_hokuyo_scan_cb(const ORTERecvInfo *info, void *vinstance,
                        break;
        }
 }
+
+void rcv_camera_result_cb(const ORTERecvInfo *info, void *vinstance,
+                       void *recvCallBackParam)
+{
+       struct camera_result_type *instance = (struct camera_result_type *)vinstance;
+
+       switch (info->status) {
+               case NEW_DATA: {
+                       ROBOT_LOCK(camera_result);
+                       robot.game_conf = instance->lot;
+                       ROBOT_UNLOCK(camera_result);
+                       break;
+               }
+               case DEADLINE:
+                       DBG("%s: ORTE deadline occurred\n", __FUNCTION__);
+                       break;
+       }
+}
 /* ---------------------------------------------------------------------- 
  * SUBSCRIBER CALLBACKS - EB2008
  * ---------------------------------------------------------------------- */
@@ -293,39 +311,22 @@ void rcv_puck_distance_cb(const ORTERecvInfo *info, void *vinstance,
        }
 }
 
-#if 0
-void rcv_cmu_cb(const ORTERecvInfo *info, void *vinstance,
-                       void *recvCallBackParam)
+void rcv_puck_inside_cb(const ORTERecvInfo *info, void *vinstance,
+                           void *recvCallBackParam)
 {
-       struct cmu_type *instance = (struct cmu_type *)vinstance;
-       static enum ball_color last_color = NO_BALL;
-       static unsigned char first = 1;
-
+       static bool previous_switch_status;
        switch (info->status) {
-               case NEW_DATA: {
-                       ROBOT_LOCK(cmu);
-                       robot.cmu = *instance;
-                       ROBOT_UNLOCK(cmu);
-                       if (first) {
-                               last_color = robot.cmu.color;
-                               first = 0;
-                       }
-                       if (robot.cmu.color != NO_BALL) {
-                               if (last_color != robot.cmu.color) {
-                                       last_color = robot.cmu.color;
-                                       //FSM_SIGNAL(MAIN, EV_BALL_INSIDE, NULL);
-                               }
-                       }
-                       robot.hw_status[STATUS_CMU] = HW_STATUS_OK;
-                       break;
+       case NEW_DATA: {
+                       if (robot.orte.puck_inside.status == 1 && previous_switch_status != 1)
+                               FSM_SIGNAL(ACT, EV_PUCK_INSIDE, NULL);
+                       previous_switch_status = robot.orte.puck_inside.status;
                }
-               case DEADLINE:
-                       robot.hw_status[STATUS_CMU] = HW_STATUS_FAILED;
-                       DBG("%s: ORTE deadline occurred\n", __FUNCTION__);
-                       break;
+               break;
+       case DEADLINE:
+               DBG("ORTE deadline occurred - servos receive\n");
+               break;
        }
 }
-#endif
 
 #define HIST_CNT 5
 #if 0
@@ -370,6 +371,7 @@ int robot_init_orte()
        robottype_publisher_fsm_main_create(&robot.orte, send_dummy_cb, &robot.orte);
        robottype_publisher_fsm_act_create(&robot.orte, send_dummy_cb, &robot.orte);
        robottype_publisher_fsm_motion_create(&robot.orte, send_dummy_cb, &robot.orte);
+       robottype_publisher_camera_control_create(&robot.orte, send_dummy_cb, &robot.orte);
 
        /* create generic subscribers */
        robottype_subscriber_motion_irc_create(&robot.orte, rcv_motion_irc_cb, &robot.orte);
@@ -377,14 +379,15 @@ int robot_init_orte()
        robottype_subscriber_motion_status_create(&robot.orte, rcv_motion_status_cb, &robot.orte);
        robottype_subscriber_corr_distances_create(&robot.orte, rcv_corr_distances_cb, &robot.orte);
        robottype_subscriber_pwr_voltage_create(&robot.orte, rcv_pwr_voltage_cb, &robot.orte);
-       robottype_subscriber_pwr_ctrl_create(&robot.orte, rcv_pwr_ctrl_cb, &robot.orte);
+       //robottype_subscriber_pwr_ctrl_create(&robot.orte, rcv_pwr_ctrl_cb, &robot.orte);
        robottype_subscriber_robot_cmd_create(&robot.orte, rcv_robot_cmd_cb, &robot.orte);
        robottype_subscriber_hokuyo_scan_create(&robot.orte, rcv_hokuyo_scan_cb, &robot.orte);
 
        /* create subscribers */
        robottype_subscriber_actuator_status_create(&robot.orte, rcv_actuator_status_cb, &robot.orte);
-       robottype_subscriber_puck_distance_create(&robot.orte, rcv_puck_distance_cb, &robot.orte);
-       //robottype_subscriber_cmu_create(&robot.orte, rcv_cmu_cb, &robot.orte);
+       //robottype_subscriber_puck_distance_create(&robot.orte, rcv_puck_distance_cb, &robot.orte);
+       robottype_subscriber_puck_inside_create(&robot.orte, rcv_puck_inside_cb, &robot.orte);
+       robottype_subscriber_camera_result_create(&robot.orte, rcv_camera_result_cb, &robot.orte);
 
        return rv;
 }
index 54d7cdb9f583a9907ec3fee9285d40b9b3ed6ad2..fcbd84de5857aa9cce6593028a5684b9ceb62d70 100644 (file)
@@ -136,7 +136,7 @@ void * handle_keyboard(void *)
                case 'p' : 
                case 'P' :
                        printf("Sending 'EV_PREPARE_THE_UNLOAD' event to the act fsm\n");
-                       FSM_SIGNAL(ACT, EV_PREPARE_THE_UNLOAD, NULL);
+                       FSM_SIGNAL(ACT, EV_PREPARE_THE_UNLOAD, (void*) floor);
                        break;
                case 'u' : 
                case 'U' :
@@ -149,13 +149,11 @@ void * handle_keyboard(void *)
                }
                fflush(stdout);
        }
-       robot_destroy();
        return NULL;
 }
 
 int main()
 {
-
        terminal_setup(); // disable canonical end echo modes of the terminal
 
        pthread_attr_t tattr;
@@ -176,13 +174,14 @@ int main()
 
        robot.fsm.main.debug_states = 0;
        robot.fsm.motion.debug_states = 0;
-       robot.fsm.act.debug_states = 0;
+       robot.fsm.act.debug_states = 1;
 
        robot.fsm.main.state = &fsm_state_main_just_receive_events;
 
         rv = robot_start();
        if (rv) error(1, errno, "robot_start() returned %d\n", rv);
 
+       robot_destroy();
 
        terminal_cleanup(); // reset terminal mode to the original state
 
index 832b5cc9f4899865280b8cc88ab754ea4d9d5be9..ba57e4ff0cc41f23ecd0e35007516a9a8a4b60ef 100644 (file)
@@ -150,3 +150,6 @@ struct camera_result {
     octet lot;
 };
 
+struct puck_inside {
+    octet status;
+};
index 0d868389ca6d1810e2f91de7ff7805aeec3e8146..9a12135ac3c84e0c03688dd7de57e6680f9440ec 100644 (file)
@@ -22,6 +22,9 @@ type=pwr_ctrl         topic=pwr_ctrl
 type=pwr_voltage       topic=pwr_voltage
 type=ref_pos           topic=ref_pos
 type=robot_cmd         topic=robot_cmd
+type=camera_result     topic=camera_result
+type=camera_control    topic=camera_control
+type=puck_inside       topic=puck_inside
 type=fsm_state         topic=fsm_main          pubdelay=1
 type=fsm_state         topic=fsm_act           pubdelay=1
 type=fsm_state         topic=fsm_motion        pubdelay=1